Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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_page/include/cpdf_page.h" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
| 8 | 8 |
| 9 #include <set> | |
| 10 | |
| 9 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" | 11 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" |
| 10 #include "core/fpdfapi/fpdf_page/pageint.h" | 12 #include "core/fpdfapi/fpdf_page/pageint.h" |
| 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
| 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" | 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" |
| 14 #include "core/fpdfapi/include/cpdf_modulemgr.h" | 16 #include "core/fpdfapi/fpdf_render/cpdf_pagerendercache.h" |
| 15 #include "core/fpdfapi/ipdf_rendermodule.h" | 17 #include "third_party/base/stl_util.h" |
| 16 | 18 |
| 17 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, | 19 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, |
| 18 const CFX_ByteStringC& name) { | 20 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.
| |
| 19 int level = 0; | 21 std::set<CPDF_Dictionary*> visited; |
| 20 while (1) { | 22 while (1) { |
| 23 visited.insert(pPageDict); | |
| 21 CPDF_Object* pObj = pPageDict->GetDirectObjectBy(name); | 24 CPDF_Object* pObj = pPageDict->GetDirectObjectBy(name); |
| 22 if (pObj) { | 25 if (pObj) |
|
dsinclair
2016/04/26 02:42:26
if (CPDF_Object* pObj = pPageDict->GetDirectObject
Lei Zhang
2016/04/26 04:24:45
Done.
| |
| 23 return pObj; | 26 return pObj; |
| 24 } | 27 |
| 25 CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent"); | 28 pPageDict = pPageDict->GetDictBy("Parent"); |
| 26 if (!pParent || pParent == pPageDict) { | 29 if (!pPageDict || pdfium::ContainsKey(visited, pPageDict)) |
| 27 return NULL; | 30 break; |
| 28 } | |
| 29 pPageDict = pParent; | |
| 30 level++; | |
| 31 if (level == 1000) { | |
| 32 return NULL; | |
| 33 } | |
| 34 } | 31 } |
| 32 return nullptr; | |
| 35 } | 33 } |
| 36 | 34 |
| 37 CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {} | 35 CPDF_Page::CPDF_Page(CPDF_Document* pDocument, |
| 36 CPDF_Dictionary* pPageDict, | |
| 37 bool bPageCache) | |
| 38 : m_PageWidth(100), | |
| 39 m_PageHeight(100), | |
| 40 m_pPageRender(bPageCache ? new CPDF_PageRenderCache(this) : nullptr) { | |
| 41 m_pFormDict = pPageDict; | |
| 42 m_pDocument = pDocument; | |
| 43 if (!pPageDict) | |
| 44 return; | |
| 38 | 45 |
| 39 CPDF_Page::~CPDF_Page() { | |
| 40 if (m_pPageRender) { | |
| 41 IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule(); | |
| 42 pModule->DestroyPageCache(m_pPageRender); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void CPDF_Page::Load(CPDF_Document* pDocument, | |
| 47 CPDF_Dictionary* pPageDict, | |
| 48 FX_BOOL bPageCache) { | |
| 49 m_pDocument = (CPDF_Document*)pDocument; | |
| 50 m_pFormDict = pPageDict; | |
| 51 if (bPageCache) { | |
| 52 m_pPageRender = | |
| 53 CPDF_ModuleMgr::Get()->GetRenderModule()->CreatePageCache(this); | |
| 54 } | |
| 55 if (!pPageDict) { | |
| 56 m_PageWidth = m_PageHeight = 100 * 1.0f; | |
| 57 m_pPageResources = m_pResources = NULL; | |
| 58 return; | |
| 59 } | |
| 60 CPDF_Object* pageAttr = GetPageAttr("Resources"); | 46 CPDF_Object* pageAttr = GetPageAttr("Resources"); |
| 61 m_pResources = pageAttr ? pageAttr->GetDict() : NULL; | 47 m_pResources = pageAttr ? pageAttr->GetDict() : nullptr; |
| 62 m_pPageResources = m_pResources; | 48 m_pPageResources = m_pResources; |
| 63 CPDF_Object* pRotate = GetPageAttr("Rotate"); | 49 CPDF_Object* pRotate = GetPageAttr("Rotate"); |
| 64 int rotate = 0; | 50 int rotate = pRotate ? pRotate->GetInteger() / 90 % 4 : 0; |
| 65 if (pRotate) { | 51 if (rotate < 0) |
| 66 rotate = pRotate->GetInteger() / 90 % 4; | |
| 67 } | |
| 68 if (rotate < 0) { | |
| 69 rotate += 4; | 52 rotate += 4; |
| 70 } | 53 |
| 71 CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox")); | 54 CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox")); |
| 72 CFX_FloatRect mediabox; | 55 CFX_FloatRect mediabox; |
| 73 if (pMediaBox) { | 56 if (pMediaBox) { |
| 74 mediabox = pMediaBox->GetRect(); | 57 mediabox = pMediaBox->GetRect(); |
| 75 mediabox.Normalize(); | 58 mediabox.Normalize(); |
| 76 } | 59 } |
| 77 if (mediabox.IsEmpty()) { | 60 if (mediabox.IsEmpty()) |
| 78 mediabox = CFX_FloatRect(0, 0, 612, 792); | 61 mediabox = CFX_FloatRect(0, 0, 612, 792); |
| 79 } | |
| 80 | 62 |
| 81 CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox")); | 63 CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox")); |
| 82 if (pCropBox) { | 64 if (pCropBox) { |
| 83 m_BBox = pCropBox->GetRect(); | 65 m_BBox = pCropBox->GetRect(); |
| 84 m_BBox.Normalize(); | 66 m_BBox.Normalize(); |
| 85 } | 67 } |
| 86 if (m_BBox.IsEmpty()) { | 68 if (m_BBox.IsEmpty()) |
| 87 m_BBox = mediabox; | 69 m_BBox = mediabox; |
| 88 } else { | 70 else |
| 89 m_BBox.Intersect(mediabox); | 71 m_BBox.Intersect(mediabox); |
| 90 } | 72 |
| 91 if (rotate % 2) { | 73 m_PageWidth = m_BBox.right - m_BBox.left; |
| 92 m_PageHeight = m_BBox.right - m_BBox.left; | 74 m_PageHeight = m_BBox.top - m_BBox.bottom; |
| 93 m_PageWidth = m_BBox.top - m_BBox.bottom; | 75 if (rotate % 2) |
| 94 } else { | 76 std::swap(m_PageWidth, m_PageHeight); |
| 95 m_PageWidth = m_BBox.right - m_BBox.left; | 77 |
| 96 m_PageHeight = m_BBox.top - m_BBox.bottom; | |
| 97 } | |
| 98 switch (rotate) { | 78 switch (rotate) { |
| 99 case 0: | 79 case 0: |
| 100 m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom); | 80 m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom); |
| 101 break; | 81 break; |
| 102 case 1: | 82 case 1: |
| 103 m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right); | 83 m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right); |
| 104 break; | 84 break; |
| 105 case 2: | 85 case 2: |
| 106 m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top); | 86 m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top); |
| 107 break; | 87 break; |
| 108 case 3: | 88 case 3: |
| 109 m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left); | 89 m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left); |
| 110 break; | 90 break; |
| 111 } | 91 } |
| 92 | |
| 112 m_Transparency = PDFTRANS_ISOLATED; | 93 m_Transparency = PDFTRANS_ISOLATED; |
| 113 LoadTransInfo(); | 94 LoadTransInfo(); |
| 114 } | 95 } |
| 115 | 96 |
| 116 void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) { | 97 CPDF_Page::~CPDF_Page() {} |
| 117 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) { | 98 |
| 99 void CPDF_Page::StartParse() { | |
| 100 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) | |
| 118 return; | 101 return; |
| 119 } | 102 |
| 120 m_pParser.reset(new CPDF_ContentParser); | 103 m_pParser.reset(new CPDF_ContentParser); |
| 121 m_pParser->Start(this, pOptions); | 104 m_pParser->Start(this); |
| 122 m_ParseState = CONTENT_PARSING; | 105 m_ParseState = CONTENT_PARSING; |
| 123 } | 106 } |
| 124 | 107 |
| 125 void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) { | 108 void CPDF_Page::ParseContent() { |
| 126 StartParse(pOptions); | 109 StartParse(); |
| 127 ContinueParse(nullptr); | 110 ContinueParse(nullptr); |
| 128 } | 111 } |
| 129 | 112 |
| 130 CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const { | 113 CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const { |
| 131 return FPDFAPI_GetPageAttr(m_pFormDict, name); | 114 return FPDFAPI_GetPageAttr(m_pFormDict, name); |
| 132 } | 115 } |
| 133 | 116 |
| 134 void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, | 117 void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, |
| 135 int xPos, | 118 int xPos, |
| 136 int yPos, | 119 int yPos, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 y2 = yPos; | 165 y2 = yPos; |
| 183 break; | 166 break; |
| 184 } | 167 } |
| 185 display_matrix.Set( | 168 display_matrix.Set( |
| 186 ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth, | 169 ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth, |
| 187 ((FX_FLOAT)(x1 - x0)) / m_PageHeight, | 170 ((FX_FLOAT)(x1 - x0)) / m_PageHeight, |
| 188 ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0); | 171 ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0); |
| 189 matrix = m_PageMatrix; | 172 matrix = m_PageMatrix; |
| 190 matrix.Concat(display_matrix); | 173 matrix.Concat(display_matrix); |
| 191 } | 174 } |
| OLD | NEW |