/src/libreoffice/xmloff/source/style/ImageStyle.cxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
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> |
29 | | |
30 | | using namespace css; |
31 | | using namespace xmloff::token; |
32 | | |
33 | | void XMLImageStyle::exportXML(OUString const & rStrName, uno::Any const & rValue, SvXMLExport& rExport) |
34 | 0 | { |
35 | 0 | if (rStrName.isEmpty()) |
36 | 0 | return; |
37 | | |
38 | 0 | if (!rValue.has<uno::Reference<awt::XBitmap>>()) |
39 | 0 | return; |
40 | | |
41 | | // Name |
42 | 0 | bool bEncoded = false; |
43 | 0 | rExport.AddAttribute(XML_NAMESPACE_DRAW, XML_NAME, |
44 | 0 | rExport.EncodeStyleName(rStrName, &bEncoded)); |
45 | 0 | if (bEncoded) |
46 | 0 | { |
47 | 0 | rExport.AddAttribute(XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, rStrName); |
48 | 0 | } |
49 | |
|
50 | 0 | auto xBitmap = rValue.get<uno::Reference<awt::XBitmap>>(); |
51 | 0 | uno::Reference<graphic::XGraphic> xGraphic(xBitmap, uno::UNO_QUERY); |
52 | |
|
53 | 0 | OUString aMimeType; |
54 | 0 | const OUString aStr = rExport.AddEmbeddedXGraphic(xGraphic, aMimeType); |
55 | | |
56 | | // uri |
57 | 0 | if (!aStr.isEmpty()) |
58 | 0 | { |
59 | 0 | rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, aStr ); |
60 | 0 | rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE ); |
61 | 0 | rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED ); |
62 | 0 | rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD ); |
63 | 0 | } |
64 | | |
65 | | // Do Write |
66 | 0 | SvXMLElementExport aElem(rExport, XML_NAMESPACE_DRAW, XML_FILL_IMAGE, true, true); |
67 | |
|
68 | 0 | if (xBitmap.is() && xGraphic.is()) |
69 | 0 | { |
70 | | // optional office:binary-data |
71 | 0 | rExport.AddEmbeddedXGraphicAsBase64(xGraphic); |
72 | 0 | } |
73 | 0 | } |
74 | | |
75 | | bool XMLImageStyle::importXML(uno::Reference<xml::sax::XFastAttributeList> const & xAttrList, |
76 | | uno::Any& rValue, OUString& rStrName, SvXMLImport& rImport) |
77 | 0 | { |
78 | 0 | bool bHasHRef = false; |
79 | 0 | bool bHasName = false; |
80 | 0 | OUString aDisplayName; |
81 | 0 | uno::Reference<graphic::XGraphic> xGraphic; |
82 | |
|
83 | 0 | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
84 | 0 | { |
85 | 0 | const OUString aStrValue = aIter.toString(); |
86 | |
|
87 | 0 | switch( aIter.getToken() ) |
88 | 0 | { |
89 | 0 | case XML_ELEMENT(DRAW, XML_NAME): |
90 | 0 | { |
91 | 0 | rStrName = aStrValue; |
92 | 0 | bHasName = true; |
93 | 0 | } |
94 | 0 | break; |
95 | 0 | case XML_ELEMENT(DRAW, XML_DISPLAY_NAME): |
96 | 0 | { |
97 | 0 | aDisplayName = aStrValue; |
98 | 0 | } |
99 | 0 | break; |
100 | 0 | case XML_ELEMENT(XLINK, XML_HREF): |
101 | 0 | { |
102 | 0 | xGraphic = rImport.loadGraphicByURL(aStrValue); |
103 | 0 | bHasHRef = true; |
104 | 0 | } |
105 | 0 | break; |
106 | 0 | case XML_ELEMENT(XLINK, XML_TYPE): |
107 | | // ignore |
108 | 0 | break; |
109 | 0 | case XML_ELEMENT(XLINK, XML_SHOW): |
110 | | // ignore |
111 | 0 | break; |
112 | 0 | case XML_ELEMENT(XLINK, XML_ACTUATE): |
113 | | // ignore |
114 | 0 | break; |
115 | 0 | default: |
116 | 0 | XMLOFF_WARN_UNKNOWN("xmloff.style", aIter); |
117 | 0 | } |
118 | 0 | } |
119 | | |
120 | 0 | if (xGraphic.is()) |
121 | 0 | rValue <<= xGraphic; |
122 | |
|
123 | 0 | if( !aDisplayName.isEmpty() ) |
124 | 0 | { |
125 | 0 | rImport.AddStyleDisplayName( XmlStyleFamily::SD_FILL_IMAGE_ID, |
126 | 0 | rStrName, aDisplayName ); |
127 | 0 | rStrName = aDisplayName; |
128 | 0 | } |
129 | |
|
130 | 0 | return bHasName && bHasHRef; |
131 | 0 | } |
132 | | |
133 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |