From 96a07863120273c8b89cba0e7d53ef29ae56d580 Mon Sep 17 00:00:00 2001 From: jaepark Date: Wed, 3 Aug 2016 14:17:02 -0700 Subject: Generate default AP stream for squiggly annotation. This patch generates a default AP stream for squiggly annotation so that squiggly annotations without AP stream can be displayed. Also, roll DEPS for testing/corpus to a89e4fb to test squiggly annotations. BUG=62625 Review-Url: https://codereview.chromium.org/2206773004 --- DEPS | 2 +- core/fpdfdoc/cpdf_annot.cpp | 2 ++ core/fpdfdoc/cpvt_generateap.cpp | 51 ++++++++++++++++++++++++++++++++++++++++ core/fpdfdoc/cpvt_generateap.h | 2 ++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/DEPS b/DEPS index cdab05098c..77ed7e901c 100644 --- a/DEPS +++ b/DEPS @@ -14,7 +14,7 @@ vars = { 'gmock_revision': '29763965ab52f24565299976b936d1265cb6a271', 'gtest_revision': '8245545b6dc9c4703e6496d1efd19e975ad2b038', 'icu_revision': 'a5f86adbb0a58d04c035a5d1228747b1823cd485', - 'pdfium_tests_revision': 'ddc1938d718be26a64192cfabdbeb64792d58fb6', + 'pdfium_tests_revision': 'a89e4fbd6b38d7551f3f6369d5776be90cfe5e49', 'skia_revision': '96206a96f357cd30b60d1b1aa98e4e3a8f9b97f1', 'tools_memory_revision': '427f10475e1a8d72424c29d00bf689122b738e5d', 'trace_event_revision': '54b8455be9505c2cb0cf5c26bb86739c236471aa', diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp index 9a3797d351..7396aa2558 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 == "Squiggly") + CPVT_GenerateAP::GenerateSquigglyAP(m_pDocument, m_pAnnotDict); else if (m_sSubtype == "StrikeOut") CPVT_GenerateAP::GenerateStrikeOutAP(m_pDocument, m_pAnnotDict); else if (m_sSubtype == "Underline") diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index a19332bb7c..6da25b61f7 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -619,6 +619,57 @@ bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc, return true; } +bool CPVT_GenerateAP::GenerateSquigglyAP(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; + CFX_ByteString sExtGSDictName = "GS"; + sAppStream << "/" << sExtGSDictName << " gs "; + + sAppStream << GetColorStringWithDefault(pAnnotDict, + CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), + PaintOperation::STROKE); + + CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect"); + rect.Normalize(); + + FX_FLOAT fLineWidth = 1.0; + sAppStream << fLineWidth << " w "; + + const FX_FLOAT fDelta = 2.0; + const FX_FLOAT fTop = rect.bottom + fDelta; + const FX_FLOAT fBottom = rect.bottom; + + sAppStream << rect.left << " " << fTop << " m "; + + FX_FLOAT fX = rect.left + fDelta; + bool isUpwards = false; + + while (fX < rect.right) { + sAppStream << fX << " " << (isUpwards ? fTop : fBottom) << " l "; + + fX += fDelta; + isUpwards = !isUpwards; + } + + FX_FLOAT fRemainder = rect.right - (fX - fDelta); + if (isUpwards) + sAppStream << rect.right << " " << fBottom + fRemainder << " l "; + else + sAppStream << rect.right << " " << fTop - fRemainder << " l "; + + sAppStream << "S\n"; + + CPDF_Dictionary* pExtGStateDict = + GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal"); + GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict); + return true; +} + bool CPVT_GenerateAP::GenerateStrikeOutAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) { // If AP dictionary exists, we use the appearance defined in the diff --git a/core/fpdfdoc/cpvt_generateap.h b/core/fpdfdoc/cpvt_generateap.h index ad4b7f0d3f..3e4bbfe5ce 100644 --- a/core/fpdfdoc/cpvt_generateap.h +++ b/core/fpdfdoc/cpvt_generateap.h @@ -31,6 +31,8 @@ class CPVT_GenerateAP { CPDF_Dictionary* pAnnotDict); static bool GenerateListBoxAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); + static bool GenerateSquigglyAP(CPDF_Document* pDoc, + CPDF_Dictionary* pAnnotDict); static bool GenerateStrikeOutAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict); static bool GenerateTextFieldAP(CPDF_Document* pDoc, -- cgit v1.2.3