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

Side by Side Diff: core/fpdfdoc/cpvt_generateap.cpp

Issue 2345063002: Use string pools in some dictionaries (Closed)
Patch Set: Remove default ctor Created 4 years, 3 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 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/fpdfdoc/cpvt_generateap.h" 7 #include "core/fpdfdoc/cpvt_generateap.h"
8 8
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 CPDF_Dictionary* pDRDict = pFormDict->GetDictFor("DR"); 49 CPDF_Dictionary* pDRDict = pFormDict->GetDictFor("DR");
50 if (!pDRDict) 50 if (!pDRDict)
51 return false; 51 return false;
52 52
53 CPDF_Dictionary* pDRFontDict = pDRDict->GetDictFor("Font"); 53 CPDF_Dictionary* pDRFontDict = pDRDict->GetDictFor("Font");
54 if (!pDRFontDict) 54 if (!pDRFontDict)
55 return false; 55 return false;
56 56
57 CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(sFontName.Mid(1)); 57 CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(sFontName.Mid(1));
58 if (!pFontDict) { 58 if (!pFontDict) {
59 pFontDict = new CPDF_Dictionary; 59 pFontDict = new CPDF_Dictionary(pDoc);
60 pFontDict->SetNameFor("Type", "Font"); 60 pFontDict->SetNameFor("Type", "Font");
61 pFontDict->SetNameFor("Subtype", "Type1"); 61 pFontDict->SetNameFor("Subtype", "Type1");
62 pFontDict->SetNameFor("BaseFont", "Helvetica"); 62 pFontDict->SetNameFor("BaseFont", "Helvetica");
63 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); 63 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding");
64 pDoc->AddIndirectObject(pFontDict); 64 pDoc->AddIndirectObject(pFontDict);
65 pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, pFontDict); 65 pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, pFontDict);
66 } 66 }
67 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); 67 CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict);
68 if (!pDefFont) 68 if (!pDefFont)
69 return false; 69 return false;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 dsBorder); 154 dsBorder);
155 if (sBorderStream.GetLength() > 0) 155 if (sBorderStream.GetLength() > 0)
156 sAppStream << "q\n" << sBorderStream << "Q\n"; 156 sAppStream << "q\n" << sBorderStream << "Q\n";
157 157
158 CFX_FloatRect rcBody = 158 CFX_FloatRect rcBody =
159 CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth, 159 CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth,
160 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth); 160 rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth);
161 rcBody.Normalize(); 161 rcBody.Normalize();
162 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP"); 162 CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP");
163 if (!pAPDict) { 163 if (!pAPDict) {
164 pAPDict = new CPDF_Dictionary; 164 pAPDict = new CPDF_Dictionary(pDoc);
165 pAnnotDict->SetFor("AP", pAPDict); 165 pAnnotDict->SetFor("AP", pAPDict);
166 } 166 }
167 CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N"); 167 CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N");
168 if (!pNormalStream) { 168 if (!pNormalStream) {
169 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); 169 pNormalStream = new CPDF_Stream(nullptr, 0, nullptr);
170 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); 170 int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
171 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum); 171 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum);
172 } 172 }
173 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); 173 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
174 if (pStreamDict) { 174 if (pStreamDict) {
175 pStreamDict->SetMatrixFor("Matrix", matrix); 175 pStreamDict->SetMatrixFor("Matrix", matrix);
176 pStreamDict->SetRectFor("BBox", rcBBox); 176 pStreamDict->SetRectFor("BBox", rcBBox);
177 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); 177 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
178 if (pStreamResList) { 178 if (pStreamResList) {
179 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); 179 CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
180 if (!pStreamResFontList) { 180 if (!pStreamResFontList) {
181 pStreamResFontList = new CPDF_Dictionary; 181 pStreamResFontList = new CPDF_Dictionary(pDoc);
182 pStreamResList->SetFor("Font", pStreamResFontList); 182 pStreamResList->SetFor("Font", pStreamResFontList);
183 } 183 }
184 if (!pStreamResFontList->KeyExist(sFontName)) 184 if (!pStreamResFontList->KeyExist(sFontName))
185 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict); 185 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict);
186 } else { 186 } else {
187 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone()); 187 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone());
188 pStreamResList = pStreamDict->GetDictFor("Resources"); 188 pStreamResList = pStreamDict->GetDictFor("Resources");
189 } 189 }
190 } 190 }
191 switch (nWidgetType) { 191 switch (nWidgetType) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 FALSE); 422 FALSE);
423 pStreamDict = pNormalStream->GetDict(); 423 pStreamDict = pNormalStream->GetDict();
424 if (pStreamDict) { 424 if (pStreamDict) {
425 pStreamDict->SetMatrixFor("Matrix", matrix); 425 pStreamDict->SetMatrixFor("Matrix", matrix);
426 pStreamDict->SetRectFor("BBox", rcBBox); 426 pStreamDict->SetRectFor("BBox", rcBBox);
427 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); 427 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
428 if (pStreamResList) { 428 if (pStreamResList) {
429 CPDF_Dictionary* pStreamResFontList = 429 CPDF_Dictionary* pStreamResFontList =
430 pStreamResList->GetDictFor("Font"); 430 pStreamResList->GetDictFor("Font");
431 if (!pStreamResFontList) { 431 if (!pStreamResFontList) {
432 pStreamResFontList = new CPDF_Dictionary; 432 pStreamResFontList = new CPDF_Dictionary(pDoc);
433 pStreamResList->SetFor("Font", pStreamResFontList); 433 pStreamResList->SetFor("Font", pStreamResFontList);
434 } 434 }
435 if (!pStreamResFontList->KeyExist(sFontName)) 435 if (!pStreamResFontList->KeyExist(sFontName))
436 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict); 436 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict);
437 } else { 437 } else {
438 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone()); 438 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone());
439 pStreamResList = pStreamDict->GetDictFor("Resources"); 439 pStreamResList = pStreamDict->GetDictFor("Resources");
440 } 440 }
441 } 441 }
442 } 442 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 << CPVT_GenerateAP::GenerateColorAP( 531 << CPVT_GenerateAP::GenerateColorAP(
532 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL) 532 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL)
533 << sContent << "ET\n" 533 << sContent << "ET\n"
534 << "Q\n"; 534 << "Q\n";
535 return sAppStream.MakeString(); 535 return sAppStream.MakeString();
536 } 536 }
537 537
538 CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict, 538 CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict,
539 const CFX_ByteString& sExtGSDictName, 539 const CFX_ByteString& sExtGSDictName,
540 const CFX_ByteString& sBlendMode) { 540 const CFX_ByteString& sBlendMode) {
541 CPDF_Dictionary* pGSDict = new CPDF_Dictionary; 541 CPDF_Dictionary* pGSDict =
542 new CPDF_Dictionary(pAnnotDict.GetByteStringPool());
542 pGSDict->SetStringFor("Type", "ExtGState"); 543 pGSDict->SetStringFor("Type", "ExtGState");
543 544
544 FX_FLOAT fOpacity = 545 FX_FLOAT fOpacity =
545 pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberFor("CA") : 1; 546 pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberFor("CA") : 1;
546 pGSDict->SetNumberFor("CA", fOpacity); 547 pGSDict->SetNumberFor("CA", fOpacity);
547 pGSDict->SetNumberFor("ca", fOpacity); 548 pGSDict->SetNumberFor("ca", fOpacity);
548 pGSDict->SetBooleanFor("AIS", false); 549 pGSDict->SetBooleanFor("AIS", false);
549 pGSDict->SetStringFor("BM", sBlendMode); 550 pGSDict->SetStringFor("BM", sBlendMode);
550 551
551 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; 552 CPDF_Dictionary* pExtGStateDict =
553 new CPDF_Dictionary(pAnnotDict.GetByteStringPool());
552 pExtGStateDict->SetFor(sExtGSDictName, pGSDict); 554 pExtGStateDict->SetFor(sExtGSDictName, pGSDict);
553
554 return pExtGStateDict; 555 return pExtGStateDict;
555 } 556 }
556 557
557 CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc, 558 CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc,
558 const CFX_ByteString& sFontDictName) { 559 const CFX_ByteString& sFontDictName) {
559 CPDF_Dictionary* pFontDict = new CPDF_Dictionary; 560 CPDF_Dictionary* pFontDict = new CPDF_Dictionary(pDoc);
560 pFontDict->SetNameFor("Type", "Font"); 561 pFontDict->SetNameFor("Type", "Font");
561 pFontDict->SetNameFor("Subtype", "Type1"); 562 pFontDict->SetNameFor("Subtype", "Type1");
562 pFontDict->SetNameFor("BaseFont", "Helvetica"); 563 pFontDict->SetNameFor("BaseFont", "Helvetica");
563 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); 564 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding");
564 pDoc->AddIndirectObject(pFontDict); 565 pDoc->AddIndirectObject(pFontDict);
565 566
566 CPDF_Dictionary* pResourceFontDict = new CPDF_Dictionary; 567 CPDF_Dictionary* pResourceFontDict = new CPDF_Dictionary(pDoc);
567 pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict); 568 pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict);
568
569 return pResourceFontDict; 569 return pResourceFontDict;
570 } 570 }
571 571
572 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|. 572 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|.
573 CPDF_Dictionary* GenerateResourceDict(CPDF_Dictionary* pExtGStateDict, 573 CPDF_Dictionary* GenerateResourceDict(CPDF_Document* pDoc,
574 CPDF_Dictionary* pExtGStateDict,
574 CPDF_Dictionary* pResourceFontDict) { 575 CPDF_Dictionary* pResourceFontDict) {
575 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; 576 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary(pDoc);
576 if (pExtGStateDict) 577 if (pExtGStateDict)
577 pResourceDict->SetFor("ExtGState", pExtGStateDict); 578 pResourceDict->SetFor("ExtGState", pExtGStateDict);
578 579
579 if (pResourceFontDict) 580 if (pResourceFontDict)
580 pResourceDict->SetFor("Font", pResourceFontDict); 581 pResourceDict->SetFor("Font", pResourceFontDict);
581 582
582 return pResourceDict; 583 return pResourceDict;
583 } 584 }
584 585
585 // Takes ownership of |pResourceDict|. 586 // Takes ownership of |pResourceDict|.
586 void GenerateAndSetAPDict(CPDF_Document* pDoc, 587 void GenerateAndSetAPDict(CPDF_Document* pDoc,
587 CPDF_Dictionary* pAnnotDict, 588 CPDF_Dictionary* pAnnotDict,
588 const CFX_ByteTextBuf& sAppStream, 589 const CFX_ByteTextBuf& sAppStream,
589 CPDF_Dictionary* pResourceDict, 590 CPDF_Dictionary* pResourceDict,
590 bool bIsTextMarkupAnnotation) { 591 bool bIsTextMarkupAnnotation) {
591 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; 592 CPDF_Dictionary* pAPDict = new CPDF_Dictionary(pDoc);
592 pAnnotDict->SetFor("AP", pAPDict); 593 pAnnotDict->SetFor("AP", pAPDict);
593 594
594 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); 595 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr);
595 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); 596 int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
596 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum); 597 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum);
597
598 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, 598 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE,
599 FALSE); 599 FALSE);
600 600
601 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); 601 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
602 pStreamDict->SetIntegerFor("FormType", 1); 602 pStreamDict->SetIntegerFor("FormType", 1);
603 pStreamDict->SetStringFor("Subtype", "Form"); 603 pStreamDict->SetStringFor("Subtype", "Form");
604 pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); 604 pStreamDict->SetMatrixFor("Matrix", CFX_Matrix());
605 605
606 CFX_FloatRect rect = bIsTextMarkupAnnotation 606 CFX_FloatRect rect = bIsTextMarkupAnnotation
607 ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) 607 ? CPDF_Annot::RectFromQuadPoints(pAnnotDict)
608 : pAnnotDict->GetRectFor("Rect"); 608 : pAnnotDict->GetRectFor("Rect");
609 pStreamDict->SetRectFor("BBox", rect); 609 pStreamDict->SetRectFor("BBox", rect);
610
611 pStreamDict->SetFor("Resources", pResourceDict); 610 pStreamDict->SetFor("Resources", pResourceDict);
612 } 611 }
613 612
614 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { 613 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) {
615 if (bIsStrokeRect) 614 if (bIsStrokeRect)
616 return bIsFillRect ? "b" : "s"; 615 return bIsFillRect ? "b" : "s";
617 return bIsFillRect ? "f" : "n"; 616 return bIsFillRect ? "f" : "n";
618 } 617 }
619 618
620 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { 619 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 sAppStream << rect.left << " " << fMiddleY + fDeltaY << " " 777 sAppStream << rect.left << " " << fMiddleY + fDeltaY << " "
779 << fMiddleX - fDeltaX << " " << rect.top << " " << fMiddleX << " " 778 << fMiddleX - fDeltaX << " " << rect.top << " " << fMiddleX << " "
780 << rect.top << " c\n"; 779 << rect.top << " c\n";
781 780
782 bool bIsFillRect = pInteriorColor && !pInteriorColor->IsEmpty(); 781 bool bIsFillRect = pInteriorColor && !pInteriorColor->IsEmpty();
783 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; 782 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n";
784 783
785 CPDF_Dictionary* pExtGStateDict = 784 CPDF_Dictionary* pExtGStateDict =
786 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 785 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
787 CPDF_Dictionary* pResourceDict = 786 CPDF_Dictionary* pResourceDict =
788 GenerateResourceDict(pExtGStateDict, nullptr); 787 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
789 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 788 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
790 false /*IsTextMarkupAnnotation*/); 789 false /*IsTextMarkupAnnotation*/);
791 return true; 790 return true;
792 } 791 }
793 792
794 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, 793 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
795 CPDF_Dictionary* pAnnotDict) { 794 CPDF_Dictionary* pAnnotDict) {
796 CFX_ByteTextBuf sAppStream; 795 CFX_ByteTextBuf sAppStream;
797 CFX_ByteString sExtGSDictName = "GS"; 796 CFX_ByteString sExtGSDictName = "GS";
798 sAppStream << "/" << sExtGSDictName << " gs "; 797 sAppStream << "/" << sExtGSDictName << " gs ";
799 798
800 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), 799 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"),
801 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), 800 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0),
802 PaintOperation::FILL); 801 PaintOperation::FILL);
803 802
804 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); 803 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict);
805 rect.Normalize(); 804 rect.Normalize();
806 805
807 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " 806 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " "
808 << rect.top << " l " << rect.right << " " << rect.bottom << " l " 807 << rect.top << " l " << rect.right << " " << rect.bottom << " l "
809 << rect.left << " " << rect.bottom << " l " 808 << rect.left << " " << rect.bottom << " l "
810 << "h f\n"; 809 << "h f\n";
811 810
812 CPDF_Dictionary* pExtGStateDict = 811 CPDF_Dictionary* pExtGStateDict =
813 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); 812 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply");
814 CPDF_Dictionary* pResourceDict = 813 CPDF_Dictionary* pResourceDict =
815 GenerateResourceDict(pExtGStateDict, nullptr); 814 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
816 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 815 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
817 true /*IsTextMarkupAnnotation*/); 816 true /*IsTextMarkupAnnotation*/);
818 817
819 return true; 818 return true;
820 } 819 }
821 820
822 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, 821 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
823 CPDF_Dictionary* pAnnotDict) { 822 CPDF_Dictionary* pAnnotDict) {
824 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); 823 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict);
825 bool bIsStroke = fBorderWidth > 0; 824 bool bIsStroke = fBorderWidth > 0;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 sAppStream << pInkCoordList->GetNumberAt(j) << " " 859 sAppStream << pInkCoordList->GetNumberAt(j) << " "
861 << pInkCoordList->GetNumberAt(j + 1) << " l "; 860 << pInkCoordList->GetNumberAt(j + 1) << " l ";
862 } 861 }
863 862
864 sAppStream << "S\n"; 863 sAppStream << "S\n";
865 } 864 }
866 865
867 CPDF_Dictionary* pExtGStateDict = 866 CPDF_Dictionary* pExtGStateDict =
868 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 867 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
869 CPDF_Dictionary* pResourceDict = 868 CPDF_Dictionary* pResourceDict =
870 GenerateResourceDict(pExtGStateDict, nullptr); 869 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
871 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 870 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
872 false /*IsTextMarkupAnnotation*/); 871 false /*IsTextMarkupAnnotation*/);
873 return true; 872 return true;
874 } 873 }
875 874
876 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, 875 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc,
877 CPDF_Dictionary* pAnnotDict) { 876 CPDF_Dictionary* pAnnotDict) {
878 CFX_ByteTextBuf sAppStream; 877 CFX_ByteTextBuf sAppStream;
879 CFX_ByteString sExtGSDictName = "GS"; 878 CFX_ByteString sExtGSDictName = "GS";
880 sAppStream << "/" << sExtGSDictName << " gs "; 879 sAppStream << "/" << sExtGSDictName << " gs ";
881 880
882 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); 881 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect");
883 const FX_FLOAT fNoteLength = 20; 882 const FX_FLOAT fNoteLength = 20;
884 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength, 883 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength,
885 rect.bottom + fNoteLength); 884 rect.bottom + fNoteLength);
886 pAnnotDict->SetRectFor("Rect", noteRect); 885 pAnnotDict->SetRectFor("Rect", noteRect);
887 886
888 sAppStream << GenerateTextSymbolAP(noteRect); 887 sAppStream << GenerateTextSymbolAP(noteRect);
889 888
890 CPDF_Dictionary* pExtGStateDict = 889 CPDF_Dictionary* pExtGStateDict =
891 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 890 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
892 CPDF_Dictionary* pResourceDict = 891 CPDF_Dictionary* pResourceDict =
893 GenerateResourceDict(pExtGStateDict, nullptr); 892 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
894 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 893 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
895 false /*IsTextMarkupAnnotation*/); 894 false /*IsTextMarkupAnnotation*/);
896 return true; 895 return true;
897 } 896 }
898 897
899 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, 898 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
900 CPDF_Dictionary* pAnnotDict) { 899 CPDF_Dictionary* pAnnotDict) {
901 CFX_ByteTextBuf sAppStream; 900 CFX_ByteTextBuf sAppStream;
902 CFX_ByteString sExtGSDictName = "GS"; 901 CFX_ByteString sExtGSDictName = "GS";
903 sAppStream << "/" << sExtGSDictName << " gs "; 902 sAppStream << "/" << sExtGSDictName << " gs ";
904 903
905 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), 904 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"),
906 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 905 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
907 PaintOperation::STROKE); 906 PaintOperation::STROKE);
908 907
909 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); 908 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict);
910 rect.Normalize(); 909 rect.Normalize();
911 910
912 FX_FLOAT fLineWidth = 1.0; 911 FX_FLOAT fLineWidth = 1.0;
913 sAppStream << fLineWidth << " w " << rect.left << " " 912 sAppStream << fLineWidth << " w " << rect.left << " "
914 << rect.bottom + fLineWidth << " m " << rect.right << " " 913 << rect.bottom + fLineWidth << " m " << rect.right << " "
915 << rect.bottom + fLineWidth << " l S\n"; 914 << rect.bottom + fLineWidth << " l S\n";
916 915
917 CPDF_Dictionary* pExtGStateDict = 916 CPDF_Dictionary* pExtGStateDict =
918 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 917 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
919 CPDF_Dictionary* pResourceDict = 918 CPDF_Dictionary* pResourceDict =
920 GenerateResourceDict(pExtGStateDict, nullptr); 919 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
921 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 920 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
922 true /*IsTextMarkupAnnotation*/); 921 true /*IsTextMarkupAnnotation*/);
923 return true; 922 return true;
924 } 923 }
925 924
926 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, 925 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc,
927 CPDF_Dictionary* pAnnotDict) { 926 CPDF_Dictionary* pAnnotDict) {
928 CFX_ByteTextBuf sAppStream; 927 CFX_ByteTextBuf sAppStream;
929 CFX_ByteString sExtGSDictName = "GS"; 928 CFX_ByteString sExtGSDictName = "GS";
930 sAppStream << "/" << sExtGSDictName << " gs\n"; 929 sAppStream << "/" << sExtGSDictName << " gs\n";
(...skipping 12 matching lines...) Expand all
943 942
944 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " 943 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " "
945 << rect.Height() << " re b\n"; 944 << rect.Height() << " re b\n";
946 945
947 CFX_ByteString sFontName = "FONT"; 946 CFX_ByteString sFontName = "FONT";
948 CPDF_Dictionary* pExtGStateDict = 947 CPDF_Dictionary* pExtGStateDict =
949 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 948 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
950 CPDF_Dictionary* pResourceFontDict = 949 CPDF_Dictionary* pResourceFontDict =
951 GenerateResourceFontDict(pDoc, sFontName); 950 GenerateResourceFontDict(pDoc, sFontName);
952 CPDF_Dictionary* pResourceDict = 951 CPDF_Dictionary* pResourceDict =
953 GenerateResourceDict(pResourceFontDict, pExtGStateDict); 952 GenerateResourceDict(pDoc, pResourceFontDict, pExtGStateDict);
954 953
955 CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict); 954 CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict);
956 if (!pDefFont) 955 if (!pDefFont)
957 return false; 956 return false;
958 957
959 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName); 958 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName);
960 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 959 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
961 false /*IsTextMarkupAnnotation*/); 960 false /*IsTextMarkupAnnotation*/);
962 return true; 961 return true;
963 } 962 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 996
998 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0); 997 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0);
999 998
1000 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " 999 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " "
1001 << rect.Height() << " re " 1000 << rect.Height() << " re "
1002 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; 1001 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n";
1003 1002
1004 CPDF_Dictionary* pExtGStateDict = 1003 CPDF_Dictionary* pExtGStateDict =
1005 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 1004 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
1006 CPDF_Dictionary* pResourceDict = 1005 CPDF_Dictionary* pResourceDict =
1007 GenerateResourceDict(pExtGStateDict, nullptr); 1006 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
1008 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 1007 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
1009 false /*IsTextMarkupAnnotation*/); 1008 false /*IsTextMarkupAnnotation*/);
1010 return true; 1009 return true;
1011 } 1010 }
1012 1011
1013 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, 1012 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
1014 CPDF_Dictionary* pAnnotDict) { 1013 CPDF_Dictionary* pAnnotDict) {
1015 CFX_ByteTextBuf sAppStream; 1014 CFX_ByteTextBuf sAppStream;
1016 CFX_ByteString sExtGSDictName = "GS"; 1015 CFX_ByteString sExtGSDictName = "GS";
1017 sAppStream << "/" << sExtGSDictName << " gs "; 1016 sAppStream << "/" << sExtGSDictName << " gs ";
(...skipping 28 matching lines...) Expand all
1046 if (isUpwards) 1045 if (isUpwards)
1047 sAppStream << rect.right << " " << fBottom + fRemainder << " l "; 1046 sAppStream << rect.right << " " << fBottom + fRemainder << " l ";
1048 else 1047 else
1049 sAppStream << rect.right << " " << fTop - fRemainder << " l "; 1048 sAppStream << rect.right << " " << fTop - fRemainder << " l ";
1050 1049
1051 sAppStream << "S\n"; 1050 sAppStream << "S\n";
1052 1051
1053 CPDF_Dictionary* pExtGStateDict = 1052 CPDF_Dictionary* pExtGStateDict =
1054 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 1053 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
1055 CPDF_Dictionary* pResourceDict = 1054 CPDF_Dictionary* pResourceDict =
1056 GenerateResourceDict(pExtGStateDict, nullptr); 1055 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
1057 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 1056 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
1058 true /*IsTextMarkupAnnotation*/); 1057 true /*IsTextMarkupAnnotation*/);
1059 return true; 1058 return true;
1060 } 1059 }
1061 1060
1062 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, 1061 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc,
1063 CPDF_Dictionary* pAnnotDict) { 1062 CPDF_Dictionary* pAnnotDict) {
1064 CFX_ByteTextBuf sAppStream; 1063 CFX_ByteTextBuf sAppStream;
1065 CFX_ByteString sExtGSDictName = "GS"; 1064 CFX_ByteString sExtGSDictName = "GS";
1066 sAppStream << "/" << sExtGSDictName << " gs "; 1065 sAppStream << "/" << sExtGSDictName << " gs ";
1067 1066
1068 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), 1067 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"),
1069 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 1068 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
1070 PaintOperation::STROKE); 1069 PaintOperation::STROKE);
1071 1070
1072 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); 1071 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict);
1073 rect.Normalize(); 1072 rect.Normalize();
1074 1073
1075 FX_FLOAT fLineWidth = 1.0; 1074 FX_FLOAT fLineWidth = 1.0;
1076 FX_FLOAT fY = (rect.top + rect.bottom) / 2; 1075 FX_FLOAT fY = (rect.top + rect.bottom) / 2;
1077 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m " 1076 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m "
1078 << rect.right << " " << fY << " l S\n"; 1077 << rect.right << " " << fY << " l S\n";
1079 1078
1080 CPDF_Dictionary* pExtGStateDict = 1079 CPDF_Dictionary* pExtGStateDict =
1081 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 1080 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
1082 CPDF_Dictionary* pResourceDict = 1081 CPDF_Dictionary* pResourceDict =
1083 GenerateResourceDict(pExtGStateDict, nullptr); 1082 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
1084 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 1083 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
1085 true /*IsTextMarkupAnnotation*/); 1084 true /*IsTextMarkupAnnotation*/);
1086 return true; 1085 return true;
1087 } 1086 }
1088 1087
1089 // Static. 1088 // Static.
1090 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( 1089 CFX_ByteString CPVT_GenerateAP::GenerateEditAP(
1091 IPVT_FontMap* pFontMap, 1090 IPVT_FontMap* pFontMap,
1092 CPDF_VariableText::Iterator* pIterator, 1091 CPDF_VariableText::Iterator* pIterator,
1093 const CFX_FloatPoint& ptOffset, 1092 const CFX_FloatPoint& ptOffset,
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 int32_t nFontIndex, 1345 int32_t nFontIndex,
1347 FX_FLOAT fFontSize) { 1346 FX_FLOAT fFontSize) {
1348 CFX_ByteTextBuf sRet; 1347 CFX_ByteTextBuf sRet;
1349 if (pFontMap) { 1348 if (pFontMap) {
1350 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 1349 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
1351 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 1350 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
1352 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 1351 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
1353 } 1352 }
1354 return sRet.MakeString(); 1353 return sRet.MakeString();
1355 } 1354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698