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