tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / style / ImageStyle.cxx
blob965d70263134d200e6a88011f53e83f1f83f1fde
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
30 using namespace css;
31 using namespace xmloff::token;
33 void XMLImageStyle::exportXML(OUString const & rStrName, uno::Any const & rValue, SvXMLExport& rExport)
35 if (rStrName.isEmpty())
36 return;
38 if (!rValue.has<uno::Reference<awt::XBitmap>>())
39 return;
41 // Name
42 bool bEncoded = false;
43 rExport.AddAttribute(XML_NAMESPACE_DRAW, XML_NAME,
44 rExport.EncodeStyleName(rStrName, &bEncoded));
45 if (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);
53 OUString aMimeType;
54 const OUString aStr = rExport.AddEmbeddedXGraphic(xGraphic, aMimeType);
56 // uri
57 if (!aStr.isEmpty())
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 );
65 // Do Write
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):
91 rStrName = aStrValue;
92 bHasName = true;
94 break;
95 case XML_ELEMENT(DRAW, XML_DISPLAY_NAME):
97 aDisplayName = aStrValue;
99 break;
100 case XML_ELEMENT(XLINK, XML_HREF):
102 xGraphic = rImport.loadGraphicByURL(aStrValue);
103 bHasHRef = true;
105 break;
106 case XML_ELEMENT(XLINK, XML_TYPE):
107 // ignore
108 break;
109 case XML_ELEMENT(XLINK, XML_SHOW):
110 // ignore
111 break;
112 case XML_ELEMENT(XLINK, XML_ACTUATE):
113 // ignore
114 break;
115 default:
116 XMLOFF_WARN_UNKNOWN("xmloff.style", aIter);
120 if (xGraphic.is())
121 rValue <<= xGraphic;
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: */