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

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

Issue 1800523005: Move core/src/ up to core/. (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
OLDNEW
(Empty)
1 // Copyright 2014 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/src/fpdfapi/fpdf_page/pageint.h"
8
9 #include <algorithm>
10
11 #include "core/include/fpdfapi/cpdf_array.h"
12 #include "core/include/fpdfapi/cpdf_dictionary.h"
13 #include "core/include/fpdfapi/cpdf_document.h"
14 #include "core/include/fpdfapi/fpdf_module.h"
15 #include "core/include/fpdfapi/fpdf_page.h"
16 #include "third_party/base/stl_util.h"
17
18 CPDF_PageObject::CPDF_PageObject() {}
19
20 CPDF_PageObject::~CPDF_PageObject() {}
21
22 void CPDF_PageObject::CopyData(const CPDF_PageObject* pSrc) {
23 CopyStates(*pSrc);
24 m_Left = pSrc->m_Left;
25 m_Right = pSrc->m_Right;
26 m_Top = pSrc->m_Top;
27 m_Bottom = pSrc->m_Bottom;
28 }
29
30 void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) {
31 if (m_ClipPath.IsNull()) {
32 return;
33 }
34 m_ClipPath.GetModify();
35 m_ClipPath.Transform(matrix);
36 }
37
38 void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) {
39 if (m_GeneralState.IsNull()) {
40 return;
41 }
42 CPDF_GeneralStateData* pGS = m_GeneralState.GetModify();
43 pGS->m_Matrix.Concat(matrix);
44 }
45
46 FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const {
47 CFX_FloatRect rect(m_Left, m_Bottom, m_Right, m_Top);
48 if (pMatrix) {
49 pMatrix->TransformRect(rect);
50 }
51 return rect.GetOutterRect();
52 }
53
54 CPDF_TextObject::CPDF_TextObject()
55 : m_PosX(0),
56 m_PosY(0),
57 m_nChars(0),
58 m_pCharCodes(nullptr),
59 m_pCharPos(nullptr) {}
60
61 CPDF_TextObject::~CPDF_TextObject() {
62 if (m_nChars > 1) {
63 FX_Free(m_pCharCodes);
64 }
65 FX_Free(m_pCharPos);
66 }
67
68 void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const {
69 pInfo->m_CharCode =
70 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[index];
71 pInfo->m_OriginX = index ? m_pCharPos[index - 1] : 0;
72 pInfo->m_OriginY = 0;
73 if (pInfo->m_CharCode == -1) {
74 return;
75 }
76 CPDF_Font* pFont = m_TextState.GetFont();
77 if (!pFont->IsCIDFont()) {
78 return;
79 }
80 if (!pFont->AsCIDFont()->IsVertWriting()) {
81 return;
82 }
83 FX_WORD CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode);
84 pInfo->m_OriginY = pInfo->m_OriginX;
85 pInfo->m_OriginX = 0;
86 short vx, vy;
87 pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy);
88 FX_FLOAT fontsize = m_TextState.GetFontSize();
89 pInfo->m_OriginX -= fontsize * vx / 1000;
90 pInfo->m_OriginY -= fontsize * vy / 1000;
91 }
92
93 int CPDF_TextObject::CountChars() const {
94 if (m_nChars == 1) {
95 return 1;
96 }
97 int count = 0;
98 for (int i = 0; i < m_nChars; ++i)
99 if (m_pCharCodes[i] != (FX_DWORD)-1) {
100 ++count;
101 }
102 return count;
103 }
104
105 void CPDF_TextObject::GetCharInfo(int index,
106 FX_DWORD& charcode,
107 FX_FLOAT& kerning) const {
108 if (m_nChars == 1) {
109 charcode = (FX_DWORD)(uintptr_t)m_pCharCodes;
110 kerning = 0;
111 return;
112 }
113 int count = 0;
114 for (int i = 0; i < m_nChars; ++i) {
115 if (m_pCharCodes[i] != (FX_DWORD)-1) {
116 if (count == index) {
117 charcode = m_pCharCodes[i];
118 if (i == m_nChars - 1 || m_pCharCodes[i + 1] != (FX_DWORD)-1) {
119 kerning = 0;
120 } else {
121 kerning = m_pCharPos[i];
122 }
123 return;
124 }
125 ++count;
126 }
127 }
128 }
129
130 void CPDF_TextObject::GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const {
131 if (m_nChars == 1) {
132 GetItemInfo(0, pInfo);
133 return;
134 }
135 int count = 0;
136 for (int i = 0; i < m_nChars; ++i) {
137 FX_DWORD charcode = m_pCharCodes[i];
138 if (charcode == (FX_DWORD)-1) {
139 continue;
140 }
141 if (count == index) {
142 GetItemInfo(i, pInfo);
143 break;
144 }
145 ++count;
146 }
147 }
148
149 CPDF_TextObject* CPDF_TextObject::Clone() const {
150 CPDF_TextObject* obj = new CPDF_TextObject;
151 obj->CopyData(this);
152
153 obj->m_nChars = m_nChars;
154 if (m_nChars > 1) {
155 obj->m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars);
156 FXSYS_memcpy(obj->m_pCharCodes, m_pCharCodes, m_nChars * sizeof(FX_DWORD));
157 obj->m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1);
158 FXSYS_memcpy(obj->m_pCharPos, m_pCharPos,
159 (m_nChars - 1) * sizeof(FX_FLOAT));
160 } else {
161 obj->m_pCharCodes = m_pCharCodes;
162 }
163 obj->m_PosX = m_PosX;
164 obj->m_PosY = m_PosY;
165 return obj;
166 }
167
168 void CPDF_TextObject::GetTextMatrix(CFX_Matrix* pMatrix) const {
169 FX_FLOAT* pTextMatrix = m_TextState.GetMatrix();
170 pMatrix->Set(pTextMatrix[0], pTextMatrix[2], pTextMatrix[1], pTextMatrix[3],
171 m_PosX, m_PosY);
172 }
173
174 void CPDF_TextObject::SetSegments(const CFX_ByteString* pStrs,
175 FX_FLOAT* pKerning,
176 int nsegs) {
177 if (m_nChars > 1) {
178 FX_Free(m_pCharCodes);
179 m_pCharCodes = nullptr;
180 }
181 FX_Free(m_pCharPos);
182 m_pCharPos = nullptr;
183 CPDF_Font* pFont = m_TextState.GetFont();
184 m_nChars = 0;
185 for (int i = 0; i < nsegs; ++i) {
186 m_nChars += pFont->CountChar(pStrs[i], pStrs[i].GetLength());
187 }
188 m_nChars += nsegs - 1;
189 if (m_nChars > 1) {
190 m_pCharCodes = FX_Alloc(FX_DWORD, m_nChars);
191 m_pCharPos = FX_Alloc(FX_FLOAT, m_nChars - 1);
192 int index = 0;
193 for (int i = 0; i < nsegs; ++i) {
194 const FX_CHAR* segment = pStrs[i];
195 int offset = 0, len = pStrs[i].GetLength();
196 while (offset < len) {
197 m_pCharCodes[index++] = pFont->GetNextChar(segment, len, offset);
198 }
199 if (i != nsegs - 1) {
200 m_pCharPos[index - 1] = pKerning[i];
201 m_pCharCodes[index++] = (FX_DWORD)-1;
202 }
203 }
204 } else {
205 int offset = 0;
206 m_pCharCodes = (FX_DWORD*)(uintptr_t)pFont->GetNextChar(
207 pStrs[0], pStrs[0].GetLength(), offset);
208 }
209 }
210
211 void CPDF_TextObject::SetText(const CFX_ByteString& str) {
212 SetSegments(&str, nullptr, 1);
213 RecalcPositionData();
214 }
215
216 FX_FLOAT CPDF_TextObject::GetCharWidth(FX_DWORD charcode) const {
217 FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000;
218 CPDF_Font* pFont = m_TextState.GetFont();
219 FX_BOOL bVertWriting = FALSE;
220 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
221 if (pCIDFont) {
222 bVertWriting = pCIDFont->IsVertWriting();
223 }
224 if (!bVertWriting)
225 return pFont->GetCharWidthF(charcode, 0) * fontsize;
226
227 FX_WORD CID = pCIDFont->CIDFromCharCode(charcode);
228 return pCIDFont->GetVertWidth(CID) * fontsize;
229 }
230
231 void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX,
232 FX_FLOAT* pTextAdvanceY,
233 FX_FLOAT horz_scale,
234 int level) {
235 FX_FLOAT curpos = 0;
236 FX_FLOAT min_x = 10000 * 1.0f;
237 FX_FLOAT max_x = -10000 * 1.0f;
238 FX_FLOAT min_y = 10000 * 1.0f;
239 FX_FLOAT max_y = -10000 * 1.0f;
240 CPDF_Font* pFont = m_TextState.GetFont();
241 FX_BOOL bVertWriting = FALSE;
242 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
243 if (pCIDFont) {
244 bVertWriting = pCIDFont->IsVertWriting();
245 }
246 FX_FLOAT fontsize = m_TextState.GetFontSize();
247 for (int i = 0; i < m_nChars; ++i) {
248 FX_DWORD charcode =
249 m_nChars == 1 ? (FX_DWORD)(uintptr_t)m_pCharCodes : m_pCharCodes[i];
250 if (i > 0) {
251 if (charcode == (FX_DWORD)-1) {
252 curpos -= (m_pCharPos[i - 1] * fontsize) / 1000;
253 continue;
254 }
255 m_pCharPos[i - 1] = curpos;
256 }
257 FX_RECT char_rect = pFont->GetCharBBox(charcode, level);
258 FX_FLOAT charwidth;
259 if (!bVertWriting) {
260 if (min_y > char_rect.top) {
261 min_y = (FX_FLOAT)char_rect.top;
262 }
263 if (max_y < char_rect.top) {
264 max_y = (FX_FLOAT)char_rect.top;
265 }
266 if (min_y > char_rect.bottom) {
267 min_y = (FX_FLOAT)char_rect.bottom;
268 }
269 if (max_y < char_rect.bottom) {
270 max_y = (FX_FLOAT)char_rect.bottom;
271 }
272 FX_FLOAT char_left = curpos + char_rect.left * fontsize / 1000;
273 FX_FLOAT char_right = curpos + char_rect.right * fontsize / 1000;
274 if (min_x > char_left) {
275 min_x = char_left;
276 }
277 if (max_x < char_left) {
278 max_x = char_left;
279 }
280 if (min_x > char_right) {
281 min_x = char_right;
282 }
283 if (max_x < char_right) {
284 max_x = char_right;
285 }
286 charwidth = pFont->GetCharWidthF(charcode, level) * fontsize / 1000;
287 } else {
288 FX_WORD CID = pCIDFont->CIDFromCharCode(charcode);
289 short vx;
290 short vy;
291 pCIDFont->GetVertOrigin(CID, vx, vy);
292 char_rect.left -= vx;
293 char_rect.right -= vx;
294 char_rect.top -= vy;
295 char_rect.bottom -= vy;
296 if (min_x > char_rect.left) {
297 min_x = (FX_FLOAT)char_rect.left;
298 }
299 if (max_x < char_rect.left) {
300 max_x = (FX_FLOAT)char_rect.left;
301 }
302 if (min_x > char_rect.right) {
303 min_x = (FX_FLOAT)char_rect.right;
304 }
305 if (max_x < char_rect.right) {
306 max_x = (FX_FLOAT)char_rect.right;
307 }
308 FX_FLOAT char_top = curpos + char_rect.top * fontsize / 1000;
309 FX_FLOAT char_bottom = curpos + char_rect.bottom * fontsize / 1000;
310 if (min_y > char_top) {
311 min_y = char_top;
312 }
313 if (max_y < char_top) {
314 max_y = char_top;
315 }
316 if (min_y > char_bottom) {
317 min_y = char_bottom;
318 }
319 if (max_y < char_bottom) {
320 max_y = char_bottom;
321 }
322 charwidth = pCIDFont->GetVertWidth(CID) * fontsize / 1000;
323 }
324 curpos += charwidth;
325 if (charcode == ' ' && (!pCIDFont || pCIDFont->GetCharSize(32) == 1)) {
326 curpos += m_TextState.GetObject()->m_WordSpace;
327 }
328 curpos += m_TextState.GetObject()->m_CharSpace;
329 }
330 if (bVertWriting) {
331 if (pTextAdvanceX) {
332 *pTextAdvanceX = 0;
333 }
334 if (pTextAdvanceY) {
335 *pTextAdvanceY = curpos;
336 }
337 min_x = min_x * fontsize / 1000;
338 max_x = max_x * fontsize / 1000;
339 } else {
340 if (pTextAdvanceX) {
341 *pTextAdvanceX = curpos * horz_scale;
342 }
343 if (pTextAdvanceY) {
344 *pTextAdvanceY = 0;
345 }
346 min_y = min_y * fontsize / 1000;
347 max_y = max_y * fontsize / 1000;
348 }
349 CFX_Matrix matrix;
350 GetTextMatrix(&matrix);
351 m_Left = min_x;
352 m_Right = max_x;
353 m_Bottom = min_y;
354 m_Top = max_y;
355 matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
356 int textmode = m_TextState.GetObject()->m_TextMode;
357 if (textmode == 1 || textmode == 2 || textmode == 5 || textmode == 6) {
358 FX_FLOAT half_width = m_GraphState.GetObject()->m_LineWidth / 2;
359 m_Left -= half_width;
360 m_Right += half_width;
361 m_Top += half_width;
362 m_Bottom -= half_width;
363 }
364 }
365
366 void CPDF_TextObject::Transform(const CFX_Matrix& matrix) {
367 m_TextState.GetModify();
368 CFX_Matrix text_matrix;
369 GetTextMatrix(&text_matrix);
370 text_matrix.Concat(matrix);
371 FX_FLOAT* pTextMatrix = m_TextState.GetMatrix();
372 pTextMatrix[0] = text_matrix.GetA();
373 pTextMatrix[1] = text_matrix.GetC();
374 pTextMatrix[2] = text_matrix.GetB();
375 pTextMatrix[3] = text_matrix.GetD();
376 m_PosX = text_matrix.GetE();
377 m_PosY = text_matrix.GetF();
378 CalcPositionData(nullptr, nullptr, 0);
379 }
380
381 void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) {
382 FX_FLOAT dx = x - m_PosX;
383 FX_FLOAT dy = y - m_PosY;
384 m_PosX = x;
385 m_PosY = y;
386 m_Left += dx;
387 m_Right += dx;
388 m_Top += dy;
389 m_Bottom += dy;
390 }
391
392 CPDF_ShadingObject::CPDF_ShadingObject() : m_pShading(nullptr) {}
393
394 CPDF_ShadingObject::~CPDF_ShadingObject() {}
395
396 CPDF_ShadingObject* CPDF_ShadingObject::Clone() const {
397 CPDF_ShadingObject* obj = new CPDF_ShadingObject;
398 obj->CopyData(this);
399
400 obj->m_pShading = m_pShading;
401 if (obj->m_pShading && obj->m_pShading->m_pDocument) {
402 CPDF_DocPageData* pDocPageData =
403 obj->m_pShading->m_pDocument->GetPageData();
404 obj->m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern(
405 obj->m_pShading->m_pShadingObj, m_pShading->m_bShadingObj,
406 &obj->m_pShading->m_ParentMatrix);
407 }
408 obj->m_Matrix = m_Matrix;
409 return obj;
410 }
411
412 void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) {
413 if (!m_ClipPath.IsNull()) {
414 m_ClipPath.GetModify();
415 m_ClipPath.Transform(matrix);
416 }
417 m_Matrix.Concat(matrix);
418 if (!m_ClipPath.IsNull()) {
419 CalcBoundingBox();
420 } else {
421 matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
422 }
423 }
424
425 void CPDF_ShadingObject::CalcBoundingBox() {
426 if (m_ClipPath.IsNull()) {
427 return;
428 }
429 CFX_FloatRect rect = m_ClipPath.GetClipBox();
430 m_Left = rect.left;
431 m_Bottom = rect.bottom;
432 m_Right = rect.right;
433 m_Top = rect.top;
434 }
435
436 CPDF_FormObject::CPDF_FormObject() : m_pForm(nullptr) {}
437
438 CPDF_FormObject::~CPDF_FormObject() {
439 delete m_pForm;
440 }
441
442 void CPDF_FormObject::Transform(const CFX_Matrix& matrix) {
443 m_FormMatrix.Concat(matrix);
444 CalcBoundingBox();
445 }
446
447 CPDF_FormObject* CPDF_FormObject::Clone() const {
448 CPDF_FormObject* obj = new CPDF_FormObject;
449 obj->CopyData(this);
450
451 obj->m_pForm = m_pForm->Clone();
452 obj->m_FormMatrix = m_FormMatrix;
453 return obj;
454 }
455
456 void CPDF_FormObject::CalcBoundingBox() {
457 CFX_FloatRect form_rect = m_pForm->CalcBoundingBox();
458 form_rect.Transform(&m_FormMatrix);
459 m_Left = form_rect.left;
460 m_Bottom = form_rect.bottom;
461 m_Right = form_rect.right;
462 m_Top = form_rect.top;
463 }
464
465 CPDF_PageObject* CPDF_PageObjectList::GetPageObjectByIndex(int index) {
466 if (index < 0 || index >= pdfium::CollectionSize<int>(*this))
467 return nullptr;
468 return (*this)[index].get();
469 }
470
471 CPDF_PageObjectHolder::CPDF_PageObjectHolder()
472 : m_pFormDict(nullptr),
473 m_pFormStream(nullptr),
474 m_pDocument(nullptr),
475 m_pPageResources(nullptr),
476 m_pResources(nullptr),
477 m_Transparency(0),
478 m_bBackgroundAlphaNeeded(FALSE),
479 m_bHasImageMask(FALSE),
480 m_ParseState(CONTENT_NOT_PARSED) {}
481
482 void CPDF_PageObjectHolder::ContinueParse(IFX_Pause* pPause) {
483 if (!m_pParser) {
484 return;
485 }
486 m_pParser->Continue(pPause);
487 if (m_pParser->GetStatus() == CPDF_ContentParser::Done) {
488 m_ParseState = CONTENT_PARSED;
489 m_pParser.reset();
490 }
491 }
492
493 void CPDF_PageObjectHolder::Transform(const CFX_Matrix& matrix) {
494 for (auto& pObj : m_PageObjectList)
495 pObj->Transform(matrix);
496 }
497
498 CFX_FloatRect CPDF_PageObjectHolder::CalcBoundingBox() const {
499 if (m_PageObjectList.empty())
500 return CFX_FloatRect(0, 0, 0, 0);
501
502 FX_FLOAT left = 1000000.0f;
503 FX_FLOAT right = -1000000.0f;
504 FX_FLOAT bottom = 1000000.0f;
505 FX_FLOAT top = -1000000.0f;
506 for (const auto& pObj : m_PageObjectList) {
507 left = std::min(left, pObj->m_Left);
508 right = std::max(right, pObj->m_Right);
509 bottom = std::min(bottom, pObj->m_Bottom);
510 top = std::max(top, pObj->m_Top);
511 }
512 return CFX_FloatRect(left, bottom, right, top);
513 }
514
515 void CPDF_PageObjectHolder::LoadTransInfo() {
516 if (!m_pFormDict) {
517 return;
518 }
519 CPDF_Dictionary* pGroup = m_pFormDict->GetDictBy("Group");
520 if (!pGroup) {
521 return;
522 }
523 if (pGroup->GetStringBy("S") != "Transparency") {
524 return;
525 }
526 m_Transparency |= PDFTRANS_GROUP;
527 if (pGroup->GetIntegerBy("I")) {
528 m_Transparency |= PDFTRANS_ISOLATED;
529 }
530 if (pGroup->GetIntegerBy("K")) {
531 m_Transparency |= PDFTRANS_KNOCKOUT;
532 }
533 }
534
535 CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {}
536
537 void CPDF_Page::Load(CPDF_Document* pDocument,
538 CPDF_Dictionary* pPageDict,
539 FX_BOOL bPageCache) {
540 m_pDocument = (CPDF_Document*)pDocument;
541 m_pFormDict = pPageDict;
542 if (bPageCache) {
543 m_pPageRender =
544 CPDF_ModuleMgr::Get()->GetRenderModule()->CreatePageCache(this);
545 }
546 if (!pPageDict) {
547 m_PageWidth = m_PageHeight = 100 * 1.0f;
548 m_pPageResources = m_pResources = NULL;
549 return;
550 }
551 CPDF_Object* pageAttr = GetPageAttr("Resources");
552 m_pResources = pageAttr ? pageAttr->GetDict() : NULL;
553 m_pPageResources = m_pResources;
554 CPDF_Object* pRotate = GetPageAttr("Rotate");
555 int rotate = 0;
556 if (pRotate) {
557 rotate = pRotate->GetInteger() / 90 % 4;
558 }
559 if (rotate < 0) {
560 rotate += 4;
561 }
562 CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox"));
563 CFX_FloatRect mediabox;
564 if (pMediaBox) {
565 mediabox = pMediaBox->GetRect();
566 mediabox.Normalize();
567 }
568 if (mediabox.IsEmpty()) {
569 mediabox = CFX_FloatRect(0, 0, 612, 792);
570 }
571
572 CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox"));
573 if (pCropBox) {
574 m_BBox = pCropBox->GetRect();
575 m_BBox.Normalize();
576 }
577 if (m_BBox.IsEmpty()) {
578 m_BBox = mediabox;
579 } else {
580 m_BBox.Intersect(mediabox);
581 }
582 if (rotate % 2) {
583 m_PageHeight = m_BBox.right - m_BBox.left;
584 m_PageWidth = m_BBox.top - m_BBox.bottom;
585 } else {
586 m_PageWidth = m_BBox.right - m_BBox.left;
587 m_PageHeight = m_BBox.top - m_BBox.bottom;
588 }
589 switch (rotate) {
590 case 0:
591 m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom);
592 break;
593 case 1:
594 m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right);
595 break;
596 case 2:
597 m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top);
598 break;
599 case 3:
600 m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left);
601 break;
602 }
603 m_Transparency = PDFTRANS_ISOLATED;
604 LoadTransInfo();
605 }
606
607 void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) {
608 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) {
609 return;
610 }
611 m_pParser.reset(new CPDF_ContentParser);
612 m_pParser->Start(this, pOptions);
613 m_ParseState = CONTENT_PARSING;
614 }
615
616 void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) {
617 StartParse(pOptions);
618 ContinueParse(nullptr);
619 }
620
621 CPDF_Page::~CPDF_Page() {
622 if (m_pPageRender) {
623 IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule();
624 pModule->DestroyPageCache(m_pPageRender);
625 }
626 }
627
628 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict,
629 const CFX_ByteStringC& name) {
630 int level = 0;
631 while (1) {
632 CPDF_Object* pObj = pPageDict->GetElementValue(name);
633 if (pObj) {
634 return pObj;
635 }
636 CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent");
637 if (!pParent || pParent == pPageDict) {
638 return NULL;
639 }
640 pPageDict = pParent;
641 level++;
642 if (level == 1000) {
643 return NULL;
644 }
645 }
646 }
647
648 CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const {
649 return FPDFAPI_GetPageAttr(m_pFormDict, name);
650 }
651
652 CPDF_Form::CPDF_Form(CPDF_Document* pDoc,
653 CPDF_Dictionary* pPageResources,
654 CPDF_Stream* pFormStream,
655 CPDF_Dictionary* pParentResources) {
656 m_pDocument = pDoc;
657 m_pFormStream = pFormStream;
658 m_pFormDict = pFormStream ? pFormStream->GetDict() : NULL;
659 m_pResources = m_pFormDict->GetDictBy("Resources");
660 m_pPageResources = pPageResources;
661 if (!m_pResources) {
662 m_pResources = pParentResources;
663 }
664 if (!m_pResources) {
665 m_pResources = pPageResources;
666 }
667 m_Transparency = 0;
668 LoadTransInfo();
669 }
670
671 CPDF_Form::~CPDF_Form() {}
672
673 void CPDF_Form::StartParse(CPDF_AllStates* pGraphicStates,
674 CFX_Matrix* pParentMatrix,
675 CPDF_Type3Char* pType3Char,
676 CPDF_ParseOptions* pOptions,
677 int level) {
678 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) {
679 return;
680 }
681 m_pParser.reset(new CPDF_ContentParser);
682 m_pParser->Start(this, pGraphicStates, pParentMatrix, pType3Char, pOptions,
683 level);
684 m_ParseState = CONTENT_PARSING;
685 }
686
687 void CPDF_Form::ParseContent(CPDF_AllStates* pGraphicStates,
688 CFX_Matrix* pParentMatrix,
689 CPDF_Type3Char* pType3Char,
690 CPDF_ParseOptions* pOptions,
691 int level) {
692 StartParse(pGraphicStates, pParentMatrix, pType3Char, pOptions, level);
693 ContinueParse(NULL);
694 }
695
696 CPDF_Form* CPDF_Form::Clone() const {
697 CPDF_Form* pCloneForm =
698 new CPDF_Form(m_pDocument, m_pPageResources, m_pFormStream, m_pResources);
699 for (const auto& pObj : m_PageObjectList)
700 pCloneForm->m_PageObjectList.emplace_back(pObj->Clone());
701
702 return pCloneForm;
703 }
704
705 void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix,
706 int xPos,
707 int yPos,
708 int xSize,
709 int ySize,
710 int iRotate) const {
711 if (m_PageWidth == 0 || m_PageHeight == 0) {
712 return;
713 }
714 CFX_Matrix display_matrix;
715 int x0, y0, x1, y1, x2, y2;
716 iRotate %= 4;
717 switch (iRotate) {
718 case 0:
719 x0 = xPos;
720 y0 = yPos + ySize;
721 x1 = xPos;
722 y1 = yPos;
723 x2 = xPos + xSize;
724 y2 = yPos + ySize;
725 break;
726 case 1:
727 x0 = xPos;
728 y0 = yPos;
729 x1 = xPos + xSize;
730 y1 = yPos;
731 x2 = xPos;
732 y2 = yPos + ySize;
733 break;
734 case 2:
735 x0 = xPos + xSize;
736 y0 = yPos;
737 x1 = xPos + xSize;
738 y1 = yPos + ySize;
739 x2 = xPos;
740 y2 = yPos;
741 break;
742 case 3:
743 x0 = xPos + xSize;
744 y0 = yPos + ySize;
745 x1 = xPos;
746 y1 = yPos + ySize;
747 x2 = xPos + xSize;
748 y2 = yPos;
749 break;
750 }
751 display_matrix.Set(
752 ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth,
753 ((FX_FLOAT)(x1 - x0)) / m_PageHeight,
754 ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0);
755 matrix = m_PageMatrix;
756 matrix.Concat(display_matrix);
757 }
758
759 CPDF_ParseOptions::CPDF_ParseOptions() {
760 m_bTextOnly = FALSE;
761 m_bMarkedContent = TRUE;
762 m_bSeparateForm = TRUE;
763 m_bDecodeInlineImage = FALSE;
764 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_font/ttgsubtable.cpp ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698