summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_fill.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-01-16 15:15:05 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-16 15:15:05 +0000
commitd3ae179dab3f63625e5dd3ddf0aa33176f8ee65c (patch)
tree151c01afa3404c846b1ab323607b244427b57ae9 /xfa/fxfa/parser/cxfa_fill.cpp
parentb36c7e1f84ea7402b7576d2a03a219d469735434 (diff)
downloadpdfium-d3ae179dab3f63625e5dd3ddf0aa33176f8ee65c.tar.xz
Cleanup CXFA_Fill
This CL cleans up the CXFA_Fill internal getters to handle nullptr returns correctly and moves some of the logic to the specific XFA classes. Change-Id: Icac487105a026a25cc9981d00fbc152e459ad0b8 Reviewed-on: https://pdfium-review.googlesource.com/22770 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_fill.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_fill.cpp113
1 files changed, 45 insertions, 68 deletions
diff --git a/xfa/fxfa/parser/cxfa_fill.cpp b/xfa/fxfa/parser/cxfa_fill.cpp
index c62006754f..e1e077b5bb 100644
--- a/xfa/fxfa/parser/cxfa_fill.cpp
+++ b/xfa/fxfa/parser/cxfa_fill.cpp
@@ -60,31 +60,19 @@ bool CXFA_Fill::IsVisible() {
}
void CXFA_Fill::SetColor(FX_ARGB color) {
- CXFA_Color* pNode =
+ CXFA_Color* pColor =
JSObject()->GetOrCreateProperty<CXFA_Color>(0, XFA_Element::Color);
- if (!pNode)
+ if (!pColor)
return;
- 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);
+ pColor->SetValue(color);
}
FX_ARGB CXFA_Fill::GetColor(bool bText) {
- if (CXFA_Color* pNode = GetChild<CXFA_Color>(0, XFA_Element::Color, false)) {
- Optional<WideString> wsColor =
- pNode->JSObject()->TryCData(XFA_Attribute::Value, false);
- if (wsColor)
- return StringToFXARGB(wsColor->AsStringView());
- }
- if (bText)
- return 0xFF000000;
- return 0xFFFFFFFF;
+ CXFA_Color* pColor = GetChild<CXFA_Color>(0, XFA_Element::Color, false);
+ if (!pColor)
+ return bText ? 0xFF000000 : 0xFFFFFFFF;
+ return pColor->GetValueOrDefault(bText ? 0xFF000000 : 0xFFFFFFFF);
}
XFA_Element CXFA_Fill::GetFillType() const {
@@ -100,86 +88,75 @@ XFA_Element CXFA_Fill::GetFillType() const {
}
XFA_AttributeEnum CXFA_Fill::GetPatternType() {
- return GetPattern()->JSObject()->GetEnum(XFA_Attribute::Type);
+ CXFA_Pattern* pattern = GetPatternIfExists();
+ return pattern ? pattern->GetType() : CXFA_Pattern::kDefaultType;
}
FX_ARGB CXFA_Fill::GetPatternColor() {
- if (CXFA_Color* pColor =
- GetPattern()->GetChild<CXFA_Color>(0, XFA_Element::Color, false)) {
- Optional<WideString> wsColor =
- pColor->JSObject()->TryCData(XFA_Attribute::Value, false);
- if (wsColor)
- return StringToFXARGB(wsColor->AsStringView());
- }
- return 0xFF000000;
+ 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() {
- return GetStipple()
- ->JSObject()
- ->TryInteger(XFA_Attribute::Rate, true)
- .value_or(50);
+ CXFA_Stipple* stipple = GetStippleIfExists();
+ if (!stipple)
+ return CXFA_Stipple::GetDefaultRate();
+ return stipple->GetRate();
}
FX_ARGB CXFA_Fill::GetStippleColor() {
- if (CXFA_Color* pColor =
- GetStipple()->GetChild<CXFA_Color>(0, XFA_Element::Color, false)) {
- Optional<WideString> wsColor =
- pColor->JSObject()->TryCData(XFA_Attribute::Value, false);
- if (wsColor)
- return StringToFXARGB(wsColor->AsStringView());
- }
- return 0xFF000000;
+ 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() {
- return GetLinear()
- ->JSObject()
- ->TryEnum(XFA_Attribute::Type, true)
- .value_or(XFA_AttributeEnum::ToRight);
+ CXFA_Linear* linear = GetLinearIfExists();
+ return linear ? linear->GetType() : CXFA_Linear::kDefaultType;
}
FX_ARGB CXFA_Fill::GetLinearColor() {
- if (CXFA_Color* pColor =
- GetLinear()->GetChild<CXFA_Color>(0, XFA_Element::Color, false)) {
- Optional<WideString> wsColor =
- pColor->JSObject()->TryCData(XFA_Attribute::Value, false);
- if (wsColor)
- return StringToFXARGB(wsColor->AsStringView());
- }
- return 0xFF000000;
+ 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() {
- return GetRadial()
- ->JSObject()
- ->TryEnum(XFA_Attribute::Type, true)
- .value_or(XFA_AttributeEnum::ToEdge) == XFA_AttributeEnum::ToEdge;
+ CXFA_Radial* radial = GetRadialIfExists();
+ return radial ? radial->IsToEdge() : false;
}
FX_ARGB CXFA_Fill::GetRadialColor() {
- if (CXFA_Color* pColor =
- GetRadial()->GetChild<CXFA_Color>(0, XFA_Element::Color, false)) {
- Optional<WideString> wsColor =
- pColor->JSObject()->TryCData(XFA_Attribute::Value, false);
- if (wsColor)
- return StringToFXARGB(wsColor->AsStringView());
- }
- return 0xFF000000;
+ 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::GetStipple() {
+CXFA_Stipple* CXFA_Fill::GetStippleIfExists() {
return JSObject()->GetOrCreateProperty<CXFA_Stipple>(0, XFA_Element::Stipple);
}
-CXFA_Radial* CXFA_Fill::GetRadial() {
+CXFA_Radial* CXFA_Fill::GetRadialIfExists() {
return JSObject()->GetOrCreateProperty<CXFA_Radial>(0, XFA_Element::Radial);
}
-CXFA_Linear* CXFA_Fill::GetLinear() {
+CXFA_Linear* CXFA_Fill::GetLinearIfExists() {
return JSObject()->GetOrCreateProperty<CXFA_Linear>(0, XFA_Element::Linear);
}
-CXFA_Pattern* CXFA_Fill::GetPattern() {
+CXFA_Pattern* CXFA_Fill::GetPatternIfExists() {
return JSObject()->GetOrCreateProperty<CXFA_Pattern>(0, XFA_Element::Pattern);
}