OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "public/fpdfview.h" | 7 #include "public/fpdfview.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 168 } |
169 | 169 |
170 FX_BOOL CFPDF_FileStream::Flush() { | 170 FX_BOOL CFPDF_FileStream::Flush() { |
171 if (!m_pFS || !m_pFS->Flush) | 171 if (!m_pFS || !m_pFS->Flush) |
172 return TRUE; | 172 return TRUE; |
173 | 173 |
174 return m_pFS->Flush(m_pFS->clientData) == 0; | 174 return m_pFS->Flush(m_pFS->clientData) == 0; |
175 } | 175 } |
176 #endif // PDF_ENABLE_XFA | 176 #endif // PDF_ENABLE_XFA |
177 | 177 |
178 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { | 178 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) |
179 m_FileAccess = *pFileAccess; | 179 : m_FileAccess(*pFileAccess) {} |
180 #ifdef PDF_ENABLE_XFA | |
181 m_BufferOffset = (uint32_t)-1; | |
182 #endif // PDF_ENABLE_XFA | |
183 } | |
184 | |
185 #ifdef PDF_ENABLE_XFA | |
186 CFX_ByteString CPDF_CustomAccess::GetFullPath() { | |
187 return ""; | |
188 } | |
189 | |
190 FX_BOOL CPDF_CustomAccess::GetByte(uint32_t pos, uint8_t& ch) { | |
191 if (pos >= m_FileAccess.m_FileLen) | |
192 return FALSE; | |
193 if (m_BufferOffset == (uint32_t)-1 || pos < m_BufferOffset || | |
194 pos >= m_BufferOffset + 512) { | |
195 // Need to read from file access | |
196 m_BufferOffset = pos; | |
197 int size = 512; | |
198 if (pos + 512 > m_FileAccess.m_FileLen) | |
199 size = m_FileAccess.m_FileLen - pos; | |
200 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer, | |
201 size)) | |
202 return FALSE; | |
203 } | |
204 ch = m_Buffer[pos - m_BufferOffset]; | |
205 return TRUE; | |
206 } | |
207 | |
208 FX_BOOL CPDF_CustomAccess::GetBlock(uint32_t pos, | |
209 uint8_t* pBuf, | |
210 uint32_t size) { | |
211 if (pos + size > m_FileAccess.m_FileLen) | |
212 return FALSE; | |
213 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); | |
214 } | |
215 #endif // PDF_ENABLE_XFA | |
216 | 180 |
217 FX_FILESIZE CPDF_CustomAccess::GetSize() { | 181 FX_FILESIZE CPDF_CustomAccess::GetSize() { |
218 return m_FileAccess.m_FileLen; | 182 return m_FileAccess.m_FileLen; |
219 } | 183 } |
220 | 184 |
221 void CPDF_CustomAccess::Release() { | 185 void CPDF_CustomAccess::Release() { |
222 delete this; | 186 delete this; |
223 } | 187 } |
224 | 188 |
225 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, | 189 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, |
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 if (!buffer) { | 1094 if (!buffer) { |
1131 *buflen = len; | 1095 *buflen = len; |
1132 } else if (*buflen >= len) { | 1096 } else if (*buflen >= len) { |
1133 memcpy(buffer, utf16Name.c_str(), len); | 1097 memcpy(buffer, utf16Name.c_str(), len); |
1134 *buflen = len; | 1098 *buflen = len; |
1135 } else { | 1099 } else { |
1136 *buflen = -1; | 1100 *buflen = -1; |
1137 } | 1101 } |
1138 return (FPDF_DEST)pDestObj; | 1102 return (FPDF_DEST)pDestObj; |
1139 } | 1103 } |
OLD | NEW |