Chromium Code Reviews| Index: core/fpdfapi/fpdf_page/cpdf_page.cpp |
| diff --git a/core/fpdfapi/fpdf_page/cpdf_page.cpp b/core/fpdfapi/fpdf_page/cpdf_page.cpp |
| index dd298f382facad69d8496d7faa24e0ebb7e43b12..4ff5eeb88328b0801563f7391452005c865c544b 100644 |
| --- a/core/fpdfapi/fpdf_page/cpdf_page.cpp |
| +++ b/core/fpdfapi/fpdf_page/cpdf_page.cpp |
| @@ -6,95 +6,75 @@ |
| #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
| +#include <set> |
| + |
| #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" |
| #include "core/fpdfapi/fpdf_page/pageint.h" |
| #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
| #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" |
| -#include "core/fpdfapi/include/cpdf_modulemgr.h" |
| -#include "core/fpdfapi/ipdf_rendermodule.h" |
| +#include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" |
| +#include "third_party/base/stl_util.h" |
| CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, |
| const CFX_ByteStringC& name) { |
|
dsinclair
2016/04/26 02:42:26
Can this be a ByteString instead of ByteStringC?
Lei Zhang
2016/04/26 04:24:45
Done.
|
| - int level = 0; |
| + std::set<CPDF_Dictionary*> visited; |
| while (1) { |
| + visited.insert(pPageDict); |
| CPDF_Object* pObj = pPageDict->GetDirectObjectBy(name); |
| - if (pObj) { |
| + if (pObj) |
|
dsinclair
2016/04/26 02:42:26
if (CPDF_Object* pObj = pPageDict->GetDirectObject
Lei Zhang
2016/04/26 04:24:45
Done.
|
| return pObj; |
| - } |
| - CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent"); |
| - if (!pParent || pParent == pPageDict) { |
| - return NULL; |
| - } |
| - pPageDict = pParent; |
| - level++; |
| - if (level == 1000) { |
| - return NULL; |
| - } |
| - } |
| -} |
| -CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {} |
| - |
| -CPDF_Page::~CPDF_Page() { |
| - if (m_pPageRender) { |
| - IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule(); |
| - pModule->DestroyPageCache(m_pPageRender); |
| + pPageDict = pPageDict->GetDictBy("Parent"); |
| + if (!pPageDict || pdfium::ContainsKey(visited, pPageDict)) |
| + break; |
| } |
| + return nullptr; |
| } |
| -void CPDF_Page::Load(CPDF_Document* pDocument, |
| +CPDF_Page::CPDF_Page(CPDF_Document* pDocument, |
| CPDF_Dictionary* pPageDict, |
| - FX_BOOL bPageCache) { |
| - m_pDocument = (CPDF_Document*)pDocument; |
| + bool bPageCache) |
| + : m_PageWidth(100), |
| + m_PageHeight(100), |
| + m_pPageRender(bPageCache ? new CPDF_PageRenderCache(this) : nullptr) { |
| m_pFormDict = pPageDict; |
| - if (bPageCache) { |
| - m_pPageRender = |
| - CPDF_ModuleMgr::Get()->GetRenderModule()->CreatePageCache(this); |
| - } |
| - if (!pPageDict) { |
| - m_PageWidth = m_PageHeight = 100 * 1.0f; |
| - m_pPageResources = m_pResources = NULL; |
| + m_pDocument = pDocument; |
| + if (!pPageDict) |
| return; |
| - } |
| + |
| CPDF_Object* pageAttr = GetPageAttr("Resources"); |
| - m_pResources = pageAttr ? pageAttr->GetDict() : NULL; |
| + m_pResources = pageAttr ? pageAttr->GetDict() : nullptr; |
| m_pPageResources = m_pResources; |
| CPDF_Object* pRotate = GetPageAttr("Rotate"); |
| - int rotate = 0; |
| - if (pRotate) { |
| - rotate = pRotate->GetInteger() / 90 % 4; |
| - } |
| - if (rotate < 0) { |
| + int rotate = pRotate ? pRotate->GetInteger() / 90 % 4 : 0; |
| + if (rotate < 0) |
| rotate += 4; |
| - } |
| + |
| CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox")); |
| CFX_FloatRect mediabox; |
| if (pMediaBox) { |
| mediabox = pMediaBox->GetRect(); |
| mediabox.Normalize(); |
| } |
| - if (mediabox.IsEmpty()) { |
| + if (mediabox.IsEmpty()) |
| mediabox = CFX_FloatRect(0, 0, 612, 792); |
| - } |
| CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox")); |
| if (pCropBox) { |
| m_BBox = pCropBox->GetRect(); |
| m_BBox.Normalize(); |
| } |
| - if (m_BBox.IsEmpty()) { |
| + if (m_BBox.IsEmpty()) |
| m_BBox = mediabox; |
| - } else { |
| + else |
| m_BBox.Intersect(mediabox); |
| - } |
| - if (rotate % 2) { |
| - m_PageHeight = m_BBox.right - m_BBox.left; |
| - m_PageWidth = m_BBox.top - m_BBox.bottom; |
| - } else { |
| - m_PageWidth = m_BBox.right - m_BBox.left; |
| - m_PageHeight = m_BBox.top - m_BBox.bottom; |
| - } |
| + |
| + m_PageWidth = m_BBox.right - m_BBox.left; |
| + m_PageHeight = m_BBox.top - m_BBox.bottom; |
| + if (rotate % 2) |
| + std::swap(m_PageWidth, m_PageHeight); |
| + |
| switch (rotate) { |
| case 0: |
| m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom); |
| @@ -109,21 +89,24 @@ void CPDF_Page::Load(CPDF_Document* pDocument, |
| m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left); |
| break; |
| } |
| + |
| m_Transparency = PDFTRANS_ISOLATED; |
| LoadTransInfo(); |
| } |
| -void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) { |
| - if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) { |
| +CPDF_Page::~CPDF_Page() {} |
| + |
| +void CPDF_Page::StartParse() { |
| + if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) |
| return; |
| - } |
| + |
| m_pParser.reset(new CPDF_ContentParser); |
| - m_pParser->Start(this, pOptions); |
| + m_pParser->Start(this); |
| m_ParseState = CONTENT_PARSING; |
| } |
| -void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) { |
| - StartParse(pOptions); |
| +void CPDF_Page::ParseContent() { |
| + StartParse(); |
| ContinueParse(nullptr); |
| } |