1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/fxfa/parser/cxfa_margin.h"
8
9 #include "fxjs/xfa/cjx_margin.h"
10 #include "third_party/base/ptr_util.h"
11
12 namespace {
13
14 const CXFA_Node::PropertyData kPropertyData[] = {{XFA_Element::Extras, 1, 0},
15 {XFA_Element::Unknown, 0, 0}};
16 const CXFA_Node::AttributeData kAttributeData[] = {
17 {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
18 {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
19 {XFA_Attribute::LeftInset, XFA_AttributeType::Measure, (void*)L"0in"},
20 {XFA_Attribute::BottomInset, XFA_AttributeType::Measure, (void*)L"0in"},
21 {XFA_Attribute::TopInset, XFA_AttributeType::Measure, (void*)L"0in"},
22 {XFA_Attribute::RightInset, XFA_AttributeType::Measure, (void*)L"0in"},
23 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
24 {XFA_Attribute::Unknown, XFA_AttributeType::Integer, nullptr}};
25
26 constexpr wchar_t kName[] = L"margin";
27
28 } // namespace
29
CXFA_Margin(CXFA_Document * doc,XFA_PacketType packet)30 CXFA_Margin::CXFA_Margin(CXFA_Document* doc, XFA_PacketType packet)
31 : CXFA_Node(doc,
32 packet,
33 (XFA_XDPPACKET_Template | XFA_XDPPACKET_Form),
34 XFA_ObjectType::Node,
35 XFA_Element::Margin,
36 kPropertyData,
37 kAttributeData,
38 kName,
39 pdfium::MakeUnique<CJX_Margin>(this)) {}
40
~CXFA_Margin()41 CXFA_Margin::~CXFA_Margin() {}
42
GetLeftInset() const43 float CXFA_Margin::GetLeftInset() const {
44 return TryLeftInset().value_or(0);
45 }
46
GetTopInset() const47 float CXFA_Margin::GetTopInset() const {
48 return TryTopInset().value_or(0);
49 }
50
GetRightInset() const51 float CXFA_Margin::GetRightInset() const {
52 return TryRightInset().value_or(0);
53 }
54
GetBottomInset() const55 float CXFA_Margin::GetBottomInset() const {
56 return TryBottomInset().value_or(0);
57 }
58
TryLeftInset() const59 Optional<float> CXFA_Margin::TryLeftInset() const {
60 return JSObject()->TryMeasureAsFloat(XFA_Attribute::LeftInset);
61 }
62
TryTopInset() const63 Optional<float> CXFA_Margin::TryTopInset() const {
64 return JSObject()->TryMeasureAsFloat(XFA_Attribute::TopInset);
65 }
66
TryRightInset() const67 Optional<float> CXFA_Margin::TryRightInset() const {
68 return JSObject()->TryMeasureAsFloat(XFA_Attribute::RightInset);
69 }
70
TryBottomInset() const71 Optional<float> CXFA_Margin::TryBottomInset() const {
72 return JSObject()->TryMeasureAsFloat(XFA_Attribute::BottomInset);
73 }
74