summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/fpdf_edit_embeddertest.cpp17
-rw-r--r--fpdfsdk/fpdf_edittext.cpp30
-rw-r--r--fpdfsdk/fpdf_view_c_api_test.c1
-rw-r--r--public/fpdf_edit.h25
4 files changed, 73 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp
index 07879c5054..c78700ea67 100644
--- a/fpdfsdk/fpdf_edit_embeddertest.cpp
+++ b/fpdfsdk/fpdf_edit_embeddertest.cpp
@@ -1122,6 +1122,23 @@ TEST_F(FPDFEditEmbeddertest, AddStandardFontText) {
CompareBitmap(page_bitmap.get(), 612, 792, md5_3);
}
+ double matrix_a = 0;
+ double matrix_b = 0;
+ double matrix_c = 0;
+ double matrix_d = 0;
+ double matrix_e = 0;
+ double matrix_f = 0;
+ EXPECT_FALSE(FPDFText_GetMatrix(nullptr, &matrix_a, &matrix_b, &matrix_c,
+ &matrix_d, &matrix_e, &matrix_f));
+ EXPECT_TRUE(FPDFText_GetMatrix(text_object3, &matrix_a, &matrix_b, &matrix_c,
+ &matrix_d, &matrix_e, &matrix_f));
+ EXPECT_EQ(1., matrix_a);
+ EXPECT_EQ(1.5, matrix_b);
+ EXPECT_EQ(2., matrix_c);
+ EXPECT_EQ(0.5, matrix_d);
+ EXPECT_EQ(200., matrix_e);
+ EXPECT_EQ(200., matrix_f);
+
// TODO(npm): Why are there issues with text rotated by 90 degrees?
// TODO(npm): FPDF_SaveAsCopy not giving the desired result after this.
FPDF_ClosePage(page);
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index 8186d8d894..a927e16e14 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -394,6 +394,11 @@ CPDF_Font* LoadCompositeFont(CPDF_Document* pDoc,
return pDoc->LoadFont(fontDict);
}
+CPDF_TextObject* CPDFTextObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object) {
+ auto* obj = CPDFPageObjectFromFPDFPageObject(page_object);
+ return obj ? obj->AsText() : nullptr;
+}
+
} // namespace
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV
@@ -481,6 +486,31 @@ FPDFText_SetFillColor(FPDF_PAGEOBJECT text_object,
return FPDFPageObj_SetFillColor(text_object, R, G, B, A);
}
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetMatrix(FPDF_PAGEOBJECT text,
+ double* a,
+ double* b,
+ double* c,
+ double* d,
+ double* e,
+ double* f) {
+ if (!text || !a || !b || !c || !d || !e || !f)
+ return false;
+
+ CPDF_TextObject* pTextObj = CPDFTextObjectFromFPDFPageObject(text);
+ if (!pTextObj)
+ return false;
+
+ CFX_Matrix text_matrix = pTextObj->GetTextMatrix();
+ *a = text_matrix.a;
+ *b = text_matrix.b;
+ *c = text_matrix.c;
+ *d = text_matrix.d;
+ *e = text_matrix.e;
+ *f = text_matrix.f;
+
+ return true;
+}
+
FPDF_EXPORT void FPDF_CALLCONV FPDFFont_Close(FPDF_FONT font) {
CPDF_Font* pFont = CPDFFontFromFPDFFont(font);
if (!pFont)
diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c
index 543a7d1a78..90eca333d5 100644
--- a/fpdfsdk/fpdf_view_c_api_test.c
+++ b/fpdfsdk/fpdf_view_c_api_test.c
@@ -195,6 +195,7 @@ int CheckPDFiumCApi() {
CHK(FPDFPath_SetMatrix);
CHK(FPDFPath_SetStrokeColor);
CHK(FPDFPath_SetStrokeWidth);
+ CHK(FPDFText_GetMatrix);
CHK(FPDFText_LoadFont);
CHK(FPDFText_LoadStandardFont);
CHK(FPDFText_SetFillColor);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index d3d7c4b277..6df5e32370 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -1065,6 +1065,31 @@ FPDFText_SetFillColor(FPDF_PAGEOBJECT text_object,
unsigned int B,
unsigned int A);
+// Experimental API.
+// Get the transform matrix of a text object.
+//
+// text - handle to a text.
+// a - matrix value.
+// b - matrix value.
+// c - matrix value.
+// d - matrix value.
+// e - matrix value.
+// f - matrix value.
+//
+// The matrix is composed as:
+// |a c e|
+// |b d f|
+// and used to scale, rotate, shear and translate the text.
+//
+// Returns TRUE on success.
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFText_GetMatrix(FPDF_PAGEOBJECT text,
+ double* a,
+ double* b,
+ double* c,
+ double* d,
+ double* e,
+ double* f);
+
// Close a loaded PDF font.
//
// font - Handle to the loaded font.