summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/fpdf_edit_embeddertest.cpp17
-rw-r--r--fpdfsdk/fpdf_edittext.cpp37
-rw-r--r--fpdfsdk/fpdf_view_c_api_test.c1
-rw-r--r--public/fpdf_edit.h17
-rw-r--r--testing/resources/text_render_mode.pdf75
5 files changed, 147 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index 9464417da1..445b0cc6b9 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -1487,6 +1487,23 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) {
FPDF_ClosePage(page);
}
+TEST_F(FPDFEditEmbeddertest, TestGetTextRenderMode) {
+ EXPECT_TRUE(OpenDocument("text_render_mode.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+ ASSERT_EQ(2, FPDFPage_CountObjects(page));
+
+ ASSERT_EQ(-1, FPDFText_GetTextRenderMode(nullptr));
+
+ FPDF_PAGEOBJECT fill = FPDFPage_GetObject(page, 0);
+ ASSERT_EQ(FPDF_TEXTRENDERMODE_FILL, FPDFText_GetTextRenderMode(fill));
+
+ FPDF_PAGEOBJECT stroke = FPDFPage_GetObject(page, 1);
+ ASSERT_EQ(FPDF_TEXTRENDERMODE_STROKE, FPDFText_GetTextRenderMode(stroke));
+
+ UnloadPage(page);
+}
+
// Tests adding text from standard font using FPDFText_LoadStandardFont.
TEST_F(FPDFEditEmbeddertest, AddStandardFontText2) {
// Start with a blank page
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index 3115e2a16e..c552d615e4 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/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c
index 997423a4a8..1837b58e2a 100644
--- a/fpdfsdk/fpdf_view_c_api_test.c
+++ b/fpdfsdk/fpdf_view_c_api_test.c
@@ -197,6 +197,7 @@ int CheckPDFiumCApi() {
CHK(FPDFPath_SetStrokeWidth);
CHK(FPDFTextObj_GetFontSize);
CHK(FPDFText_GetMatrix);
+ CHK(FPDFText_GetTextRenderMode);
CHK(FPDFText_LoadFont);
CHK(FPDFText_LoadStandardFont);
CHK(FPDFText_SetFillColor);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index 6e613bca07..6490c18c6a 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
diff --git a/testing/resources/text_render_mode.pdf b/testing/resources/text_render_mode.pdf
new file mode 100644
index 0000000000..220e143757
--- /dev/null
+++ b/testing/resources/text_render_mode.pdf
@@ -0,0 +1,75 @@
+%PDF-1.2
+%âãÏÓ
+1 0 obj
+<<
+/Resources 2 0 R
+/Contents 3 0 R
+/Parent 4 0 R
+/Type /Page
+/MediaBox [0 0 612 446]
+>>
+endobj
+3 0 obj
+<<
+/Length 102
+>>
+stream
+ BT
+ /F1 24 Tf
+ 0 Tr
+ 1 0 0 1 260 250 Tm
+ (fill)Tj
+ 1 Tr
+ 1 0 0 1 260 200 Tm
+ (stroke)Tj
+ ET
+
+endstream
+endobj
+2 0 obj
+<<
+/Font
+<<
+/F1 5 0 R
+>>
+>>
+endobj
+5 0 obj
+<<
+/Subtype /Type1
+/Name /F1
+/Type /Font
+/BaseFont /Helvetica
+>>
+endobj
+4 0 obj
+<<
+/Kids [1 0 R]
+/Type /Pages
+/MediaBox [0 0 612 446]
+/Count 1
+>>
+endobj
+6 0 obj
+<<
+/Type /Catalog
+/Pages 4 0 R
+>>
+endobj xref
+0 7
+0000000000 65535 f
+0000000015 00000 n
+0000000277 00000 n
+0000000121 00000 n
+0000000405 00000 n
+0000000323 00000 n
+0000000488 00000 n
+trailer
+
+<<
+/Root 6 0 R
+/Size 7
+>>
+startxref
+538
+%%EOF