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

pdfium: replace FPDFFormObj_GetSubObject() with backport

Change-Id: If5fc2fb328320f6cad608bebbc704ced3d69cee8
Reviewed-on: https://gerrit.libreoffice.org/59006
Tested-by: Jenkins
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst eb730584
From 1d273f1cf00676725da6f0cd17e107f114030e87 Mon Sep 17 00:00:00 2001
Date: Mon, 16 Jul 2018 19:20:36 +0000
Subject: [PATCH] Add FPDFFormObj_GetObject() API
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
To be used together with the existing FPDFFormObj_CountObjects()
function.
Change-Id: I8ed69624e967708c8db7e8f135e28fbe6a52752f
Reviewed-on: https://pdfium-review.googlesource.com/37890
Reviewed-by: Nicolás Peña Moreno <npm@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
---
fpdfsdk/fpdf_edit_embeddertest.cpp | 20 +++++++++++++++++++
fpdfsdk/fpdf_editpage.cpp | 41 +++++++++++++++++++++++++++-----------
fpdfsdk/fpdf_view_c_api_test.c | 1 +
public/fpdf_edit.h | 10 ++++++++++
4 files changed, 60 insertions(+), 12 deletions(-)
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index ded55b9be..f1dbf7019 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -140,6 +140,23 @@ unsigned int GetUnsignedAlpha(float alpha) {
return static_cast<unsigned int>(alpha * 255.f + 0.5f);
}
+const CPDF_PageObjectList* CPDFPageObjListFromFPDFFormObject(
+ FPDF_PAGEOBJECT page_object) {
+ auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object);
+ if (!pPageObj)
+ return nullptr;
+
+ CPDF_FormObject* pFormObject = pPageObj->AsForm();
+ if (!pFormObject)
+ return nullptr;
+
+ const CPDF_Form* pForm = pFormObject->form();
+ if (!pForm)
+ return nullptr;
+
+ return pForm->GetPageObjectList();
+}
+
} // namespace
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument() {
@@ -812,21 +829,21 @@ FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) {
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)
+ const CPDF_PageObjectList* pObjectList =
+ CPDFPageObjListFromFPDFFormObject(page_object);
+ if (!pObjectList)
return -1;
- const CPDF_Form* pForm = pFormObject->form();
- if (!pForm)
- return -1;
+ return pObjectList->size();
+}
- const CPDF_PageObjectList* pObjectList = pForm->GetPageObjectList();
+FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV
+FPDFFormObj_GetObject(FPDF_PAGEOBJECT form_object, unsigned long index) {
+ const CPDF_PageObjectList* pObjectList =
+ CPDFPageObjListFromFPDFFormObject(form_object);
if (!pObjectList)
- return -1;
+ return nullptr;
- return pObjectList->size();
+ return FPDFPageObjectFromCPDFPageObject(
+ pObjectList->GetPageObjectByIndex(index));
}
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index fdd8c97d0..b97a7adbd 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -1265,6 +1265,16 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text);
FPDF_EXPORT int FPDF_CALLCONV
FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object);
+// Experimental API.
+// Get page object in |form_object| at |index|.
+//
+// form_object - handle to a form object.
+// index - the 0-based index of a page object.
+//
+// Returns the handle to the page object, or NULL on error.
+FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV
+FPDFFormObj_GetObject(FPDF_PAGEOBJECT form_object, unsigned long index);
+
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
--
2.16.4
...@@ -40,9 +40,9 @@ index 912df63..3244943 100644 ...@@ -40,9 +40,9 @@ index 912df63..3244943 100644
diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
--- a/pdfium/public/fpdf_edit.h --- a/pdfium/public/fpdf_edit.h
+++ b/pdfium/public/fpdf_edit.h +++ b/pdfium/public/fpdf_edit.h
@@ -1142,6 +1142,15 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text); @@ -1152,6 +1152,15 @@ FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object);
FPDF_EXPORT int FPDF_CALLCONV FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV
FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object); FPDFFormObj_GetObject(FPDF_PAGEOBJECT form_object, unsigned long index);
+// Get the number of characters from a text object. +// Get the number of characters from a text object.
+// +//
......
From 636f92aac24f0accfbce910c9153d5479e097e5f Mon Sep 17 00:00:00 2001
From: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Date: Tue, 5 Jun 2018 11:34:38 +0200
Subject: [PATCH 10/14] svx: support importing forms from PDFs
---
pdfium/fpdfsdk/cpdfsdk_helpers.h | 5 +++++
pdfium/fpdfsdk/fpdf_editpage.cpp | 30 ++++++++++++++++++++++++++++++
pdfium/public/fpdf_edit.h | 17 +++++++++++++++++
3 files changed, 52 insertions(+)
diff --git a/pdfium/fpdfsdk/cpdfsdk_helpers.h b/pdfium/fpdfsdk/cpdfsdk_helpers.h
index 13362cf..477bb74 100644
--- a/pdfium/fpdfsdk/cpdfsdk_helpers.h
+++ b/pdfium/fpdfsdk/cpdfsdk_helpers.h
@@ -209,6 +209,11 @@ inline CPDF_TextObject* CPDFTextObjectFromFPDFPageObject(
return reinterpret_cast<CPDF_TextObject*>(page_object);
}
+inline CPDF_FormObject* CPDFFormObjectFromFPDFPageObject(
+ FPDF_PAGEOBJECT page_object) {
+ return reinterpret_cast<CPDF_FormObject*>(page_object);
+}
+
ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string);
#ifdef PDF_ENABLE_XFA
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
@@ -671,3 +671,17 @@ FPDFFormObj_CountObjects(FPDF_PAGEOBJECT page_object) {
return pObjectList->size();
}
+
+FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV
+FPDFFormObj_GetSubObject(FPDF_PAGEOBJECT form_object, int index)
+{
+ CPDF_FormObject* pFrmObj = CPDFFormObjectFromFPDFPageObject(form_object);
+ if (pFrmObj)
+ {
+ const CPDF_PageObjectList* pObjectList = pFrmObj->form()->GetPageObjectList();
+ if (pObjectList)
+ return pObjectList->GetPageObjectByIndex(index);
+ }
+
+ return nullptr;
+}
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
@@ -1151,6 +1151,15 @@ FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object);
FPDF_EXPORT int FPDF_CALLCONV
FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object);
+// Get the page object from a form object.
+//
+// form_object - Handle to a form object. Returned by FPDFPage_GetObject.
+// index - The index of a page object.
+// Return value:
+// The handle of the page object. Null for failed.
+FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV
+FPDFFormObj_GetSubObject(FPDF_PAGEOBJECT form_object, int index);
+
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
--
2.16.3
...@@ -8,13 +8,29 @@ Subject: [PATCH 11/14] svx: correctly possition form objects from PDF ...@@ -8,13 +8,29 @@ Subject: [PATCH 11/14] svx: correctly possition form objects from PDF
pdfium/public/fpdf_edit.h | 18 ++++++++++++++++++ pdfium/public/fpdf_edit.h | 18 ++++++++++++++++++
2 files changed, 43 insertions(+) 2 files changed, 43 insertions(+)
diff --git a/pdfium/fpdfsdk/cpdfsdk_helpers.h b/pdfium/fpdfsdk/cpdfsdk_helpers.h
index 13362cf..477bb74 100644
--- a/pdfium/fpdfsdk/cpdfsdk_helpers.h
+++ b/pdfium/fpdfsdk/cpdfsdk_helpers.h
@@ -209,6 +209,11 @@ inline CPDF_TextObject* CPDFTextObjectFromFPDFPageObject(
return reinterpret_cast<CPDF_TextObject*>(page_object);
}
+inline CPDF_FormObject* CPDFFormObjectFromFPDFPageObject(
+ FPDF_PAGEOBJECT page_object) {
+ return reinterpret_cast<CPDF_FormObject*>(page_object);
+}
+
ByteString CFXByteStringFromFPDFWideString(FPDF_WIDESTRING wide_string);
#ifdef PDF_ENABLE_XFA
diff --git a/pdfium/fpdfsdk/fpdf_editpage.cpp b/pdfium/fpdfsdk/fpdf_editpage.cpp diff --git a/pdfium/fpdfsdk/fpdf_editpage.cpp b/pdfium/fpdfsdk/fpdf_editpage.cpp
index bf68250..f4a1688 100644 index bf68250..f4a1688 100644
--- a/pdfium/fpdfsdk/fpdf_editpage.cpp --- a/pdfium/fpdfsdk/fpdf_editpage.cpp
+++ b/pdfium/fpdfsdk/fpdf_editpage.cpp +++ b/pdfium/fpdfsdk/fpdf_editpage.cpp
@@ -810,3 +810,28 @@ FPDFFormObj_GetSubObject(FPDF_PAGEOBJECT form_object, int index) @@ -688,3 +688,28 @@ FPDFFormObj_GetObject(FPDF_PAGEOBJECT form_object, unsigned long index) {
return FPDFPageObjectFromCPDFPageObject(
return nullptr; pObjectList->GetPageObjectByIndex(index));
} }
+ +
+FPDF_EXPORT void FPDF_CALLCONV +FPDF_EXPORT void FPDF_CALLCONV
...@@ -45,9 +61,9 @@ diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h ...@@ -45,9 +61,9 @@ diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
index ca76954..f249e64 100644 index ca76954..f249e64 100644
--- a/pdfium/public/fpdf_edit.h --- a/pdfium/public/fpdf_edit.h
+++ b/pdfium/public/fpdf_edit.h +++ b/pdfium/public/fpdf_edit.h
@@ -1098,6 +1098,24 @@ FPDFFormObj_CountSubObjects(FPDF_PAGEOBJECT form_object); @@ -1161,6 +1161,24 @@ FPDFFormObj_GetObject(FPDF_PAGEOBJECT form_object, unsigned long index);
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDF_EXPORT int FPDF_CALLCONV
FPDFFormObj_GetSubObject(FPDF_PAGEOBJECT form_object, int index); FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object);
+// Get the matrix of a particular form object. +// Get the matrix of a particular form object.
+// +//
......
...@@ -72,7 +72,7 @@ index f4a1688..f34d3b5 100644 ...@@ -72,7 +72,7 @@ index f4a1688..f34d3b5 100644
#include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_helpers.h"
#include "public/fpdf_formfill.h" #include "public/fpdf_formfill.h"
#include "third_party/base/logging.h" #include "third_party/base/logging.h"
@@ -651,6 +652,46 @@ FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) { @@ -668,6 +669,46 @@ FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) {
return true; return true;
} }
...@@ -118,14 +118,14 @@ index f4a1688..f34d3b5 100644 ...@@ -118,14 +118,14 @@ index f4a1688..f34d3b5 100644
+ +
FPDF_EXPORT int FPDF_CALLCONV FPDF_EXPORT int FPDF_CALLCONV
FPDFFormObj_CountObjects(FPDF_PAGEOBJECT page_object) { FPDFFormObj_CountObjects(FPDF_PAGEOBJECT page_object) {
auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); const CPDF_PageObjectList* pObjectList =
diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
index f249e64..e14b2a5 100644 index f249e64..e14b2a5 100644
--- a/pdfium/public/fpdf_edit.h --- a/pdfium/public/fpdf_edit.h
+++ b/pdfium/public/fpdf_edit.h +++ b/pdfium/public/fpdf_edit.h
@@ -1151,6 +1151,19 @@ FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object); @@ -1152,6 +1152,19 @@ FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object);
FPDF_EXPORT int FPDF_CALLCONV FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV
FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object); FPDFFormObj_GetObject(FPDF_PAGEOBJECT form_object, unsigned long index);
+// Get the processed text of a text object. +// Get the processed text of a text object.
+// +//
...@@ -140,9 +140,9 @@ index f249e64..e14b2a5 100644 ...@@ -140,9 +140,9 @@ index f249e64..e14b2a5 100644
+ int char_count, + int char_count,
+ unsigned short* result); + unsigned short* result);
+ +
// Get the page object from a form object. // Get the number of characters from a text object.
// //
// form_object - Handle to a form object. Returned by FPDFPage_GetObject. // text_object - Handle of text object returned by FPDFPageObj_NewTextObj
-- --
2.16.3 2.16.3
...@@ -49,15 +49,6 @@ index 29c8b01..a52e1a9 100644 ...@@ -49,15 +49,6 @@ index 29c8b01..a52e1a9 100644
return ret_count; return ret_count;
} }
@@ -714,7 +714,7 @@ FPDFFormObj_GetSubObject(FPDF_PAGEOBJECT form_object, int index)
{
const CPDF_PageObjectList* pObjectList = pFrmObj->form()->GetPageObjectList();
if (pObjectList)
- return pObjectList->GetPageObjectByIndex(index);
+ return FPDFPageObjectFromCPDFPageObject(pObjectList->GetPageObjectByIndex(index));
}
return nullptr;
-- --
2.16.3 2.16.3
...@@ -54,9 +54,9 @@ diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h ...@@ -54,9 +54,9 @@ diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
index 4351649..f858ab2 100644 index 4351649..f858ab2 100644
--- a/pdfium/public/fpdf_edit.h --- a/pdfium/public/fpdf_edit.h
+++ b/pdfium/public/fpdf_edit.h +++ b/pdfium/public/fpdf_edit.h
@@ -1142,6 +1142,17 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text); @@ -1165,6 +1165,17 @@ FPDFTextObj_GetTextProcessed(FPDF_PAGEOBJECT text_object,
FPDF_EXPORT int FPDF_CALLCONV int char_count,
FPDFFormObj_CountObjects(FPDF_PAGEOBJECT form_object); unsigned short* result);
+// Get the font name of a text object. +// Get the font name of a text object.
+// +//
......
...@@ -19,10 +19,11 @@ pdfium_patches += 0001-Add-FPDFTextObj_GetFontSize-API.patch.patch.1 ...@@ -19,10 +19,11 @@ pdfium_patches += 0001-Add-FPDFTextObj_GetFontSize-API.patch.patch.1
pdfium_patches += 0001-Add-FPDFText_GetTextRenderMode-API.patch.1 pdfium_patches += 0001-Add-FPDFText_GetTextRenderMode-API.patch.1
# Backport of <https://pdfium-review.googlesource.com/37316>. # Backport of <https://pdfium-review.googlesource.com/37316>.
pdfium_patches += 0001-Add-FPDFFormObj_CountObjects-API.patch.1 pdfium_patches += 0001-Add-FPDFFormObj_CountObjects-API.patch.1
# Backport of <https://pdfium-review.googlesource.com/37890>.
pdfium_patches += 0001-Add-FPDFFormObj_GetObject-API.patch.1
pdfium_patches += 0002-svx-more-accurate-PDF-text-importing.patch.2 pdfium_patches += 0002-svx-more-accurate-PDF-text-importing.patch.2
pdfium_patches += 0003-svx-import-PDF-images-as-BGRA.patch.2 pdfium_patches += 0003-svx-import-PDF-images-as-BGRA.patch.2
pdfium_patches += 0004-svx-support-PDF-text-color.patch.2 pdfium_patches += 0004-svx-support-PDF-text-color.patch.2
pdfium_patches += 0010-svx-support-importing-forms-from-PDFs.patch.2
pdfium_patches += 0011-svx-correctly-possition-form-objects-from-PDF.patch.2 pdfium_patches += 0011-svx-correctly-possition-form-objects-from-PDF.patch.2
pdfium_patches += 0012-svx-import-processed-PDF-text.patch.2 pdfium_patches += 0012-svx-import-processed-PDF-text.patch.2
pdfium_patches += 0014-svx-update-PDFium-patch-and-code.patch.2 pdfium_patches += 0014-svx-update-PDFium-patch-and-code.patch.2
......
...@@ -793,7 +793,7 @@ void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex ...@@ -793,7 +793,7 @@ void ImpSdrPdfImport::ImportForm(FPDF_PAGEOBJECT pPageObject, FPDF_TEXTPAGE pTex
const int nCount = FPDFFormObj_CountObjects(pPageObject); const int nCount = FPDFFormObj_CountObjects(pPageObject);
for (int nIndex = 0; nIndex < nCount; ++nIndex) for (int nIndex = 0; nIndex < nCount; ++nIndex)
{ {
FPDF_PAGEOBJECT pFormObject = FPDFFormObj_GetSubObject(pPageObject, nIndex); FPDF_PAGEOBJECT pFormObject = FPDFFormObj_GetObject(pPageObject, nIndex);
ImportPdfObject(pFormObject, pTextPage, -1); ImportPdfObject(pFormObject, pTextPage, -1);
} }
......
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