diff options
Diffstat (limited to 'xfa/fxfa/parser/cxfa_fill.cpp')
-rw-r--r-- | xfa/fxfa/parser/cxfa_fill.cpp | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/xfa/fxfa/parser/cxfa_fill.cpp b/xfa/fxfa/parser/cxfa_fill.cpp index a26bc896d7..e4bde509c9 100644 --- a/xfa/fxfa/parser/cxfa_fill.cpp +++ b/xfa/fxfa/parser/cxfa_fill.cpp @@ -8,6 +8,12 @@ #include "fxjs/xfa/cjx_fill.h" #include "third_party/base/ptr_util.h" +#include "xfa/fxfa/parser/cxfa_color.h" +#include "xfa/fxfa/parser/cxfa_linear.h" +#include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_pattern.h" +#include "xfa/fxfa/parser/cxfa_radial.h" +#include "xfa/fxfa/parser/cxfa_stipple.h" namespace { @@ -45,3 +51,132 @@ CXFA_Fill::CXFA_Fill(CXFA_Document* doc, XFA_PacketType packet) pdfium::MakeUnique<CJX_Fill>(this)) {} CXFA_Fill::~CXFA_Fill() {} + +bool CXFA_Fill::IsVisible() { + return JSObject() + ->TryEnum(XFA_Attribute::Presence, true) + .value_or(XFA_AttributeEnum::Visible) == + XFA_AttributeEnum::Visible; +} + +void CXFA_Fill::SetColor(FX_ARGB color) { + CXFA_Color* pNode = + JSObject()->GetProperty<CXFA_Color>(0, XFA_Element::Color, true); + int a; + int r; + int g; + int b; + std::tie(a, r, g, b) = ArgbDecode(color); + pNode->JSObject()->SetCData(XFA_Attribute::Value, + WideString::Format(L"%d,%d,%d", r, g, b), false, + false); +} + +FX_ARGB CXFA_Fill::GetColor(bool bText) { + if (CXFA_Color* pNode = GetChild<CXFA_Color>(0, XFA_Element::Color, false)) { + pdfium::Optional<WideString> wsColor = + pNode->JSObject()->TryCData(XFA_Attribute::Value, false); + if (wsColor) + return CXFA_DataData::ToColor(wsColor->AsStringView()); + } + if (bText) + return 0xFF000000; + return 0xFFFFFFFF; +} + +XFA_Element CXFA_Fill::GetFillType() const { + CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); + while (pChild) { + XFA_Element eType = pChild->GetElementType(); + if (eType != XFA_Element::Color && eType != XFA_Element::Extras) + return eType; + + pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + } + return XFA_Element::Solid; +} + +XFA_AttributeEnum CXFA_Fill::GetPatternType() { + return GetPattern()->JSObject()->GetEnum(XFA_Attribute::Type); +} + +FX_ARGB CXFA_Fill::GetPatternColor() { + if (CXFA_Color* pColor = + GetPattern()->GetChild<CXFA_Color>(0, XFA_Element::Color, false)) { + pdfium::Optional<WideString> wsColor = + pColor->JSObject()->TryCData(XFA_Attribute::Value, false); + if (wsColor) + return CXFA_DataData::ToColor(wsColor->AsStringView()); + } + return 0xFF000000; +} + +int32_t CXFA_Fill::GetStippleRate() { + return GetStipple() + ->JSObject() + ->TryInteger(XFA_Attribute::Rate, true) + .value_or(50); +} + +FX_ARGB CXFA_Fill::GetStippleColor() { + if (CXFA_Color* pColor = + GetStipple()->GetChild<CXFA_Color>(0, XFA_Element::Color, false)) { + pdfium::Optional<WideString> wsColor = + pColor->JSObject()->TryCData(XFA_Attribute::Value, false); + if (wsColor) + return CXFA_DataData::ToColor(wsColor->AsStringView()); + } + return 0xFF000000; +} + +XFA_AttributeEnum CXFA_Fill::GetLinearType() { + return GetLinear() + ->JSObject() + ->TryEnum(XFA_Attribute::Type, true) + .value_or(XFA_AttributeEnum::ToRight); +} + +FX_ARGB CXFA_Fill::GetLinearColor() { + if (CXFA_Color* pColor = + GetLinear()->GetChild<CXFA_Color>(0, XFA_Element::Color, false)) { + pdfium::Optional<WideString> wsColor = + pColor->JSObject()->TryCData(XFA_Attribute::Value, false); + if (wsColor) + return CXFA_DataData::ToColor(wsColor->AsStringView()); + } + return 0xFF000000; +} + +bool CXFA_Fill::IsRadialToEdge() { + return GetRadial() + ->JSObject() + ->TryEnum(XFA_Attribute::Type, true) + .value_or(XFA_AttributeEnum::ToEdge) == XFA_AttributeEnum::ToEdge; +} + +FX_ARGB CXFA_Fill::GetRadialColor() { + if (CXFA_Color* pColor = + GetRadial()->GetChild<CXFA_Color>(0, XFA_Element::Color, false)) { + pdfium::Optional<WideString> wsColor = + pColor->JSObject()->TryCData(XFA_Attribute::Value, false); + if (wsColor) + return CXFA_DataData::ToColor(wsColor->AsStringView()); + } + return 0xFF000000; +} + +CXFA_Stipple* CXFA_Fill::GetStipple() { + return JSObject()->GetProperty<CXFA_Stipple>(0, XFA_Element::Stipple, true); +} + +CXFA_Radial* CXFA_Fill::GetRadial() { + return JSObject()->GetProperty<CXFA_Radial>(0, XFA_Element::Radial, true); +} + +CXFA_Linear* CXFA_Fill::GetLinear() { + return JSObject()->GetProperty<CXFA_Linear>(0, XFA_Element::Linear, true); +} + +CXFA_Pattern* CXFA_Fill::GetPattern() { + return JSObject()->GetProperty<CXFA_Pattern>(0, XFA_Element::Pattern, true); +} |