summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-01-03 16:39:18 -0500
committerChromium commit bot <commit-bot@chromium.org>2018-01-03 22:11:40 +0000
commit45da0f2d84c97a9856492265a1fc706d04bdfccd (patch)
tree94f0e37415c91fdd7b91d22037e2d7a421e30986 /xfa/fxfa/parser
parent8afa22d5701a6c47b3f34267a2c52948efc3d301 (diff)
downloadpdfium-45da0f2d84c97a9856492265a1fc706d04bdfccd.tar.xz
Fold CXFA_FillData into CXFA_Fill
This CL removes the CXFA_FillData wrapper and puts the code directly in CXFA_Fill. Change-Id: I44ae8b53978b659480a4bb32719d086c7b91b49b Reviewed-on: https://pdfium-review.googlesource.com/22210 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_box.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_box.h5
-rw-r--r--xfa/fxfa/parser/cxfa_fill.cpp135
-rw-r--r--xfa/fxfa/parser/cxfa_fill.h30
-rw-r--r--xfa/fxfa/parser/cxfa_filldata.cpp152
-rw-r--r--xfa/fxfa/parser/cxfa_filldata.h51
-rw-r--r--xfa/fxfa/parser/cxfa_fontdata.cpp12
7 files changed, 174 insertions, 217 deletions
diff --git a/xfa/fxfa/parser/cxfa_box.cpp b/xfa/fxfa/parser/cxfa_box.cpp
index 78362020da..ccb4e713ff 100644
--- a/xfa/fxfa/parser/cxfa_box.cpp
+++ b/xfa/fxfa/parser/cxfa_box.cpp
@@ -102,10 +102,8 @@ pdfium::Optional<int32_t> CXFA_Box::GetSweepAngle() {
return JSObject()->TryInteger(XFA_Attribute::SweepAngle, false);
}
-CXFA_FillData CXFA_Box::GetFillData(bool bModified) {
- CXFA_Node* pFillNode =
- JSObject()->GetProperty<CXFA_Fill>(0, XFA_Element::Fill, bModified);
- return CXFA_FillData(pFillNode);
+CXFA_Fill* CXFA_Box::GetFill(bool bModified) {
+ return JSObject()->GetProperty<CXFA_Fill>(0, XFA_Element::Fill, bModified);
}
CXFA_Margin* CXFA_Box::GetMargin() {
diff --git a/xfa/fxfa/parser/cxfa_box.h b/xfa/fxfa/parser/cxfa_box.h
index dbc07c603d..5c2c8d20af 100644
--- a/xfa/fxfa/parser/cxfa_box.h
+++ b/xfa/fxfa/parser/cxfa_box.h
@@ -11,11 +11,10 @@
#include <tuple>
#include <vector>
-#include "xfa/fxfa/parser/cxfa_datadata.h"
-#include "xfa/fxfa/parser/cxfa_filldata.h"
#include "xfa/fxfa/parser/cxfa_node.h"
class CXFA_Edge;
+class CXFA_Fill;
class CXFA_Margin;
class CXFA_Stroke;
@@ -32,7 +31,7 @@ class CXFA_Box : public CXFA_Node {
int32_t CountEdges();
CXFA_Edge* GetEdge(int32_t nIndex);
- CXFA_FillData GetFillData(bool bModified);
+ CXFA_Fill* GetFill(bool bModified);
CXFA_Margin* GetMargin();
std::vector<CXFA_Stroke*> GetStrokes();
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);
+}
diff --git a/xfa/fxfa/parser/cxfa_fill.h b/xfa/fxfa/parser/cxfa_fill.h
index ba18b91b72..a5ee7609ee 100644
--- a/xfa/fxfa/parser/cxfa_fill.h
+++ b/xfa/fxfa/parser/cxfa_fill.h
@@ -9,10 +9,40 @@
#include "xfa/fxfa/parser/cxfa_node.h"
+class CXFA_Linear;
+class CXFA_Pattern;
+class CXFA_Radial;
+class CXFA_Stipple;
+
class CXFA_Fill : public CXFA_Node {
public:
CXFA_Fill(CXFA_Document* doc, XFA_PacketType packet);
~CXFA_Fill() override;
+
+ bool IsVisible();
+
+ 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();
+
+ private:
+ CXFA_Stipple* GetStipple();
+ CXFA_Radial* GetRadial();
+ CXFA_Linear* GetLinear();
+ CXFA_Pattern* GetPattern();
};
#endif // XFA_FXFA_PARSER_CXFA_FILL_H_
diff --git a/xfa/fxfa/parser/cxfa_filldata.cpp b/xfa/fxfa/parser/cxfa_filldata.cpp
deleted file mode 100644
index 067d75246c..0000000000
--- a/xfa/fxfa/parser/cxfa_filldata.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fxfa/parser/cxfa_filldata.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"
-
-CXFA_FillData::CXFA_FillData(CXFA_Node* pNode) : CXFA_DataData(pNode) {}
-
-CXFA_FillData::~CXFA_FillData() {}
-
-bool CXFA_FillData::IsVisible() const {
- return m_pNode->JSObject()
- ->TryEnum(XFA_Attribute::Presence, true)
- .value_or(XFA_AttributeEnum::Visible) ==
- XFA_AttributeEnum::Visible;
-}
-
-void CXFA_FillData::SetColor(FX_ARGB color) {
- CXFA_Color* pNode =
- m_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_FillData::GetColor(bool bText) const {
- if (CXFA_Color* pNode =
- m_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_FillData::GetFillType() const {
- CXFA_Node* pChild = m_pNode->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_FillData::GetPatternType() const {
- return GetPattern()->JSObject()->GetEnum(XFA_Attribute::Type);
-}
-
-FX_ARGB CXFA_FillData::GetPatternColor() const {
- 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_FillData::GetStippleRate() const {
- return GetStipple()
- ->JSObject()
- ->TryInteger(XFA_Attribute::Rate, true)
- .value_or(50);
-}
-
-FX_ARGB CXFA_FillData::GetStippleColor() const {
- 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_FillData::GetLinearType() const {
- return GetLinear()
- ->JSObject()
- ->TryEnum(XFA_Attribute::Type, true)
- .value_or(XFA_AttributeEnum::ToRight);
-}
-
-FX_ARGB CXFA_FillData::GetLinearColor() const {
- 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_FillData::IsRadialToEdge() const {
- return GetRadial()
- ->JSObject()
- ->TryEnum(XFA_Attribute::Type, true)
- .value_or(XFA_AttributeEnum::ToEdge) == XFA_AttributeEnum::ToEdge;
-}
-
-FX_ARGB CXFA_FillData::GetRadialColor() const {
- 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_FillData::GetStipple() const {
- return m_pNode->JSObject()->GetProperty<CXFA_Stipple>(0, XFA_Element::Stipple,
- true);
-}
-
-CXFA_Radial* CXFA_FillData::GetRadial() const {
- return m_pNode->JSObject()->GetProperty<CXFA_Radial>(0, XFA_Element::Radial,
- true);
-}
-
-CXFA_Linear* CXFA_FillData::GetLinear() const {
- return m_pNode->JSObject()->GetProperty<CXFA_Linear>(0, XFA_Element::Linear,
- true);
-}
-
-CXFA_Pattern* CXFA_FillData::GetPattern() const {
- return m_pNode->JSObject()->GetProperty<CXFA_Pattern>(0, XFA_Element::Pattern,
- true);
-}
diff --git a/xfa/fxfa/parser/cxfa_filldata.h b/xfa/fxfa/parser/cxfa_filldata.h
deleted file mode 100644
index 94e840e230..0000000000
--- a/xfa/fxfa/parser/cxfa_filldata.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FXFA_PARSER_CXFA_FILLDATA_H_
-#define XFA_FXFA_PARSER_CXFA_FILLDATA_H_
-
-#include "core/fxcrt/fx_system.h"
-#include "core/fxge/fx_dib.h"
-#include "xfa/fxfa/parser/cxfa_datadata.h"
-
-class CXFA_Linear;
-class CXFA_Node;
-class CXFA_Pattern;
-class CXFA_Radial;
-class CXFA_Stipple;
-
-class CXFA_FillData : public CXFA_DataData {
- public:
- explicit CXFA_FillData(CXFA_Node* pNode);
- ~CXFA_FillData() override;
-
- 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_Stipple* GetStipple() const;
- CXFA_Radial* GetRadial() const;
- CXFA_Linear* GetLinear() const;
- CXFA_Pattern* GetPattern() const;
-};
-
-#endif // XFA_FXFA_PARSER_CXFA_FILLDATA_H_
diff --git a/xfa/fxfa/parser/cxfa_fontdata.cpp b/xfa/fxfa/parser/cxfa_fontdata.cpp
index 88dc930dab..64b5af0794 100644
--- a/xfa/fxfa/parser/cxfa_fontdata.cpp
+++ b/xfa/fxfa/parser/cxfa_fontdata.cpp
@@ -8,7 +8,6 @@
#include "core/fxge/fx_dib.h"
#include "xfa/fxfa/parser/cxfa_fill.h"
-#include "xfa/fxfa/parser/cxfa_filldata.h"
#include "xfa/fxfa/parser/cxfa_measurement.h"
#include "xfa/fxfa/parser/cxfa_node.h"
@@ -78,13 +77,12 @@ bool CXFA_FontData::IsItalic() const {
}
void CXFA_FontData::SetColor(FX_ARGB color) {
- CXFA_FillData(
- m_pNode->JSObject()->GetProperty<CXFA_Fill>(0, XFA_Element::Fill, true))
- .SetColor(color);
+ m_pNode->JSObject()
+ ->GetProperty<CXFA_Fill>(0, XFA_Element::Fill, true)
+ ->SetColor(color);
}
FX_ARGB CXFA_FontData::GetColor() const {
- CXFA_FillData fillData(
- m_pNode->GetChild<CXFA_Fill>(0, XFA_Element::Fill, false));
- return fillData.HasValidNode() ? fillData.GetColor(true) : 0xFF000000;
+ CXFA_Fill* fill = m_pNode->GetChild<CXFA_Fill>(0, XFA_Element::Fill, false);
+ return fill ? fill->GetColor(true) : 0xFF000000;
}