summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/cxfa_box.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-01-03 12:01:24 -0500
committerChromium commit bot <commit-bot@chromium.org>2018-01-03 18:20:01 +0000
commit39628b04bc86461426f2dcf5a568f5e9e70ad997 (patch)
treea0cf6c494a74b83e93a5cc526ab5897a08e3d743 /xfa/fxfa/parser/cxfa_box.cpp
parent9647614a5dcd00d50aacf4e000fd23a5ebb13931 (diff)
downloadpdfium-39628b04bc86461426f2dcf5a568f5e9e70ad997.tar.xz
Change CXFA_BoxData to CXFA_Box
This CL renames CXFA_BoxData to CXFA_Box and sets it to inhert from CXFA_Node instead of CXFA_DataData. The CXFA_BoxData subclasses, CXFA_RectangleData, CXFA_BorderData and CXFA_ArcData classes are removed and the nodes now inherit from CXFA_Box. Change-Id: Ia0df7d56535b5d90be29f040180a5d5fc55a64e0 Reviewed-on: https://pdfium-review.googlesource.com/22091 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_box.cpp')
-rw-r--r--xfa/fxfa/parser/cxfa_box.cpp159
1 files changed, 159 insertions, 0 deletions
diff --git a/xfa/fxfa/parser/cxfa_box.cpp b/xfa/fxfa/parser/cxfa_box.cpp
new file mode 100644
index 0000000000..544a21dcc0
--- /dev/null
+++ b/xfa/fxfa/parser/cxfa_box.cpp
@@ -0,0 +1,159 @@
+// 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_box.h"
+
+#include <utility>
+
+#include "xfa/fxfa/parser/cxfa_corner.h"
+#include "xfa/fxfa/parser/cxfa_cornerdata.h"
+#include "xfa/fxfa/parser/cxfa_edge.h"
+#include "xfa/fxfa/parser/cxfa_fill.h"
+#include "xfa/fxfa/parser/cxfa_margin.h"
+#include "xfa/fxfa/parser/cxfa_measurement.h"
+#include "xfa/fxfa/parser/cxfa_node.h"
+
+namespace {
+
+XFA_AttributeEnum Style3D(const std::vector<CXFA_StrokeData>& strokes,
+ CXFA_StrokeData& strokeData) {
+ if (strokes.empty())
+ return XFA_AttributeEnum::Unknown;
+
+ strokeData = strokes[0];
+ for (size_t i = 1; i < strokes.size(); i++) {
+ CXFA_StrokeData find = strokes[i];
+ if (!find.HasValidNode())
+ continue;
+
+ if (!strokeData.HasValidNode())
+ strokeData = find;
+ else if (strokeData.GetStrokeType() != find.GetStrokeType())
+ strokeData = find;
+ break;
+ }
+
+ XFA_AttributeEnum iType = strokeData.GetStrokeType();
+ if (iType == XFA_AttributeEnum::Lowered ||
+ iType == XFA_AttributeEnum::Raised ||
+ iType == XFA_AttributeEnum::Etched ||
+ iType == XFA_AttributeEnum::Embossed) {
+ return iType;
+ }
+ return XFA_AttributeEnum::Unknown;
+}
+
+} // namespace
+
+CXFA_Box::CXFA_Box(CXFA_Document* pDoc,
+ XFA_PacketType ePacket,
+ uint32_t validPackets,
+ XFA_ObjectType oType,
+ XFA_Element eType,
+ const PropertyData* properties,
+ const AttributeData* attributes,
+ const WideStringView& elementName,
+ std::unique_ptr<CJX_Object> js_node)
+ : CXFA_Node(pDoc,
+ ePacket,
+ validPackets,
+ oType,
+ eType,
+ properties,
+ attributes,
+ elementName,
+ std::move(js_node)) {}
+
+CXFA_Box::~CXFA_Box() = default;
+
+XFA_AttributeEnum CXFA_Box::GetHand() {
+ return JSObject()->GetEnum(XFA_Attribute::Hand);
+}
+
+XFA_AttributeEnum CXFA_Box::GetPresence() {
+ return JSObject()
+ ->TryEnum(XFA_Attribute::Presence, true)
+ .value_or(XFA_AttributeEnum::Visible);
+}
+
+int32_t CXFA_Box::CountEdges() {
+ return CountChildren(XFA_Element::Edge, false);
+}
+
+CXFA_EdgeData CXFA_Box::GetEdgeData(int32_t nIndex) {
+ return CXFA_EdgeData(JSObject()->GetProperty<CXFA_Edge>(
+ nIndex, XFA_Element::Edge, nIndex == 0));
+}
+
+std::vector<CXFA_StrokeData> CXFA_Box::GetStrokes() {
+ return GetStrokesInternal(false);
+}
+
+bool CXFA_Box::IsCircular() {
+ return JSObject()->GetBoolean(XFA_Attribute::Circular);
+}
+
+pdfium::Optional<int32_t> CXFA_Box::GetStartAngle() {
+ return JSObject()->TryInteger(XFA_Attribute::StartAngle, false);
+}
+
+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_Margin* CXFA_Box::GetMargin() {
+ return GetChild<CXFA_Margin>(0, XFA_Element::Margin, false);
+}
+
+std::tuple<XFA_AttributeEnum, bool, float> CXFA_Box::Get3DStyle() {
+ if (IsArc())
+ return {XFA_AttributeEnum::Unknown, false, 0.0f};
+
+ std::vector<CXFA_StrokeData> strokes = GetStrokesInternal(true);
+ CXFA_StrokeData strokeData(nullptr);
+ XFA_AttributeEnum iType = Style3D(strokes, strokeData);
+ if (iType == XFA_AttributeEnum::Unknown)
+ return {XFA_AttributeEnum::Unknown, false, 0.0f};
+
+ return {iType, strokeData.IsVisible(), strokeData.GetThickness()};
+}
+
+std::vector<CXFA_StrokeData> CXFA_Box::GetStrokesInternal(bool bNull) {
+ std::vector<CXFA_StrokeData> strokes;
+ strokes.resize(8);
+ int32_t i, j;
+ for (i = 0, j = 0; i < 4; i++) {
+ CXFA_CornerData cornerData = CXFA_CornerData(
+ JSObject()->GetProperty<CXFA_Corner>(i, XFA_Element::Corner, i == 0));
+ if (cornerData.HasValidNode() || i == 0) {
+ strokes[j] = cornerData;
+ } else if (!bNull) {
+ if (i == 1 || i == 2)
+ strokes[j] = strokes[0];
+ else
+ strokes[j] = strokes[2];
+ }
+ j++;
+ CXFA_EdgeData edgeData = CXFA_EdgeData(
+ JSObject()->GetProperty<CXFA_Edge>(i, XFA_Element::Edge, i == 0));
+ if (edgeData.HasValidNode() || i == 0) {
+ strokes[j] = edgeData;
+ } else if (!bNull) {
+ if (i == 1 || i == 2)
+ strokes[j] = strokes[1];
+ else
+ strokes[j] = strokes[3];
+ }
+ j++;
+ }
+ return strokes;
+}