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/xmlnamespace.hxx>
24 #include <xmloff/xmltoken.hxx>
25 #include <xmloff/xmlexp.hxx>
26 #include <xmloff/xmlimp.hxx>
27 #include <rtl/ustring.hxx>
28 #include <sal/log.hxx>
31 using namespace xmloff::token
;
33 void XMLImageStyle::exportXML(OUString
const & rStrName
, uno::Any
const & rValue
, SvXMLExport
& rExport
)
35 if (rStrName
.isEmpty())
38 if (!rValue
.has
<uno::Reference
<awt::XBitmap
>>())
42 bool bEncoded
= false;
43 rExport
.AddAttribute(XML_NAMESPACE_DRAW
, XML_NAME
,
44 rExport
.EncodeStyleName(rStrName
, &bEncoded
));
47 rExport
.AddAttribute(XML_NAMESPACE_DRAW
, XML_DISPLAY_NAME
, rStrName
);
50 auto xBitmap
= rValue
.get
<uno::Reference
<awt::XBitmap
>>();
51 uno::Reference
<graphic::XGraphic
> xGraphic(xBitmap
, uno::UNO_QUERY
);
54 const OUString aStr
= rExport
.AddEmbeddedXGraphic(xGraphic
, aMimeType
);
59 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_HREF
, aStr
);
60 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_TYPE
, XML_SIMPLE
);
61 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_SHOW
, XML_EMBED
);
62 rExport
.AddAttribute( XML_NAMESPACE_XLINK
, XML_ACTUATE
, XML_ONLOAD
);
66 SvXMLElementExport
aElem(rExport
, XML_NAMESPACE_DRAW
, XML_FILL_IMAGE
, true, true);
68 if (xBitmap
.is() && xGraphic
.is())
70 // optional office:binary-data
71 rExport
.AddEmbeddedXGraphicAsBase64(xGraphic
);
75 bool XMLImageStyle::importXML(uno::Reference
<xml::sax::XFastAttributeList
> const & xAttrList
,
76 uno::Any
& rValue
, OUString
& rStrName
, SvXMLImport
& rImport
)
78 bool bHasHRef
= false;
79 bool bHasName
= false;
80 OUString aDisplayName
;
81 uno::Reference
<graphic::XGraphic
> xGraphic
;
83 for (auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
))
85 const OUString aStrValue
= aIter
.toString();
87 switch( aIter
.getToken() )
89 case XML_ELEMENT(DRAW
, XML_NAME
):
95 case XML_ELEMENT(DRAW
, XML_DISPLAY_NAME
):
97 aDisplayName
= aStrValue
;
100 case XML_ELEMENT(XLINK
, XML_HREF
):
102 xGraphic
= rImport
.loadGraphicByURL(aStrValue
);
106 case XML_ELEMENT(XLINK
, XML_TYPE
):
109 case XML_ELEMENT(XLINK
, XML_SHOW
):
112 case XML_ELEMENT(XLINK
, XML_ACTUATE
):
116 XMLOFF_WARN_UNKNOWN("xmloff.style", aIter
);
123 if( !aDisplayName
.isEmpty() )
125 rImport
.AddStyleDisplayName( XmlStyleFamily::SD_FILL_IMAGE_ID
,
126 rStrName
, aDisplayName
);
127 rStrName
= aDisplayName
;
130 return bHasName
&& bHasHRef
;
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */