Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_page.cpp

Issue 1918113002: Clean up CPDF_Page. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: more Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_form.cpp ('k') | core/fpdfapi/fpdf_page/cpdf_parseoptions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_Page::CPDF_Page(CPDF_Document* pDocument,
18 const CFX_ByteStringC& name) { 20 CPDF_Dictionary* pPageDict,
19 int level = 0; 21 bool bPageCache)
20 while (1) { 22 : m_PageWidth(100),
21 CPDF_Object* pObj = pPageDict->GetDirectObjectBy(name); 23 m_PageHeight(100),
22 if (pObj) { 24 m_pPageRender(bPageCache ? new CPDF_PageRenderCache(this) : nullptr) {
23 return pObj; 25 m_pFormDict = pPageDict;
24 } 26 m_pDocument = pDocument;
25 CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent"); 27 if (!pPageDict)
26 if (!pParent || pParent == pPageDict) { 28 return;
27 return NULL;
28 }
29 pPageDict = pParent;
30 level++;
31 if (level == 1000) {
32 return NULL;
33 }
34 }
35 }
36 29
37 CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {}
38
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"); 30 CPDF_Object* pageAttr = GetPageAttr("Resources");
61 m_pResources = pageAttr ? pageAttr->GetDict() : NULL; 31 m_pResources = pageAttr ? pageAttr->GetDict() : nullptr;
62 m_pPageResources = m_pResources; 32 m_pPageResources = m_pResources;
63 CPDF_Object* pRotate = GetPageAttr("Rotate"); 33 CPDF_Object* pRotate = GetPageAttr("Rotate");
64 int rotate = 0; 34 int rotate = pRotate ? pRotate->GetInteger() / 90 % 4 : 0;
65 if (pRotate) { 35 if (rotate < 0)
66 rotate = pRotate->GetInteger() / 90 % 4;
67 }
68 if (rotate < 0) {
69 rotate += 4; 36 rotate += 4;
70 } 37
71 CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox")); 38 CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox"));
72 CFX_FloatRect mediabox; 39 CFX_FloatRect mediabox;
73 if (pMediaBox) { 40 if (pMediaBox) {
74 mediabox = pMediaBox->GetRect(); 41 mediabox = pMediaBox->GetRect();
75 mediabox.Normalize(); 42 mediabox.Normalize();
76 } 43 }
77 if (mediabox.IsEmpty()) { 44 if (mediabox.IsEmpty())
78 mediabox = CFX_FloatRect(0, 0, 612, 792); 45 mediabox = CFX_FloatRect(0, 0, 612, 792);
79 }
80 46
81 CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox")); 47 CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox"));
82 if (pCropBox) { 48 if (pCropBox) {
83 m_BBox = pCropBox->GetRect(); 49 m_BBox = pCropBox->GetRect();
84 m_BBox.Normalize(); 50 m_BBox.Normalize();
85 } 51 }
86 if (m_BBox.IsEmpty()) { 52 if (m_BBox.IsEmpty())
87 m_BBox = mediabox; 53 m_BBox = mediabox;
88 } else { 54 else
89 m_BBox.Intersect(mediabox); 55 m_BBox.Intersect(mediabox);
90 } 56
91 if (rotate % 2) { 57 m_PageWidth = m_BBox.right - m_BBox.left;
92 m_PageHeight = m_BBox.right - m_BBox.left; 58 m_PageHeight = m_BBox.top - m_BBox.bottom;
93 m_PageWidth = m_BBox.top - m_BBox.bottom; 59 if (rotate % 2)
94 } else { 60 std::swap(m_PageWidth, m_PageHeight);
95 m_PageWidth = m_BBox.right - m_BBox.left; 61
96 m_PageHeight = m_BBox.top - m_BBox.bottom;
97 }
98 switch (rotate) { 62 switch (rotate) {
99 case 0: 63 case 0:
100 m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom); 64 m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom);
101 break; 65 break;
102 case 1: 66 case 1:
103 m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right); 67 m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right);
104 break; 68 break;
105 case 2: 69 case 2:
106 m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top); 70 m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top);
107 break; 71 break;
108 case 3: 72 case 3:
109 m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left); 73 m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left);
110 break; 74 break;
111 } 75 }
76
112 m_Transparency = PDFTRANS_ISOLATED; 77 m_Transparency = PDFTRANS_ISOLATED;
113 LoadTransInfo(); 78 LoadTransInfo();
114 } 79 }
115 80
116 void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) { 81 CPDF_Page::~CPDF_Page() {}
117 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) { 82
83 void CPDF_Page::StartParse() {
84 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING)
118 return; 85 return;
119 } 86
120 m_pParser.reset(new CPDF_ContentParser); 87 m_pParser.reset(new CPDF_ContentParser);
121 m_pParser->Start(this, pOptions); 88 m_pParser->Start(this);
122 m_ParseState = CONTENT_PARSING; 89 m_ParseState = CONTENT_PARSING;
123 } 90 }
124 91
125 void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) { 92 void CPDF_Page::ParseContent() {
126 StartParse(pOptions); 93 StartParse();
127 ContinueParse(nullptr); 94 ContinueParse(nullptr);
128 } 95 }
129 96
130 CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const { 97 CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteString& name) const {
131 return FPDFAPI_GetPageAttr(m_pFormDict, name); 98 CPDF_Dictionary* pPageDict = m_pFormDict;
99 std::set<CPDF_Dictionary*> visited;
100 while (1) {
101 visited.insert(pPageDict);
102 if (CPDF_Object* pObj = pPageDict->GetDirectObjectBy(name))
103 return pObj;
104
105 pPageDict = pPageDict->GetDictBy("Parent");
106 if (!pPageDict || pdfium::ContainsKey(visited, pPageDict))
107 break;
108 }
109 return nullptr;
132 } 110 }
133 111
134 void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix, 112 void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix,
135 int xPos, 113 int xPos,
136 int yPos, 114 int yPos,
137 int xSize, 115 int xSize,
138 int ySize, 116 int ySize,
139 int iRotate) const { 117 int iRotate) const {
140 if (m_PageWidth == 0 || m_PageHeight == 0) { 118 if (m_PageWidth == 0 || m_PageHeight == 0) {
141 return; 119 return;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 y2 = yPos; 160 y2 = yPos;
183 break; 161 break;
184 } 162 }
185 display_matrix.Set( 163 display_matrix.Set(
186 ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth, 164 ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth,
187 ((FX_FLOAT)(x1 - x0)) / m_PageHeight, 165 ((FX_FLOAT)(x1 - x0)) / m_PageHeight,
188 ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0); 166 ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0);
189 matrix = m_PageMatrix; 167 matrix = m_PageMatrix;
190 matrix.Concat(display_matrix); 168 matrix.Concat(display_matrix);
191 } 169 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_form.cpp ('k') | core/fpdfapi/fpdf_page/cpdf_parseoptions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698