From 864e9fb67f42186ce24d9bf09e643c85ff89a175 Mon Sep 17 00:00:00 2001 From: wileyrya Date: Fri, 26 May 2017 11:38:14 -0500 Subject: Add public API for setting the fill color on a text object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG=pdfium:719 R=npm@chromium.org Change-Id: Ifd9330de265f8419d588b65fbd6a6187f17badd1 Reviewed-on: https://pdfium-review.googlesource.com/5950 Reviewed-by: Nicolás Peña Commit-Queue: Nicolás Peña --- fpdfsdk/fpdfeditpage.cpp | 16 ++++++++++++++++ fpdfsdk/fpdfeditpath.cpp | 11 ++--------- fpdfsdk/fpdfedittext.cpp | 8 ++++++++ fpdfsdk/fsdk_define.h | 5 +++++ 4 files changed, 31 insertions(+), 9 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index 6ed375807f..2c58caf6db 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -304,3 +304,19 @@ DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) { rotate %= 4; pPage->m_pFormDict->SetNewFor("Rotate", rotate * 90); } + +FPDF_BOOL FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A) { + if (!page_object || R > 255 || G > 255 || B > 255 || A > 255) + return false; + + float rgb[3] = {R / 255.f, G / 255.f, B / 255.f}; + auto* pPageObj = static_cast(page_object); + pPageObj->m_GeneralState.SetFillAlpha(A / 255.f); + pPageObj->m_ColorState.SetFillColor( + CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); + return true; +} diff --git a/fpdfsdk/fpdfeditpath.cpp b/fpdfsdk/fpdfeditpath.cpp index 54937ef91a..ad5ca9433f 100644 --- a/fpdfsdk/fpdfeditpath.cpp +++ b/fpdfsdk/fpdfeditpath.cpp @@ -7,6 +7,7 @@ #include "core/fpdfapi/page/cpdf_path.h" #include "core/fpdfapi/page/cpdf_pathobject.h" #include "core/fxcrt/fx_system.h" +#include "fpdfsdk/fsdk_define.h" #include "third_party/base/ptr_util.h" DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_CreateNewPath(float x, float y) { @@ -56,15 +57,7 @@ DLLEXPORT FPDF_BOOL FPDFPath_SetFillColor(FPDF_PAGEOBJECT path, unsigned int G, unsigned int B, unsigned int A) { - if (!path || R > 255 || G > 255 || B > 255 || A > 255) - return false; - - float rgb[3] = {R / 255.f, G / 255.f, B / 255.f}; - auto* pPathObj = static_cast(path); - pPathObj->m_GeneralState.SetFillAlpha(A / 255.f); - pPathObj->m_ColorState.SetFillColor( - CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb, 3); - return true; + return FPDFPageObj_SetFillColor(path, R, G, B, A); } DLLEXPORT FPDF_BOOL FPDFPath_GetFillColor(FPDF_PAGEOBJECT path, diff --git a/fpdfsdk/fpdfedittext.cpp b/fpdfsdk/fpdfedittext.cpp index 2dde2e6624..3deae7ea20 100644 --- a/fpdfsdk/fpdfedittext.cpp +++ b/fpdfsdk/fpdfedittext.cpp @@ -447,6 +447,14 @@ DLLEXPORT FPDF_FONT STDCALL FPDFText_LoadFont(FPDF_DOCUMENT document, : LoadSimpleFont(pDoc, std::move(pFont), data, size, font_type); } +DLLEXPORT FPDF_BOOL STDCALL FPDFText_SetFillColor(FPDF_PAGEOBJECT text_object, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A) { + return FPDFPageObj_SetFillColor(text_object, R, G, B, A); +} + DLLEXPORT void STDCALL FPDFFont_Close(FPDF_FONT font) { CPDF_Font* pFont = static_cast(font); if (!pFont) diff --git a/fpdfsdk/fsdk_define.h b/fpdfsdk/fsdk_define.h index b7691bbdd9..e14cc19ea1 100644 --- a/fpdfsdk/fsdk_define.h +++ b/fpdfsdk/fsdk_define.h @@ -79,5 +79,10 @@ void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code); void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot); void ProcessParseError(CPDF_Parser::Error err); +FPDF_BOOL FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A); #endif // FPDFSDK_FSDK_DEFINE_H_ -- cgit v1.2.3