summaryrefslogtreecommitdiff
path: root/external/pdfium/0001-Add-FPDFText_GetTextRenderMode-API.patch.1
blob: 47874119baeba2d3847969edd670f77ab2cce05f (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
From 1448cc11b9be67d2d1fcd3f2f833cc6f79ad8d42 Mon Sep 17 00:00:00 2001
Date: Tue, 3 Jul 2018 13:52:33 +0000
Subject: [PATCH] Add FPDFText_GetTextRenderMode() API

This allows deciding if FPDFPageObj_GetFillColor() or
FPDFPageObj_GetStrokeColor() should be used to get the effective color
of a text object.

Change-Id: Ic6e99a9eb8512b164756da8b5fcd8cd7771271ae
Reviewed-on: https://pdfium-review.googlesource.com/36750
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
---
 fpdfsdk/fpdf_edit_embeddertest.cpp     | 17 ++++++++
 fpdfsdk/fpdf_edittext.cpp              | 37 +++++++++++++++++
 fpdfsdk/fpdf_view_c_api_test.c         |  1 +
 public/fpdf_edit.h                     | 17 ++++++++
 testing/resources/text_render_mode.pdf | 75 ++++++++++++++++++++++++++++++++++
 5 files changed, 147 insertions(+)
 create mode 100644 testing/resources/text_render_mode.pdf

diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index 3115e2a16..c552d615e 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -14,6 +14,7 @@
 #include "core/fpdfapi/font/cpdf_type1font.h"
 #include "core/fpdfapi/page/cpdf_docpagedata.h"
 #include "core/fpdfapi/page/cpdf_textobject.h"
+#include "core/fpdfapi/page/cpdf_textstate.h"
 #include "core/fpdfapi/parser/cpdf_array.h"
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
 #include "core/fpdfapi/parser/cpdf_document.h"
@@ -27,6 +28,31 @@
 #include "fpdfsdk/cpdfsdk_helpers.h"
 #include "public/fpdf_edit.h"
 
+// These checks are here because core/ and public/ cannot depend on each other.
+static_assert(static_cast<int>(TextRenderingMode::MODE_FILL) ==
+                  FPDF_TEXTRENDERMODE_FILL,
+              "TextRenderingMode::MODE_FILL value mismatch");
+static_assert(static_cast<int>(TextRenderingMode::MODE_STROKE) ==
+                  FPDF_TEXTRENDERMODE_STROKE,
+              "TextRenderingMode::MODE_STROKE value mismatch");
+static_assert(static_cast<int>(TextRenderingMode::MODE_FILL_STROKE) ==
+                  FPDF_TEXTRENDERMODE_FILL_STROKE,
+              "TextRenderingMode::MODE_FILL_STROKE value mismatch");
+static_assert(static_cast<int>(TextRenderingMode::MODE_INVISIBLE) ==
+                  FPDF_TEXTRENDERMODE_INVISIBLE,
+              "TextRenderingMode::MODE_INVISIBLE value mismatch");
+static_assert(static_cast<int>(TextRenderingMode::MODE_FILL_CLIP) ==
+                  FPDF_TEXTRENDERMODE_FILL_CLIP,
+              "TextRenderingMode::MODE_FILL_CLIP value mismatch");
+static_assert(static_cast<int>(TextRenderingMode::MODE_STROKE_CLIP) ==
+                  FPDF_TEXTRENDERMODE_STROKE_CLIP,
+              "TextRenderingMode::MODE_STROKE_CLIP value mismatch");
+static_assert(static_cast<int>(TextRenderingMode::MODE_FILL_STROKE_CLIP) ==
+                  FPDF_TEXTRENDERMODE_FILL_STROKE_CLIP,
+              "TextRenderingMode::MODE_FILL_STROKE_CLIP value mismatch");
+static_assert(static_cast<int>(TextRenderingMode::MODE_CLIP) ==
+                  FPDF_TEXTRENDERMODE_CLIP,
+              "TextRenderingMode::MODE_CLIP value mismatch");
 namespace {
 
 CPDF_Dictionary* LoadFontDesc(CPDF_Document* pDoc,
@@ -545,3 +571,14 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
   pTextObj->DefaultStates();
   return FPDFPageObjectFromCPDFPageObject(pTextObj.release());
 }
+
+FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text) {
+  if (!text)
+    return -1;
+
+  CPDF_TextObject* pTextObj = CPDFTextObjectFromFPDFPageObject(text);
+  if (!pTextObj)
+    return -1;
+
+  return static_cast<int>(pTextObj->m_TextState.GetTextMode());
+}
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index 6e613bca0..6490c18c6 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -70,6 +70,15 @@
 #define FPDF_PRINTMODE_POSTSCRIPT2_PASSTHROUGH 4
 #define FPDF_PRINTMODE_POSTSCRIPT3_PASSTHROUGH 5
 
+#define FPDF_TEXTRENDERMODE_FILL 0
+#define FPDF_TEXTRENDERMODE_STROKE 1
+#define FPDF_TEXTRENDERMODE_FILL_STROKE 2
+#define FPDF_TEXTRENDERMODE_INVISIBLE 3
+#define FPDF_TEXTRENDERMODE_FILL_CLIP 4
+#define FPDF_TEXTRENDERMODE_STROKE_CLIP 5
+#define FPDF_TEXTRENDERMODE_FILL_STROKE_CLIP 6
+#define FPDF_TEXTRENDERMODE_CLIP 7
+
 typedef struct FPDF_IMAGEOBJ_METADATA {
   // The image width in pixels.
   unsigned int width;
@@ -1116,6 +1125,14 @@ FPDFPageObj_CreateTextObj(FPDF_DOCUMENT document,
                           FPDF_FONT font,
                           float font_size);
 
+// Experimental API.
+// Get the text rendering mode of a text object.
+//
+// text     - the handle to the text object.
+//
+// Returns one of the FPDF_TEXTRENDERMODE_* flags on success, -1 on error.
+FPDF_EXPORT int FPDF_CALLCONV FPDFText_GetTextRenderMode(FPDF_PAGEOBJECT text);
+
 #ifdef __cplusplus
 }  // extern "C"
 #endif  // __cplusplus
-- 
2.16.4