Kaydet (Commit) 3820aff0 authored tarafından Miklos Vajna's avatar Miklos Vajna

pdfium: replace FPDFFormObj_CountSubObjects() with backport

Change-Id: Ie7aaf6790c29818236f38b90409860dedecb3cb3
Reviewed-on: https://gerrit.libreoffice.org/58711
Tested-by: Jenkins
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst b9a739e0
From b66077d3ef7ba594f2a831840783549f4dd70d86 Mon Sep 17 00:00:00 2001
Date: Wed, 11 Jul 2018 13:25:02 +0000
Subject: [PATCH] Add FPDFFormObj_CountObjects() API
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
To find out the number of sub-objects a form object has, similar to how
FPDFPage_CountObjects() does it for page objects.
Change-Id: I7e5775dece42b74fd5b71b1d9622a1aa37bf64ac
Reviewed-on: https://pdfium-review.googlesource.com/37316
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Reviewed-by: Nicolás Peña Moreno <npm@chromium.org>
---
fpdfsdk/fpdf_edit_embeddertest.cpp | 14 ++++++
fpdfsdk/fpdf_editpage.cpp | 21 +++++++++
fpdfsdk/fpdf_view_c_api_test.c | 1 +
public/fpdf_edit.h | 9 ++++
testing/resources/form_object.in | 80 +++++++++++++++++++++++++++++++++
testing/resources/form_object.pdf | 91 ++++++++++++++++++++++++++++++++++++++
6 files changed, 216 insertions(+)
create mode 100644 testing/resources/form_object.in
create mode 100644 testing/resources/form_object.pdf
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index 8a1200885..4151de5df 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -751,3 +751,24 @@ FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) {
pPageObj->SetDirty(true);
return true;
}
+
+FPDF_EXPORT int FPDF_CALLCONV
+FPDFFormObj_CountObjects(FPDF_PAGEOBJECT page_object) {
+ auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
+ if (!pPageObj)
+ return -1;
+
+ CPDF_FormObject* pFormObject = pPageObj->AsForm();
+ if (!pFormObject)
+ return -1;
+
+ const CPDF_Form* pForm = pFormObject->form();
+ if (!pForm)
+ return -1;
+
+ const CPDF_PageObjectList* pObjectList = pForm->GetPageObjectList();
+ if (!pObjectList)
+ return -1;
+
+ return pObjectList->size();
+}
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index b85537d0b..e6f193a37 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -1226,6 +1226,15 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
// Returns one of the FPDF_TEXTRENDERMODE_* flags on success, -1 on error.
FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text);
+// Experimental API.
+// Get number of page objects inside |form_object|.
+//
+// form_object - handle to a form object.
+//
+// Returns the number of objects in |form_object| on success, -1 on error.
+FPDF_EXPORT int FPDF_CALLCONV
+FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object);
+
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
--
2.16.4
......@@ -40,9 +40,9 @@ index 912df63..3244943 100644
diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
--- a/pdfium/public/fpdf_edit.h
+++ b/pdfium/public/fpdf_edit.h
@@ -1133,6 +1133,15 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
// Returns one of the FPDF_TEXTRENDERMODE_* flags on success, -1 on error.
FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text);
@@ -1142,6 +1142,15 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text);
FPDF_EXPORT int FPDF_CALLCONV
FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object);
+// Get the number of characters from a text object.
+//
......
......@@ -29,25 +29,11 @@ diff --git a/pdfium/fpdfsdk/fpdf_editpage.cpp b/pdfium/fpdfsdk/fpdf_editpage.cpp
index 9c353a4..bf68250 100644
--- a/pdfium/fpdfsdk/fpdf_editpage.cpp
+++ b/pdfium/fpdfsdk/fpdf_editpage.cpp
@@ -650,3 +650,31 @@ FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) {
pPageObj->SetDirty(true);
return true;
@@ -671,3 +671,17 @@ FPDFFormObj_CountObjects(FPDF_PAGEOBJECT page_object) {
return pObjectList->size();
}
+
+FPDF_EXPORT int FPDF_CALLCONV
+FPDFFormObj_CountSubObjects(FPDF_PAGEOBJECT form_object)
+{
+ CPDF_FormObject* pFrmObj = CPDFFormObjectFromFPDFPageObject(form_object);
+ if (pFrmObj)
+ {
+ const CPDF_PageObjectList* pObjectList = pFrmObj->form()->GetPageObjectList();
+ if (pObjectList)
+ return pObjectList->size();
+ }
+
+ return 0;
+}
+
+FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV
+FPDFFormObj_GetSubObject(FPDF_PAGEOBJECT form_object, int index)
+{
......@@ -65,18 +51,10 @@ diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
index 4264ccd..ca76954 100644
--- a/pdfium/public/fpdf_edit.h
+++ b/pdfium/public/fpdf_edit.h
@@ -1142,6 +1142,23 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text);
@@ -1151,6 +1151,15 @@ FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object);
FPDF_EXPORT int FPDF_CALLCONV
FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object);
+// Get number of page objects inside the form object.
+//
+// form_object - Handle to a form object. Returned by FPDFPage_GetObject.
+// Return value:
+// The number of the page objects.
+FPDF_EXPORT int FPDF_CALLCONV
+FPDFFormObj_CountSubObjects(FPDF_PAGEOBJECT form_object);
+
+// Get the page object from a form object.
+//
+// form_object - Handle to a form object. Returned by FPDFPage_GetObject.
......
......@@ -117,13 +117,13 @@ index f4a1688..f34d3b5 100644
+}
+
FPDF_EXPORT int FPDF_CALLCONV
FPDFFormObj_CountSubObjects(FPDF_PAGEOBJECT form_object)
{
FPDFFormObj_CountObjects(FPDF_PAGEOBJECT page_object) {
auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
index f249e64..e14b2a5 100644
--- a/pdfium/public/fpdf_edit.h
+++ b/pdfium/public/fpdf_edit.h
@@ -1142,6 +1142,19 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text);
@@ -1151,6 +1151,19 @@ FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object);
FPDF_EXPORT int FPDF_CALLCONV
FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object);
......@@ -140,7 +140,7 @@ index f249e64..e14b2a5 100644
+ int char_count,
+ unsigned short* result);
+
// Get number of page objects inside the form object.
// Get the page object from a form object.
//
// form_object - Handle to a form object. Returned by FPDFPage_GetObject.
--
......
......@@ -54,9 +54,9 @@ diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
index 4351649..f858ab2 100644
--- a/pdfium/public/fpdf_edit.h
+++ b/pdfium/public/fpdf_edit.h
@@ -1133,6 +1133,17 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
// Returns one of the FPDF_TEXTRENDERMODE_* flags on success, -1 on error.
FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text);
@@ -1142,6 +1142,17 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text);
FPDF_EXPORT int FPDF_CALLCONV
FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object);
+// Get the font name of a text object.
+//
......
......@@ -17,6 +17,8 @@ pdfium_patches += build.patch.1
pdfium_patches += 0001-Add-FPDFTextObj_GetFontSize-API.patch.patch.1
# Backport of <https://pdfium-review.googlesource.com/36750>.
pdfium_patches += 0001-Add-FPDFText_GetTextRenderMode-API.patch.1
# Backport of <https://pdfium-review.googlesource.com/37316>.
pdfium_patches += 0001-Add-FPDFFormObj_CountObjects-API.patch.1
pdfium_patches += 0002-svx-more-accurate-PDF-text-importing.patch.2
pdfium_patches += 0003-svx-import-PDF-images-as-BGRA.patch.2
pdfium_patches += 0004-svx-support-PDF-text-color.patch.2
......
......@@ -790,7 +790,7 @@ void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
FPDFFormObj_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f);
mCurMatrix = Matrix(a, b, c, d, e, f);
const int nCount = FPDFFormObj_CountSubObjects(pPageObject);
const int nCount = FPDFFormObj_CountObjects(pPageObject);
for (int nIndex = 0; nIndex < nCount; ++nIndex)
{
FPDF_PAGEOBJECT pFormObject = FPDFFormObj_GetSubObject(pPageObject, nIndex);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment