Chromium Code Reviews| 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 <utility> | 7 #include <utility> | 
| 8 #include <vector> | 8 #include <vector> | 
| 9 | 9 | 
| 10 #include "../../../include/fpdfapi/fpdf_module.h" | 10 #include "../../../include/fpdfapi/fpdf_module.h" | 
| (...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1986 } | 1986 } | 
| 1987 } | 1987 } | 
| 1988 if (!bFirst) { | 1988 if (!bFirst) { | 
| 1989 buf.AppendByte((uint8_t)code); | 1989 buf.AppendByte((uint8_t)code); | 
| 1990 } | 1990 } | 
| 1991 return buf.GetByteString(); | 1991 return buf.GetByteString(); | 
| 1992 } | 1992 } | 
| 1993 void CPDF_SyntaxParser::ToNextLine() | 1993 void CPDF_SyntaxParser::ToNextLine() | 
| 1994 { | 1994 { | 
| 1995 uint8_t ch; | 1995 uint8_t ch; | 
| 1996 while (1) { | 1996 while (GetNextChar(ch)) { | 
| 1997 if (!GetNextChar(ch)) { | |
| 1998 return; | |
| 1999 } | |
| 2000 if (ch == '\n') { | 1997 if (ch == '\n') { | 
| 2001 return; | 1998 break; | 
| 2002 } | 1999 } | 
| 2003 if (ch == '\r') { | 2000 if (ch == '\r') { | 
| 2004 GetNextChar(ch); | 2001 GetNextChar(ch); | 
| 2005 if (ch == '\n') { | 2002 if (ch != '\n') { | 
| 2006 return; | 2003 --m_Pos; | 
| 2007 } else { | |
| 2008 m_Pos --; | |
| 2009 return; | |
| 2010 } | 2004 } | 
| 2005 break; | |
| 2011 } | 2006 } | 
| 2012 } | 2007 } | 
| 2013 } | 2008 } | 
| 2014 void CPDF_SyntaxParser::ToNextWord() | 2009 void CPDF_SyntaxParser::ToNextWord() | 
| 2015 { | 2010 { | 
| 2016 uint8_t ch; | 2011 uint8_t ch; | 
| 2017 if (!GetNextChar(ch)) { | 2012 if (!GetNextChar(ch)) { | 
| 2018 return; | 2013 return; | 
| 2019 } | 2014 } | 
| 2020 uint8_t type = PDF_CharType[ch]; | 2015 uint8_t type = PDF_CharType[ch]; | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2072 FX_FILESIZE SavedPos = m_Pos; | 2067 FX_FILESIZE SavedPos = m_Pos; | 
| 2073 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2068 CFX_ByteString nextword = GetNextWord(bIsNumber); | 
| 2074 if (bIsNumber) { | 2069 if (bIsNumber) { | 
| 2075 CFX_ByteString nextword2 = GetNextWord(bIsNumber); | 2070 CFX_ByteString nextword2 = GetNextWord(bIsNumber); | 
| 2076 if (nextword2 == FX_BSTRC("R")) { | 2071 if (nextword2 == FX_BSTRC("R")) { | 
| 2077 FX_DWORD objnum = FXSYS_atoi(word); | 2072 FX_DWORD objnum = FXSYS_atoi(word); | 
| 2078 if (bTypeOnly) { | 2073 if (bTypeOnly) { | 
| 2079 return (CPDF_Object*)PDFOBJ_REFERENCE; | 2074 return (CPDF_Object*)PDFOBJ_REFERENCE; | 
| 2080 } | 2075 } | 
| 2081 return new CPDF_Reference(pObjList, objnum); | 2076 return new CPDF_Reference(pObjList, objnum); | 
| 2082 } else { | |
| 2083 m_Pos = SavedPos; | |
| 2084 if (bTypeOnly) { | |
| 2085 return (CPDF_Object*)PDFOBJ_NUMBER; | |
| 2086 } | |
| 2087 return CPDF_Number::Create(word); | |
| 2088 } | 2077 } | 
| 2089 } else { | |
| 2090 m_Pos = SavedPos; | 2078 m_Pos = SavedPos; | 
| 
 
Lei Zhang
2015/07/21 23:43:23
Just remove the rest of this block and fall throug
 
Tom Sepez
2015/07/22 20:38:24
Done.
 
 | |
| 2091 if (bTypeOnly) { | 2079 if (bTypeOnly) { | 
| 2092 return (CPDF_Object*)PDFOBJ_NUMBER; | 2080 return (CPDF_Object*)PDFOBJ_NUMBER; | 
| 2093 } | 2081 } | 
| 2094 return CPDF_Number::Create(word); | 2082 return CPDF_Number::Create(word); | 
| 2095 } | 2083 } | 
| 2084 m_Pos = SavedPos; | |
| 2085 if (bTypeOnly) { | |
| 2086 return (CPDF_Object*)PDFOBJ_NUMBER; | |
| 2087 } | |
| 2088 return CPDF_Number::Create(word); | |
| 2096 } | 2089 } | 
| 2097 if (word == FX_BSTRC("true") || word == FX_BSTRC("false")) { | 2090 if (word == FX_BSTRC("true") || word == FX_BSTRC("false")) { | 
| 2098 if (bTypeOnly) { | 2091 if (bTypeOnly) { | 
| 2099 return (CPDF_Object*)PDFOBJ_BOOLEAN; | 2092 return (CPDF_Object*)PDFOBJ_BOOLEAN; | 
| 2100 } | 2093 } | 
| 2101 return CPDF_Boolean::Create(word == FX_BSTRC("true")); | 2094 return CPDF_Boolean::Create(word == FX_BSTRC("true")); | 
| 2102 } | 2095 } | 
| 2103 if (word == FX_BSTRC("null")) { | 2096 if (word == FX_BSTRC("null")) { | 
| 2104 if (bTypeOnly) { | 2097 if (bTypeOnly) { | 
| 2105 return (CPDF_Object*)PDFOBJ_NULL; | 2098 return (CPDF_Object*)PDFOBJ_NULL; | 
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2245 return (CPDF_Object*)PDFOBJ_INVALID; | 2238 return (CPDF_Object*)PDFOBJ_INVALID; | 
| 2246 } | 2239 } | 
| 2247 return NULL; | 2240 return NULL; | 
| 2248 } | 2241 } | 
| 2249 if (bIsNumber) { | 2242 if (bIsNumber) { | 
| 2250 FX_FILESIZE SavedPos = m_Pos; | 2243 FX_FILESIZE SavedPos = m_Pos; | 
| 2251 CFX_ByteString nextword = GetNextWord(bIsNumber); | 2244 CFX_ByteString nextword = GetNextWord(bIsNumber); | 
| 2252 if (bIsNumber) { | 2245 if (bIsNumber) { | 
| 2253 CFX_ByteString nextword2 = GetNextWord(bIsNumber); | 2246 CFX_ByteString nextword2 = GetNextWord(bIsNumber); | 
| 2254 if (nextword2 == FX_BSTRC("R")) { | 2247 if (nextword2 == FX_BSTRC("R")) { | 
| 2255 FX_DWORD objnum = FXSYS_atoi(word); | |
| 2256 if (bTypeOnly) { | 2248 if (bTypeOnly) { | 
| 2257 return (CPDF_Object*)PDFOBJ_REFERENCE; | 2249 return (CPDF_Object*)PDFOBJ_REFERENCE; | 
| 2258 } | 2250 } | 
| 2251 FX_DWORD objnum = FXSYS_atoi(word); | |
| 2259 return new CPDF_Reference(pObjList, objnum); | 2252 return new CPDF_Reference(pObjList, objnum); | 
| 2260 } else { | |
| 2261 m_Pos = SavedPos; | |
| 2262 if (bTypeOnly) { | |
| 2263 return (CPDF_Object*)PDFOBJ_NUMBER; | |
| 2264 } | |
| 2265 return CPDF_Number::Create(word); | |
| 2266 } | 2253 } | 
| 2267 } else { | |
| 2268 m_Pos = SavedPos; | 2254 m_Pos = SavedPos; | 
| 
 
Lei Zhang
2015/07/21 23:43:23
Ditto, identical code here.
 
Tom Sepez
2015/07/22 20:38:24
Done.
 
 | |
| 2269 if (bTypeOnly) { | 2255 if (bTypeOnly) { | 
| 2270 return (CPDF_Object*)PDFOBJ_NUMBER; | 2256 return (CPDF_Object*)PDFOBJ_NUMBER; | 
| 2271 } | 2257 } | 
| 2272 return CPDF_Number::Create(word); | 2258 return CPDF_Number::Create(word); | 
| 2273 } | 2259 } | 
| 2260 m_Pos = SavedPos; | |
| 2261 if (bTypeOnly) { | |
| 2262 return (CPDF_Object*)PDFOBJ_NUMBER; | |
| 2263 } | |
| 2264 return CPDF_Number::Create(word); | |
| 2274 } | 2265 } | 
| 2275 if (word == FX_BSTRC("true") || word == FX_BSTRC("false")) { | 2266 if (word == FX_BSTRC("true") || word == FX_BSTRC("false")) { | 
| 2276 if (bTypeOnly) { | 2267 if (bTypeOnly) { | 
| 2277 return (CPDF_Object*)PDFOBJ_BOOLEAN; | 2268 return (CPDF_Object*)PDFOBJ_BOOLEAN; | 
| 2278 } | 2269 } | 
| 2279 return CPDF_Boolean::Create(word == FX_BSTRC("true")); | 2270 return CPDF_Boolean::Create(word == FX_BSTRC("true")); | 
| 2280 } | 2271 } | 
| 2281 if (word == FX_BSTRC("null")) { | 2272 if (word == FX_BSTRC("null")) { | 
| 2282 if (bTypeOnly) { | 2273 if (bTypeOnly) { | 
| 2283 return (CPDF_Object*)PDFOBJ_NULL; | 2274 return (CPDF_Object*)PDFOBJ_NULL; | 
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3133 if (!m_objs_array.GetSize()) { | 3124 if (!m_objs_array.GetSize()) { | 
| 3134 m_objs_array.RemoveAll(); | 3125 m_objs_array.RemoveAll(); | 
| 3135 m_objnum_array.RemoveAll(); | 3126 m_objnum_array.RemoveAll(); | 
| 3136 CFX_PtrArray obj_array; | 3127 CFX_PtrArray obj_array; | 
| 3137 obj_array.Append(m_arrayAcroforms); | 3128 obj_array.Append(m_arrayAcroforms); | 
| 3138 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 3129 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 
| 3139 if (bRet) { | 3130 if (bRet) { | 
| 3140 m_objs_array.RemoveAll(); | 3131 m_objs_array.RemoveAll(); | 
| 3141 } | 3132 } | 
| 3142 return bRet; | 3133 return bRet; | 
| 3134 } | |
| 3135 CFX_PtrArray new_objs_array; | |
| 3136 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | |
| 3137 if (bRet) { | |
| 3138 int32_t iSize = m_arrayAcroforms.GetSize(); | |
| 3139 for (int32_t i = 0; i < iSize; ++i) { | |
| 3140 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release(); | |
| 3141 } | |
| 3142 m_arrayAcroforms.RemoveAll(); | |
| 3143 } else { | 3143 } else { | 
| 3144 CFX_PtrArray new_objs_array; | 3144 m_objs_array.RemoveAll(); | 
| 3145 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_arra y); | 3145 m_objs_array.Append(new_objs_array); | 
| 3146 if (bRet) { | |
| 3147 int32_t iSize = m_arrayAcroforms.GetSize(); | |
| 3148 for (int32_t i = 0; i < iSize; ++i) { | |
| 3149 ((CPDF_Object *)m_arrayAcroforms.GetAt(i))->Release(); | |
| 3150 } | |
| 3151 m_arrayAcroforms.RemoveAll(); | |
| 3152 } else { | |
| 3153 m_objs_array.RemoveAll(); | |
| 3154 m_objs_array.Append(new_objs_array); | |
| 3155 } | |
| 3156 return bRet; | |
| 3157 } | 3146 } | 
| 3147 return bRet; | |
| 3158 } | 3148 } | 
| 3159 FX_BOOL CPDF_DataAvail::CheckAcroForm(IFX_DownloadHints* pHints) | 3149 FX_BOOL CPDF_DataAvail::CheckAcroForm(IFX_DownloadHints* pHints) | 
| 3160 { | 3150 { | 
| 3161 FX_BOOL bExist = FALSE; | 3151 FX_BOOL bExist = FALSE; | 
| 3162 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); | 3152 m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist); | 
| 3163 if (!bExist) { | 3153 if (!bExist) { | 
| 3164 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 3154 m_docStatus = PDF_DATAAVAIL_PAGETREE; | 
| 3165 return TRUE; | 3155 return TRUE; | 
| 3166 } | 3156 } | 
| 3167 if (!m_pAcroForm) { | 3157 if (!m_pAcroForm) { | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3201 return LoadAllFile(pHints); | 3191 return LoadAllFile(pHints); | 
| 3202 case PDF_DATAAVAIL_ROOT: | 3192 case PDF_DATAAVAIL_ROOT: | 
| 3203 return CheckRoot(pHints); | 3193 return CheckRoot(pHints); | 
| 3204 case PDF_DATAAVAIL_INFO: | 3194 case PDF_DATAAVAIL_INFO: | 
| 3205 return CheckInfo(pHints); | 3195 return CheckInfo(pHints); | 
| 3206 case PDF_DATAAVAIL_ACROFORM: | 3196 case PDF_DATAAVAIL_ACROFORM: | 
| 3207 return CheckAcroForm(pHints); | 3197 return CheckAcroForm(pHints); | 
| 3208 case PDF_DATAAVAIL_PAGETREE: | 3198 case PDF_DATAAVAIL_PAGETREE: | 
| 3209 if (m_bTotalLoadPageTree) { | 3199 if (m_bTotalLoadPageTree) { | 
| 3210 return CheckPages(pHints); | 3200 return CheckPages(pHints); | 
| 3211 } else { | |
| 3212 return LoadDocPages(pHints); | |
| 3213 } | 3201 } | 
| 3202 return LoadDocPages(pHints); | |
| 3214 case PDF_DATAAVAIL_PAGE: | 3203 case PDF_DATAAVAIL_PAGE: | 
| 3215 if (m_bTotalLoadPageTree) { | 3204 if (m_bTotalLoadPageTree) { | 
| 3216 return CheckPage(pHints); | 3205 return CheckPage(pHints); | 
| 3217 } else { | |
| 3218 m_docStatus = PDF_DATAAVAIL_PAGE_LATERLOAD; | |
| 3219 return TRUE; | |
| 3220 } | 3206 } | 
| 3207 m_docStatus = PDF_DATAAVAIL_PAGE_LATERLOAD; | |
| 3208 return TRUE; | |
| 3221 case PDF_DATAAVAIL_ERROR: | 3209 case PDF_DATAAVAIL_ERROR: | 
| 3222 return LoadAllFile(pHints); | 3210 return LoadAllFile(pHints); | 
| 3223 case PDF_DATAAVAIL_PAGE_LATERLOAD: | 3211 case PDF_DATAAVAIL_PAGE_LATERLOAD: | 
| 3224 m_docStatus = PDF_DATAAVAIL_PAGE; | 3212 m_docStatus = PDF_DATAAVAIL_PAGE; | 
| 3225 default: | 3213 default: | 
| 3226 m_bDocAvail = TRUE; | 3214 m_bDocAvail = TRUE; | 
| 3227 return TRUE; | 3215 return TRUE; | 
| 3228 } | 3216 } | 
| 3229 } | 3217 } | 
| 3230 FX_BOOL CPDF_DataAvail::CheckPageStatus(IFX_DownloadHints* pHints) | 3218 FX_BOOL CPDF_DataAvail::CheckPageStatus(IFX_DownloadHints* pHints) | 
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3754 } | 3742 } | 
| 3755 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); | 3743 m_dwXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); | 
| 3756 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { | 3744 if (!m_dwXRefOffset || m_dwXRefOffset > m_dwFileLen) { | 
| 3757 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 3745 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 
| 3758 return TRUE; | 3746 return TRUE; | 
| 3759 } | 3747 } | 
| 3760 m_dwLastXRefOffset = m_dwXRefOffset; | 3748 m_dwLastXRefOffset = m_dwXRefOffset; | 
| 3761 SetStartOffset(m_dwXRefOffset); | 3749 SetStartOffset(m_dwXRefOffset); | 
| 3762 m_docStatus = PDF_DATAAVAIL_CROSSREF; | 3750 m_docStatus = PDF_DATAAVAIL_CROSSREF; | 
| 3763 return TRUE; | 3751 return TRUE; | 
| 3764 } else { | |
| 3765 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | |
| 3766 return TRUE; | |
| 3767 } | 3752 } | 
| 3753 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | |
| 3754 return TRUE; | |
| 3768 } | 3755 } | 
| 3769 pHints->AddSegment(req_pos, dwSize); | 3756 pHints->AddSegment(req_pos, dwSize); | 
| 3770 return FALSE; | 3757 return FALSE; | 
| 3771 } | 3758 } | 
| 3772 int32_t CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, FX_FILESI ZE &xref_offset) | 3759 int32_t CPDF_DataAvail::CheckCrossRefStream(IFX_DownloadHints* pHints, FX_FILESI ZE &xref_offset) | 
| 3773 { | 3760 { | 
| 3774 xref_offset = 0; | 3761 xref_offset = 0; | 
| 3775 FX_DWORD req_size = (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_P os : 512); | 3762 FX_DWORD req_size = (FX_DWORD)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_P os : 512); | 
| 3776 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { | 3763 if (m_pFileAvail->IsDataAvail(m_Pos, req_size)) { | 
| 3777 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); | 3764 int32_t iSize = (int32_t)(m_Pos + req_size - m_dwCurrentXRefSteam); | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 3792 return 0; | 3779 return 0; | 
| 3793 } | 3780 } | 
| 3794 CPDF_Dictionary* pDict = pObj->GetDict(); | 3781 CPDF_Dictionary* pDict = pObj->GetDict(); | 
| 3795 CPDF_Object *pName = pDict ? pDict->GetElement(FX_BSTRC("Type")) : NULL; | 3782 CPDF_Object *pName = pDict ? pDict->GetElement(FX_BSTRC("Type")) : NULL; | 
| 3796 if (pName && pName->GetType() == PDFOBJ_NAME) { | 3783 if (pName && pName->GetType() == PDFOBJ_NAME) { | 
| 3797 if (pName->GetString() == FX_BSTRC("XRef")) { | 3784 if (pName->GetString() == FX_BSTRC("XRef")) { | 
| 3798 m_Pos += m_parser.m_Syntax.SavePos(); | 3785 m_Pos += m_parser.m_Syntax.SavePos(); | 
| 3799 xref_offset = pObj->GetDict()->GetInteger(FX_BSTRC("Prev")); | 3786 xref_offset = pObj->GetDict()->GetInteger(FX_BSTRC("Prev")); | 
| 3800 pObj->Release(); | 3787 pObj->Release(); | 
| 3801 return 1; | 3788 return 1; | 
| 3802 } else { | |
| 3803 pObj->Release(); | |
| 3804 return -1; | |
| 3805 } | 3789 } | 
| 3806 } | 3790 } | 
| 3807 pObj->Release(); | 3791 pObj->Release(); | 
| 3808 return -1; | 3792 return -1; | 
| 3809 } | 3793 } | 
| 3810 pHints->AddSegment(m_Pos, req_size); | 3794 pHints->AddSegment(m_Pos, req_size); | 
| 3811 return 0; | 3795 return 0; | 
| 3812 } | 3796 } | 
| 3813 inline void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset) | 3797 inline void CPDF_DataAvail::SetStartOffset(FX_FILESIZE dwOffset) | 
| 3814 { | 3798 { | 
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3948 FX_FILESIZE xref_offset = 0; | 3932 FX_FILESIZE xref_offset = 0; | 
| 3949 int32_t nRet = CheckCrossRefStream(pHints, xref_offset); | 3933 int32_t nRet = CheckCrossRefStream(pHints, xref_offset); | 
| 3950 if (nRet == 1) { | 3934 if (nRet == 1) { | 
| 3951 if (!xref_offset) { | 3935 if (!xref_offset) { | 
| 3952 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; | 3936 m_docStatus = PDF_DATAAVAIL_LOADALLCRSOSSREF; | 
| 3953 } else { | 3937 } else { | 
| 3954 m_dwCurrentXRefSteam = xref_offset; | 3938 m_dwCurrentXRefSteam = xref_offset; | 
| 3955 m_Pos = xref_offset; | 3939 m_Pos = xref_offset; | 
| 3956 } | 3940 } | 
| 3957 return TRUE; | 3941 return TRUE; | 
| 3958 } else if (nRet == -1) { | 3942 } | 
| 3943 if (nRet == -1) { | |
| 3959 m_docStatus = PDF_DATAAVAIL_ERROR; | 3944 m_docStatus = PDF_DATAAVAIL_ERROR; | 
| 3960 } | 3945 } | 
| 3961 return FALSE; | 3946 return FALSE; | 
| 3962 } | 3947 } | 
| 3963 FX_BOOL CPDF_DataAvail::CheckCrossRef(IFX_DownloadHints* pHints) | 3948 FX_BOOL CPDF_DataAvail::CheckCrossRef(IFX_DownloadHints* pHints) | 
| 3964 { | 3949 { | 
| 3965 int32_t iSize = 0; | 3950 int32_t iSize = 0; | 
| 3966 CFX_ByteString token; | 3951 CFX_ByteString token; | 
| 3967 if (!GetNextToken(token)) { | 3952 if (!GetNextToken(token)) { | 
| 3968 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512) ; | 3953 iSize = (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512) ; | 
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4051 } else { | 4036 } else { | 
| 4052 m_dwPrevXRefOffset = xrefpos; | 4037 m_dwPrevXRefOffset = xrefpos; | 
| 4053 if (m_dwPrevXRefOffset >= m_dwFileLen) { | 4038 if (m_dwPrevXRefOffset >= m_dwFileLen) { | 
| 4054 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 4039 m_docStatus = PDF_DATAAVAIL_LOADALLFILE; | 
| 4055 } else { | 4040 } else { | 
| 4056 SetStartOffset(m_dwPrevXRefOffset); | 4041 SetStartOffset(m_dwPrevXRefOffset); | 
| 4057 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; | 4042 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; | 
| 4058 } | 4043 } | 
| 4059 } | 4044 } | 
| 4060 return TRUE; | 4045 return TRUE; | 
| 4061 } else { | |
| 4062 m_dwPrevXRefOffset = 0; | |
| 4063 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; | |
| 4064 pTrailer->Release(); | |
| 4065 } | 4046 } | 
| 4047 m_dwPrevXRefOffset = 0; | |
| 4048 m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; | |
| 4049 pTrailer->Release(); | |
| 4066 return TRUE; | 4050 return TRUE; | 
| 4067 } | 4051 } | 
| 4068 pHints->AddSegment(m_Pos, iTrailerSize); | 4052 pHints->AddSegment(m_Pos, iTrailerSize); | 
| 4069 return FALSE; | 4053 return FALSE; | 
| 4070 } | 4054 } | 
| 4071 FX_BOOL CPDF_DataAvail::CheckPage(int32_t iPage, IFX_DownloadHints* pHints) | 4055 FX_BOOL CPDF_DataAvail::CheckPage(int32_t iPage, IFX_DownloadHints* pHints) | 
| 4072 { | 4056 { | 
| 4073 while (TRUE) { | 4057 while (TRUE) { | 
| 4074 switch (m_docStatus) { | 4058 switch (m_docStatus) { | 
| 4075 case PDF_DATAAVAIL_PAGETREE: | 4059 case PDF_DATAAVAIL_PAGETREE: | 
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4288 return FALSE; | 4272 return FALSE; | 
| 4289 } | 4273 } | 
| 4290 FX_BOOL CPDF_DataAvail::LoadDocPages(IFX_DownloadHints* pHints) | 4274 FX_BOOL CPDF_DataAvail::LoadDocPages(IFX_DownloadHints* pHints) | 
| 4291 { | 4275 { | 
| 4292 if (!CheckUnkownPageNode(m_PagesObjNum, &m_pageNodes, pHints)) { | 4276 if (!CheckUnkownPageNode(m_PagesObjNum, &m_pageNodes, pHints)) { | 
| 4293 return FALSE; | 4277 return FALSE; | 
| 4294 } | 4278 } | 
| 4295 if (CheckPageCount(pHints)) { | 4279 if (CheckPageCount(pHints)) { | 
| 4296 m_docStatus = PDF_DATAAVAIL_PAGE; | 4280 m_docStatus = PDF_DATAAVAIL_PAGE; | 
| 4297 return TRUE; | 4281 return TRUE; | 
| 4298 } else { | |
| 4299 m_bTotalLoadPageTree = TRUE; | |
| 4300 } | 4282 } | 
| 4283 m_bTotalLoadPageTree = TRUE; | |
| 4301 return FALSE; | 4284 return FALSE; | 
| 4302 } | 4285 } | 
| 4303 FX_BOOL CPDF_DataAvail::LoadPages(IFX_DownloadHints* pHints) | 4286 FX_BOOL CPDF_DataAvail::LoadPages(IFX_DownloadHints* pHints) | 
| 4304 { | 4287 { | 
| 4305 while (!m_bPagesTreeLoad) { | 4288 while (!m_bPagesTreeLoad) { | 
| 4306 if (!CheckPageStatus(pHints)) { | 4289 if (!CheckPageStatus(pHints)) { | 
| 4307 return FALSE; | 4290 return FALSE; | 
| 4308 } | 4291 } | 
| 4309 } | 4292 } | 
| 4310 if (m_bPagesLoad) { | 4293 if (m_bPagesLoad) { | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4356 if (!pAnnots) { | 4339 if (!pAnnots) { | 
| 4357 return TRUE; | 4340 return TRUE; | 
| 4358 } | 4341 } | 
| 4359 CFX_PtrArray obj_array; | 4342 CFX_PtrArray obj_array; | 
| 4360 obj_array.Add(pAnnots); | 4343 obj_array.Add(pAnnots); | 
| 4361 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 4344 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 
| 4362 if (bRet) { | 4345 if (bRet) { | 
| 4363 m_objs_array.RemoveAll(); | 4346 m_objs_array.RemoveAll(); | 
| 4364 } | 4347 } | 
| 4365 return bRet; | 4348 return bRet; | 
| 4366 } else { | |
| 4367 CFX_PtrArray new_objs_array; | |
| 4368 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_arra y); | |
| 4369 m_objs_array.RemoveAll(); | |
| 4370 if (!bRet) { | |
| 4371 m_objs_array.Append(new_objs_array); | |
| 4372 } | |
| 4373 return bRet; | |
| 4374 } | 4349 } | 
| 4350 CFX_PtrArray new_objs_array; | |
| 4351 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | |
| 4352 m_objs_array.RemoveAll(); | |
| 4353 if (!bRet) { | |
| 4354 m_objs_array.Append(new_objs_array); | |
| 4355 } | |
| 4356 return bRet; | |
| 4375 } | 4357 } | 
| 4376 FX_BOOL CPDF_DataAvail::CheckLinearizedFirstPage(int32_t iPage, IFX_DownloadHint s* pHints) | 4358 FX_BOOL CPDF_DataAvail::CheckLinearizedFirstPage(int32_t iPage, IFX_DownloadHint s* pHints) | 
| 4377 { | 4359 { | 
| 4378 if (!m_bAnnotsLoad) { | 4360 if (!m_bAnnotsLoad) { | 
| 4379 if (!CheckPageAnnots(iPage, pHints)) { | 4361 if (!CheckPageAnnots(iPage, pHints)) { | 
| 4380 return FALSE; | 4362 return FALSE; | 
| 4381 } | 4363 } | 
| 4382 m_bAnnotsLoad = TRUE; | 4364 m_bAnnotsLoad = TRUE; | 
| 4383 } | 4365 } | 
| 4384 if (m_bAnnotsLoad) | 4366 if (m_bAnnotsLoad) { | 
| 4385 if (!CheckLinearizedData(pHints)) { | 4367 if (!CheckLinearizedData(pHints)) | 
| 4386 return FALSE; | 4368 return FALSE; | 
| 4387 } | 4369 } | 
| 4388 m_bPageLoadedOK = FALSE; | 4370 m_bPageLoadedOK = FALSE; | 
| 4389 return TRUE; | 4371 return TRUE; | 
| 4390 } | 4372 } | 
| 4391 FX_BOOL CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary *pDict) | 4373 FX_BOOL CPDF_DataAvail::HaveResourceAncestor(CPDF_Dictionary *pDict) | 
| 4392 { | 4374 { | 
| 4393 CFX_AutoRestorer<int> restorer(&s_CurrentDataAvailRecursionDepth); | 4375 CFX_AutoRestorer<int> restorer(&s_CurrentDataAvailRecursionDepth); | 
| 4394 if (++s_CurrentDataAvailRecursionDepth > kMaxDataAvailRecursionDepth) { | 4376 if (++s_CurrentDataAvailRecursionDepth > kMaxDataAvailRecursionDepth) { | 
| 4395 return FALSE; | 4377 return FALSE; | 
| 4396 } | 4378 } | 
| 4397 CPDF_Object *pParent = pDict->GetElement("Parent"); | 4379 CPDF_Object *pParent = pDict->GetElement("Parent"); | 
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4532 { | 4514 { | 
| 4533 if (!m_objs_array.GetSize()) { | 4515 if (!m_objs_array.GetSize()) { | 
| 4534 m_objs_array.RemoveAll(); | 4516 m_objs_array.RemoveAll(); | 
| 4535 CFX_PtrArray obj_array; | 4517 CFX_PtrArray obj_array; | 
| 4536 obj_array.Add(m_pPageResource); | 4518 obj_array.Add(m_pPageResource); | 
| 4537 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); | 4519 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); | 
| 4538 if (bRet) { | 4520 if (bRet) { | 
| 4539 m_objs_array.RemoveAll(); | 4521 m_objs_array.RemoveAll(); | 
| 4540 } | 4522 } | 
| 4541 return bRet; | 4523 return bRet; | 
| 4542 } else { | |
| 4543 CFX_PtrArray new_objs_array; | |
| 4544 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_arra y); | |
| 4545 m_objs_array.RemoveAll(); | |
| 4546 if (!bRet) { | |
| 4547 m_objs_array.Append(new_objs_array); | |
| 4548 } | |
| 4549 return bRet; | |
| 4550 } | 4524 } | 
| 4525 CFX_PtrArray new_objs_array; | |
| 4526 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | |
| 4527 m_objs_array.RemoveAll(); | |
| 4528 if (!bRet) { | |
| 4529 m_objs_array.Append(new_objs_array); | |
| 4530 } | |
| 4531 return bRet; | |
| 4551 } | 4532 } | 
| 4552 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSiz e) | 4533 void CPDF_DataAvail::GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSiz e) | 
| 4553 { | 4534 { | 
| 4554 if (pPos) { | 4535 if (pPos) { | 
| 4555 *pPos = m_dwLastXRefOffset; | 4536 *pPos = m_dwLastXRefOffset; | 
| 4556 } | 4537 } | 
| 4557 if (pSize) { | 4538 if (pSize) { | 
| 4558 *pSize = (FX_DWORD)(m_dwFileLen - m_dwLastXRefOffset); | 4539 *pSize = (FX_DWORD)(m_dwFileLen - m_dwLastXRefOffset); | 
| 4559 } | 4540 } | 
| 4560 } | 4541 } | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4597 } | 4578 } | 
| 4598 m_number_array.InsertAt(iNext, dwObjNum); | 4579 m_number_array.InsertAt(iNext, dwObjNum); | 
| 4599 } | 4580 } | 
| 4600 FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) | 4581 FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) | 
| 4601 { | 4582 { | 
| 4602 int32_t iNext = 0; | 4583 int32_t iNext = 0; | 
| 4603 return BinarySearch(dwObjNum, iNext); | 4584 return BinarySearch(dwObjNum, iNext); | 
| 4604 } | 4585 } | 
| 4605 FX_BOOL CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t &iNext) | 4586 FX_BOOL CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t &iNext) | 
| 4606 { | 4587 { | 
| 4607 int32_t iLen = m_number_array.GetSize(); | |
| 4608 int32_t iLow = 0; | 4588 int32_t iLow = 0; | 
| 4609 int32_t iHigh = iLen - 1; | 4589 int32_t iHigh = m_number_array.GetSize() - 1; | 
| 4610 int32_t iMid = 0; | |
| 4611 while (iLow <= iHigh) { | 4590 while (iLow <= iHigh) { | 
| 4612 iMid = (iLow + iHigh) / 2; | 4591 int32_t iMid = (iLow + iHigh) / 2; | 
| 4613 if (m_number_array.GetAt(iMid) == value) { | 4592 if (m_number_array.GetAt(iMid) == value) { | 
| 4614 iNext = iMid; | 4593 iNext = iMid; | 
| 4615 return TRUE; | 4594 return TRUE; | 
| 4616 } else if (m_number_array.GetAt(iMid) > value) { | 4595 } | 
| 4596 if (m_number_array.GetAt(iMid) > value) { | |
| 4617 iHigh = iMid - 1; | 4597 iHigh = iMid - 1; | 
| 4618 } else if (m_number_array.GetAt(iMid) < value) { | 4598 } else if (m_number_array.GetAt(iMid) < value) { | 
| 
 
Lei Zhang
2015/07/21 23:43:23
This can just be "else" since we covered all the o
 
 | |
| 4619 iLow = iMid + 1; | 4599 iLow = iMid + 1; | 
| 4620 } | 4600 } | 
| 4621 } | 4601 } | 
| 4622 iNext = iLow; | 4602 iNext = iLow; | 
| 4623 return FALSE; | 4603 return FALSE; | 
| 4624 } | 4604 } | 
| 4625 CPDF_PageNode::~CPDF_PageNode() | 4605 CPDF_PageNode::~CPDF_PageNode() | 
| 4626 { | 4606 { | 
| 4627 int32_t iSize = m_childNode.GetSize(); | 4607 int32_t iSize = m_childNode.GetSize(); | 
| 4628 for (int32_t i = 0; i < iSize; ++i) { | 4608 for (int32_t i = 0; i < iSize; ++i) { | 
| 4629 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 4609 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 
| 4630 delete pNode; | 4610 delete pNode; | 
| 4631 } | 4611 } | 
| 4632 m_childNode.RemoveAll(); | 4612 m_childNode.RemoveAll(); | 
| 4633 } | 4613 } | 
| OLD | NEW |