diff options
Diffstat (limited to 'core/fpdfapi/fpdf_page/cpdf_page.cpp')
-rw-r--r-- | core/fpdfapi/fpdf_page/cpdf_page.cpp | 116 |
1 files changed, 47 insertions, 69 deletions
diff --git a/core/fpdfapi/fpdf_page/cpdf_page.cpp b/core/fpdfapi/fpdf_page/cpdf_page.cpp index dd298f382f..6b0609ff00 100644 --- a/core/fpdfapi/fpdf_page/cpdf_page.cpp +++ b/core/fpdfapi/fpdf_page/cpdf_page.cpp @@ -6,95 +6,59 @@ #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" - -CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, - const CFX_ByteStringC& name) { - int level = 0; - while (1) { - CPDF_Object* pObj = pPageDict->GetDirectObjectBy(name); - if (pObj) { - return pObj; - } - CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent"); - if (!pParent || pParent == pPageDict) { - return NULL; - } - pPageDict = pParent; - level++; - if (level == 1000) { - return NULL; - } - } -} +#include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" +#include "third_party/base/stl_util.h" -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); - } -} - -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,26 +73,40 @@ 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); } -CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const { - return FPDFAPI_GetPageAttr(m_pFormDict, name); +CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteString& name) const { + CPDF_Dictionary* pPageDict = m_pFormDict; + std::set<CPDF_Dictionary*> visited; + while (1) { + visited.insert(pPageDict); + if (CPDF_Object* pObj = pPageDict->GetDirectObjectBy(name)) + return pObj; + + pPageDict = pPageDict->GetDictBy("Parent"); + if (!pPageDict || pdfium::ContainsKey(visited, pPageDict)) + break; + } + return nullptr; } void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, |