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 "../include/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
8 #include "../include/fpdfview.h" | 8 #include "../include/fpdfview.h" |
9 #include "../include/fsdk_rendercontext.h" | 9 #include "../include/fsdk_rendercontext.h" |
10 #include "../include/fpdf_progressive.h" | 10 #include "../include/fpdf_progressive.h" |
11 #include "../include/fpdf_ext.h" | 11 #include "../include/fpdf_ext.h" |
12 #include "../../third_party/numerics/safe_conversions_impl.h" | 12 #include "../../third_party/numerics/safe_conversions_impl.h" |
13 | 13 |
14 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) | 14 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) |
15 { | 15 { |
16 » m_FileAccess = *pFileAccess; | 16 » if (pFileAccess) |
17 » m_BufferOffset = (FX_DWORD)-1; | 17 » » m_FileAccess = *pFileAccess; |
18 } | |
19 | |
20 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, FX_BYTE& ch) | |
21 { | |
22 » if (pos >= m_FileAccess.m_FileLen) return FALSE; | |
23 » if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || pos >= m_B
ufferOffset + 512) { | |
24 » » // Need to read from file access | |
25 » » m_BufferOffset = pos; | |
26 » » int size = 512; | |
27 » » if (pos + 512 > m_FileAccess.m_FileLen) | |
28 » » » size = m_FileAccess.m_FileLen - pos; | |
29 » » if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffse
t, m_Buffer, size)) | |
30 » » » return FALSE; | |
31 » } | |
32 » ch = m_Buffer[pos - m_BufferOffset]; | |
33 » return TRUE; | |
34 } | |
35 | |
36 FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, FX_LPBYTE pBuf, FX_DWORD size) | |
37 { | |
38 FX_SAFE_DWORD newPos = size; | |
39 newPos += pos; | |
40 if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) { | |
41 return FALSE; | |
42 } | |
43 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); | |
44 } | 18 } |
45 | 19 |
46 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t si
ze) | 20 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t si
ze) |
47 { | 21 { |
48 if (offset < 0) { | 22 if (offset < 0) { |
49 return FALSE; | 23 return FALSE; |
50 } | 24 } |
51 FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t>(size); | 25 FX_SAFE_FILESIZE newPos = base::checked_cast<FX_FILESIZE, size_t>(size); |
52 newPos += offset; | 26 newPos += offset; |
53 if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) { | 27 if (!newPos.IsValid() || newPos.ValueOrDie() > m_FileAccess.m_FileLen) { |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 { | 882 { |
909 if (document == NULL) | 883 if (document == NULL) |
910 return NULL; | 884 return NULL; |
911 if (name == NULL || name[0] == 0) | 885 if (name == NULL || name[0] == 0) |
912 return NULL; | 886 return NULL; |
913 | 887 |
914 CPDF_Document* pDoc = (CPDF_Document*)document; | 888 CPDF_Document* pDoc = (CPDF_Document*)document; |
915 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); | 889 CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests")); |
916 return name_tree.LookupNamedDest(pDoc, name); | 890 return name_tree.LookupNamedDest(pDoc, name); |
917 } | 891 } |
OLD | NEW |