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_para.h"
8
9 #include "fxjs/xfa/cjx_node.h"
10 #include "xfa/fxfa/parser/cxfa_document.h"
11 #include "xfa/fxfa/parser/cxfa_measurement.h"
12
13 namespace {
14
15 const CXFA_Node::PropertyData kParaPropertyData[] = {
16 {XFA_Element::Hyphenation, 1, {}},
17 };
18
19 const CXFA_Node::AttributeData kParaAttributeData[] = {
20 {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
21 {XFA_Attribute::HAlign, XFA_AttributeType::Enum,
22 (void*)XFA_AttributeValue::Left},
23 {XFA_Attribute::TextIndent, XFA_AttributeType::Measure, (void*)L"0in"},
24 {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
25 {XFA_Attribute::Widows, XFA_AttributeType::Integer, (void*)0},
26 {XFA_Attribute::MarginRight, XFA_AttributeType::Measure, (void*)L"0in"},
27 {XFA_Attribute::MarginLeft, XFA_AttributeType::Measure, (void*)L"0in"},
28 {XFA_Attribute::RadixOffset, XFA_AttributeType::Measure, (void*)L"0in"},
29 {XFA_Attribute::Preserve, XFA_AttributeType::CData, nullptr},
30 {XFA_Attribute::SpaceBelow, XFA_AttributeType::Measure, (void*)L"0in"},
31 {XFA_Attribute::VAlign, XFA_AttributeType::Enum,
32 (void*)XFA_AttributeValue::Top},
33 {XFA_Attribute::TabDefault, XFA_AttributeType::CData, nullptr},
34 {XFA_Attribute::TabStops, XFA_AttributeType::CData, nullptr},
35 {XFA_Attribute::Orphans, XFA_AttributeType::Integer, (void*)0},
36 {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
37 {XFA_Attribute::LineHeight, XFA_AttributeType::Measure, (void*)L"0pt"},
38 {XFA_Attribute::SpaceAbove, XFA_AttributeType::Measure, (void*)L"0in"},
39 };
40
41 } // namespace
42
CXFA_Para(CXFA_Document * doc,XFA_PacketType packet)43 CXFA_Para::CXFA_Para(CXFA_Document* doc, XFA_PacketType packet)
44 : CXFA_Node(doc,
45 packet,
46 {XFA_XDPPACKET::kTemplate, XFA_XDPPACKET::kForm},
47 XFA_ObjectType::Node,
48 XFA_Element::Para,
49 kParaPropertyData,
50 kParaAttributeData,
51 cppgc::MakeGarbageCollected<CJX_Node>(
52 doc->GetHeap()->GetAllocationHandle(),
53 this)) {}
54
55 CXFA_Para::~CXFA_Para() = default;
56
GetHorizontalAlign()57 XFA_AttributeValue CXFA_Para::GetHorizontalAlign() {
58 return JSObject()
59 ->TryEnum(XFA_Attribute::HAlign, true)
60 .value_or(XFA_AttributeValue::Left);
61 }
62
GetVerticalAlign()63 XFA_AttributeValue CXFA_Para::GetVerticalAlign() {
64 return JSObject()
65 ->TryEnum(XFA_Attribute::VAlign, true)
66 .value_or(XFA_AttributeValue::Top);
67 }
68
GetLineHeight()69 float CXFA_Para::GetLineHeight() {
70 return JSObject()->GetMeasureInUnit(XFA_Attribute::LineHeight, XFA_Unit::Pt);
71 }
72
GetMarginLeft()73 float CXFA_Para::GetMarginLeft() {
74 return JSObject()->GetMeasureInUnit(XFA_Attribute::MarginLeft, XFA_Unit::Pt);
75 }
76
GetMarginRight()77 float CXFA_Para::GetMarginRight() {
78 return JSObject()->GetMeasureInUnit(XFA_Attribute::MarginRight, XFA_Unit::Pt);
79 }
80
GetSpaceAbove()81 float CXFA_Para::GetSpaceAbove() {
82 return JSObject()->GetMeasureInUnit(XFA_Attribute::SpaceAbove, XFA_Unit::Pt);
83 }
84
GetSpaceBelow()85 float CXFA_Para::GetSpaceBelow() {
86 return JSObject()->GetMeasureInUnit(XFA_Attribute::SpaceBelow, XFA_Unit::Pt);
87 }
88
GetTextIndent()89 float CXFA_Para::GetTextIndent() {
90 return JSObject()->GetMeasureInUnit(XFA_Attribute::TextIndent, XFA_Unit::Pt);
91 }
92