• 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_caption.h"
8 
9 #include "fxjs/xfa/cjx_node.h"
10 #include "xfa/fxfa/parser/cxfa_document.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, {}}, {XFA_Element::Para, 1, {}},
20     {XFA_Element::Font, 1, {}},   {XFA_Element::Value, 1, {}},
21     {XFA_Element::Extras, 1, {}},
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::kTemplate, XFA_XDPPACKET::kForm},
41                 XFA_ObjectType::Node,
42                 XFA_Element::Caption,
43                 kCaptionPropertyData,
44                 kCaptionAttributeData,
45                 cppgc::MakeGarbageCollected<CJX_Node>(
46                     doc->GetHeap()->GetAllocationHandle(),
47                     this)) {}
48 
49 CXFA_Caption::~CXFA_Caption() = default;
50 
IsVisible()51 bool CXFA_Caption::IsVisible() {
52   auto value = JSObject()->TryEnum(XFA_Attribute::Presence, true);
53   return !value.has_value() || value.value() == XFA_AttributeValue::Visible;
54 }
55 
IsHidden()56 bool CXFA_Caption::IsHidden() {
57   auto value = JSObject()->TryEnum(XFA_Attribute::Presence, true);
58   return !value.has_value() || value.value() == XFA_AttributeValue::Hidden;
59 }
60 
GetPlacementType()61 XFA_AttributeValue CXFA_Caption::GetPlacementType() {
62   auto value = JSObject()->TryEnum(XFA_Attribute::Placement, true);
63   return value.value_or(XFA_AttributeValue::Left);
64 }
65 
GetReserve() const66 float CXFA_Caption::GetReserve() const {
67   return JSObject()->GetMeasureInUnit(XFA_Attribute::Reserve, XFA_Unit::Pt);
68 }
69 
GetMarginIfExists()70 CXFA_Margin* CXFA_Caption::GetMarginIfExists() {
71   return GetChild<CXFA_Margin>(0, XFA_Element::Margin, false);
72 }
73 
GetFontIfExists()74 CXFA_Font* CXFA_Caption::GetFontIfExists() {
75   return GetChild<CXFA_Font>(0, XFA_Element::Font, false);
76 }
77 
GetValueIfExists()78 CXFA_Value* CXFA_Caption::GetValueIfExists() {
79   return GetChild<CXFA_Value>(0, XFA_Element::Value, false);
80 }
81