From ab47acec5252d4a09da3cbde1a118b5255fe52ae Mon Sep 17 00:00:00 2001 From: jaepark Date: Fri, 29 Jul 2016 19:53:40 -0700 Subject: Generate default AP stream for highlight annotation. This patch generates a default AP stream for highlight annotation so that highlight annotations without AP stream can be displayed. BUG=62625 Review-Url: https://codereview.chromium.org/2193983002 --- DEPS | 2 +- core/fpdfdoc/cpdf_annot.cpp | 6 +++- core/fpdfdoc/cpvt_generateap.cpp | 60 ++++++++++++++++++++++++++++++++++++++++ core/fpdfdoc/cpvt_generateap.h | 2 ++ 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/DEPS b/DEPS index 1f263b8db3..fb636a9cba 100644 --- a/DEPS +++ b/DEPS @@ -14,7 +14,7 @@ vars = { 'gmock_revision': '29763965ab52f24565299976b936d1265cb6a271', 'gtest_revision': '8245545b6dc9c4703e6496d1efd19e975ad2b038', 'icu_revision': 'a5f86adbb0a58d04c035a5d1228747b1823cd485', - 'pdfium_tests_revision': 'd307839b3d4c8e521208172155718c945af696e0', + 'pdfium_tests_revision': '62d61d99f65f4a9ce266ca0ecf74bc098d397fd3', 'skia_revision': '7d46f4af7dc759002537a172af121f2bfe200981', 'tools_memory_revision': '427f10475e1a8d72424c29d00bf689122b738e5d', 'trace_event_revision': '54b8455be9505c2cb0cf5c26bb86739c236471aa', diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp index 18b1e9d946..a8578fc28d 100644 --- a/core/fpdfdoc/cpdf_annot.cpp +++ b/core/fpdfdoc/cpdf_annot.cpp @@ -12,13 +12,17 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h" #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" +#include "core/fpdfdoc/cpvt_generateap.h" #include "core/fxcrt/include/fx_memory.h" #include "core/fxge/include/fx_ge.h" CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument) : m_pAnnotDict(pDict), m_pDocument(pDocument), - m_sSubtype(m_pAnnotDict->GetStringBy("Subtype")) {} + m_sSubtype(m_pAnnotDict->GetStringBy("Subtype")) { + if (m_sSubtype == "Highlight") + CPVT_GenerateAP::GenerateHighlightAP(m_pDocument, m_pAnnotDict); +} CPDF_Annot::~CPDF_Annot() { ClearCachedAP(); diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index fa69609e0e..56b6612717 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -493,6 +493,66 @@ bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc, return GenerateWidgetAP(pDoc, pAnnotDict, 0); } +bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc, + CPDF_Dictionary* pAnnotDict) { + // If AP dictionary exists, we use the appearance defined in the + // existing AP dictionary. + if (pAnnotDict->KeyExist("AP")) + return false; + + CFX_ByteTextBuf sAppStream; + sAppStream << "/GS gs "; + + if (pAnnotDict->KeyExist("C")) { + CPDF_Array* pColor = pAnnotDict->GetArrayBy("C"); + CPVT_Color color = CPVT_Color::ParseColor(*pColor); + sAppStream << CPVT_GenerateAP::GenerateColorAP(color, TRUE); + } else { + // Defaults to 0xFFFF00 color for highlight. + sAppStream << "1 1 0 rg \n"; + } + + CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); + rect.Normalize(); + + sAppStream << rect.left << " " << rect.top << " m " << rect.right << " " + << rect.top << " l " << rect.right << " " << rect.bottom << " l " + << rect.left << " " << rect.bottom << " l " + << "h f\n"; + + CPDF_Dictionary* pAPDict = new CPDF_Dictionary; + pAnnotDict->SetAt("AP", pAPDict); + + CPDF_Stream* pNormalStream = new CPDF_Stream(nullptr, 0, nullptr); + int32_t objnum = pDoc->AddIndirectObject(pNormalStream); + pAnnotDict->GetDictBy("AP")->SetAtReference("N", pDoc, objnum); + + pNormalStream->SetData(reinterpret_cast(sAppStream.GetBuffer()), + sAppStream.GetSize(), FALSE, FALSE); + + CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); + pStreamDict->SetAtInteger("FormType", 1); + pStreamDict->SetAtString("Subtype", "Form"); + pStreamDict->SetAtMatrix("Matrix", CFX_Matrix()); + pStreamDict->SetAtRect("BBox", rect); + + CPDF_Dictionary* pGSDict = new CPDF_Dictionary; + pGSDict->SetAtString("Type", "ExtGState"); + pGSDict->SetAtNumber("ca", 1); + pGSDict->SetAtNumber("CA", 1); + pGSDict->SetAtBoolean("AIS", false); + pGSDict->SetAtString("BM", "Multiply"); + + CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary; + pExtGStateDict->SetAt("GS", pGSDict); + + CPDF_Dictionary* pResourceDict = new CPDF_Dictionary; + pResourceDict->SetAt("ExtGState", pExtGStateDict); + + pStreamDict->SetAt("Resources", pResourceDict); + return true; +} + // Static. CFX_ByteString CPVT_GenerateAP::GenerateEditAP( IPVT_FontMap* pFontMap, diff --git a/core/fpdfdoc/cpvt_generateap.h b/core/fpdfdoc/cpvt_generateap.h index 3a984199a9..4b4d7d093b 100644 --- a/core/fpdfdoc/cpvt_generateap.h +++ b/core/fpdfdoc/cpvt_generateap.h @@ -27,6 +27,8 @@ class CPVT_GenerateAP { public: static bool GenerateComboBoxAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); + static bool GenerateHighlightAP(CPDF_Document* pDoc, + CPDF_Dictionary* pAnnotDict); static bool GenerateListBoxAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); static bool GenerateTextFieldAP(CPDF_Document* pDoc, -- cgit v1.2.3