1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <xmloff/ImageStyle.hxx>
21 #include <com/sun/star/awt/XBitmap.hpp>
22 #include <com/sun/star/graphic/XGraphic.hpp>
23 #include <xmloff/namespacemap.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlexp.hxx>
27 #include <xmloff/xmlimp.hxx>
28 #include <rtl/ustring.hxx>
29 #include <sal/log.hxx>
30 #include <xmloff/xmltkmap.hxx>
33 using namespace xmloff::token
;
35 void XMLImageStyle::exportXML(OUString
const & rStrName
, uno::Any
const & rValue
, SvXMLExport
& rExport
)
37 if (rStrName
.isEmpty())
40 if (!rValue
.has
<uno::Reference
<awt::XBitmap
>>())
44 bool bEncoded
= false;
45 rExport
.AddAttribute(XML_NAMESPACE_DRAW
, XML_NAME
,
46 rExport
.EncodeStyleName(rStrName
, &bEncoded
));
49 rExport
.AddAttribute(XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
, rStrName
);
52 auto xBitmap
= rValue
.get
<uno::Reference
<awt::XBitmap
>>();
53 uno::Reference
<graphic::XGraphic
> xGraphic(xBitmap
, uno::UNO_QUERY
);
56 const OUString aStr
= rExport
.AddEmbeddedXGraphic(xGraphic
, aMimeType
);
61 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_HREF
, aStr
);
62 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_TYPE
, XML_SIMPLE
);
63 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_SHOW
, XML_EMBED
);
64 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_ACTUATE
, XML_ONLOAD
);
68 SvXMLElementExport
aElem(rExport
, XML_NAMESPACE_DRAW
, XML_FILL_IMAGE
, true, true);
70 if (xBitmap
.is() && xGraphic
.is())
72 // optional office:binary-data
73 rExport
.AddEmbeddedXGraphicAsBase64(xGraphic
);
77 bool XMLImageStyle::importXML(uno::Reference
<xml::sax::XFastAttributeList
> const & xAttrList
,
78 uno::Any
& rValue
, OUString
& rStrName
, SvXMLImport
& rImport
)
80 bool bHasHRef
= false;
81 bool bHasName
= false;
82 OUString aDisplayName
;
83 uno::Reference
<graphic::XGraphic
> xGraphic
;
85 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
87 const OUString aStrValue
= aIter
.toString();
89 switch( aIter
.getToken() )
91 case XML_ELEMENT(DRAW
, XML_NAME
):
97 case XML_ELEMENT(DRAW
, XML_DISPLAY_NAME
):
99 aDisplayName
= aStrValue
;
102 case XML_ELEMENT(XLINK
, XML_HREF
):
104 xGraphic
= rImport
.loadGraphicByURL(aStrValue
);
108 case XML_ELEMENT(XLINK
, XML_TYPE
):
111 case XML_ELEMENT(XLINK
, XML_SHOW
):
114 case XML_ELEMENT(XLINK
, XML_ACTUATE
):
118 XMLOFF_WARN_UNKNOWN("xmloff.style", aIter
);
125 if( !aDisplayName
.isEmpty() )
127 rImport
.AddStyleDisplayName( XmlStyleFamily::SD_FILL_IMAGE_ID
,
128 rStrName
, aDisplayName
);
129 rStrName
= aDisplayName
;
132 return bHasName
&& bHasHRef
;
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */