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

Unified Diff: core/fpdfdoc/cpvt_generateap.cpp

Issue 2193983002: Generate default AP stream for highlight annotation. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Generate default AP stream for highlight annotation. Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fpdfdoc/cpvt_generateap.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfdoc/cpvt_generateap.cpp
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 7eb6188c94baeba8c2e58c2f5f88abf9b953b1ff..8067f0ed1365f0329c66b4961c62d7c46a05ed3d 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -493,6 +493,66 @@ FX_BOOL CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc,
return GenerateWidgetAP(pDoc, pAnnotDict, 2);
}
+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;
Lei Zhang 2016/07/30 00:56:44 return true/false
jaepark 2016/07/30 01:28:27 Done.
+
+ CFX_ByteTextBuf sAppStream;
+ sAppStream << "/TransGs 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* pTransGsDict = new CPDF_Dictionary;
+ pTransGsDict->SetAtString("Type", "ExtGState");
+ pTransGsDict->SetAtNumber("ca", 1);
+ pTransGsDict->SetAtNumber("CA", 1);
jaepark 2016/07/29 23:32:26 Data type for CA and ca field are Number.
Lei Zhang 2016/07/30 00:56:44 I can't find references to "ca" in the PDF spec. D
jaepark 2016/07/30 01:28:27 It's in the "4.3.4 Graphics State Parameter Dictio
+ pTransGsDict->SetAtBoolean("AIS", false);
+ pTransGsDict->SetAtString("BM", "Multiply");
+
+ CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary;
+ pExtGStateDict->SetAt("TransGs", pTransGsDict);
+
+ 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,
« no previous file with comments | « core/fpdfdoc/cpvt_generateap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698