From 97f4d67fbf0707feea298afa2f6471013185e066 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 4 Jun 2018 14:47:17 +0000 Subject: Add FPDFPath_GetMatrix() and FPDFPath_SetMatrix() APIs This is similar to the existing FPDFImageObj_SetMatrix(), but this exposes the matrix of CPDF_PathObject and provides both a getter and a setter. Change-Id: Ib90a64929dae1b2be3889eca57e4af822d7823be Reviewed-on: https://pdfium-review.googlesource.com/33670 Reviewed-by: dsinclair Commit-Queue: dsinclair --- fpdfsdk/fpdf_edit_embeddertest.cpp | 30 +++++++++++++++++++++++ fpdfsdk/fpdf_editpath.cpp | 49 ++++++++++++++++++++++++++++++++++++++ fpdfsdk/fpdf_view_c_api_test.c | 2 ++ 3 files changed, 81 insertions(+) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index f9b165c28d..7ca2174440 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -248,6 +248,36 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) { EXPECT_EQ(FPDF_FILLMODE_ALTERNATE, fillmode); EXPECT_FALSE(stroke); + double matrix_a = 1; + double matrix_b = 2; + double matrix_c = 3; + double matrix_d = 4; + double matrix_e = 5; + double matrix_f = 6; + EXPECT_FALSE(FPDFPath_SetMatrix(nullptr, matrix_a, matrix_b, matrix_c, + matrix_d, matrix_e, matrix_f)); + EXPECT_TRUE(FPDFPath_SetMatrix(red_rect, matrix_a, matrix_b, matrix_c, + matrix_d, matrix_e, matrix_f)); + EXPECT_FALSE(FPDFPath_GetMatrix(nullptr, &matrix_a, &matrix_b, &matrix_c, + &matrix_d, &matrix_e, &matrix_f)); + EXPECT_TRUE(FPDFPath_GetMatrix(red_rect, &matrix_a, &matrix_b, &matrix_c, + &matrix_d, &matrix_e, &matrix_f)); + EXPECT_EQ(1, static_cast(matrix_a)); + EXPECT_EQ(2, static_cast(matrix_b)); + EXPECT_EQ(3, static_cast(matrix_c)); + EXPECT_EQ(4, static_cast(matrix_d)); + EXPECT_EQ(5, static_cast(matrix_e)); + EXPECT_EQ(6, static_cast(matrix_f)); + // Set back the default + matrix_a = 1; + matrix_b = 0; + matrix_c = 0; + matrix_d = 1; + matrix_e = 0; + matrix_f = 0; + EXPECT_TRUE(FPDFPath_SetMatrix(red_rect, matrix_a, matrix_b, matrix_c, + matrix_d, matrix_e, matrix_f)); + FPDFPage_InsertObject(page, red_rect); { ScopedFPDFBitmap page_bitmap = RenderPageWithFlags(page, nullptr, 0); diff --git a/fpdfsdk/fpdf_editpath.cpp b/fpdfsdk/fpdf_editpath.cpp index 7f00b85d7b..70a558d2f1 100644 --- a/fpdfsdk/fpdf_editpath.cpp +++ b/fpdfsdk/fpdf_editpath.cpp @@ -236,6 +236,55 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetDrawMode(FPDF_PAGEOBJECT path, return true; } +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetMatrix(FPDF_PAGEOBJECT path, + double* a, + double* b, + double* c, + double* d, + double* e, + double* f) { + if (!path || !a || !b || !c || !d || !e || !f) + return false; + + CPDF_PathObject* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + if (!pPathObj) + return false; + + *a = pPathObj->m_Matrix.a; + *b = pPathObj->m_Matrix.b; + *c = pPathObj->m_Matrix.c; + *d = pPathObj->m_Matrix.d; + *e = pPathObj->m_Matrix.e; + *f = pPathObj->m_Matrix.f; + + return true; +} + +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetMatrix(FPDF_PAGEOBJECT path, + double a, + double b, + double c, + double d, + double e, + double f) { + if (!path) + return false; + + CPDF_PathObject* pPathObj = CPDFPathObjectFromFPDFPageObject(path); + if (!pPathObj) + return false; + + pPathObj->m_Matrix.a = a; + pPathObj->m_Matrix.b = b; + pPathObj->m_Matrix.c = c; + pPathObj->m_Matrix.d = d; + pPathObj->m_Matrix.e = e; + pPathObj->m_Matrix.f = f; + pPathObj->SetDirty(true); + + return true; +} + FPDF_EXPORT void FPDF_CALLCONV FPDFPath_SetLineJoin(FPDF_PAGEOBJECT path, int line_join) { auto* pPathObj = CPDFPathObjectFromFPDFPageObject(path); diff --git a/fpdfsdk/fpdf_view_c_api_test.c b/fpdfsdk/fpdf_view_c_api_test.c index dd97a6e330..34ac5518a3 100644 --- a/fpdfsdk/fpdf_view_c_api_test.c +++ b/fpdfsdk/fpdf_view_c_api_test.c @@ -183,6 +183,7 @@ int CheckPDFiumCApi() { CHK(FPDFPath_CountSegments); CHK(FPDFPath_GetDrawMode); CHK(FPDFPath_GetFillColor); + CHK(FPDFPath_GetMatrix); CHK(FPDFPath_GetPathSegment); CHK(FPDFPath_GetStrokeColor); CHK(FPDFPath_LineTo); @@ -191,6 +192,7 @@ int CheckPDFiumCApi() { CHK(FPDFPath_SetFillColor); CHK(FPDFPath_SetLineCap); CHK(FPDFPath_SetLineJoin); + CHK(FPDFPath_SetMatrix); CHK(FPDFPath_SetStrokeColor); CHK(FPDFPath_SetStrokeWidth); CHK(FPDFText_LoadFont); -- cgit v1.2.3