summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaepark <jaepark@google.com>2016-08-02 16:22:52 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-02 16:22:52 -0700
commit33e9b26ba3c191262d0abb945fda1efb3cdb3051 (patch)
treed57ffe115ab83b837a3d77b473c08885136c04c7
parent27053d81ca80a2f9433abf3e9c393d2914c91ad8 (diff)
downloadpdfium-33e9b26ba3c191262d0abb945fda1efb3cdb3051.tar.xz
Generate default AP stream for underline annotation.
This patch generates a default AP stream for underline annotation so that underline annotations without AP stream can be displayed. Also, roll DEPS for testing/corpus to cae29d1 to test underline annotations. BUG=62625 Review-Url: https://codereview.chromium.org/2205543002
-rw-r--r--DEPS2
-rw-r--r--core/fpdfdoc/cpdf_annot.cpp2
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp124
-rw-r--r--core/fpdfdoc/cpvt_generateap.h2
4 files changed, 94 insertions, 36 deletions
diff --git a/DEPS b/DEPS
index 134703950c..ed8924771b 100644
--- a/DEPS
+++ b/DEPS
@@ -14,7 +14,7 @@ vars = {
'gmock_revision': '29763965ab52f24565299976b936d1265cb6a271',
'gtest_revision': '8245545b6dc9c4703e6496d1efd19e975ad2b038',
'icu_revision': 'a5f86adbb0a58d04c035a5d1228747b1823cd485',
- 'pdfium_tests_revision': 'b63db0698bd3cac932807eb552e565b89dd2df9d',
+ 'pdfium_tests_revision': 'cae29d1e4ac7a9c32add1a6ac0d04d60298a278e',
'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 a8578fc28d..77c117dae4 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -22,6 +22,8 @@ CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument)
m_sSubtype(m_pAnnotDict->GetStringBy("Subtype")) {
if (m_sSubtype == "Highlight")
CPVT_GenerateAP::GenerateHighlightAP(m_pDocument, m_pAnnotDict);
+ else if (m_sSubtype == "Underline")
+ CPVT_GenerateAP::GenerateUnderlineAP(m_pDocument, m_pAnnotDict);
}
CPDF_Annot::~CPDF_Annot() {
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index aaf4b79858..9bde7e6b85 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -452,6 +452,65 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
return true;
}
+CFX_ByteString GetColorStringWithDefault(CPDF_Dictionary* pAnnotDict,
+ const CPVT_Color& crDefaultColor,
+ PaintOperation nOperation) {
+ if (CPDF_Array* pColor = pAnnotDict->GetArrayBy("C")) {
+ CPVT_Color color = CPVT_Color::ParseColor(*pColor);
+ return CPVT_GenerateAP::GenerateColorAP(color, nOperation);
+ }
+
+ return CPVT_GenerateAP::GenerateColorAP(crDefaultColor, nOperation);
+}
+
+CPDF_Dictionary* GenerateExtGStateDict(const CPDF_Dictionary& pAnnotDict,
+ const CFX_ByteString& sExtGSDictName,
+ const CFX_ByteString& sBlendMode) {
+ CPDF_Dictionary* pGSDict = new CPDF_Dictionary;
+ pGSDict->SetAtString("Type", "ExtGState");
+
+ FX_FLOAT fOpacity =
+ pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberBy("CA") : 1;
+ pGSDict->SetAtNumber("CA", fOpacity);
+ pGSDict->SetAtNumber("ca", fOpacity);
+ pGSDict->SetAtBoolean("AIS", false);
+ pGSDict->SetAtString("BM", sBlendMode);
+
+ CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary;
+ pExtGStateDict->SetAt(sExtGSDictName, pGSDict);
+
+ return pExtGStateDict;
+}
+
+// Takes ownership of |pExtGStateDict|.
+void GenerateAndSetAPDict(CPDF_Document* pDoc,
+ CPDF_Dictionary* pAnnotDict,
+ const CFX_ByteTextBuf& sAppStream,
+ CPDF_Dictionary* pExtGStateDict) {
+ 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());
+
+ CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
+ pStreamDict->SetAtRect("BBox", rect);
+
+ CPDF_Dictionary* pResourceDict = new CPDF_Dictionary;
+ pResourceDict->SetAt("ExtGState", pExtGStateDict);
+
+ pStreamDict->SetAt("Resources", pResourceDict);
+}
+
} // namespace
bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
@@ -510,16 +569,11 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
return false;
CFX_ByteTextBuf sAppStream;
- sAppStream << "/GS gs ";
+ CFX_ByteString sExtGSDictName = "GS";
+ sAppStream << "/" << sExtGSDictName << " gs ";
- if (pAnnotDict->KeyExist("C")) {
- CPDF_Array* pColor = pAnnotDict->GetArrayBy("C");
- CPVT_Color color = CPVT_Color::ParseColor(*pColor);
- sAppStream << CPVT_GenerateAP::GenerateColorAP(color, PaintOperation::FILL);
- } else {
- // Defaults to 0xFFFF00 color for highlight.
- sAppStream << "1 1 0 rg \n";
- }
+ sAppStream << GetColorStringWithDefault(
+ pAnnotDict, CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), PaintOperation::FILL);
CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
rect.Normalize();
@@ -529,39 +583,39 @@ bool CPVT_GenerateAP::GenerateHighlightAP(CPDF_Document* pDoc,
<< rect.left << " " << rect.bottom << " l "
<< "h f\n";
- CPDF_Dictionary* pAPDict = new CPDF_Dictionary;
- pAnnotDict->SetAt("AP", pAPDict);
+ CPDF_Dictionary* pExtGStateDict =
+ GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Multiply");
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
- 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);
+ return true;
+}
- CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
- pStreamDict->SetAtInteger("FormType", 1);
- pStreamDict->SetAtString("Subtype", "Form");
- pStreamDict->SetAtMatrix("Matrix", CFX_Matrix());
- pStreamDict->SetAtRect("BBox", rect);
+bool CPVT_GenerateAP::GenerateUnderlineAP(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;
- CPDF_Dictionary* pGSDict = new CPDF_Dictionary;
- pGSDict->SetAtString("Type", "ExtGState");
+ CFX_ByteTextBuf sAppStream;
+ CFX_ByteString sExtGSDictName = "GS";
+ sAppStream << "/" << sExtGSDictName << " gs ";
- FX_FLOAT fOpacity =
- pAnnotDict->KeyExist("CA") ? pAnnotDict->GetNumberBy("CA") : 1;
- pGSDict->SetAtNumber("ca", fOpacity);
- pGSDict->SetAtNumber("CA", fOpacity);
- pGSDict->SetAtBoolean("AIS", false);
- pGSDict->SetAtString("BM", "Multiply");
+ sAppStream << GetColorStringWithDefault(pAnnotDict,
+ CPVT_Color(CPVT_Color::kRGB, 0, 0, 0),
+ PaintOperation::STROKE);
- CPDF_Dictionary* pExtGStateDict = new CPDF_Dictionary;
- pExtGStateDict->SetAt("GS", pGSDict);
+ CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
+ rect.Normalize();
- CPDF_Dictionary* pResourceDict = new CPDF_Dictionary;
- pResourceDict->SetAt("ExtGState", pExtGStateDict);
+ FX_FLOAT fLineWidth = 1.0;
+ sAppStream << fLineWidth << " w " << rect.left << " "
+ << rect.bottom + fLineWidth << " m " << rect.right << " "
+ << rect.bottom + fLineWidth << " l S\n";
- pStreamDict->SetAt("Resources", pResourceDict);
+ CPDF_Dictionary* pExtGStateDict =
+ GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
+ GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
return true;
}
diff --git a/core/fpdfdoc/cpvt_generateap.h b/core/fpdfdoc/cpvt_generateap.h
index 6cd9dcea67..233a6f39fe 100644
--- a/core/fpdfdoc/cpvt_generateap.h
+++ b/core/fpdfdoc/cpvt_generateap.h
@@ -33,6 +33,8 @@ class CPVT_GenerateAP {
CPDF_Dictionary* pAnnotDict);
static bool GenerateTextFieldAP(CPDF_Document* pDoc,
CPDF_Dictionary* pAnnotDict);
+ static bool GenerateUnderlineAP(CPDF_Document* pDoc,
+ CPDF_Dictionary* pAnnotDict);
static CFX_ByteString GenerateEditAP(IPVT_FontMap* pFontMap,
CPDF_VariableText::Iterator* pIterator,
const CFX_FloatPoint& ptOffset,