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

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

Issue 1811053002: Move core/include/fpdfapi/fpdf_pageobj.h into core/fpdfapi. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 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_imageobject.cpp ('k') | core/fpdfapi/fpdf_page/cpdf_pageobject.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
8
9 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
10 #include "core/fpdfapi/fpdf_page/pageint.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
13 #include "core/fpdfapi/include/cpdf_modulemgr.h"
14 #include "core/fpdfapi/ipdf_rendermodule.h"
15
16 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict,
17 const CFX_ByteStringC& name) {
18 int level = 0;
19 while (1) {
20 CPDF_Object* pObj = pPageDict->GetElementValue(name);
21 if (pObj) {
22 return pObj;
23 }
24 CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent");
25 if (!pParent || pParent == pPageDict) {
26 return NULL;
27 }
28 pPageDict = pParent;
29 level++;
30 if (level == 1000) {
31 return NULL;
32 }
33 }
34 }
35
36 CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {}
37
38 CPDF_Page::~CPDF_Page() {
39 if (m_pPageRender) {
40 IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule();
41 pModule->DestroyPageCache(m_pPageRender);
42 }
43 }
44
45 void CPDF_Page::Load(CPDF_Document* pDocument,
46 CPDF_Dictionary* pPageDict,
47 FX_BOOL bPageCache) {
48 m_pDocument = (CPDF_Document*)pDocument;
49 m_pFormDict = pPageDict;
50 if (bPageCache) {
51 m_pPageRender =
52 CPDF_ModuleMgr::Get()->GetRenderModule()->CreatePageCache(this);
53 }
54 if (!pPageDict) {
55 m_PageWidth = m_PageHeight = 100 * 1.0f;
56 m_pPageResources = m_pResources = NULL;
57 return;
58 }
59 CPDF_Object* pageAttr = GetPageAttr("Resources");
60 m_pResources = pageAttr ? pageAttr->GetDict() : NULL;
61 m_pPageResources = m_pResources;
62 CPDF_Object* pRotate = GetPageAttr("Rotate");
63 int rotate = 0;
64 if (pRotate) {
65 rotate = pRotate->GetInteger() / 90 % 4;
66 }
67 if (rotate < 0) {
68 rotate += 4;
69 }
70 CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox"));
71 CFX_FloatRect mediabox;
72 if (pMediaBox) {
73 mediabox = pMediaBox->GetRect();
74 mediabox.Normalize();
75 }
76 if (mediabox.IsEmpty()) {
77 mediabox = CFX_FloatRect(0, 0, 612, 792);
78 }
79
80 CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox"));
81 if (pCropBox) {
82 m_BBox = pCropBox->GetRect();
83 m_BBox.Normalize();
84 }
85 if (m_BBox.IsEmpty()) {
86 m_BBox = mediabox;
87 } else {
88 m_BBox.Intersect(mediabox);
89 }
90 if (rotate % 2) {
91 m_PageHeight = m_BBox.right - m_BBox.left;
92 m_PageWidth = m_BBox.top - m_BBox.bottom;
93 } else {
94 m_PageWidth = m_BBox.right - m_BBox.left;
95 m_PageHeight = m_BBox.top - m_BBox.bottom;
96 }
97 switch (rotate) {
98 case 0:
99 m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom);
100 break;
101 case 1:
102 m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right);
103 break;
104 case 2:
105 m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top);
106 break;
107 case 3:
108 m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left);
109 break;
110 }
111 m_Transparency = PDFTRANS_ISOLATED;
112 LoadTransInfo();
113 }
114
115 void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) {
116 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) {
117 return;
118 }
119 m_pParser.reset(new CPDF_ContentParser);
120 m_pParser->Start(this, pOptions);
121 m_ParseState = CONTENT_PARSING;
122 }
123
124 void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) {
125 StartParse(pOptions);
126 ContinueParse(nullptr);
127 }
128
129 CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const {
130 return FPDFAPI_GetPageAttr(m_pFormDict, name);
131 }
132
133 void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix,
134 int xPos,
135 int yPos,
136 int xSize,
137 int ySize,
138 int iRotate) const {
139 if (m_PageWidth == 0 || m_PageHeight == 0) {
140 return;
141 }
142 CFX_Matrix display_matrix;
143 int x0, y0, x1, y1, x2, y2;
144 iRotate %= 4;
145 switch (iRotate) {
146 case 0:
147 x0 = xPos;
148 y0 = yPos + ySize;
149 x1 = xPos;
150 y1 = yPos;
151 x2 = xPos + xSize;
152 y2 = yPos + ySize;
153 break;
154 case 1:
155 x0 = xPos;
156 y0 = yPos;
157 x1 = xPos + xSize;
158 y1 = yPos;
159 x2 = xPos;
160 y2 = yPos + ySize;
161 break;
162 case 2:
163 x0 = xPos + xSize;
164 y0 = yPos;
165 x1 = xPos + xSize;
166 y1 = yPos + ySize;
167 x2 = xPos;
168 y2 = yPos;
169 break;
170 case 3:
171 x0 = xPos + xSize;
172 y0 = yPos + ySize;
173 x1 = xPos;
174 y1 = yPos + ySize;
175 x2 = xPos + xSize;
176 y2 = yPos;
177 break;
178 }
179 display_matrix.Set(
180 ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth,
181 ((FX_FLOAT)(x1 - x0)) / m_PageHeight,
182 ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0);
183 matrix = m_PageMatrix;
184 matrix.Concat(display_matrix);
185 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_imageobject.cpp ('k') | core/fpdfapi/fpdf_page/cpdf_pageobject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698