• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_node.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 kParaPropertyData[] = {
16     {XFA_Element::Hyphenation, 1, 0},
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_Template | XFA_XDPPACKET_Form),
47                 XFA_ObjectType::Node,
48                 XFA_Element::Para,
49                 kParaPropertyData,
50                 kParaAttributeData,
51                 pdfium::MakeUnique<CJX_Node>(this)) {}
52 
53 CXFA_Para::~CXFA_Para() = default;
54 
GetHorizontalAlign()55 XFA_AttributeValue CXFA_Para::GetHorizontalAlign() {
56   return JSObject()
57       ->TryEnum(XFA_Attribute::HAlign, true)
58       .value_or(XFA_AttributeValue::Left);
59 }
60 
GetVerticalAlign()61 XFA_AttributeValue CXFA_Para::GetVerticalAlign() {
62   return JSObject()
63       ->TryEnum(XFA_Attribute::VAlign, true)
64       .value_or(XFA_AttributeValue::Top);
65 }
66 
GetLineHeight()67 float CXFA_Para::GetLineHeight() {
68   return JSObject()->GetMeasureInUnit(XFA_Attribute::LineHeight, XFA_Unit::Pt);
69 }
70 
GetMarginLeft()71 float CXFA_Para::GetMarginLeft() {
72   return JSObject()->GetMeasureInUnit(XFA_Attribute::MarginLeft, XFA_Unit::Pt);
73 }
74 
GetMarginRight()75 float CXFA_Para::GetMarginRight() {
76   return JSObject()->GetMeasureInUnit(XFA_Attribute::MarginRight, XFA_Unit::Pt);
77 }
78 
GetSpaceAbove()79 float CXFA_Para::GetSpaceAbove() {
80   return JSObject()->GetMeasureInUnit(XFA_Attribute::SpaceAbove, XFA_Unit::Pt);
81 }
82 
GetSpaceBelow()83 float CXFA_Para::GetSpaceBelow() {
84   return JSObject()->GetMeasureInUnit(XFA_Attribute::SpaceBelow, XFA_Unit::Pt);
85 }
86 
GetTextIndent()87 float CXFA_Para::GetTextIndent() {
88   return JSObject()->GetMeasureInUnit(XFA_Attribute::TextIndent, XFA_Unit::Pt);
89 }
90