summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpvt_generateap.cpp
diff options
context:
space:
mode:
authorjaepark <jaepark@google.com>2016-07-29 19:53:40 -0700
committerCommit bot <commit-bot@chromium.org>2016-07-29 19:53:40 -0700
commitab47acec5252d4a09da3cbde1a118b5255fe52ae (patch)
treea138249d262390c0058239552db53c070eca5b4f /core/fpdfdoc/cpvt_generateap.cpp
parentc54bb4340324fab9e860fd625b4b380b6135c385 (diff)
downloadpdfium-ab47acec5252d4a09da3cbde1a118b5255fe52ae.tar.xz
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
Diffstat (limited to 'core/fpdfdoc/cpvt_generateap.cpp')
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp60
1 files changed, 60 insertions, 0 deletions
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<uint8_t*>(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,