From f855489794ffd575d073eb575b04ac1ca1f286c2 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 17 Jan 2018 16:29:15 +0000 Subject: Move fill draw code to fill classes This CL moves the code related to drawing fills and the various types of fill to the specific fill classes. Change-Id: Ie151089b00ca96c5fa88d22ab5f697d9425297cd Reviewed-on: https://pdfium-review.googlesource.com/23071 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_box.cpp | 161 +++++---------------------------------- xfa/fxfa/parser/cxfa_box.h | 5 ++ xfa/fxfa/parser/cxfa_fill.cpp | 138 ++++++++++++++++----------------- xfa/fxfa/parser/cxfa_fill.h | 42 +++++----- xfa/fxfa/parser/cxfa_linear.cpp | 40 ++++++++++ xfa/fxfa/parser/cxfa_linear.h | 10 +++ xfa/fxfa/parser/cxfa_pattern.cpp | 38 +++++++++ xfa/fxfa/parser/cxfa_pattern.h | 10 +++ xfa/fxfa/parser/cxfa_radial.cpp | 25 ++++++ xfa/fxfa/parser/cxfa_radial.h | 10 +++ xfa/fxfa/parser/cxfa_stipple.cpp | 22 ++++++ xfa/fxfa/parser/cxfa_stipple.h | 9 +++ 12 files changed, 280 insertions(+), 230 deletions(-) (limited to 'xfa') diff --git a/xfa/fxfa/parser/cxfa_box.cpp b/xfa/fxfa/parser/cxfa_box.cpp index 38bbc59595..a62ce01146 100644 --- a/xfa/fxfa/parser/cxfa_box.cpp +++ b/xfa/fxfa/parser/cxfa_box.cpp @@ -394,146 +394,6 @@ void XFA_BOX_GetFillPath(CXFA_Box* box, } } -void XFA_BOX_Fill_Radial(CXFA_Fill* fill, - CXFA_Graphics* pGS, - CXFA_GEPath& fillPath, - CFX_RectF rtFill, - const CFX_Matrix& matrix) { - ASSERT(fill); - - FX_ARGB crStart = fill->GetColor(false); - FX_ARGB crEnd = fill->GetRadialColor(); - if (!fill->IsRadialToEdge()) - std::swap(crStart, crEnd); - - CXFA_GEShading shading(rtFill.Center(), rtFill.Center(), 0, - sqrt(rtFill.Width() * rtFill.Width() + - rtFill.Height() * rtFill.Height()) / - 2, - true, true, crStart, crEnd); - pGS->SetFillColor(CXFA_GEColor(&shading)); - pGS->FillPath(&fillPath, FXFILL_WINDING, &matrix); -} - -void XFA_BOX_Fill_Pattern(CXFA_Fill* fill, - CXFA_Graphics* pGS, - CXFA_GEPath& fillPath, - CFX_RectF rtFill, - const CFX_Matrix& matrix) { - ASSERT(fill); - - FX_ARGB crStart = fill->GetColor(false); - FX_ARGB crEnd = fill->GetPatternColor(); - FX_HatchStyle iHatch = FX_HatchStyle::Cross; - switch (fill->GetPatternType()) { - case XFA_AttributeEnum::CrossDiagonal: - iHatch = FX_HatchStyle::DiagonalCross; - break; - case XFA_AttributeEnum::DiagonalLeft: - iHatch = FX_HatchStyle::ForwardDiagonal; - break; - case XFA_AttributeEnum::DiagonalRight: - iHatch = FX_HatchStyle::BackwardDiagonal; - break; - case XFA_AttributeEnum::Horizontal: - iHatch = FX_HatchStyle::Horizontal; - break; - case XFA_AttributeEnum::Vertical: - iHatch = FX_HatchStyle::Vertical; - break; - default: - break; - } - - CXFA_GEPattern pattern(iHatch, crEnd, crStart); - pGS->SetFillColor(CXFA_GEColor(&pattern, 0x0)); - pGS->FillPath(&fillPath, FXFILL_WINDING, &matrix); -} - -void XFA_BOX_Fill_Linear(CXFA_Fill* fill, - CXFA_Graphics* pGS, - CXFA_GEPath& fillPath, - CFX_RectF rtFill, - const CFX_Matrix& matrix) { - ASSERT(fill); - - FX_ARGB crStart = fill->GetColor(false); - FX_ARGB crEnd = fill->GetLinearColor(); - - CFX_PointF ptStart; - CFX_PointF ptEnd; - switch (fill->GetLinearType()) { - case XFA_AttributeEnum::ToRight: - ptStart = CFX_PointF(rtFill.left, rtFill.top); - ptEnd = CFX_PointF(rtFill.right(), rtFill.top); - break; - case XFA_AttributeEnum::ToBottom: - ptStart = CFX_PointF(rtFill.left, rtFill.top); - ptEnd = CFX_PointF(rtFill.left, rtFill.bottom()); - break; - case XFA_AttributeEnum::ToLeft: - ptStart = CFX_PointF(rtFill.right(), rtFill.top); - ptEnd = CFX_PointF(rtFill.left, rtFill.top); - break; - case XFA_AttributeEnum::ToTop: - ptStart = CFX_PointF(rtFill.left, rtFill.bottom()); - ptEnd = CFX_PointF(rtFill.left, rtFill.top); - break; - default: - break; - } - - CXFA_GEShading shading(ptStart, ptEnd, false, false, crStart, crEnd); - pGS->SetFillColor(CXFA_GEColor(&shading)); - pGS->FillPath(&fillPath, FXFILL_WINDING, &matrix); -} - -void XFA_BOX_Fill(CXFA_Box* box, - const std::vector& strokes, - CXFA_Graphics* pGS, - const CFX_RectF& rtWidget, - const CFX_Matrix& matrix, - bool forceRound) { - CXFA_Fill* fill = box->GetFillIfExists(); - if (!fill || !fill->IsVisible()) - return; - - pGS->SaveGraphState(); - CXFA_GEPath fillPath; - XFA_BOX_GetFillPath(box, strokes, rtWidget, fillPath, forceRound); - fillPath.Close(); - XFA_Element eType = fill->GetFillType(); - switch (eType) { - case XFA_Element::Radial: - XFA_BOX_Fill_Radial(fill, pGS, fillPath, rtWidget, matrix); - break; - case XFA_Element::Pattern: - XFA_BOX_Fill_Pattern(fill, pGS, fillPath, rtWidget, matrix); - break; - case XFA_Element::Linear: - XFA_BOX_Fill_Linear(fill, pGS, fillPath, rtWidget, matrix); - break; - default: { - FX_ARGB cr; - if (eType == XFA_Element::Stipple) { - int32_t iRate = fill->GetStippleRate(); - if (iRate == 0) - iRate = 100; - - int32_t a; - FX_COLORREF rgb; - std::tie(a, rgb) = ArgbToColorRef(fill->GetStippleColor()); - cr = ArgbEncode(iRate * a / 100, rgb); - } else { - cr = fill->GetColor(false); - } - pGS->SetFillColor(CXFA_GEColor(cr)); - pGS->FillPath(&fillPath, FXFILL_WINDING, &matrix); - } break; - } - pGS->RestoreGraphState(); -} - void XFA_BOX_StrokeArc(CXFA_Box* box, CXFA_Graphics* pGS, CFX_RectF rtWidget, @@ -1016,6 +876,25 @@ void CXFA_Box::Draw(CXFA_Graphics* pGS, if (!forceRound && eType != XFA_Element::Arc) strokes = GetStrokes(); - XFA_BOX_Fill(this, strokes, pGS, rtWidget, matrix, forceRound); + DrawFill(strokes, pGS, rtWidget, matrix, forceRound); XFA_BOX_Stroke(this, strokes, pGS, rtWidget, matrix, forceRound); } + +void CXFA_Box::DrawFill(const std::vector& strokes, + CXFA_Graphics* pGS, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix, + bool forceRound) { + CXFA_Fill* fill = GetFillIfExists(); + if (!fill || !fill->IsVisible()) + return; + + pGS->SaveGraphState(); + + CXFA_GEPath fillPath; + XFA_BOX_GetFillPath(this, strokes, rtWidget, fillPath, forceRound); + fillPath.Close(); + + fill->Draw(pGS, &fillPath, rtWidget, matrix); + pGS->RestoreGraphState(); +} diff --git a/xfa/fxfa/parser/cxfa_box.h b/xfa/fxfa/parser/cxfa_box.h index 215925fe7c..170a874510 100644 --- a/xfa/fxfa/parser/cxfa_box.h +++ b/xfa/fxfa/parser/cxfa_box.h @@ -60,6 +60,11 @@ class CXFA_Box : public CXFA_Node { private: std::vector GetStrokesInternal(bool bNull); + void DrawFill(const std::vector& strokes, + CXFA_Graphics* pGS, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix, + bool forceRound); }; #endif // XFA_FXFA_PARSER_CXFA_BOX_H_ diff --git a/xfa/fxfa/parser/cxfa_fill.cpp b/xfa/fxfa/parser/cxfa_fill.cpp index e1e077b5bb..4cbd8f812c 100644 --- a/xfa/fxfa/parser/cxfa_fill.cpp +++ b/xfa/fxfa/parser/cxfa_fill.cpp @@ -75,7 +75,7 @@ FX_ARGB CXFA_Fill::GetColor(bool bText) { return pColor->GetValueOrDefault(bText ? 0xFF000000 : 0xFFFFFFFF); } -XFA_Element CXFA_Fill::GetFillType() const { +XFA_Element CXFA_Fill::GetType() const { CXFA_Node* pChild = GetFirstChild(); while (pChild) { XFA_Element eType = pChild->GetElementType(); @@ -87,76 +87,70 @@ XFA_Element CXFA_Fill::GetFillType() const { return XFA_Element::Solid; } -XFA_AttributeEnum CXFA_Fill::GetPatternType() { - CXFA_Pattern* pattern = GetPatternIfExists(); - return pattern ? pattern->GetType() : CXFA_Pattern::kDefaultType; -} - -FX_ARGB CXFA_Fill::GetPatternColor() { - CXFA_Pattern* pattern = GetPatternIfExists(); - if (!pattern) - return CXFA_Color::kBlackColor; - - CXFA_Color* pColor = pattern->GetColorIfExists(); - return pColor ? pColor->GetValue() : CXFA_Color::kBlackColor; -} - -int32_t CXFA_Fill::GetStippleRate() { - CXFA_Stipple* stipple = GetStippleIfExists(); - if (!stipple) - return CXFA_Stipple::GetDefaultRate(); - return stipple->GetRate(); -} - -FX_ARGB CXFA_Fill::GetStippleColor() { - CXFA_Stipple* stipple = GetStippleIfExists(); - if (!stipple) - return CXFA_Color::kBlackColor; - - CXFA_Color* pColor = stipple->GetColorIfExists(); - return pColor ? pColor->GetValue() : CXFA_Color::kBlackColor; -} - -XFA_AttributeEnum CXFA_Fill::GetLinearType() { - CXFA_Linear* linear = GetLinearIfExists(); - return linear ? linear->GetType() : CXFA_Linear::kDefaultType; -} - -FX_ARGB CXFA_Fill::GetLinearColor() { - CXFA_Linear* linear = GetLinearIfExists(); - if (!linear) - return CXFA_Color::kBlackColor; - - CXFA_Color* pColor = linear->GetColorIfExists(); - return pColor ? pColor->GetValue() : CXFA_Color::kBlackColor; -} - -bool CXFA_Fill::IsRadialToEdge() { - CXFA_Radial* radial = GetRadialIfExists(); - return radial ? radial->IsToEdge() : false; -} - -FX_ARGB CXFA_Fill::GetRadialColor() { - CXFA_Radial* radial = GetRadialIfExists(); - if (!radial) - return CXFA_Color::kBlackColor; - - CXFA_Color* pColor = radial->GetColorIfExists(); - return pColor ? pColor->GetValue() : CXFA_Color::kBlackColor; -} - -CXFA_Stipple* CXFA_Fill::GetStippleIfExists() { - return JSObject()->GetOrCreateProperty(0, XFA_Element::Stipple); -} - -CXFA_Radial* CXFA_Fill::GetRadialIfExists() { - return JSObject()->GetOrCreateProperty(0, XFA_Element::Radial); -} - -CXFA_Linear* CXFA_Fill::GetLinearIfExists() { - return JSObject()->GetOrCreateProperty(0, XFA_Element::Linear); -} +void CXFA_Fill::Draw(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix) { + pGS->SaveGraphState(); + + switch (GetType()) { + case XFA_Element::Radial: + DrawRadial(pGS, fillPath, rtWidget, matrix); + break; + case XFA_Element::Pattern: + DrawPattern(pGS, fillPath, rtWidget, matrix); + break; + case XFA_Element::Linear: + DrawLinear(pGS, fillPath, rtWidget, matrix); + break; + case XFA_Element::Stipple: + DrawStipple(pGS, fillPath, rtWidget, matrix); + break; + default: + pGS->SetFillColor(CXFA_GEColor(GetColor(false))); + pGS->FillPath(fillPath, FXFILL_WINDING, &matrix); + break; + } -CXFA_Pattern* CXFA_Fill::GetPatternIfExists() { - return JSObject()->GetOrCreateProperty(0, XFA_Element::Pattern); + pGS->RestoreGraphState(); +} + +void CXFA_Fill::DrawStipple(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix) { + CXFA_Stipple* stipple = + JSObject()->GetOrCreateProperty(0, XFA_Element::Stipple); + if (stipple) + stipple->Draw(pGS, fillPath, rtWidget, matrix); +} + +void CXFA_Fill::DrawRadial(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix) { + CXFA_Radial* radial = + JSObject()->GetOrCreateProperty(0, XFA_Element::Radial); + if (radial) + radial->Draw(pGS, fillPath, GetColor(false), rtWidget, matrix); +} + +void CXFA_Fill::DrawLinear(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix) { + CXFA_Linear* linear = + JSObject()->GetOrCreateProperty(0, XFA_Element::Linear); + if (linear) + linear->Draw(pGS, fillPath, GetColor(false), rtWidget, matrix); +} + +void CXFA_Fill::DrawPattern(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix) { + CXFA_Pattern* pattern = + JSObject()->GetOrCreateProperty(0, XFA_Element::Pattern); + if (pattern) + pattern->Draw(pGS, fillPath, GetColor(false), rtWidget, matrix); } diff --git a/xfa/fxfa/parser/cxfa_fill.h b/xfa/fxfa/parser/cxfa_fill.h index dc733f5a24..1ffdcdf2a3 100644 --- a/xfa/fxfa/parser/cxfa_fill.h +++ b/xfa/fxfa/parser/cxfa_fill.h @@ -7,9 +7,12 @@ #ifndef XFA_FXFA_PARSER_CXFA_FILL_H_ #define XFA_FXFA_PARSER_CXFA_FILL_H_ +#include "core/fxcrt/fx_coordinates.h" #include "core/fxge/fx_dib.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxgraphics/cxfa_gepath.h" +class CXFA_Graphics; class CXFA_Linear; class CXFA_Pattern; class CXFA_Radial; @@ -25,25 +28,30 @@ class CXFA_Fill : public CXFA_Node { FX_ARGB GetColor(bool bText); void SetColor(FX_ARGB color); - XFA_Element GetFillType() const; - - XFA_AttributeEnum GetPatternType(); - FX_ARGB GetPatternColor(); - - XFA_AttributeEnum GetLinearType(); - FX_ARGB GetLinearColor(); - - int32_t GetStippleRate(); - FX_ARGB GetStippleColor(); - - bool IsRadialToEdge(); - FX_ARGB GetRadialColor(); + void Draw(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix); private: - CXFA_Stipple* GetStippleIfExists(); - CXFA_Radial* GetRadialIfExists(); - CXFA_Linear* GetLinearIfExists(); - CXFA_Pattern* GetPatternIfExists(); + XFA_Element GetType() const; + + void DrawStipple(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix); + void DrawRadial(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix); + void DrawLinear(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix); + void DrawPattern(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtWidget, + const CFX_Matrix& matrix); }; #endif // XFA_FXFA_PARSER_CXFA_FILL_H_ diff --git a/xfa/fxfa/parser/cxfa_linear.cpp b/xfa/fxfa/parser/cxfa_linear.cpp index f5b605dcb8..8506d247d4 100644 --- a/xfa/fxfa/parser/cxfa_linear.cpp +++ b/xfa/fxfa/parser/cxfa_linear.cpp @@ -9,6 +9,7 @@ #include "fxjs/xfa/cjx_linear.h" #include "third_party/base/ptr_util.h" #include "xfa/fxfa/parser/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_geshading.h" namespace { @@ -49,3 +50,42 @@ XFA_AttributeEnum CXFA_Linear::GetType() { CXFA_Color* CXFA_Linear::GetColorIfExists() { return GetChild(0, XFA_Element::Color, false); } + +void CXFA_Linear::Draw(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + FX_ARGB crStart, + const CFX_RectF& rtFill, + const CFX_Matrix& matrix) { + CXFA_Color* pColor = GetColorIfExists(); + FX_ARGB crEnd = pColor ? pColor->GetValue() : CXFA_Color::kBlackColor; + + CFX_PointF ptStart; + CFX_PointF ptEnd; + switch (GetType()) { + case XFA_AttributeEnum::ToRight: + ptStart = CFX_PointF(rtFill.left, rtFill.top); + ptEnd = CFX_PointF(rtFill.right(), rtFill.top); + break; + case XFA_AttributeEnum::ToBottom: + ptStart = CFX_PointF(rtFill.left, rtFill.top); + ptEnd = CFX_PointF(rtFill.left, rtFill.bottom()); + break; + case XFA_AttributeEnum::ToLeft: + ptStart = CFX_PointF(rtFill.right(), rtFill.top); + ptEnd = CFX_PointF(rtFill.left, rtFill.top); + break; + case XFA_AttributeEnum::ToTop: + ptStart = CFX_PointF(rtFill.left, rtFill.bottom()); + ptEnd = CFX_PointF(rtFill.left, rtFill.top); + break; + default: + break; + } + + CXFA_GEShading shading(ptStart, ptEnd, false, false, crStart, crEnd); + + pGS->SaveGraphState(); + pGS->SetFillColor(CXFA_GEColor(&shading)); + pGS->FillPath(fillPath, FXFILL_WINDING, &matrix); + pGS->RestoreGraphState(); +} diff --git a/xfa/fxfa/parser/cxfa_linear.h b/xfa/fxfa/parser/cxfa_linear.h index d17f7ffcb2..bb55f8073c 100644 --- a/xfa/fxfa/parser/cxfa_linear.h +++ b/xfa/fxfa/parser/cxfa_linear.h @@ -7,9 +7,12 @@ #ifndef XFA_FXFA_PARSER_CXFA_LINEAR_H_ #define XFA_FXFA_PARSER_CXFA_LINEAR_H_ +#include "core/fxcrt/fx_coordinates.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxgraphics/cxfa_gepath.h" class CXFA_Color; +class CXFA_Graphics; class CXFA_Linear : public CXFA_Node { public: @@ -18,6 +21,13 @@ class CXFA_Linear : public CXFA_Node { CXFA_Linear(CXFA_Document* doc, XFA_PacketType packet); ~CXFA_Linear() override; + void Draw(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + FX_ARGB crStart, + const CFX_RectF& rtFill, + const CFX_Matrix& matrix); + + private: XFA_AttributeEnum GetType(); CXFA_Color* GetColorIfExists(); }; diff --git a/xfa/fxfa/parser/cxfa_pattern.cpp b/xfa/fxfa/parser/cxfa_pattern.cpp index 3102f77beb..4cd32cced8 100644 --- a/xfa/fxfa/parser/cxfa_pattern.cpp +++ b/xfa/fxfa/parser/cxfa_pattern.cpp @@ -9,6 +9,7 @@ #include "fxjs/xfa/cjx_pattern.h" #include "third_party/base/ptr_util.h" #include "xfa/fxfa/parser/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_gepattern.h" namespace { @@ -47,3 +48,40 @@ CXFA_Color* CXFA_Pattern::GetColorIfExists() { XFA_AttributeEnum CXFA_Pattern::GetType() { return JSObject()->GetEnum(XFA_Attribute::Type); } + +void CXFA_Pattern::Draw(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + FX_ARGB crStart, + const CFX_RectF& rtFill, + const CFX_Matrix& matrix) { + CXFA_Color* pColor = GetColorIfExists(); + FX_ARGB crEnd = pColor ? pColor->GetValue() : CXFA_Color::kBlackColor; + + FX_HatchStyle iHatch = FX_HatchStyle::Cross; + switch (GetType()) { + case XFA_AttributeEnum::CrossDiagonal: + iHatch = FX_HatchStyle::DiagonalCross; + break; + case XFA_AttributeEnum::DiagonalLeft: + iHatch = FX_HatchStyle::ForwardDiagonal; + break; + case XFA_AttributeEnum::DiagonalRight: + iHatch = FX_HatchStyle::BackwardDiagonal; + break; + case XFA_AttributeEnum::Horizontal: + iHatch = FX_HatchStyle::Horizontal; + break; + case XFA_AttributeEnum::Vertical: + iHatch = FX_HatchStyle::Vertical; + break; + default: + break; + } + + CXFA_GEPattern pattern(iHatch, crEnd, crStart); + + pGS->SaveGraphState(); + pGS->SetFillColor(CXFA_GEColor(&pattern, 0x0)); + pGS->FillPath(fillPath, FXFILL_WINDING, &matrix); + pGS->RestoreGraphState(); +} diff --git a/xfa/fxfa/parser/cxfa_pattern.h b/xfa/fxfa/parser/cxfa_pattern.h index 7e115f2d9d..7533ac91a4 100644 --- a/xfa/fxfa/parser/cxfa_pattern.h +++ b/xfa/fxfa/parser/cxfa_pattern.h @@ -7,9 +7,12 @@ #ifndef XFA_FXFA_PARSER_CXFA_PATTERN_H_ #define XFA_FXFA_PARSER_CXFA_PATTERN_H_ +#include "core/fxcrt/fx_coordinates.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxgraphics/cxfa_gepath.h" class CXFA_Color; +class CXFA_Graphics; class CXFA_Pattern : public CXFA_Node { public: @@ -18,6 +21,13 @@ class CXFA_Pattern : public CXFA_Node { CXFA_Pattern(CXFA_Document* doc, XFA_PacketType packet); ~CXFA_Pattern() override; + void Draw(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + FX_ARGB crStart, + const CFX_RectF& rtFill, + const CFX_Matrix& matrix); + + private: XFA_AttributeEnum GetType(); CXFA_Color* GetColorIfExists(); }; diff --git a/xfa/fxfa/parser/cxfa_radial.cpp b/xfa/fxfa/parser/cxfa_radial.cpp index 80753b3803..3d024e744d 100644 --- a/xfa/fxfa/parser/cxfa_radial.cpp +++ b/xfa/fxfa/parser/cxfa_radial.cpp @@ -6,9 +6,12 @@ #include "xfa/fxfa/parser/cxfa_radial.h" +#include + #include "fxjs/xfa/cjx_radial.h" #include "third_party/base/ptr_util.h" #include "xfa/fxfa/parser/cxfa_color.h" +#include "xfa/fxgraphics/cxfa_geshading.h" namespace { @@ -49,3 +52,25 @@ bool CXFA_Radial::IsToEdge() { CXFA_Color* CXFA_Radial::GetColorIfExists() { return GetChild(0, XFA_Element::Color, false); } + +void CXFA_Radial::Draw(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + FX_ARGB crStart, + const CFX_RectF& rtFill, + const CFX_Matrix& matrix) { + CXFA_Color* pColor = GetColorIfExists(); + FX_ARGB crEnd = pColor ? pColor->GetValue() : CXFA_Color::kBlackColor; + if (!IsToEdge()) + std::swap(crStart, crEnd); + + float endRadius = sqrt(rtFill.Width() * rtFill.Width() + + rtFill.Height() * rtFill.Height()) / + 2; + CXFA_GEShading shading(rtFill.Center(), rtFill.Center(), 0, endRadius, true, + true, crStart, crEnd); + + pGS->SaveGraphState(); + pGS->SetFillColor(CXFA_GEColor(&shading)); + pGS->FillPath(fillPath, FXFILL_WINDING, &matrix); + pGS->RestoreGraphState(); +} diff --git a/xfa/fxfa/parser/cxfa_radial.h b/xfa/fxfa/parser/cxfa_radial.h index e3a3645e0c..b7ce95c695 100644 --- a/xfa/fxfa/parser/cxfa_radial.h +++ b/xfa/fxfa/parser/cxfa_radial.h @@ -7,15 +7,25 @@ #ifndef XFA_FXFA_PARSER_CXFA_RADIAL_H_ #define XFA_FXFA_PARSER_CXFA_RADIAL_H_ +#include "core/fxcrt/fx_coordinates.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxgraphics/cxfa_gepath.h" class CXFA_Color; +class CXFA_Graphics; class CXFA_Radial : public CXFA_Node { public: CXFA_Radial(CXFA_Document* doc, XFA_PacketType packet); ~CXFA_Radial() override; + void Draw(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + FX_ARGB crStart, + const CFX_RectF& rtFill, + const CFX_Matrix& matrix); + + private: bool IsToEdge(); CXFA_Color* GetColorIfExists(); }; diff --git a/xfa/fxfa/parser/cxfa_stipple.cpp b/xfa/fxfa/parser/cxfa_stipple.cpp index 24715171b8..f8c059e328 100644 --- a/xfa/fxfa/parser/cxfa_stipple.cpp +++ b/xfa/fxfa/parser/cxfa_stipple.cpp @@ -48,3 +48,25 @@ int32_t CXFA_Stipple::GetRate() { ->TryInteger(XFA_Attribute::Rate, true) .value_or(GetDefaultRate()); } + +void CXFA_Stipple::Draw(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtFill, + const CFX_Matrix& matrix) { + int32_t iRate = GetRate(); + if (iRate == 0) + iRate = 100; + + CXFA_Color* pColor = GetColorIfExists(); + FX_ARGB crColor = pColor ? pColor->GetValue() : CXFA_Color::kBlackColor; + + int32_t a; + FX_COLORREF rgb; + std::tie(a, rgb) = ArgbToColorRef(crColor); + FX_ARGB cr = ArgbEncode(iRate * a / 100, rgb); + + pGS->SaveGraphState(); + pGS->SetFillColor(CXFA_GEColor(cr)); + pGS->FillPath(fillPath, FXFILL_WINDING, &matrix); + pGS->RestoreGraphState(); +} diff --git a/xfa/fxfa/parser/cxfa_stipple.h b/xfa/fxfa/parser/cxfa_stipple.h index 3211e24d9e..839534b9c9 100644 --- a/xfa/fxfa/parser/cxfa_stipple.h +++ b/xfa/fxfa/parser/cxfa_stipple.h @@ -7,9 +7,12 @@ #ifndef XFA_FXFA_PARSER_CXFA_STIPPLE_H_ #define XFA_FXFA_PARSER_CXFA_STIPPLE_H_ +#include "core/fxcrt/fx_coordinates.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxgraphics/cxfa_gepath.h" class CXFA_Color; +class CXFA_Graphics; class CXFA_Stipple : public CXFA_Node { public: @@ -18,6 +21,12 @@ class CXFA_Stipple : public CXFA_Node { CXFA_Stipple(CXFA_Document* doc, XFA_PacketType packet); ~CXFA_Stipple() override; + void Draw(CXFA_Graphics* pGS, + CXFA_GEPath* fillPath, + const CFX_RectF& rtFill, + const CFX_Matrix& matrix); + + private: CXFA_Color* GetColorIfExists(); int32_t GetRate(); }; -- cgit v1.2.3