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