• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The PDFium Authors
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_node.h"
10 #include "xfa/fxfa/parser/cxfa_document.h"
11 
12 namespace {
13 
14 const CXFA_Node::PropertyData kMarginPropertyData[] = {
15     {XFA_Element::Extras, 1, {}},
16 };
17 
18 const CXFA_Node::AttributeData kMarginAttributeData[] = {
19     {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
20     {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
21     {XFA_Attribute::LeftInset, XFA_AttributeType::Measure, (void*)L"0in"},
22     {XFA_Attribute::BottomInset, XFA_AttributeType::Measure, (void*)L"0in"},
23     {XFA_Attribute::TopInset, XFA_AttributeType::Measure, (void*)L"0in"},
24     {XFA_Attribute::RightInset, XFA_AttributeType::Measure, (void*)L"0in"},
25     {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
26 };
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::kTemplate, XFA_XDPPACKET::kForm},
34                 XFA_ObjectType::Node,
35                 XFA_Element::Margin,
36                 kMarginPropertyData,
37                 kMarginAttributeData,
38                 cppgc::MakeGarbageCollected<CJX_Node>(
39                     doc->GetHeap()->GetAllocationHandle(),
40                     this)) {}
41 
42 CXFA_Margin::~CXFA_Margin() = default;
43 
GetLeftInset() const44 float CXFA_Margin::GetLeftInset() const {
45   return TryLeftInset().value_or(0);
46 }
47 
GetTopInset() const48 float CXFA_Margin::GetTopInset() const {
49   return TryTopInset().value_or(0);
50 }
51 
GetRightInset() const52 float CXFA_Margin::GetRightInset() const {
53   return TryRightInset().value_or(0);
54 }
55 
GetBottomInset() const56 float CXFA_Margin::GetBottomInset() const {
57   return TryBottomInset().value_or(0);
58 }
59 
TryLeftInset() const60 absl::optional<float> CXFA_Margin::TryLeftInset() const {
61   return JSObject()->TryMeasureAsFloat(XFA_Attribute::LeftInset);
62 }
63 
TryTopInset() const64 absl::optional<float> CXFA_Margin::TryTopInset() const {
65   return JSObject()->TryMeasureAsFloat(XFA_Attribute::TopInset);
66 }
67 
TryRightInset() const68 absl::optional<float> CXFA_Margin::TryRightInset() const {
69   return JSObject()->TryMeasureAsFloat(XFA_Attribute::RightInset);
70 }
71 
TryBottomInset() const72 absl::optional<float> CXFA_Margin::TryBottomInset() const {
73   return JSObject()->TryMeasureAsFloat(XFA_Attribute::BottomInset);
74 }
75