diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-06-04 14:47:17 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-04 14:47:17 +0000 |
commit | 97f4d67fbf0707feea298afa2f6471013185e066 (patch) | |
tree | 8591d399806c5d441e646a3f879227574e9217b4 | |
parent | 714bf7821d2de6249d2779424c47027a981d5032 (diff) | |
download | pdfium-97f4d67fbf0707feea298afa2f6471013185e066.tar.xz |
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 <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | fpdfsdk/fpdf_edit_embeddertest.cpp | 30 | ||||
-rw-r--r-- | fpdfsdk/fpdf_editpath.cpp | 49 | ||||
-rw-r--r-- | fpdfsdk/fpdf_view_c_api_test.c | 2 | ||||
-rw-r--r-- | public/fpdf_edit.h | 50 |
4 files changed, 131 insertions, 0 deletions
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<int>(matrix_a)); + EXPECT_EQ(2, static_cast<int>(matrix_b)); + EXPECT_EQ(3, static_cast<int>(matrix_c)); + EXPECT_EQ(4, static_cast<int>(matrix_d)); + EXPECT_EQ(5, static_cast<int>(matrix_e)); + EXPECT_EQ(6, static_cast<int>(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); diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h index 8cb97eed15..338b42b588 100644 --- a/public/fpdf_edit.h +++ b/public/fpdf_edit.h @@ -941,6 +941,56 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetDrawMode(FPDF_PAGEOBJECT path, int* fillmode, FPDF_BOOL* stroke); +// Experimental API. +// Get the transform matrix of a path. +// +// path - handle to a path. +// 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 path. +// +// Returns TRUE on success. +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_GetMatrix(FPDF_PAGEOBJECT path, + double* a, + double* b, + double* c, + double* d, + double* e, + double* f); + +// Experimental API. +// Set the transform matrix of a path. +// +// path - handle to a path. +// 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 can be used to scale, rotate, shear and translate the path. +// +// Returns TRUE on success. +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetMatrix(FPDF_PAGEOBJECT path, + double a, + double b, + double c, + double d, + double e, + double f); + // Create a new text object using one of the standard PDF fonts. // // document - handle to the document. |