diff options
author | Nicolas Pena <npm@chromium.org> | 2018-05-08 22:22:41 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-08 22:22:41 +0000 |
commit | df1298a228abb59eb167d0be43d46a50c0333497 (patch) | |
tree | 9dd021fd3a97f2208367faa7737985821896a05f /fpdfsdk/fpdf_editpage.cpp | |
parent | 7b094f81483240f50dfc12e51cf545a8f0d5933d (diff) | |
download | pdfium-df1298a228abb59eb167d0be43d46a50c0333497.tar.xz |
Add several FPDFPageObj_* APIschromium/3425
This CL adds the following APIs:
FPDFPageObj_SetStrokeColor
FPDFPageObj_GetStrokeColor
FPDFPageObj_SetStrokeWidth
FPDFPageObj_SetLineJoin
FPDFPageObj_SetLineCap
FPDFPageObj_SetFillColor
FPDFPageObj_GetFillColor
Bug: pdfium:980
Change-Id: I19f9abb6756314ba8bd2f66a6c38e2e722cd8473
Reviewed-on: https://pdfium-review.googlesource.com/32192
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdf_editpage.cpp')
-rw-r--r-- | fpdfsdk/fpdf_editpage.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp index ce597d6d6e..ec29891fdf 100644 --- a/fpdfsdk/fpdf_editpage.cpp +++ b/fpdfsdk/fpdf_editpage.cpp @@ -120,6 +120,10 @@ GetMarkParamPairAtIndex(FPDF_PAGEOBJECTMARK mark, unsigned long index) { return nullptr; } +unsigned int GetUnsignedAlpha(float alpha) { + return static_cast<unsigned int>(alpha * 255.f + 0.5f); +} + } // namespace FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument() { @@ -505,6 +509,24 @@ FPDF_BOOL FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object, } FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV +FPDFPageObj_GetFillColor(FPDF_PAGEOBJECT page_object, + unsigned int* R, + unsigned int* G, + unsigned int* B, + unsigned int* A) { + auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); + if (!pPageObj || !R || !G || !B || !A) + return false; + + FX_COLORREF fillColor = pPageObj->m_ColorState.GetFillColorRef(); + *R = FXSYS_GetRValue(fillColor); + *G = FXSYS_GetGValue(fillColor); + *B = FXSYS_GetBValue(fillColor); + *A = GetUnsignedAlpha(pPageObj->m_GeneralState.GetFillAlpha()); + return true; +} + +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject, float* left, float* bottom, @@ -521,3 +543,84 @@ FPDFPageObj_GetBounds(FPDF_PAGEOBJECT pageObject, *top = bbox.top; return true; } + +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV +FPDFPageObj_SetStrokeColor(FPDF_PAGEOBJECT page_object, + unsigned int R, + unsigned int G, + unsigned int B, + unsigned int A) { + auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); + if (!pPageObj || R > 255 || G > 255 || B > 255 || A > 255) + return false; + + std::vector<float> rgb = {R / 255.f, G / 255.f, B / 255.f}; + pPageObj->m_GeneralState.SetStrokeAlpha(A / 255.f); + pPageObj->m_ColorState.SetStrokeColor( + CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB), rgb); + pPageObj->SetDirty(true); + return true; +} + +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV +FPDFPageObj_GetStrokeColor(FPDF_PAGEOBJECT page_object, + unsigned int* R, + unsigned int* G, + unsigned int* B, + unsigned int* A) { + auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); + if (!pPageObj || !R || !G || !B || !A) + return false; + + FX_COLORREF strokeColor = pPageObj->m_ColorState.GetStrokeColorRef(); + *R = FXSYS_GetRValue(strokeColor); + *G = FXSYS_GetGValue(strokeColor); + *B = FXSYS_GetBValue(strokeColor); + *A = GetUnsignedAlpha(pPageObj->m_GeneralState.GetStrokeAlpha()); + return true; +} + +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV +FPDFPageObj_SetStrokeWidth(FPDF_PAGEOBJECT page_object, float width) { + auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); + if (!pPageObj || width < 0.0f) + return false; + + pPageObj->m_GraphState.SetLineWidth(width); + pPageObj->SetDirty(true); + return true; +} + +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV +FPDFPageObj_SetLineJoin(FPDF_PAGEOBJECT page_object, int line_join) { + if (!page_object) + return false; + if (line_join < + static_cast<int>(CFX_GraphStateData::LineJoin::LineJoinMiter) || + line_join > + static_cast<int>(CFX_GraphStateData::LineJoin::LineJoinBevel)) { + return false; + } + auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); + CFX_GraphStateData::LineJoin lineJoin = + static_cast<CFX_GraphStateData::LineJoin>(line_join); + pPageObj->m_GraphState.SetLineJoin(lineJoin); + pPageObj->SetDirty(true); + return true; +} + +FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV +FPDFPageObj_SetLineCap(FPDF_PAGEOBJECT page_object, int line_cap) { + if (!page_object) + return false; + if (line_cap < static_cast<int>(CFX_GraphStateData::LineCap::LineCapButt) || + line_cap > static_cast<int>(CFX_GraphStateData::LineCap::LineCapSquare)) { + return false; + } + auto* pPageObj = CPDFPageObjectFromFPDFPageObject(page_object); + CFX_GraphStateData::LineCap lineCap = + static_cast<CFX_GraphStateData::LineCap>(line_cap); + pPageObj->m_GraphState.SetLineCap(lineCap); + pPageObj->SetDirty(true); + return true; +} |