• 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_image.h"
8 
9 #include "fxjs/xfa/cjx_image.h"
10 #include "third_party/base/ptr_util.h"
11 
12 namespace {
13 
14 const CXFA_Node::AttributeData kAttributeData[] = {
15     {XFA_Attribute::Id, XFA_AttributeType::CData, nullptr},
16     {XFA_Attribute::Name, XFA_AttributeType::CData, nullptr},
17     {XFA_Attribute::Use, XFA_AttributeType::CData, nullptr},
18     {XFA_Attribute::ContentType, XFA_AttributeType::CData, nullptr},
19     {XFA_Attribute::TransferEncoding, XFA_AttributeType::Enum,
20      (void*)XFA_AttributeEnum::Base64},
21     {XFA_Attribute::Usehref, XFA_AttributeType::CData, nullptr},
22     {XFA_Attribute::Aspect, XFA_AttributeType::Enum,
23      (void*)XFA_AttributeEnum::Fit},
24     {XFA_Attribute::Href, XFA_AttributeType::CData, nullptr},
25     {XFA_Attribute::Unknown, XFA_AttributeType::Integer, nullptr}};
26 
27 constexpr wchar_t kName[] = L"image";
28 
29 }  // namespace
30 
CXFA_Image(CXFA_Document * doc,XFA_PacketType packet)31 CXFA_Image::CXFA_Image(CXFA_Document* doc, XFA_PacketType packet)
32     : CXFA_Node(doc,
33                 packet,
34                 (XFA_XDPPACKET_Template | XFA_XDPPACKET_Form),
35                 XFA_ObjectType::ContentNode,
36                 XFA_Element::Image,
37                 nullptr,
38                 kAttributeData,
39                 kName) {}
40 
~CXFA_Image()41 CXFA_Image::~CXFA_Image() {}
42 
GetAspect()43 XFA_AttributeEnum CXFA_Image::GetAspect() {
44   return JSObject()->GetEnum(XFA_Attribute::Aspect);
45 }
46 
GetContentType()47 WideString CXFA_Image::GetContentType() {
48   return JSObject()->TryCData(XFA_Attribute::ContentType, true).value_or(L"");
49 }
50 
GetHref()51 WideString CXFA_Image::GetHref() {
52   return JSObject()->TryCData(XFA_Attribute::Href, true).value_or(L"");
53 }
54 
GetTransferEncoding()55 XFA_AttributeEnum CXFA_Image::GetTransferEncoding() {
56   return static_cast<XFA_AttributeEnum>(
57       JSObject()->GetEnum(XFA_Attribute::TransferEncoding));
58 }
59 
GetContent()60 WideString CXFA_Image::GetContent() {
61   return JSObject()->TryContent(false, true).value_or(L"");
62 }
63 
SetContentType(const WideString & wsContentType)64 void CXFA_Image::SetContentType(const WideString& wsContentType) {
65   JSObject()->SetCData(XFA_Attribute::ContentType, wsContentType, false, false);
66 }
67 
SetHref(const WideString & wsHref)68 void CXFA_Image::SetHref(const WideString& wsHref) {
69   JSObject()->SetCData(XFA_Attribute::Href, wsHref, false, false);
70 }
71 
SetTransferEncoding(XFA_AttributeEnum iTransferEncoding)72 void CXFA_Image::SetTransferEncoding(XFA_AttributeEnum iTransferEncoding) {
73   JSObject()->SetEnum(XFA_Attribute::TransferEncoding, iTransferEncoding,
74                       false);
75 }
76