summaryrefslogtreecommitdiffstats
path: root/external/pdfium/0001-Add-FPDFFormObj_CountObjects-API.patch.1
blob: 190fc6b2c9b64040cbb31b39696b3ec03476e4cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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