• 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_caption.h"
8 
9 #include "fxjs/xfa/cjx_node.h"
10 #include "third_party/base/ptr_util.h"
11 #include "xfa/fxfa/parser/cxfa_font.h"
12 #include "xfa/fxfa/parser/cxfa_margin.h"
13 #include "xfa/fxfa/parser/cxfa_measurement.h"
14 #include "xfa/fxfa/parser/cxfa_value.h"
15 
16 namespace {
17 
18 const CXFA_Node::PropertyData kCaptionPropertyData[] = {
19     {XFA_Element::Margin, 1, 0}, {XFA_Element::Para, 1, 0},
20     {XFA_Element::Font, 1, 0},   {XFA_Element::Value, 1, 0},
21     {XFA_Element::Extras, 1, 0},
22 };
23 
24 const CXFA_Node::AttributeData kCaptionAttributeData[] = {
25     {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
26     {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
27     {XFA_Attribute::Reserve, XFA_AttributeType::Measure, (void*)L"-1un"},
28     {XFA_Attribute::Presence, XFA_AttributeType::Enum,
29      (void*)XFA_AttributeValue::Visible},
30     {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
31     {XFA_Attribute::Placement, XFA_AttributeType::Enum,
32      (void*)XFA_AttributeValue::Left},
33 };
34 
35 }  // namespace
36 
CXFA_Caption(CXFA_Document * doc,XFA_PacketType packet)37 CXFA_Caption::CXFA_Caption(CXFA_Document* doc, XFA_PacketType packet)
38     : CXFA_Node(doc,
39                 packet,
40                 (XFA_XDPPACKET_Template | XFA_XDPPACKET_Form),
41                 XFA_ObjectType::Node,
42                 XFA_Element::Caption,
43                 kCaptionPropertyData,
44                 kCaptionAttributeData,
45                 pdfium::MakeUnique<CJX_Node>(this)) {}
46 
47 CXFA_Caption::~CXFA_Caption() = default;
48 
IsVisible()49 bool CXFA_Caption::IsVisible() {
50   auto value = JSObject()->TryEnum(XFA_Attribute::Presence, true);
51   return !value.has_value() || value.value() == XFA_AttributeValue::Visible;
52 }
53 
IsHidden()54 bool CXFA_Caption::IsHidden() {
55   auto value = JSObject()->TryEnum(XFA_Attribute::Presence, true);
56   return !value.has_value() || value.value() == XFA_AttributeValue::Hidden;
57 }
58 
GetPlacementType()59 XFA_AttributeValue CXFA_Caption::GetPlacementType() {
60   auto value = JSObject()->TryEnum(XFA_Attribute::Placement, true);
61   return value.value_or(XFA_AttributeValue::Left);
62 }
63 
GetReserve() const64 float CXFA_Caption::GetReserve() const {
65   return JSObject()->GetMeasureInUnit(XFA_Attribute::Reserve, XFA_Unit::Pt);
66 }
67 
GetMarginIfExists()68 CXFA_Margin* CXFA_Caption::GetMarginIfExists() {
69   return GetChild<CXFA_Margin>(0, XFA_Element::Margin, false);
70 }
71 
GetFontIfExists()72 CXFA_Font* CXFA_Caption::GetFontIfExists() {
73   return GetChild<CXFA_Font>(0, XFA_Element::Font, false);
74 }
75 
GetValueIfExists()76 CXFA_Value* CXFA_Caption::GetValueIfExists() {
77   return GetChild<CXFA_Value>(0, XFA_Element::Value, false);
78 }
79