summaryrefslogtreecommitdiffstats
path: root/external/pdfium/0004-svx-support-PDF-text-color.patch.2
blob: 5bf196cdfefa19b9288b5fa7bcb403d699070b48 (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
119
120
121
122
123
124
125
126
127
128
129
130
From 914467a56b9c4cd6a27cfa9b7ed61ebfb5a122d3 Mon Sep 17 00:00:00 2001
From: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Date: Tue, 5 Jun 2018 11:29:49 +0200
Subject: [PATCH 04/14] svx: support PDF text color

---
 pdfium/fpdfsdk/cpdfsdk_helpers.h |  5 +++++
 pdfium/fpdfsdk/fpdf_editpage.cpp | 30 +++++++++++++++++++++++++-----
 pdfium/public/fpdf_edit.h        | 16 ++++++++++++++++
 3 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/pdfium/fpdfsdk/cpdfsdk_helpers.h b/pdfium/fpdfsdk/cpdfsdk_helpers.h
index d93ecfc..13362cf 100644
--- a/pdfium/fpdfsdk/cpdfsdk_helpers.h
+++ b/pdfium/fpdfsdk/cpdfsdk_helpers.h
@@ -204,6 +204,11 @@ inline CPDF_TextPageFind* CPDFTextPageFindFromFPDFSchHandle(
   return reinterpret_cast<CPDF_TextPageFind*>(handle);
 }
 
+inline CPDF_TextObject* CPDFTextObjectFromFPDFPageObject(
+    FPDF_PAGEOBJECT page_object) {
+  return reinterpret_cast<CPDF_TextObject*>(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 3244943..f8e2418 100644
--- a/pdfium/fpdfsdk/fpdf_editpage.cpp
+++ b/pdfium/fpdfsdk/fpdf_editpage.cpp
@@ -633,7 +633,7 @@ FPDFTextObj_CountChars(FPDF_PAGEOBJECT text_object)
   if (!text_object)
     return 0;
 
-  CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
+  CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
   return pTxtObj->CountChars();
 }
 
@@ -643,7 +643,7 @@ FPDFTextObj_GetFontSize(FPDF_PAGEOBJECT text_object)
   if (!text_object)
     return 0;
 
-  CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
+  CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
   return pTxtObj->GetFontSize();
 }
 
@@ -656,7 +656,7 @@ FPDFTextObj_GetMatrix(FPDF_PAGEOBJECT text_object,
   if (!text_object)
     return;
 
-  CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
+  CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
   const CFX_Matrix& matrix = pTxtObj->GetTextMatrix();
   *a = matrix.a;
   *b = matrix.b;
@@ -670,7 +670,7 @@ FPDFTextObj_GetUnicode(FPDF_PAGEOBJECT text_object, int index)
   if (!text_object || index < 0)
     return 0;
 
-  CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
+  CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
   if (index > pTxtObj->CountChars())
     return 0;
 
@@ -686,7 +686,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFTextObj_GetText(FPDF_PAGEOBJECT text_object,
   if (!text_object || char_start < 0 || char_count < 0 || !result)
     return 0;
 
-  CPDF_TextObject* pTxtObj = static_cast<CPDF_TextObject*>(text_object);
+  CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
   int char_available = pTxtObj->CountChars() - char_start;
   if (char_available <= 0)
     return 0;
@@ -726,3 +726,23 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFTextObj_GetText(FPDF_PAGEOBJECT text_object,
   memcpy(result, byte_str.GetBuffer(byte_str_len), byte_str_len);
   return ret_count;
 }
+
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFTextObj_GetStrokeColor(FPDF_PAGEOBJECT text_object,
+                           unsigned int* R,
+                           unsigned int* G,
+                           unsigned int* B,
+                           unsigned int* A)
+{
+  CPDF_TextObject* pTxtObj = CPDFTextObjectFromFPDFPageObject(text_object);
+  if (!pTxtObj || !R || !G || !B || !A)
+    return false;
+
+  const uint32_t strokeRGB = pTxtObj->m_ColorState.GetStrokeRGB();
+  *R = FXSYS_GetRValue(strokeRGB);
+  *G = FXSYS_GetGValue(strokeRGB);
+  *B = FXSYS_GetBValue(strokeRGB);
+  *A = static_cast<unsigned int>(
+      (pTxtObj->m_GeneralState.GetStrokeAlpha() * 255.f) + 0.5f);
+  return true;
+}
diff --git a/pdfium/public/fpdf_edit.h b/pdfium/public/fpdf_edit.h
index 602849f..fa9902e 100644
--- a/pdfium/public/fpdf_edit.h
+++ b/pdfium/public/fpdf_edit.h
@@ -1022,6 +1022,22 @@ FPDFTextObj_GetText(FPDF_PAGEOBJECT text_object,
                     int char_count,
                     unsigned short* result);
 
+// Get the stroke RGBA of a text. Range of values: 0 - 255.
+//
+// path   - the handle to the path object.
+// R      - the red component of the path stroke color.
+// G      - the green component of the path stroke color.
+// B      - the blue component of the path stroke color.
+// A      - the stroke alpha of the path.
+//
+// Returns TRUE on success.
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
+FPDFTextObj_GetStrokeColor(FPDF_PAGEOBJECT text_object,
+                           unsigned int* R,
+                           unsigned int* G,
+                           unsigned int* B,
+                           unsigned int* A);
+
 #ifdef __cplusplus
 }  // extern "C"
 #endif  // __cplusplus
-- 
2.16.3