summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdf_editpage.cpp
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-07-10 21:04:05 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-10 21:04:05 +0000
commit144107d3ca6ddd2724a460c4da4a20e6e1b7f1b7 (patch)
tree7fc11c898c7d5397f8b910d447eccfd04680f288 /fpdfsdk/fpdf_editpage.cpp
parent416cbeab1d93b1261dfb4584e0c8e47d9cd4720f (diff)
downloadpdfium-144107d3ca6ddd2724a460c4da4a20e6e1b7f1b7.tar.xz
Create API for adding content marks and setting their params.chromium/3488
This CL creates the following new functions in the public API: - FPDFPageObj_AddMark - FPDFPageObjMark_SetIntParam - FPDFPageObjMark_SetStringParam Bug: pdfium:1037 Change-Id: Icabf3fdd8e8153b9156bab807a3708d38a9365d8 Reviewed-on: https://pdfium-review.googlesource.com/37330 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_editpage.cpp')
-rw-r--r--fpdfsdk/fpdf_editpage.cpp64
1 files changed, 63 insertions, 1 deletions
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index d275559107..8a1200885a 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -125,6 +125,30 @@ GetMarkParamPairAtIndex(FPDF_PAGEOBJECTMARK mark, unsigned long index) {
return nullptr;
}
+CPDF_Dictionary* GetOrCreateMarkParamsDict(FPDF_DOCUMENT document,
+ FPDF_PAGEOBJECTMARK mark) {
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
+
+ CPDF_ContentMarkItem* pMarkItem =
+ CPDFContentMarkItemFromFPDFPageObjectMark(mark);
+ if (!pMarkItem)
+ return nullptr;
+
+ CPDF_Dictionary* pParams = pMarkItem->GetParam();
+
+ // If the Params dict does not exist, create a new one.
+ if (!pParams) {
+ auto new_dict =
+ pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
+ pParams = new_dict.get();
+ pMarkItem->SetDirectDict(std::move(new_dict));
+ }
+
+ return pParams;
+}
+
unsigned int GetUnsignedAlpha(float alpha) {
return static_cast<unsigned int>(alpha * 255.f + 0.5f);
}
@@ -293,7 +317,19 @@ FPDFPageObj_GetMark(FPDF_PAGEOBJECT page_object, unsigned long index) {
if (index >= mark->CountItems())
return nullptr;
- return FPDFPageObjectMarkFromCPDFContentMarkItem(&mark->GetItem(index));
+ return FPDFPageObjectMarkFromCPDFContentMarkItem(mark->GetItem(index));
+}
+
+FPDF_EXPORT FPDF_PAGEOBJECTMARK FPDF_CALLCONV
+FPDFPageObj_AddMark(FPDF_PAGEOBJECT page_object, FPDF_BYTESTRING name) {
+ if (!page_object)
+ return nullptr;
+
+ auto* mark = &CPDFPageObjectFromFPDFPageObject(page_object)->m_ContentMark;
+ mark->AddMark(name, nullptr, true);
+ unsigned long index = mark->CountItems() - 1;
+
+ return FPDFPageObjectMarkFromCPDFContentMarkItem(mark->GetItem(index));
}
FPDF_EXPORT unsigned long FPDF_CALLCONV
@@ -456,6 +492,32 @@ FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObject) {
return false;
}
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFPageObjMark_SetIntParam(FPDF_DOCUMENT document,
+ FPDF_PAGEOBJECTMARK mark,
+ FPDF_BYTESTRING key,
+ int value) {
+ CPDF_Dictionary* pParams = GetOrCreateMarkParamsDict(document, mark);
+ if (!pParams)
+ return false;
+
+ pParams->SetNewFor<CPDF_Number>(key, value);
+ return true;
+}
+
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFPageObjMark_SetStringParam(FPDF_DOCUMENT document,
+ FPDF_PAGEOBJECTMARK mark,
+ FPDF_BYTESTRING key,
+ FPDF_BYTESTRING value) {
+ CPDF_Dictionary* pParams = GetOrCreateMarkParamsDict(document, mark);
+ if (!pParams)
+ return false;
+
+ pParams->SetNewFor<CPDF_String>(key, value, false);
+ return true;
+}
+
FPDF_EXPORT int FPDF_CALLCONV FPDFPageObj_GetType(FPDF_PAGEOBJECT pageObject) {
if (!pageObject)
return FPDF_PAGEOBJ_UNKNOWN;