From 7c986a085631639d38076918e0df719d11f40e59 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 21 Nov 2017 21:49:30 +0000 Subject: Cleanup CXFA_FillData This CL makes the CXFA_FillData methods const and splits them into retrieving fill information and fill colour methods. Change-Id: Ie407be87c631ea68efa0934d9a98e412ed1eb922 Reviewed-on: https://pdfium-review.googlesource.com/18950 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- xfa/fxfa/cxfa_ffwidget.cpp | 41 ++++++++--------- xfa/fxfa/parser/cxfa_filldata.cpp | 96 ++++++++++++++++++++++++--------------- xfa/fxfa/parser/cxfa_filldata.h | 30 +++++++++--- 3 files changed, 102 insertions(+), 65 deletions(-) (limited to 'xfa') diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index 24e647a1cd..a593ff45a2 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "core/fpdfapi/cpdf_modulemgr.h" @@ -390,14 +391,11 @@ void XFA_BOX_Fill_Radial(const CXFA_BoxData& boxData, CFX_RectF rtFill, const CFX_Matrix& matrix) { CXFA_FillData fillData = boxData.GetFillData(false); - FX_ARGB crStart, crEnd; - crStart = fillData.GetColor(); - int32_t iType = fillData.GetRadial(crEnd); - if (iType != XFA_ATTRIBUTEENUM_ToEdge) { - FX_ARGB temp = crEnd; - crEnd = crStart; - crStart = temp; - } + FX_ARGB crStart = fillData.GetColor(false); + FX_ARGB crEnd = fillData.GetRadialColor(); + if (!fillData.IsRadialToEdge()) + std::swap(crStart, crEnd); + CXFA_GEShading shading(rtFill.Center(), rtFill.Center(), 0, sqrt(rtFill.Width() * rtFill.Width() + rtFill.Height() * rtFill.Height()) / @@ -413,11 +411,10 @@ void XFA_BOX_Fill_Pattern(const CXFA_BoxData& boxData, CFX_RectF rtFill, const CFX_Matrix& matrix) { CXFA_FillData fillData = boxData.GetFillData(false); - FX_ARGB crStart, crEnd; - crStart = fillData.GetColor(); - int32_t iType = fillData.GetPattern(crEnd); + FX_ARGB crStart = fillData.GetColor(false); + FX_ARGB crEnd = fillData.GetPatternColor(); FX_HatchStyle iHatch = FX_HatchStyle::Cross; - switch (iType) { + switch (fillData.GetPatternType()) { case XFA_ATTRIBUTEENUM_CrossDiagonal: iHatch = FX_HatchStyle::DiagonalCross; break; @@ -448,12 +445,12 @@ void XFA_BOX_Fill_Linear(const CXFA_BoxData& boxData, CFX_RectF rtFill, const CFX_Matrix& matrix) { CXFA_FillData fillData = boxData.GetFillData(false); - FX_ARGB crStart = fillData.GetColor(); - FX_ARGB crEnd; - int32_t iType = fillData.GetLinear(crEnd); + FX_ARGB crStart = fillData.GetColor(false); + FX_ARGB crEnd = fillData.GetLinearColor(); + CFX_PointF ptStart; CFX_PointF ptEnd; - switch (iType) { + switch (fillData.GetLinearType()) { case XFA_ATTRIBUTEENUM_ToRight: ptStart = CFX_PointF(rtFill.left, rtFill.top); ptEnd = CFX_PointF(rtFill.right(), rtFill.top); @@ -473,6 +470,7 @@ void XFA_BOX_Fill_Linear(const CXFA_BoxData& boxData, default: break; } + CXFA_GEShading shading(ptStart, ptEnd, false, false, crStart, crEnd); pGS->SetFillColor(CXFA_GEColor(&shading)); pGS->FillPath(&fillPath, FXFILL_WINDING, &matrix); @@ -485,10 +483,8 @@ void XFA_BOX_Fill(const CXFA_BoxData& boxData, const CFX_Matrix& matrix, uint32_t dwFlags) { CXFA_FillData fillData = boxData.GetFillData(false); - if (!fillData.HasValidNode() || - fillData.GetPresence() != XFA_ATTRIBUTEENUM_Visible) { + if (!fillData.HasValidNode() || !fillData.IsVisible()) return; - } pGS->SaveGraphState(); CXFA_GEPath fillPath; @@ -509,15 +505,16 @@ void XFA_BOX_Fill(const CXFA_BoxData& boxData, default: { FX_ARGB cr; if (eType == XFA_Element::Stipple) { - int32_t iRate = fillData.GetStipple(cr); + int32_t iRate = fillData.GetStippleRate(); if (iRate == 0) iRate = 100; + int32_t a; FX_COLORREF rgb; - std::tie(a, rgb) = ArgbToColorRef(cr); + std::tie(a, rgb) = ArgbToColorRef(fillData.GetStippleColor()); cr = ArgbEncode(iRate * a / 100, rgb); } else { - cr = fillData.GetColor(); + cr = fillData.GetColor(false); } pGS->SetFillColor(CXFA_GEColor(cr)); pGS->FillPath(&fillPath, FXFILL_WINDING, &matrix); diff --git a/xfa/fxfa/parser/cxfa_filldata.cpp b/xfa/fxfa/parser/cxfa_filldata.cpp index 9f57b8de7d..0bbb36a891 100644 --- a/xfa/fxfa/parser/cxfa_filldata.cpp +++ b/xfa/fxfa/parser/cxfa_filldata.cpp @@ -12,8 +12,9 @@ CXFA_FillData::CXFA_FillData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} CXFA_FillData::~CXFA_FillData() {} -int32_t CXFA_FillData::GetPresence() { - return m_pNode->JSNode()->GetEnum(XFA_Attribute::Presence); +bool CXFA_FillData::IsVisible() const { + return m_pNode->JSNode()->GetEnum(XFA_Attribute::Presence) == + XFA_ATTRIBUTEENUM_Visible; } void CXFA_FillData::SetColor(FX_ARGB color) { @@ -29,7 +30,7 @@ void CXFA_FillData::SetColor(FX_ARGB color) { false); } -FX_ARGB CXFA_FillData::GetColor(bool bText) { +FX_ARGB CXFA_FillData::GetColor(bool bText) const { if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Color, false)) { pdfium::Optional wsColor = pNode->JSNode()->TryCData(XFA_Attribute::Value, false); @@ -41,7 +42,7 @@ FX_ARGB CXFA_FillData::GetColor(bool bText) { return 0xFFFFFFFF; } -XFA_Element CXFA_FillData::GetFillType() { +XFA_Element CXFA_FillData::GetFillType() const { CXFA_Node* pChild = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); while (pChild) { XFA_Element eType = pChild->GetElementType(); @@ -53,62 +54,85 @@ XFA_Element CXFA_FillData::GetFillType() { return XFA_Element::Solid; } -int32_t CXFA_FillData::GetPattern(FX_ARGB& foreColor) { - foreColor = 0xFF000000; +XFA_ATTRIBUTEENUM CXFA_FillData::GetPatternType() const { + return GetPattern()->JSNode()->GetEnum(XFA_Attribute::Type); +} - CXFA_Node* pNode = - m_pNode->JSNode()->GetProperty(0, XFA_Element::Pattern, true); - if (CXFA_Node* pColor = pNode->GetChild(0, XFA_Element::Color, false)) { +FX_ARGB CXFA_FillData::GetPatternColor() const { + if (CXFA_Node* pColor = + GetPattern()->GetChild(0, XFA_Element::Color, false)) { pdfium::Optional wsColor = pColor->JSNode()->TryCData(XFA_Attribute::Value, false); if (wsColor) - foreColor = CXFA_DataData::ToColor(wsColor->AsStringView()); + return CXFA_DataData::ToColor(wsColor->AsStringView()); } - return pNode->JSNode()->GetEnum(XFA_Attribute::Type); + return 0xFF000000; } -int32_t CXFA_FillData::GetStipple(FX_ARGB& stippleColor) { - stippleColor = 0xFF000000; +int32_t CXFA_FillData::GetStippleRate() const { + return GetStipple() + ->JSNode() + ->TryInteger(XFA_Attribute::Rate, true) + .value_or(50); +} - CXFA_Node* pNode = - m_pNode->JSNode()->GetProperty(0, XFA_Element::Stipple, true); - if (CXFA_Node* pColor = pNode->GetChild(0, XFA_Element::Color, false)) { +FX_ARGB CXFA_FillData::GetStippleColor() const { + if (CXFA_Node* pColor = + GetStipple()->GetChild(0, XFA_Element::Color, false)) { pdfium::Optional wsColor = pColor->JSNode()->TryCData(XFA_Attribute::Value, false); if (wsColor) - stippleColor = CXFA_DataData::ToColor(wsColor->AsStringView()); + return CXFA_DataData::ToColor(wsColor->AsStringView()); } - return pNode->JSNode()->TryInteger(XFA_Attribute::Rate, true).value_or(50); + return 0xFF000000; } -int32_t CXFA_FillData::GetLinear(FX_ARGB& endColor) { - endColor = 0xFF000000; +XFA_ATTRIBUTEENUM CXFA_FillData::GetLinearType() const { + return GetLinear() + ->JSNode() + ->TryEnum(XFA_Attribute::Type, true) + .value_or(XFA_ATTRIBUTEENUM_ToRight); +} - CXFA_Node* pNode = - m_pNode->JSNode()->GetProperty(0, XFA_Element::Linear, true); - if (CXFA_Node* pColor = pNode->GetChild(0, XFA_Element::Color, false)) { +FX_ARGB CXFA_FillData::GetLinearColor() const { + if (CXFA_Node* pColor = GetLinear()->GetChild(0, XFA_Element::Color, false)) { pdfium::Optional wsColor = pColor->JSNode()->TryCData(XFA_Attribute::Value, false); if (wsColor) - endColor = CXFA_DataData::ToColor(wsColor->AsStringView()); + return CXFA_DataData::ToColor(wsColor->AsStringView()); } - return pNode->JSNode() - ->TryEnum(XFA_Attribute::Type, true) - .value_or(XFA_ATTRIBUTEENUM_ToRight); + return 0xFF000000; } -int32_t CXFA_FillData::GetRadial(FX_ARGB& endColor) { - endColor = 0xFF000000; +bool CXFA_FillData::IsRadialToEdge() const { + return GetRadial() + ->JSNode() + ->TryEnum(XFA_Attribute::Type, true) + .value_or(XFA_ATTRIBUTEENUM_ToEdge) == XFA_ATTRIBUTEENUM_ToEdge; +} - CXFA_Node* pNode = - m_pNode->JSNode()->GetProperty(0, XFA_Element::Radial, true); - if (CXFA_Node* pColor = pNode->GetChild(0, XFA_Element::Color, false)) { +FX_ARGB CXFA_FillData::GetRadialColor() const { + if (CXFA_Node* pColor = GetRadial()->GetChild(0, XFA_Element::Color, false)) { pdfium::Optional wsColor = pColor->JSNode()->TryCData(XFA_Attribute::Value, false); if (wsColor) - endColor = CXFA_DataData::ToColor(wsColor->AsStringView()); + return CXFA_DataData::ToColor(wsColor->AsStringView()); } - return pNode->JSNode() - ->TryEnum(XFA_Attribute::Type, true) - .value_or(XFA_ATTRIBUTEENUM_ToEdge); + return 0xFF000000; +} + +CXFA_Node* CXFA_FillData::GetStipple() const { + return m_pNode->JSNode()->GetProperty(0, XFA_Element::Stipple, true); +} + +CXFA_Node* CXFA_FillData::GetRadial() const { + return m_pNode->JSNode()->GetProperty(0, XFA_Element::Radial, true); +} + +CXFA_Node* CXFA_FillData::GetLinear() const { + return m_pNode->JSNode()->GetProperty(0, XFA_Element::Linear, true); +} + +CXFA_Node* CXFA_FillData::GetPattern() const { + return m_pNode->JSNode()->GetProperty(0, XFA_Element::Pattern, true); } diff --git a/xfa/fxfa/parser/cxfa_filldata.h b/xfa/fxfa/parser/cxfa_filldata.h index 7faca4a95a..6890952c25 100644 --- a/xfa/fxfa/parser/cxfa_filldata.h +++ b/xfa/fxfa/parser/cxfa_filldata.h @@ -18,14 +18,30 @@ class CXFA_FillData : public CXFA_DataData { explicit CXFA_FillData(CXFA_Node* pNode); ~CXFA_FillData() override; - int32_t GetPresence(); - FX_ARGB GetColor(bool bText = false); - XFA_Element GetFillType(); - int32_t GetPattern(FX_ARGB& foreColor); - int32_t GetStipple(FX_ARGB& stippleColor); - int32_t GetLinear(FX_ARGB& endColor); - int32_t GetRadial(FX_ARGB& endColor); + bool IsVisible() const; + + FX_ARGB GetColor(bool bText) const; void SetColor(FX_ARGB color); + + XFA_Element GetFillType() const; + + XFA_ATTRIBUTEENUM GetPatternType() const; + FX_ARGB GetPatternColor() const; + + XFA_ATTRIBUTEENUM GetLinearType() const; + FX_ARGB GetLinearColor() const; + + int32_t GetStippleRate() const; + FX_ARGB GetStippleColor() const; + + bool IsRadialToEdge() const; + FX_ARGB GetRadialColor() const; + + private: + CXFA_Node* GetStipple() const; + CXFA_Node* GetRadial() const; + CXFA_Node* GetLinear() const; + CXFA_Node* GetPattern() const; }; #endif // XFA_FXFA_PARSER_CXFA_FILLDATA_H_ -- cgit v1.2.3