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 "parser_int.h" | 7 #include "parser_int.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 2799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2810 FX_FILESIZE m_dwTrailerOffset; | 2810 FX_FILESIZE m_dwTrailerOffset; |
2811 | 2811 |
2812 FX_FILESIZE m_dwCurrentOffset; | 2812 FX_FILESIZE m_dwCurrentOffset; |
2813 | 2813 |
2814 PDF_DATAAVAIL_STATUS m_docStatus; | 2814 PDF_DATAAVAIL_STATUS m_docStatus; |
2815 | 2815 |
2816 FX_FILESIZE m_dwFileLen; | 2816 FX_FILESIZE m_dwFileLen; |
2817 | 2817 |
2818 CPDF_Document* m_pDocument; | 2818 CPDF_Document* m_pDocument; |
2819 | 2819 |
2820 CPDF_SortObjNumArray m_objnum_array; | 2820 std::set<FX_DWORD> m_objnum_set; |
Tom Sepez
2016/01/06 00:49:56
nit: the naming convention for a class that is dir
Lei Zhang
2016/01/06 00:52:26
m_ObjectSet it is.
| |
2821 | 2821 |
2822 CFX_ArrayTemplate<CPDF_Object*> m_objs_array; | 2822 CFX_ArrayTemplate<CPDF_Object*> m_objs_array; |
2823 | 2823 |
2824 FX_FILESIZE m_Pos; | 2824 FX_FILESIZE m_Pos; |
2825 | 2825 |
2826 FX_FILESIZE m_bufferOffset; | 2826 FX_FILESIZE m_bufferOffset; |
2827 | 2827 |
2828 FX_DWORD m_bufferSize; | 2828 FX_DWORD m_bufferSize; |
2829 | 2829 |
2830 CFX_ByteString m_WordBuf; | 2830 CFX_ByteString m_WordBuf; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3052 CPDF_Reference* pRef = pObj->AsReference(); | 3052 CPDF_Reference* pRef = pObj->AsReference(); |
3053 FX_DWORD dwNum = pRef->GetRefObjNum(); | 3053 FX_DWORD dwNum = pRef->GetRefObjNum(); |
3054 FX_FILESIZE offset; | 3054 FX_FILESIZE offset; |
3055 FX_DWORD size = GetObjectSize(dwNum, offset); | 3055 FX_DWORD size = GetObjectSize(dwNum, offset); |
3056 if (size == 0 || offset < 0 || offset >= m_dwFileLen) { | 3056 if (size == 0 || offset < 0 || offset >= m_dwFileLen) { |
3057 break; | 3057 break; |
3058 } | 3058 } |
3059 if (!IsDataAvail(offset, size, pHints)) { | 3059 if (!IsDataAvail(offset, size, pHints)) { |
3060 ret_array.Add(pObj); | 3060 ret_array.Add(pObj); |
3061 count++; | 3061 count++; |
3062 } else if (!m_objnum_array.Find(dwNum)) { | 3062 } else if (!pdfium::ContainsKey(m_objnum_set, dwNum)) { |
3063 m_objnum_array.AddObjNum(dwNum); | 3063 m_objnum_set.insert(dwNum); |
3064 CPDF_Object* pReferred = | 3064 CPDF_Object* pReferred = |
3065 m_pDocument->GetIndirectObject(pRef->GetRefObjNum(), NULL); | 3065 m_pDocument->GetIndirectObject(pRef->GetRefObjNum(), NULL); |
3066 if (pReferred) { | 3066 if (pReferred) { |
3067 new_obj_array.Add(pReferred); | 3067 new_obj_array.Add(pReferred); |
3068 } | 3068 } |
3069 } | 3069 } |
3070 } break; | 3070 } break; |
3071 } | 3071 } |
3072 } | 3072 } |
3073 if (count > 0) { | 3073 if (count > 0) { |
3074 int32_t iSize = new_obj_array.GetSize(); | 3074 int32_t iSize = new_obj_array.GetSize(); |
3075 for (i = 0; i < iSize; ++i) { | 3075 for (i = 0; i < iSize; ++i) { |
3076 CPDF_Object* pObj = new_obj_array[i]; | 3076 CPDF_Object* pObj = new_obj_array[i]; |
3077 if (CPDF_Reference* pRef = pObj->AsReference()) { | 3077 if (CPDF_Reference* pRef = pObj->AsReference()) { |
3078 FX_DWORD dwNum = pRef->GetRefObjNum(); | 3078 FX_DWORD dwNum = pRef->GetRefObjNum(); |
3079 if (!m_objnum_array.Find(dwNum)) | 3079 if (!pdfium::ContainsKey(m_objnum_set, dwNum)) |
3080 ret_array.Add(pObj); | 3080 ret_array.Add(pObj); |
3081 } else { | 3081 } else { |
3082 ret_array.Add(pObj); | 3082 ret_array.Add(pObj); |
3083 } | 3083 } |
3084 } | 3084 } |
3085 return FALSE; | 3085 return FALSE; |
3086 } | 3086 } |
3087 obj_array.RemoveAll(); | 3087 obj_array.RemoveAll(); |
3088 obj_array.Append(new_obj_array); | 3088 obj_array.Append(new_obj_array); |
3089 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); | 3089 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); |
(...skipping 11 matching lines...) Expand all Loading... | |
3101 if (!CheckDocStatus(pHints)) { | 3101 if (!CheckDocStatus(pHints)) { |
3102 return DataNotAvailable; | 3102 return DataNotAvailable; |
3103 } | 3103 } |
3104 } | 3104 } |
3105 return DataAvailable; | 3105 return DataAvailable; |
3106 } | 3106 } |
3107 | 3107 |
3108 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) { | 3108 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) { |
3109 if (!m_objs_array.GetSize()) { | 3109 if (!m_objs_array.GetSize()) { |
3110 m_objs_array.RemoveAll(); | 3110 m_objs_array.RemoveAll(); |
3111 m_objnum_array.RemoveAll(); | 3111 m_objnum_set.clear(); |
3112 CFX_ArrayTemplate<CPDF_Object*> obj_array; | 3112 CFX_ArrayTemplate<CPDF_Object*> obj_array; |
3113 obj_array.Append(m_arrayAcroforms); | 3113 obj_array.Append(m_arrayAcroforms); |
3114 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); | 3114 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); |
3115 if (bRet) { | 3115 if (bRet) { |
3116 m_objs_array.RemoveAll(); | 3116 m_objs_array.RemoveAll(); |
3117 } | 3117 } |
3118 return bRet; | 3118 return bRet; |
3119 } | 3119 } |
3120 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; | 3120 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; |
3121 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 3121 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); |
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4307 m_bMainXRefLoadedOK = TRUE; | 4307 m_bMainXRefLoadedOK = TRUE; |
4308 m_bLinearedDataOK = TRUE; | 4308 m_bLinearedDataOK = TRUE; |
4309 } | 4309 } |
4310 | 4310 |
4311 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable; | 4311 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable; |
4312 } | 4312 } |
4313 FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, | 4313 FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, |
4314 IFX_DownloadHints* pHints) { | 4314 IFX_DownloadHints* pHints) { |
4315 if (!m_objs_array.GetSize()) { | 4315 if (!m_objs_array.GetSize()) { |
4316 m_objs_array.RemoveAll(); | 4316 m_objs_array.RemoveAll(); |
4317 m_objnum_array.RemoveAll(); | 4317 m_objnum_set.clear(); |
4318 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(iPage); | 4318 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(iPage); |
4319 if (!pPageDict) { | 4319 if (!pPageDict) { |
4320 return TRUE; | 4320 return TRUE; |
4321 } | 4321 } |
4322 CPDF_Object* pAnnots = pPageDict->GetElement("Annots"); | 4322 CPDF_Object* pAnnots = pPageDict->GetElement("Annots"); |
4323 if (!pAnnots) { | 4323 if (!pAnnots) { |
4324 return TRUE; | 4324 return TRUE; |
4325 } | 4325 } |
4326 CFX_ArrayTemplate<CPDF_Object*> obj_array; | 4326 CFX_ArrayTemplate<CPDF_Object*> obj_array; |
4327 obj_array.Add(pAnnots); | 4327 obj_array.Add(pAnnots); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4377 int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { | 4377 int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { |
4378 if (!m_pDocument) { | 4378 if (!m_pDocument) { |
4379 return DataError; | 4379 return DataError; |
4380 } | 4380 } |
4381 if (IsFirstCheck(iPage)) { | 4381 if (IsFirstCheck(iPage)) { |
4382 m_bCurPageDictLoadOK = FALSE; | 4382 m_bCurPageDictLoadOK = FALSE; |
4383 m_bPageLoadedOK = FALSE; | 4383 m_bPageLoadedOK = FALSE; |
4384 m_bAnnotsLoad = FALSE; | 4384 m_bAnnotsLoad = FALSE; |
4385 m_bNeedDownLoadResource = FALSE; | 4385 m_bNeedDownLoadResource = FALSE; |
4386 m_objs_array.RemoveAll(); | 4386 m_objs_array.RemoveAll(); |
4387 m_objnum_array.RemoveAll(); | 4387 m_objnum_set.clear(); |
4388 } | 4388 } |
4389 if (pdfium::ContainsKey(m_pagesLoadState, iPage)) | 4389 if (pdfium::ContainsKey(m_pagesLoadState, iPage)) |
4390 return DataAvailable; | 4390 return DataAvailable; |
4391 | 4391 |
4392 if (m_bLinearized) { | 4392 if (m_bLinearized) { |
4393 if ((FX_DWORD)iPage == m_dwFirstPageNo) { | 4393 if ((FX_DWORD)iPage == m_dwFirstPageNo) { |
4394 if (!CheckLinearizedFirstPage(iPage, pHints)) | 4394 if (!CheckLinearizedFirstPage(iPage, pHints)) |
4395 return DataNotAvailable; | 4395 return DataNotAvailable; |
4396 m_pagesLoadState.insert(iPage); | 4396 m_pagesLoadState.insert(iPage); |
4397 return DataAvailable; | 4397 return DataAvailable; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4434 } | 4434 } |
4435 if (m_bHaveAcroForm && !m_bAcroFormLoad) { | 4435 if (m_bHaveAcroForm && !m_bAcroFormLoad) { |
4436 if (!CheckAcroFormSubObject(pHints)) { | 4436 if (!CheckAcroFormSubObject(pHints)) { |
4437 return DataNotAvailable; | 4437 return DataNotAvailable; |
4438 } | 4438 } |
4439 m_bAcroFormLoad = TRUE; | 4439 m_bAcroFormLoad = TRUE; |
4440 } | 4440 } |
4441 if (!m_bPageLoadedOK) { | 4441 if (!m_bPageLoadedOK) { |
4442 if (!m_objs_array.GetSize()) { | 4442 if (!m_objs_array.GetSize()) { |
4443 m_objs_array.RemoveAll(); | 4443 m_objs_array.RemoveAll(); |
4444 m_objnum_array.RemoveAll(); | 4444 m_objnum_set.clear(); |
4445 m_pPageDict = m_pDocument->GetPage(iPage); | 4445 m_pPageDict = m_pDocument->GetPage(iPage); |
4446 if (!m_pPageDict) { | 4446 if (!m_pPageDict) { |
4447 ResetFirstCheck(iPage); | 4447 ResetFirstCheck(iPage); |
4448 return DataAvailable; | 4448 return DataAvailable; |
4449 } | 4449 } |
4450 CFX_ArrayTemplate<CPDF_Object*> obj_array; | 4450 CFX_ArrayTemplate<CPDF_Object*> obj_array; |
4451 obj_array.Add(m_pPageDict); | 4451 obj_array.Add(m_pPageDict); |
4452 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); | 4452 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); |
4453 if (bRet) { | 4453 if (bRet) { |
4454 m_objs_array.RemoveAll(); | 4454 m_objs_array.RemoveAll(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4588 } | 4588 } |
4589 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; | 4589 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; |
4590 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); | 4590 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); |
4591 m_objs_array.RemoveAll(); | 4591 m_objs_array.RemoveAll(); |
4592 if (!bRet) { | 4592 if (!bRet) { |
4593 m_objs_array.Append(new_objs_array); | 4593 m_objs_array.Append(new_objs_array); |
4594 return FormNotAvailable; | 4594 return FormNotAvailable; |
4595 } | 4595 } |
4596 return FormAvailable; | 4596 return FormAvailable; |
4597 } | 4597 } |
4598 void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum) { | 4598 |
4599 int32_t iNext = 0; | |
4600 if (BinarySearch(dwObjNum, iNext)) { | |
4601 return; | |
4602 } | |
4603 m_number_array.InsertAt(iNext, dwObjNum); | |
4604 } | |
4605 FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) { | |
4606 int32_t iNext = 0; | |
4607 return BinarySearch(dwObjNum, iNext); | |
4608 } | |
4609 FX_BOOL CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t& iNext) { | |
4610 int32_t iLow = 0; | |
4611 int32_t iHigh = m_number_array.GetSize() - 1; | |
4612 while (iLow <= iHigh) { | |
4613 int32_t iMid = (iLow + iHigh) / 2; | |
4614 if (m_number_array.GetAt(iMid) == value) { | |
4615 iNext = iMid; | |
4616 return TRUE; | |
4617 } | |
4618 if (m_number_array.GetAt(iMid) > value) { | |
4619 iHigh = iMid - 1; | |
4620 } else if (m_number_array.GetAt(iMid) < value) { | |
4621 iLow = iMid + 1; | |
4622 } | |
4623 } | |
4624 iNext = iLow; | |
4625 return FALSE; | |
4626 } | |
4627 CPDF_PageNode::~CPDF_PageNode() { | 4599 CPDF_PageNode::~CPDF_PageNode() { |
4628 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) { | 4600 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) { |
4629 delete m_childNode[i]; | 4601 delete m_childNode[i]; |
4630 } | 4602 } |
4631 m_childNode.RemoveAll(); | 4603 m_childNode.RemoveAll(); |
4632 } | 4604 } |
4633 CPDF_HintTables::~CPDF_HintTables() { | 4605 CPDF_HintTables::~CPDF_HintTables() { |
4634 m_dwDeltaNObjsArray.RemoveAll(); | 4606 m_dwDeltaNObjsArray.RemoveAll(); |
4635 m_dwNSharedObjsArray.RemoveAll(); | 4607 m_dwNSharedObjsArray.RemoveAll(); |
4636 m_dwSharedObjNumArray.RemoveAll(); | 4608 m_dwSharedObjNumArray.RemoveAll(); |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4997 if (!m_pLinearizedDict) | 4969 if (!m_pLinearizedDict) |
4998 return -1; | 4970 return -1; |
4999 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4971 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
5000 if (!pRange) | 4972 if (!pRange) |
5001 return -1; | 4973 return -1; |
5002 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4974 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
5003 if (!pStreamLen) | 4975 if (!pStreamLen) |
5004 return -1; | 4976 return -1; |
5005 return pStreamLen->GetInteger(); | 4977 return pStreamLen->GetInteger(); |
5006 } | 4978 } |
OLD | NEW |