| 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 "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 Loading... |
| 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 Loading... |
| 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(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->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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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->GetByteStringPool()); |
| 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 Loading... |
| 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->GetByteStringPool()); |
| 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 = |
| 568 new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 567 pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict); | 569 pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict); |
| 568 | |
| 569 return pResourceFontDict; | 570 return pResourceFontDict; |
| 570 } | 571 } |
| 571 | 572 |
| 572 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|. | 573 // Takes ownership of |pExtGStateDict| and |pResourceFontDict|. |
| 573 CPDF_Dictionary* GenerateResourceDict(CPDF_Dictionary* pExtGStateDict, | 574 CPDF_Dictionary* GenerateResourceDict(CPDF_Document* pDoc, |
| 575 CPDF_Dictionary* pExtGStateDict, |
| 574 CPDF_Dictionary* pResourceFontDict) { | 576 CPDF_Dictionary* pResourceFontDict) { |
| 575 CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; | 577 CPDF_Dictionary* pResourceDict = |
| 578 new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 579 |
| 576 if (pExtGStateDict) | 580 if (pExtGStateDict) |
| 577 pResourceDict->SetFor("ExtGState", pExtGStateDict); | 581 pResourceDict->SetFor("ExtGState", pExtGStateDict); |
| 578 | 582 |
| 579 if (pResourceFontDict) | 583 if (pResourceFontDict) |
| 580 pResourceDict->SetFor("Font", pResourceFontDict); | 584 pResourceDict->SetFor("Font", pResourceFontDict); |
| 581 | 585 |
| 582 return pResourceDict; | 586 return pResourceDict; |
| 583 } | 587 } |
| 584 | 588 |
| 585 // Takes ownership of |pResourceDict|. | 589 // Takes ownership of |pResourceDict|. |
| 586 void GenerateAndSetAPDict(CPDF_Document* pDoc, | 590 void GenerateAndSetAPDict(CPDF_Document* pDoc, |
| 587 CPDF_Dictionary* pAnnotDict, | 591 CPDF_Dictionary* pAnnotDict, |
| 588 const CFX_ByteTextBuf& sAppStream, | 592 const CFX_ByteTextBuf& sAppStream, |
| 589 CPDF_Dictionary* pResourceDict, | 593 CPDF_Dictionary* pResourceDict, |
| 590 bool bIsTextMarkupAnnotation) { | 594 bool bIsTextMarkupAnnotation) { |
| 591 CPDF_Dictionary* pAPDict = new CPDF_Dictionary; | 595 CPDF_Dictionary* pAPDict = new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 592 pAnnotDict->SetFor("AP", pAPDict); | 596 pAnnotDict->SetFor("AP", pAPDict); |
| 593 | 597 |
| 594 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); | 598 CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); |
| 595 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); | 599 int32_t objnum = pDoc->AddIndirectObject(pNormalStream); |
| 596 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum); | 600 pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum); |
| 597 | |
| 598 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, | 601 pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize(), FALSE, |
| 599 FALSE); | 602 FALSE); |
| 600 | 603 |
| 601 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); | 604 CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); |
| 602 pStreamDict->SetIntegerFor("FormType", 1); | 605 pStreamDict->SetIntegerFor("FormType", 1); |
| 603 pStreamDict->SetStringFor("Subtype", "Form"); | 606 pStreamDict->SetStringFor("Subtype", "Form"); |
| 604 pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); | 607 pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); |
| 605 | 608 |
| 606 CFX_FloatRect rect = bIsTextMarkupAnnotation | 609 CFX_FloatRect rect = bIsTextMarkupAnnotation |
| 607 ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) | 610 ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) |
| 608 : pAnnotDict->GetRectFor("Rect"); | 611 : pAnnotDict->GetRectFor("Rect"); |
| 609 pStreamDict->SetRectFor("BBox", rect); | 612 pStreamDict->SetRectFor("BBox", rect); |
| 610 | |
| 611 pStreamDict->SetFor("Resources", pResourceDict); | 613 pStreamDict->SetFor("Resources", pResourceDict); |
| 612 } | 614 } |
| 613 | 615 |
| 614 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { | 616 CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { |
| 615 if (bIsStrokeRect) | 617 if (bIsStrokeRect) |
| 616 return bIsFillRect ? "b" : "s"; | 618 return bIsFillRect ? "b" : "s"; |
| 617 return bIsFillRect ? "f" : "n"; | 619 return bIsFillRect ? "f" : "n"; |
| 618 } | 620 } |
| 619 | 621 |
| 620 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { | 622 CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 sAppStream << rect.left << " " << fMiddleY + fDeltaY << " " | 780 sAppStream << rect.left << " " << fMiddleY + fDeltaY << " " |
| 779 << fMiddleX - fDeltaX << " " << rect.top << " " << fMiddleX << " " | 781 << fMiddleX - fDeltaX << " " << rect.top << " " << fMiddleX << " " |
| 780 << rect.top << " c\n"; | 782 << rect.top << " c\n"; |
| 781 | 783 |
| 782 bool bIsFillRect = pInteriorColor && !pInteriorColor->IsEmpty(); | 784 bool bIsFillRect = pInteriorColor && !pInteriorColor->IsEmpty(); |
| 783 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; | 785 sAppStream << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; |
| 784 | 786 |
| 785 CPDF_Dictionary* pExtGStateDict = | 787 CPDF_Dictionary* pExtGStateDict = |
| 786 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 788 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 787 CPDF_Dictionary* pResourceDict = | 789 CPDF_Dictionary* pResourceDict = |
| 788 GenerateResourceDict(pExtGStateDict, nullptr); | 790 GenerateResourceDict(pDoc, pExtGStateDict, nullptr); |
| 789 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, | 791 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
| 790 false /*IsTextMarkupAnnotation*/); | 792 false /*IsTextMarkupAnnotation*/); |
| 791 return true; | 793 return true; |
| 792 } | 794 } |
| 793 | 795 |
| 794 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, | 796 bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, |
| 795 CPDF_Dictionary* pAnnotDict) { | 797 CPDF_Dictionary* pAnnotDict) { |
| 796 CFX_ByteTextBuf sAppStream; | 798 CFX_ByteTextBuf sAppStream; |
| 797 CFX_ByteString sExtGSDictName = "GS"; | 799 CFX_ByteString sExtGSDictName = "GS"; |
| 798 sAppStream << "/" << sExtGSDictName << " gs "; | 800 sAppStream << "/" << sExtGSDictName << " gs "; |
| 799 | 801 |
| 800 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), | 802 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), |
| 801 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), | 803 CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), |
| 802 PaintOperation::FILL); | 804 PaintOperation::FILL); |
| 803 | 805 |
| 804 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); | 806 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); |
| 805 rect.Normalize(); | 807 rect.Normalize(); |
| 806 | 808 |
| 807 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " | 809 sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " |
| 808 << rect.top << " l " << rect.right << " " << rect.bottom << " l " | 810 << rect.top << " l " << rect.right << " " << rect.bottom << " l " |
| 809 << rect.left << " " << rect.bottom << " l " | 811 << rect.left << " " << rect.bottom << " l " |
| 810 << "h f\n"; | 812 << "h f\n"; |
| 811 | 813 |
| 812 CPDF_Dictionary* pExtGStateDict = | 814 CPDF_Dictionary* pExtGStateDict = |
| 813 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); | 815 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply"); |
| 814 CPDF_Dictionary* pResourceDict = | 816 CPDF_Dictionary* pResourceDict = |
| 815 GenerateResourceDict(pExtGStateDict, nullptr); | 817 GenerateResourceDict(pDoc, pExtGStateDict, nullptr); |
| 816 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, | 818 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
| 817 true /*IsTextMarkupAnnotation*/); | 819 true /*IsTextMarkupAnnotation*/); |
| 818 | 820 |
| 819 return true; | 821 return true; |
| 820 } | 822 } |
| 821 | 823 |
| 822 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, | 824 bool CPVT_GenerateAP::GenerateInkAP(CPDF_Document* pDoc, |
| 823 CPDF_Dictionary* pAnnotDict) { | 825 CPDF_Dictionary* pAnnotDict) { |
| 824 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); | 826 FX_FLOAT fBorderWidth = GetBorderWidth(*pAnnotDict); |
| 825 bool bIsStroke = fBorderWidth > 0; | 827 bool bIsStroke = fBorderWidth > 0; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 sAppStream << pInkCoordList->GetNumberAt(j) << " " | 862 sAppStream << pInkCoordList->GetNumberAt(j) << " " |
| 861 << pInkCoordList->GetNumberAt(j + 1) << " l "; | 863 << pInkCoordList->GetNumberAt(j + 1) << " l "; |
| 862 } | 864 } |
| 863 | 865 |
| 864 sAppStream << "S\n"; | 866 sAppStream << "S\n"; |
| 865 } | 867 } |
| 866 | 868 |
| 867 CPDF_Dictionary* pExtGStateDict = | 869 CPDF_Dictionary* pExtGStateDict = |
| 868 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 870 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 869 CPDF_Dictionary* pResourceDict = | 871 CPDF_Dictionary* pResourceDict = |
| 870 GenerateResourceDict(pExtGStateDict, nullptr); | 872 GenerateResourceDict(pDoc, pExtGStateDict, nullptr); |
| 871 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, | 873 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
| 872 false /*IsTextMarkupAnnotation*/); | 874 false /*IsTextMarkupAnnotation*/); |
| 873 return true; | 875 return true; |
| 874 } | 876 } |
| 875 | 877 |
| 876 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, | 878 bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc, |
| 877 CPDF_Dictionary* pAnnotDict) { | 879 CPDF_Dictionary* pAnnotDict) { |
| 878 CFX_ByteTextBuf sAppStream; | 880 CFX_ByteTextBuf sAppStream; |
| 879 CFX_ByteString sExtGSDictName = "GS"; | 881 CFX_ByteString sExtGSDictName = "GS"; |
| 880 sAppStream << "/" << sExtGSDictName << " gs "; | 882 sAppStream << "/" << sExtGSDictName << " gs "; |
| 881 | 883 |
| 882 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); | 884 CFX_FloatRect rect = pAnnotDict->GetRectFor("Rect"); |
| 883 const FX_FLOAT fNoteLength = 20; | 885 const FX_FLOAT fNoteLength = 20; |
| 884 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength, | 886 CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength, |
| 885 rect.bottom + fNoteLength); | 887 rect.bottom + fNoteLength); |
| 886 pAnnotDict->SetRectFor("Rect", noteRect); | 888 pAnnotDict->SetRectFor("Rect", noteRect); |
| 887 | 889 |
| 888 sAppStream << GenerateTextSymbolAP(noteRect); | 890 sAppStream << GenerateTextSymbolAP(noteRect); |
| 889 | 891 |
| 890 CPDF_Dictionary* pExtGStateDict = | 892 CPDF_Dictionary* pExtGStateDict = |
| 891 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 893 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 892 CPDF_Dictionary* pResourceDict = | 894 CPDF_Dictionary* pResourceDict = |
| 893 GenerateResourceDict(pExtGStateDict, nullptr); | 895 GenerateResourceDict(pDoc, pExtGStateDict, nullptr); |
| 894 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, | 896 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
| 895 false /*IsTextMarkupAnnotation*/); | 897 false /*IsTextMarkupAnnotation*/); |
| 896 return true; | 898 return true; |
| 897 } | 899 } |
| 898 | 900 |
| 899 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, | 901 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, |
| 900 CPDF_Dictionary* pAnnotDict) { | 902 CPDF_Dictionary* pAnnotDict) { |
| 901 CFX_ByteTextBuf sAppStream; | 903 CFX_ByteTextBuf sAppStream; |
| 902 CFX_ByteString sExtGSDictName = "GS"; | 904 CFX_ByteString sExtGSDictName = "GS"; |
| 903 sAppStream << "/" << sExtGSDictName << " gs "; | 905 sAppStream << "/" << sExtGSDictName << " gs "; |
| 904 | 906 |
| 905 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), | 907 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), |
| 906 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 908 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
| 907 PaintOperation::STROKE); | 909 PaintOperation::STROKE); |
| 908 | 910 |
| 909 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); | 911 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); |
| 910 rect.Normalize(); | 912 rect.Normalize(); |
| 911 | 913 |
| 912 FX_FLOAT fLineWidth = 1.0; | 914 FX_FLOAT fLineWidth = 1.0; |
| 913 sAppStream << fLineWidth << " w " << rect.left << " " | 915 sAppStream << fLineWidth << " w " << rect.left << " " |
| 914 << rect.bottom + fLineWidth << " m " << rect.right << " " | 916 << rect.bottom + fLineWidth << " m " << rect.right << " " |
| 915 << rect.bottom + fLineWidth << " l S\n"; | 917 << rect.bottom + fLineWidth << " l S\n"; |
| 916 | 918 |
| 917 CPDF_Dictionary* pExtGStateDict = | 919 CPDF_Dictionary* pExtGStateDict = |
| 918 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 920 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 919 CPDF_Dictionary* pResourceDict = | 921 CPDF_Dictionary* pResourceDict = |
| 920 GenerateResourceDict(pExtGStateDict, nullptr); | 922 GenerateResourceDict(pDoc, pExtGStateDict, nullptr); |
| 921 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, | 923 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
| 922 true /*IsTextMarkupAnnotation*/); | 924 true /*IsTextMarkupAnnotation*/); |
| 923 return true; | 925 return true; |
| 924 } | 926 } |
| 925 | 927 |
| 926 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, | 928 bool CPVT_GenerateAP::GeneratePopupAP(CPDF_Document* pDoc, |
| 927 CPDF_Dictionary* pAnnotDict) { | 929 CPDF_Dictionary* pAnnotDict) { |
| 928 CFX_ByteTextBuf sAppStream; | 930 CFX_ByteTextBuf sAppStream; |
| 929 CFX_ByteString sExtGSDictName = "GS"; | 931 CFX_ByteString sExtGSDictName = "GS"; |
| 930 sAppStream << "/" << sExtGSDictName << " gs\n"; | 932 sAppStream << "/" << sExtGSDictName << " gs\n"; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 943 | 945 |
| 944 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " | 946 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " |
| 945 << rect.Height() << " re b\n"; | 947 << rect.Height() << " re b\n"; |
| 946 | 948 |
| 947 CFX_ByteString sFontName = "FONT"; | 949 CFX_ByteString sFontName = "FONT"; |
| 948 CPDF_Dictionary* pExtGStateDict = | 950 CPDF_Dictionary* pExtGStateDict = |
| 949 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 951 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 950 CPDF_Dictionary* pResourceFontDict = | 952 CPDF_Dictionary* pResourceFontDict = |
| 951 GenerateResourceFontDict(pDoc, sFontName); | 953 GenerateResourceFontDict(pDoc, sFontName); |
| 952 CPDF_Dictionary* pResourceDict = | 954 CPDF_Dictionary* pResourceDict = |
| 953 GenerateResourceDict(pResourceFontDict, pExtGStateDict); | 955 GenerateResourceDict(pDoc, pResourceFontDict, pExtGStateDict); |
| 954 | 956 |
| 955 CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict); | 957 CPDF_Font* pDefFont = pDoc->LoadFont(pResourceFontDict); |
| 956 if (!pDefFont) | 958 if (!pDefFont) |
| 957 return false; | 959 return false; |
| 958 | 960 |
| 959 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName); | 961 sAppStream << GetPopupContentsString(pDoc, *pAnnotDict, pDefFont, sFontName); |
| 960 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, | 962 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
| 961 false /*IsTextMarkupAnnotation*/); | 963 false /*IsTextMarkupAnnotation*/); |
| 962 return true; | 964 return true; |
| 963 } | 965 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 | 999 |
| 998 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0); | 1000 bool bIsFillRect = pInteriorColor && (pInteriorColor->GetCount() > 0); |
| 999 | 1001 |
| 1000 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " | 1002 sAppStream << rect.left << " " << rect.bottom << " " << rect.Width() << " " |
| 1001 << rect.Height() << " re " | 1003 << rect.Height() << " re " |
| 1002 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; | 1004 << GetPaintOperatorString(bIsStrokeRect, bIsFillRect) << "\n"; |
| 1003 | 1005 |
| 1004 CPDF_Dictionary* pExtGStateDict = | 1006 CPDF_Dictionary* pExtGStateDict = |
| 1005 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 1007 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 1006 CPDF_Dictionary* pResourceDict = | 1008 CPDF_Dictionary* pResourceDict = |
| 1007 GenerateResourceDict(pExtGStateDict, nullptr); | 1009 GenerateResourceDict(pDoc, pExtGStateDict, nullptr); |
| 1008 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, | 1010 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
| 1009 false /*IsTextMarkupAnnotation*/); | 1011 false /*IsTextMarkupAnnotation*/); |
| 1010 return true; | 1012 return true; |
| 1011 } | 1013 } |
| 1012 | 1014 |
| 1013 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, | 1015 bool CPVT_GenerateAP::GenerateSquigglyAP(CPDF_Document* pDoc, |
| 1014 CPDF_Dictionary* pAnnotDict) { | 1016 CPDF_Dictionary* pAnnotDict) { |
| 1015 CFX_ByteTextBuf sAppStream; | 1017 CFX_ByteTextBuf sAppStream; |
| 1016 CFX_ByteString sExtGSDictName = "GS"; | 1018 CFX_ByteString sExtGSDictName = "GS"; |
| 1017 sAppStream << "/" << sExtGSDictName << " gs "; | 1019 sAppStream << "/" << sExtGSDictName << " gs "; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1046 if (isUpwards) | 1048 if (isUpwards) |
| 1047 sAppStream << rect.right << " " << fBottom + fRemainder << " l "; | 1049 sAppStream << rect.right << " " << fBottom + fRemainder << " l "; |
| 1048 else | 1050 else |
| 1049 sAppStream << rect.right << " " << fTop - fRemainder << " l "; | 1051 sAppStream << rect.right << " " << fTop - fRemainder << " l "; |
| 1050 | 1052 |
| 1051 sAppStream << "S\n"; | 1053 sAppStream << "S\n"; |
| 1052 | 1054 |
| 1053 CPDF_Dictionary* pExtGStateDict = | 1055 CPDF_Dictionary* pExtGStateDict = |
| 1054 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 1056 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 1055 CPDF_Dictionary* pResourceDict = | 1057 CPDF_Dictionary* pResourceDict = |
| 1056 GenerateResourceDict(pExtGStateDict, nullptr); | 1058 GenerateResourceDict(pDoc, pExtGStateDict, nullptr); |
| 1057 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, | 1059 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
| 1058 true /*IsTextMarkupAnnotation*/); | 1060 true /*IsTextMarkupAnnotation*/); |
| 1059 return true; | 1061 return true; |
| 1060 } | 1062 } |
| 1061 | 1063 |
| 1062 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, | 1064 bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, |
| 1063 CPDF_Dictionary* pAnnotDict) { | 1065 CPDF_Dictionary* pAnnotDict) { |
| 1064 CFX_ByteTextBuf sAppStream; | 1066 CFX_ByteTextBuf sAppStream; |
| 1065 CFX_ByteString sExtGSDictName = "GS"; | 1067 CFX_ByteString sExtGSDictName = "GS"; |
| 1066 sAppStream << "/" << sExtGSDictName << " gs "; | 1068 sAppStream << "/" << sExtGSDictName << " gs "; |
| 1067 | 1069 |
| 1068 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), | 1070 sAppStream << GetColorStringWithDefault(pAnnotDict->GetArrayFor("C"), |
| 1069 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), | 1071 CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), |
| 1070 PaintOperation::STROKE); | 1072 PaintOperation::STROKE); |
| 1071 | 1073 |
| 1072 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); | 1074 CFX_FloatRect rect = CPDF_Annot::RectFromQuadPoints(pAnnotDict); |
| 1073 rect.Normalize(); | 1075 rect.Normalize(); |
| 1074 | 1076 |
| 1075 FX_FLOAT fLineWidth = 1.0; | 1077 FX_FLOAT fLineWidth = 1.0; |
| 1076 FX_FLOAT fY = (rect.top + rect.bottom) / 2; | 1078 FX_FLOAT fY = (rect.top + rect.bottom) / 2; |
| 1077 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m " | 1079 sAppStream << fLineWidth << " w " << rect.left << " " << fY << " m " |
| 1078 << rect.right << " " << fY << " l S\n"; | 1080 << rect.right << " " << fY << " l S\n"; |
| 1079 | 1081 |
| 1080 CPDF_Dictionary* pExtGStateDict = | 1082 CPDF_Dictionary* pExtGStateDict = |
| 1081 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); | 1083 GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); |
| 1082 CPDF_Dictionary* pResourceDict = | 1084 CPDF_Dictionary* pResourceDict = |
| 1083 GenerateResourceDict(pExtGStateDict, nullptr); | 1085 GenerateResourceDict(pDoc, pExtGStateDict, nullptr); |
| 1084 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, | 1086 GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pResourceDict, |
| 1085 true /*IsTextMarkupAnnotation*/); | 1087 true /*IsTextMarkupAnnotation*/); |
| 1086 return true; | 1088 return true; |
| 1087 } | 1089 } |
| 1088 | 1090 |
| 1089 // Static. | 1091 // Static. |
| 1090 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( | 1092 CFX_ByteString CPVT_GenerateAP::GenerateEditAP( |
| 1091 IPVT_FontMap* pFontMap, | 1093 IPVT_FontMap* pFontMap, |
| 1092 CPDF_VariableText::Iterator* pIterator, | 1094 CPDF_VariableText::Iterator* pIterator, |
| 1093 const CFX_FloatPoint& ptOffset, | 1095 const CFX_FloatPoint& ptOffset, |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 int32_t nFontIndex, | 1348 int32_t nFontIndex, |
| 1347 FX_FLOAT fFontSize) { | 1349 FX_FLOAT fFontSize) { |
| 1348 CFX_ByteTextBuf sRet; | 1350 CFX_ByteTextBuf sRet; |
| 1349 if (pFontMap) { | 1351 if (pFontMap) { |
| 1350 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); | 1352 CFX_ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex); |
| 1351 if (sFontAlias.GetLength() > 0 && fFontSize > 0) | 1353 if (sFontAlias.GetLength() > 0 && fFontSize > 0) |
| 1352 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; | 1354 sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n"; |
| 1353 } | 1355 } |
| 1354 return sRet.MakeString(); | 1356 return sRet.MakeString(); |
| 1355 } | 1357 } |
| OLD | NEW |