summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp12
-rw-r--r--fpdfsdk/fpdfeditpath.cpp18
-rw-r--r--fpdfsdk/fpdfview_c_api_test.c1
-rw-r--r--public/fpdf_edit.h15
4 files changed, 46 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index a54a9b93af..6454c34df1 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -279,6 +279,18 @@ TEST_F(FPDFEditEmbeddertest, AddPaths) {
// Now add to that a green rectangle with some medium alpha
FPDF_PAGEOBJECT green_rect = FPDFPageObj_CreateNewRect(100, 100, 40, 40);
EXPECT_TRUE(FPDFPath_SetFillColor(green_rect, 0, 255, 0, 128));
+
+ // Make sure we get back the same color we set previously.
+ unsigned int R;
+ unsigned int G;
+ unsigned int B;
+ unsigned int A;
+ EXPECT_TRUE(FPDFPath_GetFillColor(green_rect, &R, &G, &B, &A));
+ EXPECT_EQ(0U, R);
+ EXPECT_EQ(255U, G);
+ EXPECT_EQ(0U, B);
+ EXPECT_EQ(128U, A);
+
EXPECT_TRUE(FPDFPath_SetDrawMode(green_rect, FPDF_FILLMODE_WINDING, 0));
FPDFPage_InsertObject(page, green_rect);
EXPECT_TRUE(FPDFPage_GenerateContent(page));
diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp
index f085ed3481..155dda5c7d 100644
--- a/fpdfsdk/fpdfeditpath.cpp
+++ b/fpdfsdk/fpdfeditpath.cpp
@@ -66,6 +66,24 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetFillColor(FPDF_PAGEOBJECT path,
return true;
}
+DLLEXPORT FPDF_BOOL FPDFPath_GetFillColor(FPDF_PAGEOBJECT path,
+ unsigned int* R,
+ unsigned int* G,
+ unsigned int* B,
+ unsigned int* A) {
+ if (!path || !R || !G || !B || !A)
+ return false;
+
+ auto* pPathObj = reinterpret_cast<CPDF_PathObject*>(path);
+ uint32_t fillRGB = pPathObj->m_ColorState.GetFillRGB();
+ *R = FXSYS_GetRValue(fillRGB);
+ *G = FXSYS_GetGValue(fillRGB);
+ *B = FXSYS_GetBValue(fillRGB);
+ *A = static_cast<unsigned int>(pPathObj->m_GeneralState.GetFillAlpha() *
+ 255.f);
+ return true;
+}
+
DLLEXPORT FPDF_BOOL FPDFPath_MoveTo(FPDF_PAGEOBJECT path, float x, float y) {
if (!path)
return false;
diff --git a/fpdfsdk/fpdfview_c_api_test.c b/fpdfsdk/fpdfview_c_api_test.c
index 9afbdd479e..b4da951947 100644
--- a/fpdfsdk/fpdfview_c_api_test.c
+++ b/fpdfsdk/fpdfview_c_api_test.c
@@ -93,6 +93,7 @@ int CheckPDFiumCApi() {
CHK(FPDFPath_SetStrokeColor);
CHK(FPDFPath_SetStrokeWidth);
CHK(FPDFPath_SetFillColor);
+ CHK(FPDFPath_GetFillColor);
CHK(FPDFPath_MoveTo);
CHK(FPDFPath_LineTo);
CHK(FPDFPath_BezierTo);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index ce02a6406d..4d06c2a0c8 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -343,6 +343,21 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetFillColor(FPDF_PAGEOBJECT path,
unsigned int B,
unsigned int A);
+// Get the fill RGBA of a path. Range of values: 0 - 255.
+//
+// path - the handle to the path object.
+// R - the red component of the path fill color.
+// G - the green component of the path fill color.
+// B - the blue component of the path fill color.
+// A - the fill alpha of the path.
+//
+// Returns TRUE on success.
+DLLEXPORT FPDF_BOOL FPDFPath_GetFillColor(FPDF_PAGEOBJECT path,
+ unsigned int* R,
+ unsigned int* G,
+ unsigned int* B,
+ unsigned int* A);
+
// Move a path's current point.
//
// path - the handle to the path object.