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

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

Issue 2345063002: Use string pools in some dictionaries (Closed)
Patch Set: windows compilation 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->GetByteStringPool());
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->GetByteStringPool());
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; 169 pNormalStream = new CPDF_Stream;
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->GetByteStringPool());
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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize()); 421 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize());
422 pStreamDict = pNormalStream->GetDict(); 422 pStreamDict = pNormalStream->GetDict();
423 if (pStreamDict) { 423 if (pStreamDict) {
424 pStreamDict->SetMatrixFor("Matrix", matrix); 424 pStreamDict->SetMatrixFor("Matrix", matrix);
425 pStreamDict->SetRectFor("BBox", rcBBox); 425 pStreamDict->SetRectFor("BBox", rcBBox);
426 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); 426 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
427 if (pStreamResList) { 427 if (pStreamResList) {
428 CPDF_Dictionary* pStreamResFontList = 428 CPDF_Dictionary* pStreamResFontList =
429 pStreamResList->GetDictFor("Font"); 429 pStreamResList->GetDictFor("Font");
430 if (!pStreamResFontList) { 430 if (!pStreamResFontList) {
431 pStreamResFontList = new CPDF_Dictionary; 431 pStreamResFontList = new CPDF_Dictionary(pDoc->GetByteStringPool());
432 pStreamResList->SetFor("Font", pStreamResFontList); 432 pStreamResList->SetFor("Font", pStreamResFontList);
433 } 433 }
434 if (!pStreamResFontList->KeyExist(sFontName)) 434 if (!pStreamResFontList->KeyExist(sFontName))
435 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict); 435 pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict);
436 } else { 436 } else {
437 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone()); 437 pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone());
438 pStreamResList = pStreamDict->GetDictFor("Resources"); 438 pStreamResList = pStreamDict->GetDictFor("Resources");
439 } 439 }
440 } 440 }
441 } 441 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 << CPVT_GenerateAP::GenerateColorAP( 530 << CPVT_GenerateAP::GenerateColorAP(
531 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL) 531 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::FILL)
532 << sContent << "ET\n" 532 << sContent << "ET\n"
533 << "Q\n"; 533 << "Q\n";
534 return sAppStream.MakeString(); 534 return sAppStream.MakeString();
535 } 535 }
536 536
537 CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict, 537 CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict,
538 const CFX_ByteString& sExtGSDictName, 538 const CFX_ByteString& sExtGSDictName,
539 const CFX_ByteString& sBlendMode) { 539 const CFX_ByteString& sBlendMode) {
540 CPDF_Dictionary* pGSDict = new CPDF_Dictionary; 540 CPDF_Dictionary* pGSDict =
541 new CPDF_Dictionary(pAnnotDict.GetByteStringPool());
541 pGSDict->SetStringFor("Type", "ExtGState"); 542 pGSDict->SetStringFor("Type", "ExtGState");
542 543
543 FX_FLOAT fOpacity = 544 FX_FLOAT fOpacity =
544 pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberFor("CA") : 1; 545 pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberFor("CA") : 1;
545 pGSDict->SetNumberFor("CA", fOpacity); 546 pGSDict->SetNumberFor("CA", fOpacity);
546 pGSDict->SetNumberFor("ca", fOpacity); 547 pGSDict->SetNumberFor("ca", fOpacity);
547 pGSDict->SetBooleanFor("AIS", false); 548 pGSDict->SetBooleanFor("AIS", false);
548 pGSDict->SetStringFor("BM", sBlendMode); 549 pGSDict->SetStringFor("BM", sBlendMode);
549 550
550 CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; 551 CPDF_Dictionary* pExtGStateDict =
552 new CPDF_Dictionary(pAnnotDict.GetByteStringPool());
551 pExtGStateDict->SetFor(sExtGSDictName, pGSDict); 553 pExtGStateDict->SetFor(sExtGSDictName, pGSDict);
552
553 return pExtGStateDict; 554 return pExtGStateDict;
554 } 555 }
555 556
556 CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc, 557 CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc,
557 const CFX_ByteString& sFontDictName) { 558 const CFX_ByteString& sFontDictName) {
558 CPDF_Dictionary* pFontDict = new CPDF_Dictionary; 559 CPDF_Dictionary* pFontDict = new CPDF_Dictionary(pDoc->GetByteStringPool());
559 pFontDict->SetNameFor("Type", "Font"); 560 pFontDict->SetNameFor("Type", "Font");
560 pFontDict->SetNameFor("Subtype", "Type1"); 561 pFontDict->SetNameFor("Subtype", "Type1");
561 pFontDict->SetNameFor("BaseFont", "Helvetica"); 562 pFontDict->SetNameFor("BaseFont", "Helvetica");
562 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding"); 563 pFontDict->SetNameFor("Encoding", "WinAnsiEncoding");
563 pDoc->AddIndirectObject(pFontDict); 564 pDoc->AddIndirectObject(pFontDict);
564 565
565 CPDF_Dictionary* pResourceFontDict = new CPDF_Dictionary; 566 CPDF_Dictionary* pResourceFontDict =
567 new CPDF_Dictionary(pDoc->GetByteStringPool());
566 pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict); 568 pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict);
567
568 return pResourceFontDict; 569 return pResourceFontDict;
569 } 570 }
570 571
571 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|. 572 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|.
572 CPDF_Dictionary* GenerateResourceDict(CPDF_Dictionary* pExtGStateDict, 573 CPDF_Dictionary* GenerateResourceDict(CPDF_Document* pDoc,
574 CPDF_Dictionary* pExtGStateDict,
573 CPDF_Dictionary* pResourceFontDict) { 575 CPDF_Dictionary* pResourceFontDict) {
574 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; 576 CPDF_Dictionary* pResourceDict =
577 new CPDF_Dictionary(pDoc->GetByteStringPool());
575 if (pExtGStateDict) 578 if (pExtGStateDict)
576 pResourceDict->SetFor("ExtGState", pExtGStateDict); 579 pResourceDict->SetFor("ExtGState", pExtGStateDict);
577 580
578 if (pResourceFontDict) 581 if (pResourceFontDict)
579 pResourceDict->SetFor("Font", pResourceFontDict); 582 pResourceDict->SetFor("Font", pResourceFontDict);
580 583
581 return pResourceDict; 584 return pResourceDict;
582 } 585 }
583 586
584 // Takes ownership of |pResourceDict|. 587 // Takes ownership of |pResourceDict|.
585 void GenerateAndSetAPDict(CPDF_Document* pDoc, 588 void GenerateAndSetAPDict(CPDF_Document* pDoc,
586 CPDF_Dictionary* pAnnotDict, 589 CPDF_Dictionary* pAnnotDict,
587 const CFX_ByteTextBuf& sAppStream, 590 const CFX_ByteTextBuf& sAppStream,
588 CPDF_Dictionary* pResourceDict, 591 CPDF_Dictionary* pResourceDict,
589 bool bIsTextMarkupAnnotation) { 592 bool bIsTextMarkupAnnotation) {
590 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; 593 CPDF_Dictionary* pAPDict = new CPDF_Dictionary(pDoc->GetByteStringPool());
591 pAnnotDict->SetFor("AP", pAPDict); 594 pAnnotDict->SetFor("AP", pAPDict);
592 595
593 CPDF_Stream* pNormalStream = new CPDF_Stream; 596 CPDF_Stream* pNormalStream = new CPDF_Stream;
594 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); 597 int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
595 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum); 598 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum);
596 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize()); 599 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize());
597 600
598 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); 601 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
599 pStreamDict->SetIntegerFor("FormType", 1); 602 pStreamDict->SetIntegerFor("FormType", 1);
600 pStreamDict->SetStringFor("Subtype", "Form"); 603 pStreamDict->SetStringFor("Subtype", "Form");
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 sAppStream << rect.left << " " << fMiddleY + fDeltaY << " " 777 sAppStream << rect.left << " " << fMiddleY + fDeltaY << " "
775 << fMiddleX - fDeltaX << " " << rect.top << " " << fMiddleX << " " 778 << fMiddleX - fDeltaX << " " << rect.top << " " << fMiddleX << " "
776 << rect.top << " c\n"; 779 << rect.top << " c\n";
777 780
778 bool bIsFillRect = pInteriorColor && !pInteriorColor->IsEmpty(); 781 bool bIsFillRect = pInteriorColor && !pInteriorColor->IsEmpty();
779 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; 782 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n";
780 783
781 CPDF_Dictionary* pExtGStateDict = 784 CPDF_Dictionary* pExtGStateDict =
782 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 785 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
783 CPDF_Dictionary* pResourceDict = 786 CPDF_Dictionary* pResourceDict =
784 GenerateResourceDict(pExtGStateDict, nullptr); 787 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
785 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 788 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
786 false /*IsTextMarkupAnnotation*/); 789 false /*IsTextMarkupAnnotation*/);
787 return true; 790 return true;
788 } 791 }
789 792
790 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, 793 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
791 CPDF_Dictionary* pAnnotDict) { 794 CPDF_Dictionary* pAnnotDict) {
792 CFX_ByteTextBuf sAppStream; 795 CFX_ByteTextBuf sAppStream;
793 CFX_ByteString sExtGSDictName = "GS"; 796 CFX_ByteString sExtGSDictName = "GS";
794 sAppStream << "/" << sExtGSDictName << " gs "; 797 sAppStream << "/" << sExtGSDictName << " gs ";
795 798
796 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), 799 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"),
797 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), 800 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0),
798 PaintOperation::FILL); 801 PaintOperation::FILL);
799 802
800 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); 803 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict);
801 rect.Normalize(); 804 rect.Normalize();
802 805
803 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " 806 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " "
804 << rect.top << " l " << rect.right << " " << rect.bottom << " l " 807 << rect.top << " l " << rect.right << " " << rect.bottom << " l "
805 << rect.left << " " << rect.bottom << " l " 808 << rect.left << " " << rect.bottom << " l "
806 << "h f\n"; 809 << "h f\n";
807 810
808 CPDF_Dictionary* pExtGStateDict = 811 CPDF_Dictionary* pExtGStateDict =
809 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); 812 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply");
810 CPDF_Dictionary* pResourceDict = 813 CPDF_Dictionary* pResourceDict =
811 GenerateResourceDict(pExtGStateDict, nullptr); 814 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
812 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 815 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
813 true /*IsTextMarkupAnnotation*/); 816 true /*IsTextMarkupAnnotation*/);
814 817
815 return true; 818 return true;
816 } 819 }
817 820
818 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, 821 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc,
819 CPDF_Dictionary* pAnnotDict) { 822 CPDF_Dictionary* pAnnotDict) {
820 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); 823 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict);
821 bool bIsStroke = fBorderWidth > 0; 824 bool bIsStroke = fBorderWidth > 0;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 sAppStream << pInkCoordList->GetNumberAt(j) << " " 859 sAppStream << pInkCoordList->GetNumberAt(j) << " "
857 << pInkCoordList->GetNumberAt(j + 1) << " l "; 860 << pInkCoordList->GetNumberAt(j + 1) << " l ";
858 } 861 }
859 862
860 sAppStream << "S\n"; 863 sAppStream << "S\n";
861 } 864 }
862 865
863 CPDF_Dictionary* pExtGStateDict = 866 CPDF_Dictionary* pExtGStateDict =
864 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 867 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
865 CPDF_Dictionary* pResourceDict = 868 CPDF_Dictionary* pResourceDict =
866 GenerateResourceDict(pExtGStateDict, nullptr); 869 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
867 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 870 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
868 false /*IsTextMarkupAnnotation*/); 871 false /*IsTextMarkupAnnotation*/);
869 return true; 872 return true;
870 } 873 }
871 874
872 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, 875 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc,
873 CPDF_Dictionary* pAnnotDict) { 876 CPDF_Dictionary* pAnnotDict) {
874 CFX_ByteTextBuf sAppStream; 877 CFX_ByteTextBuf sAppStream;
875 CFX_ByteString sExtGSDictName = "GS"; 878 CFX_ByteString sExtGSDictName = "GS";
876 sAppStream << "/" << sExtGSDictName << " gs "; 879 sAppStream << "/" << sExtGSDictName << " gs ";
877 880
878 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); 881 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect");
879 const FX_FLOAT fNoteLength = 20; 882 const FX_FLOAT fNoteLength = 20;
880 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength, 883 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength,
881 rect.bottom + fNoteLength); 884 rect.bottom + fNoteLength);
882 pAnnotDict->SetRectFor("Rect", noteRect); 885 pAnnotDict->SetRectFor("Rect", noteRect);
883 886
884 sAppStream << GenerateTextSymbolAP(noteRect); 887 sAppStream << GenerateTextSymbolAP(noteRect);
885 888
886 CPDF_Dictionary* pExtGStateDict = 889 CPDF_Dictionary* pExtGStateDict =
887 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 890 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
888 CPDF_Dictionary* pResourceDict = 891 CPDF_Dictionary* pResourceDict =
889 GenerateResourceDict(pExtGStateDict, nullptr); 892 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
890 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 893 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
891 false /*IsTextMarkupAnnotation*/); 894 false /*IsTextMarkupAnnotation*/);
892 return true; 895 return true;
893 } 896 }
894 897
895 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, 898 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
896 CPDF_Dictionary* pAnnotDict) { 899 CPDF_Dictionary* pAnnotDict) {
897 CFX_ByteTextBuf sAppStream; 900 CFX_ByteTextBuf sAppStream;
898 CFX_ByteString sExtGSDictName = "GS"; 901 CFX_ByteString sExtGSDictName = "GS";
899 sAppStream << "/" << sExtGSDictName << " gs "; 902 sAppStream << "/" << sExtGSDictName << " gs ";
900 903
901 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), 904 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"),
902 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 905 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
903 PaintOperation::STROKE); 906 PaintOperation::STROKE);
904 907
905 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); 908 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict);
906 rect.Normalize(); 909 rect.Normalize();
907 910
908 FX_FLOAT fLineWidth = 1.0; 911 FX_FLOAT fLineWidth = 1.0;
909 sAppStream << fLineWidth << " w " << rect.left << " " 912 sAppStream << fLineWidth << " w " << rect.left << " "
910 << rect.bottom + fLineWidth << " m " << rect.right << " " 913 << rect.bottom + fLineWidth << " m " << rect.right << " "
911 << rect.bottom + fLineWidth << " l S\n"; 914 << rect.bottom + fLineWidth << " l S\n";
912 915
913 CPDF_Dictionary* pExtGStateDict = 916 CPDF_Dictionary* pExtGStateDict =
914 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 917 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
915 CPDF_Dictionary* pResourceDict = 918 CPDF_Dictionary* pResourceDict =
916 GenerateResourceDict(pExtGStateDict, nullptr); 919 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
917 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 920 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
918 true /*IsTextMarkupAnnotation*/); 921 true /*IsTextMarkupAnnotation*/);
919 return true; 922 return true;
920 } 923 }
921 924
922 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, 925 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc,
923 CPDF_Dictionary* pAnnotDict) { 926 CPDF_Dictionary* pAnnotDict) {
924 CFX_ByteTextBuf sAppStream; 927 CFX_ByteTextBuf sAppStream;
925 CFX_ByteString sExtGSDictName = "GS"; 928 CFX_ByteString sExtGSDictName = "GS";
926 sAppStream << "/" << sExtGSDictName << " gs\n"; 929 sAppStream << "/" << sExtGSDictName << " gs\n";
(...skipping 12 matching lines...) Expand all
939 942
940 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " 943 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " "
941 << rect.Height() << " re b\n"; 944 << rect.Height() << " re b\n";
942 945
943 CFX_ByteString sFontName = "FONT"; 946 CFX_ByteString sFontName = "FONT";
944 CPDF_Dictionary* pExtGStateDict = 947 CPDF_Dictionary* pExtGStateDict =
945 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 948 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
946 CPDF_Dictionary* pResourceFontDict = 949 CPDF_Dictionary* pResourceFontDict =
947 GenerateResourceFontDict(pDoc, sFontName); 950 GenerateResourceFontDict(pDoc, sFontName);
948 CPDF_Dictionary* pResourceDict = 951 CPDF_Dictionary* pResourceDict =
949 GenerateResourceDict(pResourceFontDict, pExtGStateDict); 952 GenerateResourceDict(pDoc, pResourceFontDict, pExtGStateDict);
950 953
951 CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict); 954 CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict);
952 if (!pDefFont) 955 if (!pDefFont)
953 return false; 956 return false;
954 957
955 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName); 958 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName);
956 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 959 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
957 false /*IsTextMarkupAnnotation*/); 960 false /*IsTextMarkupAnnotation*/);
958 return true; 961 return true;
959 } 962 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 996
994 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0); 997 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0);
995 998
996 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " 999 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " "
997 << rect.Height() << " re " 1000 << rect.Height() << " re "
998 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; 1001 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n";
999 1002
1000 CPDF_Dictionary* pExtGStateDict = 1003 CPDF_Dictionary* pExtGStateDict =
1001 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 1004 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
1002 CPDF_Dictionary* pResourceDict = 1005 CPDF_Dictionary* pResourceDict =
1003 GenerateResourceDict(pExtGStateDict, nullptr); 1006 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
1004 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 1007 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
1005 false /*IsTextMarkupAnnotation*/); 1008 false /*IsTextMarkupAnnotation*/);
1006 return true; 1009 return true;
1007 } 1010 }
1008 1011
1009 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, 1012 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc,
1010 CPDF_Dictionary* pAnnotDict) { 1013 CPDF_Dictionary* pAnnotDict) {
1011 CFX_ByteTextBuf sAppStream; 1014 CFX_ByteTextBuf sAppStream;
1012 CFX_ByteString sExtGSDictName = "GS"; 1015 CFX_ByteString sExtGSDictName = "GS";
1013 sAppStream << "/" << sExtGSDictName << " gs "; 1016 sAppStream << "/" << sExtGSDictName << " gs ";
(...skipping 28 matching lines...) Expand all
1042 if (isUpwards) 1045 if (isUpwards)
1043 sAppStream << rect.right << " " << fBottom + fRemainder << " l "; 1046 sAppStream << rect.right << " " << fBottom + fRemainder << " l ";
1044 else 1047 else
1045 sAppStream << rect.right << " " << fTop - fRemainder << " l "; 1048 sAppStream << rect.right << " " << fTop - fRemainder << " l ";
1046 1049
1047 sAppStream << "S\n"; 1050 sAppStream << "S\n";
1048 1051
1049 CPDF_Dictionary* pExtGStateDict = 1052 CPDF_Dictionary* pExtGStateDict =
1050 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 1053 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
1051 CPDF_Dictionary* pResourceDict = 1054 CPDF_Dictionary* pResourceDict =
1052 GenerateResourceDict(pExtGStateDict, nullptr); 1055 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
1053 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 1056 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
1054 true /*IsTextMarkupAnnotation*/); 1057 true /*IsTextMarkupAnnotation*/);
1055 return true; 1058 return true;
1056 } 1059 }
1057 1060
1058 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, 1061 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc,
1059 CPDF_Dictionary* pAnnotDict) { 1062 CPDF_Dictionary* pAnnotDict) {
1060 CFX_ByteTextBuf sAppStream; 1063 CFX_ByteTextBuf sAppStream;
1061 CFX_ByteString sExtGSDictName = "GS"; 1064 CFX_ByteString sExtGSDictName = "GS";
1062 sAppStream << "/" << sExtGSDictName << " gs "; 1065 sAppStream << "/" << sExtGSDictName << " gs ";
1063 1066
1064 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), 1067 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"),
1065 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), 1068 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
1066 PaintOperation::STROKE); 1069 PaintOperation::STROKE);
1067 1070
1068 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); 1071 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict);
1069 rect.Normalize(); 1072 rect.Normalize();
1070 1073
1071 FX_FLOAT fLineWidth = 1.0; 1074 FX_FLOAT fLineWidth = 1.0;
1072 FX_FLOAT fY = (rect.top + rect.bottom) / 2; 1075 FX_FLOAT fY = (rect.top + rect.bottom) / 2;
1073 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m " 1076 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m "
1074 << rect.right << " " << fY << " l S\n"; 1077 << rect.right << " " << fY << " l S\n";
1075 1078
1076 CPDF_Dictionary* pExtGStateDict = 1079 CPDF_Dictionary* pExtGStateDict =
1077 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); 1080 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
1078 CPDF_Dictionary* pResourceDict = 1081 CPDF_Dictionary* pResourceDict =
1079 GenerateResourceDict(pExtGStateDict, nullptr); 1082 GenerateResourceDict(pDoc, pExtGStateDict, nullptr);
1080 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, 1083 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict,
1081 true /*IsTextMarkupAnnotation*/); 1084 true /*IsTextMarkupAnnotation*/);
1082 return true; 1085 return true;
1083 } 1086 }
1084 1087
1085 // Static. 1088 // Static.
1086 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( 1089 CFX_ByteString CPVT_GenerateAP::GenerateEditAP(
1087 IPVT_FontMap* pFontMap, 1090 IPVT_FontMap* pFontMap,
1088 CPDF_VariableText::Iterator* pIterator, 1091 CPDF_VariableText::Iterator* pIterator,
1089 const CFX_FloatPoint& ptOffset, 1092 const CFX_FloatPoint& ptOffset,
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 int32_t nFontIndex, 1345 int32_t nFontIndex,
1343 FX_FLOAT fFontSize) { 1346 FX_FLOAT fFontSize) {
1344 CFX_ByteTextBuf sRet; 1347 CFX_ByteTextBuf sRet;
1345 if (pFontMap) { 1348 if (pFontMap) {
1346 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); 1349 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
1347 if (sFontAlias.GetLength() > 0 && fFontSize > 0) 1350 if (sFontAlias.GetLength() > 0 && fFontSize > 0)
1348 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; 1351 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
1349 } 1352 }
1350 return sRet.MakeString(); 1353 return sRet.MakeString();
1351 } 1354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698