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