| 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 "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 
| 8 | 8 | 
| 9 #include <set> | 9 #include <set> | 
| 10 | 10 | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 25                std::set<CPDF_Dictionary*>* visited_pages) { | 25                std::set<CPDF_Dictionary*>* visited_pages) { | 
| 26   int count = pPages->GetIntegerBy("Count"); | 26   int count = pPages->GetIntegerBy("Count"); | 
| 27   if (count > 0 && count < FPDF_PAGE_MAX_NUM) { | 27   if (count > 0 && count < FPDF_PAGE_MAX_NUM) { | 
| 28     return count; | 28     return count; | 
| 29   } | 29   } | 
| 30   CPDF_Array* pKidList = pPages->GetArrayBy("Kids"); | 30   CPDF_Array* pKidList = pPages->GetArrayBy("Kids"); | 
| 31   if (!pKidList) { | 31   if (!pKidList) { | 
| 32     return 0; | 32     return 0; | 
| 33   } | 33   } | 
| 34   count = 0; | 34   count = 0; | 
| 35   for (FX_DWORD i = 0; i < pKidList->GetCount(); i++) { | 35   for (uint32_t i = 0; i < pKidList->GetCount(); i++) { | 
| 36     CPDF_Dictionary* pKid = pKidList->GetDictAt(i); | 36     CPDF_Dictionary* pKid = pKidList->GetDictAt(i); | 
| 37     if (!pKid || pdfium::ContainsKey(*visited_pages, pKid)) { | 37     if (!pKid || pdfium::ContainsKey(*visited_pages, pKid)) { | 
| 38       continue; | 38       continue; | 
| 39     } | 39     } | 
| 40     if (pKid->KeyExist("Kids")) { | 40     if (pKid->KeyExist("Kids")) { | 
| 41       // Use |visited_pages| to help detect circular references of pages. | 41       // Use |visited_pages| to help detect circular references of pages. | 
| 42       pdfium::ScopedSetInsertion<CPDF_Dictionary*> local_add(visited_pages, | 42       pdfium::ScopedSetInsertion<CPDF_Dictionary*> local_add(visited_pages, | 
| 43                                                              pKid); | 43                                                              pKid); | 
| 44       count += CountPages(pKid, visited_pages); | 44       count += CountPages(pKid, visited_pages); | 
| 45     } else { | 45     } else { | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 107   if (!m_pRootDict) { | 107   if (!m_pRootDict) { | 
| 108     return; | 108     return; | 
| 109   } | 109   } | 
| 110   pIndirectObj = GetIndirectObject(m_pParser->GetInfoObjNum()); | 110   pIndirectObj = GetIndirectObject(m_pParser->GetInfoObjNum()); | 
| 111   m_pInfoDict = pIndirectObj ? pIndirectObj->GetDict() : nullptr; | 111   m_pInfoDict = pIndirectObj ? pIndirectObj->GetDict() : nullptr; | 
| 112   CPDF_Array* pIDArray = m_pParser->GetIDArray(); | 112   CPDF_Array* pIDArray = m_pParser->GetIDArray(); | 
| 113   if (pIDArray) { | 113   if (pIDArray) { | 
| 114     m_ID1 = pIDArray->GetStringAt(0); | 114     m_ID1 = pIDArray->GetStringAt(0); | 
| 115     m_ID2 = pIDArray->GetStringAt(1); | 115     m_ID2 = pIDArray->GetStringAt(1); | 
| 116   } | 116   } | 
| 117   FX_DWORD dwPageCount = 0; | 117   uint32_t dwPageCount = 0; | 
| 118   CPDF_Object* pCount = pLinearized->GetElement("N"); | 118   CPDF_Object* pCount = pLinearized->GetElement("N"); | 
| 119   if (ToNumber(pCount)) | 119   if (ToNumber(pCount)) | 
| 120     dwPageCount = pCount->GetInteger(); | 120     dwPageCount = pCount->GetInteger(); | 
| 121 | 121 | 
| 122   m_PageList.SetSize(dwPageCount); | 122   m_PageList.SetSize(dwPageCount); | 
| 123   CPDF_Object* pNo = pLinearized->GetElement("P"); | 123   CPDF_Object* pNo = pLinearized->GetElement("P"); | 
| 124   if (ToNumber(pNo)) | 124   if (ToNumber(pNo)) | 
| 125     m_dwFirstPageNo = pNo->GetInteger(); | 125     m_dwFirstPageNo = pNo->GetInteger(); | 
| 126 | 126 | 
| 127   CPDF_Object* pObjNum = pLinearized->GetElement("O"); | 127   CPDF_Object* pObjNum = pLinearized->GetElement("O"); | 
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 209 | 209 | 
| 210   CPDF_Dictionary* pPage = _FindPDFPage(pPages, iPage, iPage, 0); | 210   CPDF_Dictionary* pPage = _FindPDFPage(pPages, iPage, iPage, 0); | 
| 211   if (!pPage) | 211   if (!pPage) | 
| 212     return nullptr; | 212     return nullptr; | 
| 213 | 213 | 
| 214   m_PageList.SetAt(iPage, pPage->GetObjNum()); | 214   m_PageList.SetAt(iPage, pPage->GetObjNum()); | 
| 215   return pPage; | 215   return pPage; | 
| 216 } | 216 } | 
| 217 | 217 | 
| 218 int CPDF_Document::_FindPageIndex(CPDF_Dictionary* pNode, | 218 int CPDF_Document::_FindPageIndex(CPDF_Dictionary* pNode, | 
| 219                                   FX_DWORD& skip_count, | 219                                   uint32_t& skip_count, | 
| 220                                   FX_DWORD objnum, | 220                                   uint32_t objnum, | 
| 221                                   int& index, | 221                                   int& index, | 
| 222                                   int level) { | 222                                   int level) { | 
| 223   if (pNode->KeyExist("Kids")) { | 223   if (pNode->KeyExist("Kids")) { | 
| 224     CPDF_Array* pKidList = pNode->GetArrayBy("Kids"); | 224     CPDF_Array* pKidList = pNode->GetArrayBy("Kids"); | 
| 225     if (!pKidList) { | 225     if (!pKidList) { | 
| 226       return -1; | 226       return -1; | 
| 227     } | 227     } | 
| 228     if (level >= FX_MAX_PAGE_LEVEL) { | 228     if (level >= FX_MAX_PAGE_LEVEL) { | 
| 229       return -1; | 229       return -1; | 
| 230     } | 230     } | 
| 231     FX_DWORD count = pNode->GetIntegerBy("Count"); | 231     uint32_t count = pNode->GetIntegerBy("Count"); | 
| 232     if (count <= skip_count) { | 232     if (count <= skip_count) { | 
| 233       skip_count -= count; | 233       skip_count -= count; | 
| 234       index += count; | 234       index += count; | 
| 235       return -1; | 235       return -1; | 
| 236     } | 236     } | 
| 237     if (count && count == pKidList->GetCount()) { | 237     if (count && count == pKidList->GetCount()) { | 
| 238       for (FX_DWORD i = 0; i < count; i++) { | 238       for (uint32_t i = 0; i < count; i++) { | 
| 239         if (CPDF_Reference* pKid = ToReference(pKidList->GetElement(i))) { | 239         if (CPDF_Reference* pKid = ToReference(pKidList->GetElement(i))) { | 
| 240           if (pKid->GetRefObjNum() == objnum) { | 240           if (pKid->GetRefObjNum() == objnum) { | 
| 241             m_PageList.SetAt(index + i, objnum); | 241             m_PageList.SetAt(index + i, objnum); | 
| 242             return index + i; | 242             return index + i; | 
| 243           } | 243           } | 
| 244         } | 244         } | 
| 245       } | 245       } | 
| 246     } | 246     } | 
| 247     for (FX_DWORD i = 0; i < pKidList->GetCount(); i++) { | 247     for (uint32_t i = 0; i < pKidList->GetCount(); i++) { | 
| 248       CPDF_Dictionary* pKid = pKidList->GetDictAt(i); | 248       CPDF_Dictionary* pKid = pKidList->GetDictAt(i); | 
| 249       if (!pKid) { | 249       if (!pKid) { | 
| 250         continue; | 250         continue; | 
| 251       } | 251       } | 
| 252       if (pKid == pNode) { | 252       if (pKid == pNode) { | 
| 253         continue; | 253         continue; | 
| 254       } | 254       } | 
| 255       int found_index = | 255       int found_index = | 
| 256           _FindPageIndex(pKid, skip_count, objnum, index, level + 1); | 256           _FindPageIndex(pKid, skip_count, objnum, index, level + 1); | 
| 257       if (found_index >= 0) { | 257       if (found_index >= 0) { | 
| 258         return found_index; | 258         return found_index; | 
| 259       } | 259       } | 
| 260     } | 260     } | 
| 261   } else { | 261   } else { | 
| 262     if (objnum == pNode->GetObjNum()) { | 262     if (objnum == pNode->GetObjNum()) { | 
| 263       return index; | 263       return index; | 
| 264     } | 264     } | 
| 265     if (skip_count) { | 265     if (skip_count) { | 
| 266       skip_count--; | 266       skip_count--; | 
| 267     } | 267     } | 
| 268     index++; | 268     index++; | 
| 269   } | 269   } | 
| 270   return -1; | 270   return -1; | 
| 271 } | 271 } | 
| 272 int CPDF_Document::GetPageIndex(FX_DWORD objnum) { | 272 int CPDF_Document::GetPageIndex(uint32_t objnum) { | 
| 273   FX_DWORD nPages = m_PageList.GetSize(); | 273   uint32_t nPages = m_PageList.GetSize(); | 
| 274   FX_DWORD skip_count = 0; | 274   uint32_t skip_count = 0; | 
| 275   FX_BOOL bSkipped = FALSE; | 275   FX_BOOL bSkipped = FALSE; | 
| 276   for (FX_DWORD i = 0; i < nPages; i++) { | 276   for (uint32_t i = 0; i < nPages; i++) { | 
| 277     FX_DWORD objnum1 = m_PageList.GetAt(i); | 277     uint32_t objnum1 = m_PageList.GetAt(i); | 
| 278     if (objnum1 == objnum) { | 278     if (objnum1 == objnum) { | 
| 279       return i; | 279       return i; | 
| 280     } | 280     } | 
| 281     if (!bSkipped && objnum1 == 0) { | 281     if (!bSkipped && objnum1 == 0) { | 
| 282       skip_count = i; | 282       skip_count = i; | 
| 283       bSkipped = TRUE; | 283       bSkipped = TRUE; | 
| 284     } | 284     } | 
| 285   } | 285   } | 
| 286   CPDF_Dictionary* pRoot = GetRoot(); | 286   CPDF_Dictionary* pRoot = GetRoot(); | 
| 287   if (!pRoot) { | 287   if (!pRoot) { | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 308     return 0; | 308     return 0; | 
| 309   } | 309   } | 
| 310   if (!pPages->KeyExist("Kids")) { | 310   if (!pPages->KeyExist("Kids")) { | 
| 311     return 1; | 311     return 1; | 
| 312   } | 312   } | 
| 313   std::set<CPDF_Dictionary*> visited_pages; | 313   std::set<CPDF_Dictionary*> visited_pages; | 
| 314   visited_pages.insert(pPages); | 314   visited_pages.insert(pPages); | 
| 315   return CountPages(pPages, &visited_pages); | 315   return CountPages(pPages, &visited_pages); | 
| 316 } | 316 } | 
| 317 | 317 | 
| 318 FX_DWORD CPDF_Document::GetUserPermissions(FX_BOOL bCheckRevision) const { | 318 uint32_t CPDF_Document::GetUserPermissions(FX_BOOL bCheckRevision) const { | 
| 319   if (!m_pParser) { | 319   if (!m_pParser) { | 
| 320     return (FX_DWORD)-1; | 320     return (uint32_t)-1; | 
| 321   } | 321   } | 
| 322   return m_pParser->GetPermissions(bCheckRevision); | 322   return m_pParser->GetPermissions(bCheckRevision); | 
| 323 } | 323 } | 
| 324 | 324 | 
| 325 FX_BOOL CPDF_Document::IsFormStream(FX_DWORD objnum, FX_BOOL& bForm) const { | 325 FX_BOOL CPDF_Document::IsFormStream(uint32_t objnum, FX_BOOL& bForm) const { | 
| 326   auto it = m_IndirectObjs.find(objnum); | 326   auto it = m_IndirectObjs.find(objnum); | 
| 327   if (it != m_IndirectObjs.end()) { | 327   if (it != m_IndirectObjs.end()) { | 
| 328     CPDF_Stream* pStream = it->second->AsStream(); | 328     CPDF_Stream* pStream = it->second->AsStream(); | 
| 329     bForm = pStream && pStream->GetDict()->GetStringBy("Subtype") == "Form"; | 329     bForm = pStream && pStream->GetDict()->GetStringBy("Subtype") == "Form"; | 
| 330     return TRUE; | 330     return TRUE; | 
| 331   } | 331   } | 
| 332   if (!m_pParser) { | 332   if (!m_pParser) { | 
| 333     bForm = FALSE; | 333     bForm = FALSE; | 
| 334     return TRUE; | 334     return TRUE; | 
| 335   } | 335   } | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 347 } | 347 } | 
| 348 | 348 | 
| 349 void CPDF_Document::ClearRenderFont() { | 349 void CPDF_Document::ClearRenderFont() { | 
| 350   if (!m_pDocRender) | 350   if (!m_pDocRender) | 
| 351     return; | 351     return; | 
| 352 | 352 | 
| 353   CFX_FontCache* pCache = m_pDocRender->GetFontCache(); | 353   CFX_FontCache* pCache = m_pDocRender->GetFontCache(); | 
| 354   if (pCache) | 354   if (pCache) | 
| 355     pCache->FreeCache(FALSE); | 355     pCache->FreeCache(FALSE); | 
| 356 } | 356 } | 
| OLD | NEW | 
|---|