From baa7ff4390b8b36c2d58c1b1f8d9775c76da656a Mon Sep 17 00:00:00 2001 From: Jane Liu Date: Thu, 29 Jun 2017 19:18:23 -0400 Subject: Basic APIs and tests for extracting and setting annotation paths 1. Added APIs for retrieving existing annotation paths and setting annotation paths. * Added an embedder test testing all the new functions. Bug=pdfium:737 Change-Id: Ic451bcd3be488261baf2182549c4238b887b219e Reviewed-on: https://pdfium-review.googlesource.com/6676 Commit-Queue: Jane Liu Reviewed-by: Lei Zhang Reviewed-by: dsinclair --- core/fpdfdoc/cpvt_generateap.cpp | 124 ++++++++++++++++++++------------------- core/fpdfdoc/cpvt_generateap.h | 14 +++++ 2 files changed, 78 insertions(+), 60 deletions(-) (limited to 'core/fpdfdoc') diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index ff7f4b68ee..eb874b3352 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -545,27 +545,6 @@ CFX_ByteString GetPopupContentsString(CPDF_Document* pDoc, return CFX_ByteString(sAppStream); } -std::unique_ptr GenerateExtGStateDict( - const CPDF_Dictionary& pAnnotDict, - const CFX_ByteString& sExtGSDictName, - const CFX_ByteString& sBlendMode) { - auto pGSDict = - pdfium::MakeUnique(pAnnotDict.GetByteStringPool()); - pGSDict->SetNewFor("Type", "ExtGState", false); - - float fOpacity = - pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberFor("CA") : 1; - pGSDict->SetNewFor("CA", fOpacity); - pGSDict->SetNewFor("ca", fOpacity); - pGSDict->SetNewFor("AIS", false); - pGSDict->SetNewFor("BM", sBlendMode, false); - - auto pExtGStateDict = - pdfium::MakeUnique(pAnnotDict.GetByteStringPool()); - pExtGStateDict->SetFor(sExtGSDictName, std::move(pGSDict)); - return pExtGStateDict; -} - std::unique_ptr GenerateResourceFontDict( CPDF_Document* pDoc, const CFX_ByteString& sFontDictName) { @@ -582,45 +561,6 @@ std::unique_ptr GenerateResourceFontDict( return pResourceFontDict; } -std::unique_ptr GenerateResourceDict( - CPDF_Document* pDoc, - std::unique_ptr pExtGStateDict, - std::unique_ptr pResourceFontDict) { - auto pResourceDict = - pdfium::MakeUnique(pDoc->GetByteStringPool()); - if (pExtGStateDict) - pResourceDict->SetFor("ExtGState", std::move(pExtGStateDict)); - if (pResourceFontDict) - pResourceDict->SetFor("Font", std::move(pResourceFontDict)); - return pResourceDict; -} - -void GenerateAndSetAPDict(CPDF_Document* pDoc, - CPDF_Dictionary* pAnnotDict, - std::ostringstream* psAppStream, - std::unique_ptr pResourceDict, - bool bIsTextMarkupAnnotation) { - CPDF_Stream* pNormalStream = pDoc->NewIndirect(); - pNormalStream->SetData(psAppStream); - - CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP"); - if (!pAPDict) - pAPDict = pAnnotDict->SetNewFor("AP"); - - pAPDict->SetNewFor("N", pDoc, pNormalStream->GetObjNum()); - - CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); - pStreamDict->SetNewFor("FormType", 1); - pStreamDict->SetNewFor("Subtype", "Form", false); - pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); - - CFX_FloatRect rect = bIsTextMarkupAnnotation - ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) - : pAnnotDict->GetRectFor("Rect"); - pStreamDict->SetRectFor("BBox", rect); - pStreamDict->SetFor("Resources", std::move(pResourceDict)); -} - CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) { if (bIsStrokeRect) return bIsFillRect ? "b" : "s"; @@ -1321,6 +1261,70 @@ CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color, return CFX_ByteString(sColorStream); } +// Static. +std::unique_ptr CPVT_GenerateAP::GenerateExtGStateDict( + const CPDF_Dictionary& pAnnotDict, + const CFX_ByteString& sExtGSDictName, + const CFX_ByteString& sBlendMode) { + auto pGSDict = + pdfium::MakeUnique(pAnnotDict.GetByteStringPool()); + pGSDict->SetNewFor("Type", "ExtGState", false); + + float fOpacity = + pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberFor("CA") : 1; + pGSDict->SetNewFor("CA", fOpacity); + pGSDict->SetNewFor("ca", fOpacity); + pGSDict->SetNewFor("AIS", false); + pGSDict->SetNewFor("BM", sBlendMode, false); + + auto pExtGStateDict = + pdfium::MakeUnique(pAnnotDict.GetByteStringPool()); + pExtGStateDict->SetFor(sExtGSDictName, std::move(pGSDict)); + return pExtGStateDict; +} + +// Static. +std::unique_ptr CPVT_GenerateAP::GenerateResourceDict( + CPDF_Document* pDoc, + std::unique_ptr pExtGStateDict, + std::unique_ptr pResourceFontDict) { + auto pResourceDict = + pdfium::MakeUnique(pDoc->GetByteStringPool()); + if (pExtGStateDict) + pResourceDict->SetFor("ExtGState", std::move(pExtGStateDict)); + if (pResourceFontDict) + pResourceDict->SetFor("Font", std::move(pResourceFontDict)); + return pResourceDict; +} + +// Static. +void CPVT_GenerateAP::GenerateAndSetAPDict( + CPDF_Document* pDoc, + CPDF_Dictionary* pAnnotDict, + std::ostringstream* psAppStream, + std::unique_ptr pResourceDict, + bool bIsTextMarkupAnnotation) { + CPDF_Stream* pNormalStream = pDoc->NewIndirect(); + pNormalStream->SetData(psAppStream); + + CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP"); + if (!pAPDict) + pAPDict = pAnnotDict->SetNewFor("AP"); + + pAPDict->SetNewFor("N", pDoc, pNormalStream->GetObjNum()); + + CPDF_Dictionary* pStreamDict = pNormalStream->GetDict(); + pStreamDict->SetNewFor("FormType", 1); + pStreamDict->SetNewFor("Subtype", "Form", false); + pStreamDict->SetMatrixFor("Matrix", CFX_Matrix()); + + CFX_FloatRect rect = bIsTextMarkupAnnotation + ? CPDF_Annot::RectFromQuadPoints(pAnnotDict) + : pAnnotDict->GetRectFor("Rect"); + pStreamDict->SetRectFor("BBox", rect); + pStreamDict->SetFor("Resources", std::move(pResourceDict)); +} + // Static. CFX_ByteString CPVT_GenerateAP::GetPDFWordString(IPVT_FontMap* pFontMap, int32_t nFontIndex, diff --git a/core/fpdfdoc/cpvt_generateap.h b/core/fpdfdoc/cpvt_generateap.h index c558636255..cee96cda50 100644 --- a/core/fpdfdoc/cpvt_generateap.h +++ b/core/fpdfdoc/cpvt_generateap.h @@ -60,6 +60,20 @@ class CPVT_GenerateAP { const CPVT_Dash& dash); static CFX_ByteString GenerateColorAP(const CPVT_Color& color, PaintOperation nOperation); + static std::unique_ptr GenerateExtGStateDict( + const CPDF_Dictionary& pAnnotDict, + const CFX_ByteString& sExtGSDictName, + const CFX_ByteString& sBlendMode); + static std::unique_ptr GenerateResourceDict( + CPDF_Document* pDoc, + std::unique_ptr pExtGStateDict, + std::unique_ptr pResourceFontDict); + static void GenerateAndSetAPDict( + CPDF_Document* pDoc, + CPDF_Dictionary* pAnnotDict, + std::ostringstream* psAppStream, + std::unique_ptr pResourceDict, + bool bIsTextMarkupAnnotation); static CFX_ByteString GetPDFWordString(IPVT_FontMap* pFontMap, int32_t nFontIndex, -- cgit v1.2.3