LibreOffice Module xmloff (master)  1
FillStyleContext.cxx
Go to the documentation of this file.
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 <com/sun/star/container/XNameContainer.hpp>
21 #include <com/sun/star/graphic/XGraphic.hpp>
22 #include <com/sun/star/awt/XBitmap.hpp>
23 #include "FillStyleContext.hxx"
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/GradientStyle.hxx>
26 #include <xmloff/HatchStyle.hxx>
27 #include <xmloff/ImageStyle.hxx>
28 #include <TransGradientStyle.hxx>
29 #include <xmloff/MarkerStyle.hxx>
30 #include <xmloff/DashStyle.hxx>
31 #include <xmloff/xmlnamespace.hxx>
33 
34 using namespace ::com::sun::star;
35 
36 
38  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
39 : SvXMLStyleContext(rImport)
40 {
41  // start import
42  XMLGradientStyleImport aGradientStyle( GetImport() );
43  aGradientStyle.importXML( xAttrList, maAny, maStrName );
44 }
45 
47 {
48 }
49 
51 {
52  uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() );
53 
54  try
55  {
56  if(xGradient.is())
57  {
58  if( xGradient->hasByName( maStrName ) )
59  {
60  xGradient->replaceByName( maStrName, maAny );
61  }
62  else
63  {
64  xGradient->insertByName( maStrName, maAny );
65  }
66  }
67  }
68  catch( container::ElementExistException& )
69  {}
70 }
71 
73 {
74  return true;
75 }
76 
77 
78 XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport& rImport, sal_Int32 /*nElement*/,
79  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
80 : SvXMLStyleContext(rImport)
81 {
82  // start import
83  XMLHatchStyleImport aHatchStyle( GetImport() );
84  aHatchStyle.importXML( xAttrList, maAny, maStrName );
85 }
86 
88 {
89 }
90 
92 {
93  uno::Reference< container::XNameContainer > xHatch( GetImport().GetHatchHelper() );
94 
95  try
96  {
97  if(xHatch.is())
98  {
99  if( xHatch->hasByName( maStrName ) )
100  {
101  xHatch->replaceByName( maStrName, maAny );
102  }
103  else
104  {
105  xHatch->insertByName( maStrName, maAny );
106  }
107  }
108  }
109  catch( container::ElementExistException& )
110  {}
111 }
112 
114 {
115  return true;
116 }
117 
118 
120  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
121 : SvXMLStyleContext(rImport)
122 {
123  // start import
124  XMLImageStyle::importXML( xAttrList, maAny, maStrName, rImport );
125 }
126 
128 {
129 }
130 
131 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLBitmapStyleContext::createFastChildContext(
132  sal_Int32 nElement,
133  const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
134 {
136  {
137  OUString sURL;
138  maAny >>= sURL;
139  if( sURL.isEmpty() && !mxBase64Stream.is() )
140  {
142  if( mxBase64Stream.is() )
144  }
145  }
146 
147  return nullptr;
148 }
149 
151 {
152  if (!maAny.has<uno::Reference<graphic::XGraphic>>() && mxBase64Stream.is())
153  {
154  // No graphic so far? Then see if it's inline.
155  uno::Reference<graphic::XGraphic> xGraphic = GetImport().loadGraphicFromBase64(mxBase64Stream);
156  if (xGraphic.is())
157  {
158  maAny <<= xGraphic;
159  }
160  }
161 
162  if (!maAny.has<uno::Reference<graphic::XGraphic>>())
163  return;
164 
165  uno::Reference<container::XNameContainer> xBitmapContainer(GetImport().GetBitmapHelper());
166 
167  uno::Reference<graphic::XGraphic> xGraphic = maAny.get<uno::Reference<graphic::XGraphic>>();
168  uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
169 
170  try
171  {
172  if (xBitmapContainer.is())
173  {
174  if (xBitmapContainer->hasByName(maStrName))
175  {
176  xBitmapContainer->replaceByName(maStrName, uno::Any(xBitmap));
177  }
178  else
179  {
180  xBitmapContainer->insertByName(maStrName, uno::Any(xBitmap));
181  }
182  }
183  }
184  catch (container::ElementExistException&)
185  {}
186 }
187 
189 {
190  return true;
191 }
192 
193 
195  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
196 : SvXMLStyleContext(rImport)
197 {
198  // start import
199  XMLTransGradientStyleImport aTransGradientStyle( GetImport() );
200  aTransGradientStyle.importXML( xAttrList, maAny, maStrName );
201 }
202 
204 {
205 }
206 
208 {
209  uno::Reference< container::XNameContainer > xTransGradient( GetImport().GetTransGradientHelper() );
210 
211  try
212  {
213  if(xTransGradient.is())
214  {
215  if( xTransGradient->hasByName( maStrName ) )
216  {
217  xTransGradient->replaceByName( maStrName, maAny );
218  }
219  else
220  {
221  xTransGradient->insertByName( maStrName, maAny );
222  }
223  }
224  }
225  catch( container::ElementExistException& )
226  {}
227 }
228 
230 {
231  return true;
232 }
233 
234 
236  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
237 : SvXMLStyleContext(rImport)
238 {
239  // start import
240  XMLMarkerStyleImport aMarkerStyle( GetImport() );
241  aMarkerStyle.importXML( xAttrList, maAny, maStrName );
242 }
243 
245 {
246 }
247 
249 {
250  uno::Reference< container::XNameContainer > xMarker( GetImport().GetMarkerHelper() );
251 
252  try
253  {
254  if(xMarker.is())
255  {
256  if( xMarker->hasByName( maStrName ) )
257  {
258  xMarker->replaceByName( maStrName, maAny );
259  }
260  else
261  {
262  xMarker->insertByName( maStrName, maAny );
263  }
264  }
265  }
266  catch( container::ElementExistException& )
267  {}
268 }
269 
271 {
272  return true;
273 }
274 
275 
276 XMLDashStyleContext::XMLDashStyleContext( SvXMLImport& rImport, sal_Int32 /*nElement*/,
277  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
278 : SvXMLStyleContext(rImport)
279 {
280  // start import
281  XMLDashStyleImport aDashStyle( GetImport() );
282  aDashStyle.importXML( xAttrList, maAny, maStrName );
283 }
284 
286 {
287 }
288 
290 {
291  uno::Reference< container::XNameContainer > xDashes( GetImport().GetDashHelper() );
292 
293  try
294  {
295  if(xDashes.is())
296  {
297  if( xDashes->hasByName( maStrName ) )
298  {
299  xDashes->replaceByName( maStrName, maAny );
300  }
301  else
302  {
303  xDashes->insertByName( maStrName, maAny );
304  }
305  }
306  }
307  catch( container::ElementExistException& )
308  {}
309 }
310 
312 {
313  return true;
314 }
315 
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
virtual ~XMLHatchStyleContext() override
css::uno::Reference< css::graphic::XGraphic > loadGraphicFromBase64(css::uno::Reference< css::io::XOutputStream > const &rxOutputStream)
Definition: xmlimp.cxx:1381
XMLHatchStyleContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XMLTransGradientStyleContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
XMLGradientStyleContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual ~XMLMarkerStyleContext() override
XMLMarkerStyleContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual bool IsTransient() const override
if this method returns true, its parent styles context should not add it to its container.
css::uno::Reference< css::io::XOutputStream > mxBase64Stream
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
css::uno::Reference< css::io::XOutputStream > GetStreamForGraphicObjectURLFromBase64() const
Definition: xmlimp.cxx:1393
XMLDashStyleContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual bool IsTransient() const override
if this method returns true, its parent styles context should not add it to its container.
virtual bool IsTransient() const override
if this method returns true, its parent styles context should not add it to its container.
XMLBitmapStyleContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
virtual ~XMLBitmapStyleContext() override
virtual bool IsTransient() const override
if this method returns true, its parent styles context should not add it to its container.
virtual bool IsTransient() const override
if this method returns true, its parent styles context should not add it to its container.
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
virtual ~XMLTransGradientStyleContext() override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
virtual bool IsTransient() const override
if this method returns true, its parent styles context should not add it to its container.
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:94
void importXML(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Any &rValue, OUString &rStrName)
virtual ~XMLGradientStyleContext() override
Reference< XGraphic > xGraphic
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
virtual ~XMLDashStyleContext() override