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

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_textobject.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
OLDNEW
1 // Copyright 2014 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/pageint.h" 7 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
8
9 #include <algorithm>
10
11 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
12 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
15 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
16 #include "core/fpdfapi/include/cpdf_modulemgr.h"
17 #include "core/fpdfapi/ipdf_rendermodule.h"
18 #include "third_party/base/stl_util.h"
19
20 CPDF_PageObject::CPDF_PageObject() {}
21
22 CPDF_PageObject::~CPDF_PageObject() {}
23
24 void CPDF_PageObject::CopyData(const CPDF_PageObject* pSrc) {
25 CopyStates(*pSrc);
26 m_Left = pSrc->m_Left;
27 m_Right = pSrc->m_Right;
28 m_Top = pSrc->m_Top;
29 m_Bottom = pSrc->m_Bottom;
30 }
31
32 void CPDF_PageObject::TransformClipPath(CFX_Matrix& matrix) {
33 if (m_ClipPath.IsNull()) {
34 return;
35 }
36 m_ClipPath.GetModify();
37 m_ClipPath.Transform(matrix);
38 }
39
40 void CPDF_PageObject::TransformGeneralState(CFX_Matrix& matrix) {
41 if (m_GeneralState.IsNull()) {
42 return;
43 }
44 CPDF_GeneralStateData* pGS = m_GeneralState.GetModify();
45 pGS->m_Matrix.Concat(matrix);
46 }
47
48 FX_RECT CPDF_PageObject::GetBBox(const CFX_Matrix* pMatrix) const {
49 CFX_FloatRect rect(m_Left, m_Bottom, m_Right, m_Top);
50 if (pMatrix) {
51 pMatrix->TransformRect(rect);
52 }
53 return rect.GetOutterRect();
54 }
55 8
56 CPDF_TextObject::CPDF_TextObject() 9 CPDF_TextObject::CPDF_TextObject()
57 : m_PosX(0), 10 : m_PosX(0),
58 m_PosY(0), 11 m_PosY(0),
59 m_nChars(0), 12 m_nChars(0),
60 m_pCharCodes(nullptr), 13 m_pCharCodes(nullptr),
61 m_pCharPos(nullptr) {} 14 m_pCharPos(nullptr) {}
62 15
63 CPDF_TextObject::~CPDF_TextObject() { 16 CPDF_TextObject::~CPDF_TextObject() {
64 if (m_nChars > 1) { 17 if (m_nChars > 1) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) { 336 void CPDF_TextObject::SetPosition(FX_FLOAT x, FX_FLOAT y) {
384 FX_FLOAT dx = x - m_PosX; 337 FX_FLOAT dx = x - m_PosX;
385 FX_FLOAT dy = y - m_PosY; 338 FX_FLOAT dy = y - m_PosY;
386 m_PosX = x; 339 m_PosX = x;
387 m_PosY = y; 340 m_PosY = y;
388 m_Left += dx; 341 m_Left += dx;
389 m_Right += dx; 342 m_Right += dx;
390 m_Top += dy; 343 m_Top += dy;
391 m_Bottom += dy; 344 m_Bottom += dy;
392 } 345 }
393
394 CPDF_ShadingObject::CPDF_ShadingObject() : m_pShading(nullptr) {}
395
396 CPDF_ShadingObject::~CPDF_ShadingObject() {}
397
398 CPDF_ShadingObject* CPDF_ShadingObject::Clone() const {
399 CPDF_ShadingObject* obj = new CPDF_ShadingObject;
400 obj->CopyData(this);
401
402 obj->m_pShading = m_pShading;
403 if (obj->m_pShading && obj->m_pShading->m_pDocument) {
404 CPDF_DocPageData* pDocPageData =
405 obj->m_pShading->m_pDocument->GetPageData();
406 obj->m_pShading = (CPDF_ShadingPattern*)pDocPageData->GetPattern(
407 obj->m_pShading->m_pShadingObj, m_pShading->m_bShadingObj,
408 &obj->m_pShading->m_ParentMatrix);
409 }
410 obj->m_Matrix = m_Matrix;
411 return obj;
412 }
413
414 void CPDF_ShadingObject::Transform(const CFX_Matrix& matrix) {
415 if (!m_ClipPath.IsNull()) {
416 m_ClipPath.GetModify();
417 m_ClipPath.Transform(matrix);
418 }
419 m_Matrix.Concat(matrix);
420 if (!m_ClipPath.IsNull()) {
421 CalcBoundingBox();
422 } else {
423 matrix.TransformRect(m_Left, m_Right, m_Top, m_Bottom);
424 }
425 }
426
427 void CPDF_ShadingObject::CalcBoundingBox() {
428 if (m_ClipPath.IsNull()) {
429 return;
430 }
431 CFX_FloatRect rect = m_ClipPath.GetClipBox();
432 m_Left = rect.left;
433 m_Bottom = rect.bottom;
434 m_Right = rect.right;
435 m_Top = rect.top;
436 }
437
438 CPDF_FormObject::CPDF_FormObject() : m_pForm(nullptr) {}
439
440 CPDF_FormObject::~CPDF_FormObject() {
441 delete m_pForm;
442 }
443
444 void CPDF_FormObject::Transform(const CFX_Matrix& matrix) {
445 m_FormMatrix.Concat(matrix);
446 CalcBoundingBox();
447 }
448
449 CPDF_FormObject* CPDF_FormObject::Clone() const {
450 CPDF_FormObject* obj = new CPDF_FormObject;
451 obj->CopyData(this);
452
453 obj->m_pForm = m_pForm->Clone();
454 obj->m_FormMatrix = m_FormMatrix;
455 return obj;
456 }
457
458 void CPDF_FormObject::CalcBoundingBox() {
459 CFX_FloatRect form_rect = m_pForm->CalcBoundingBox();
460 form_rect.Transform(&m_FormMatrix);
461 m_Left = form_rect.left;
462 m_Bottom = form_rect.bottom;
463 m_Right = form_rect.right;
464 m_Top = form_rect.top;
465 }
466
467 CPDF_Page::CPDF_Page() : m_pPageRender(nullptr) {}
468
469 void CPDF_Page::Load(CPDF_Document* pDocument,
470 CPDF_Dictionary* pPageDict,
471 FX_BOOL bPageCache) {
472 m_pDocument = (CPDF_Document*)pDocument;
473 m_pFormDict = pPageDict;
474 if (bPageCache) {
475 m_pPageRender =
476 CPDF_ModuleMgr::Get()->GetRenderModule()->CreatePageCache(this);
477 }
478 if (!pPageDict) {
479 m_PageWidth = m_PageHeight = 100 * 1.0f;
480 m_pPageResources = m_pResources = NULL;
481 return;
482 }
483 CPDF_Object* pageAttr = GetPageAttr("Resources");
484 m_pResources = pageAttr ? pageAttr->GetDict() : NULL;
485 m_pPageResources = m_pResources;
486 CPDF_Object* pRotate = GetPageAttr("Rotate");
487 int rotate = 0;
488 if (pRotate) {
489 rotate = pRotate->GetInteger() / 90 % 4;
490 }
491 if (rotate < 0) {
492 rotate += 4;
493 }
494 CPDF_Array* pMediaBox = ToArray(GetPageAttr("MediaBox"));
495 CFX_FloatRect mediabox;
496 if (pMediaBox) {
497 mediabox = pMediaBox->GetRect();
498 mediabox.Normalize();
499 }
500 if (mediabox.IsEmpty()) {
501 mediabox = CFX_FloatRect(0, 0, 612, 792);
502 }
503
504 CPDF_Array* pCropBox = ToArray(GetPageAttr("CropBox"));
505 if (pCropBox) {
506 m_BBox = pCropBox->GetRect();
507 m_BBox.Normalize();
508 }
509 if (m_BBox.IsEmpty()) {
510 m_BBox = mediabox;
511 } else {
512 m_BBox.Intersect(mediabox);
513 }
514 if (rotate % 2) {
515 m_PageHeight = m_BBox.right - m_BBox.left;
516 m_PageWidth = m_BBox.top - m_BBox.bottom;
517 } else {
518 m_PageWidth = m_BBox.right - m_BBox.left;
519 m_PageHeight = m_BBox.top - m_BBox.bottom;
520 }
521 switch (rotate) {
522 case 0:
523 m_PageMatrix.Set(1.0f, 0, 0, 1.0f, -m_BBox.left, -m_BBox.bottom);
524 break;
525 case 1:
526 m_PageMatrix.Set(0, -1.0f, 1.0f, 0, -m_BBox.bottom, m_BBox.right);
527 break;
528 case 2:
529 m_PageMatrix.Set(-1.0f, 0, 0, -1.0f, m_BBox.right, m_BBox.top);
530 break;
531 case 3:
532 m_PageMatrix.Set(0, 1.0f, -1.0f, 0, m_BBox.top, -m_BBox.left);
533 break;
534 }
535 m_Transparency = PDFTRANS_ISOLATED;
536 LoadTransInfo();
537 }
538
539 void CPDF_Page::StartParse(CPDF_ParseOptions* pOptions) {
540 if (m_ParseState == CONTENT_PARSED || m_ParseState == CONTENT_PARSING) {
541 return;
542 }
543 m_pParser.reset(new CPDF_ContentParser);
544 m_pParser->Start(this, pOptions);
545 m_ParseState = CONTENT_PARSING;
546 }
547
548 void CPDF_Page::ParseContent(CPDF_ParseOptions* pOptions) {
549 StartParse(pOptions);
550 ContinueParse(nullptr);
551 }
552
553 CPDF_Page::~CPDF_Page() {
554 if (m_pPageRender) {
555 IPDF_RenderModule* pModule = CPDF_ModuleMgr::Get()->GetRenderModule();
556 pModule->DestroyPageCache(m_pPageRender);
557 }
558 }
559
560 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict,
561 const CFX_ByteStringC& name) {
562 int level = 0;
563 while (1) {
564 CPDF_Object* pObj = pPageDict->GetElementValue(name);
565 if (pObj) {
566 return pObj;
567 }
568 CPDF_Dictionary* pParent = pPageDict->GetDictBy("Parent");
569 if (!pParent || pParent == pPageDict) {
570 return NULL;
571 }
572 pPageDict = pParent;
573 level++;
574 if (level == 1000) {
575 return NULL;
576 }
577 }
578 }
579
580 CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteStringC& name) const {
581 return FPDFAPI_GetPageAttr(m_pFormDict, name);
582 }
583
584 void CPDF_Page::GetDisplayMatrix(CFX_Matrix& matrix,
585 int xPos,
586 int yPos,
587 int xSize,
588 int ySize,
589 int iRotate) const {
590 if (m_PageWidth == 0 || m_PageHeight == 0) {
591 return;
592 }
593 CFX_Matrix display_matrix;
594 int x0, y0, x1, y1, x2, y2;
595 iRotate %= 4;
596 switch (iRotate) {
597 case 0:
598 x0 = xPos;
599 y0 = yPos + ySize;
600 x1 = xPos;
601 y1 = yPos;
602 x2 = xPos + xSize;
603 y2 = yPos + ySize;
604 break;
605 case 1:
606 x0 = xPos;
607 y0 = yPos;
608 x1 = xPos + xSize;
609 y1 = yPos;
610 x2 = xPos;
611 y2 = yPos + ySize;
612 break;
613 case 2:
614 x0 = xPos + xSize;
615 y0 = yPos;
616 x1 = xPos + xSize;
617 y1 = yPos + ySize;
618 x2 = xPos;
619 y2 = yPos;
620 break;
621 case 3:
622 x0 = xPos + xSize;
623 y0 = yPos + ySize;
624 x1 = xPos;
625 y1 = yPos + ySize;
626 x2 = xPos + xSize;
627 y2 = yPos;
628 break;
629 }
630 display_matrix.Set(
631 ((FX_FLOAT)(x2 - x0)) / m_PageWidth, ((FX_FLOAT)(y2 - y0)) / m_PageWidth,
632 ((FX_FLOAT)(x1 - x0)) / m_PageHeight,
633 ((FX_FLOAT)(y1 - y0)) / m_PageHeight, (FX_FLOAT)x0, (FX_FLOAT)y0);
634 matrix = m_PageMatrix;
635 matrix.Concat(display_matrix);
636 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698