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/xmlnmspe.hxx>
33 
34 using namespace ::com::sun::star;
35 
36 
38  const OUString& rLName,
39  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
40 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
41 {
42 
43  // start import
44  XMLGradientStyleImport aGradientStyle( GetImport() );
45  aGradientStyle.importXML( xAttrList, maAny, maStrName );
46 }
47 
49 {
50 }
51 
53 {
54  uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() );
55 
56  try
57  {
58  if(xGradient.is())
59  {
60  if( xGradient->hasByName( maStrName ) )
61  {
62  xGradient->replaceByName( maStrName, maAny );
63  }
64  else
65  {
66  xGradient->insertByName( maStrName, maAny );
67  }
68  }
69  }
70  catch( container::ElementExistException& )
71  {}
72 }
73 
75 {
76  return true;
77 }
78 
79 
81  const OUString& rLName,
82  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
83 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
84 {
85  // start import
86  XMLHatchStyleImport aHatchStyle( GetImport() );
87  aHatchStyle.importXML( xAttrList, maAny, maStrName );
88 }
89 
91 {
92 }
93 
95 {
96  uno::Reference< container::XNameContainer > xHatch( GetImport().GetHatchHelper() );
97 
98  try
99  {
100  if(xHatch.is())
101  {
102  if( xHatch->hasByName( maStrName ) )
103  {
104  xHatch->replaceByName( maStrName, maAny );
105  }
106  else
107  {
108  xHatch->insertByName( maStrName, maAny );
109  }
110  }
111  }
112  catch( container::ElementExistException& )
113  {}
114 }
115 
117 {
118  return true;
119 }
120 
121 
123  const OUString& rLName,
124  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
125 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
126 {
127  // start import
128  XMLImageStyle::importXML( xAttrList, maAny, maStrName, rImport );
129 }
130 
132 {
133 }
134 
135 SvXMLImportContextRef XMLBitmapStyleContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList )
136 {
137  SvXMLImportContext *pContext = nullptr;
139  {
140  OUString sURL;
141  maAny >>= sURL;
142  if( sURL.isEmpty() && !mxBase64Stream.is() )
143  {
145  if( mxBase64Stream.is() )
146  pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
147  rLocalName, xAttrList,
148  mxBase64Stream );
149  }
150  }
151 
152  return pContext;
153 }
154 
156 {
157  if (maAny.has<uno::Reference<graphic::XGraphic>>())
158  {
159  uno::Reference<container::XNameContainer> xBitmapContainer(GetImport().GetBitmapHelper());
160 
161  uno::Reference<graphic::XGraphic> xGraphic = maAny.get<uno::Reference<graphic::XGraphic>>();
162  uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
163 
164  try
165  {
166  if (xBitmapContainer.is())
167  {
168  if (xBitmapContainer->hasByName(maStrName))
169  {
170  xBitmapContainer->replaceByName(maStrName, uno::Any(xBitmap));
171  }
172  else
173  {
174  xBitmapContainer->insertByName(maStrName, uno::Any(xBitmap));
175  }
176  }
177  }
178  catch (container::ElementExistException&)
179  {}
180  }
181 }
182 
184 {
185  return true;
186 }
187 
188 
190  const OUString& rLName,
191  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
192 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
193 {
194  // start import
195  XMLTransGradientStyleImport aTransGradientStyle( GetImport() );
196  aTransGradientStyle.importXML( xAttrList, maAny, maStrName );
197 }
198 
200 {
201 }
202 
204 {
205  uno::Reference< container::XNameContainer > xTransGradient( GetImport().GetTransGradientHelper() );
206 
207  try
208  {
209  if(xTransGradient.is())
210  {
211  if( xTransGradient->hasByName( maStrName ) )
212  {
213  xTransGradient->replaceByName( maStrName, maAny );
214  }
215  else
216  {
217  xTransGradient->insertByName( maStrName, maAny );
218  }
219  }
220  }
221  catch( container::ElementExistException& )
222  {}
223 }
224 
226 {
227  return true;
228 }
229 
230 
232  const OUString& rLName,
233  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
234 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
235 {
236  // start import
237  XMLMarkerStyleImport aMarkerStyle( GetImport() );
238  aMarkerStyle.importXML( xAttrList, maAny, maStrName );
239 }
240 
242 {
243 }
244 
246 {
247  uno::Reference< container::XNameContainer > xMarker( GetImport().GetMarkerHelper() );
248 
249  try
250  {
251  if(xMarker.is())
252  {
253  if( xMarker->hasByName( maStrName ) )
254  {
255  xMarker->replaceByName( maStrName, maAny );
256  }
257  else
258  {
259  xMarker->insertByName( maStrName, maAny );
260  }
261  }
262  }
263  catch( container::ElementExistException& )
264  {}
265 }
266 
268 {
269  return true;
270 }
271 
272 
274  const OUString& rLName,
275  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
276 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
277 {
278  // start import
279  XMLDashStyleImport aDashStyle( GetImport() );
280  aDashStyle.importXML( xAttrList, maAny, maStrName );
281 }
282 
284 {
285 }
286 
288 {
289  uno::Reference< container::XNameContainer > xDashes( GetImport().GetDashHelper() );
290 
291  try
292  {
293  if(xDashes.is())
294  {
295  if( xDashes->hasByName( maStrName ) )
296  {
297  xDashes->replaceByName( maStrName, maAny );
298  }
299  else
300  {
301  xDashes->insertByName( maStrName, maAny );
302  }
303  }
304  }
305  catch( container::ElementExistException& )
306  {}
307 }
308 
310 {
311  return true;
312 }
313 
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
XMLTransGradientStyleContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
virtual ~XMLHatchStyleContext() override
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
void importXML(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, css::uno::Any &rValue, OUString &rStrName)
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
virtual ~XMLMarkerStyleContext() override
virtual bool IsTransient() const override
if this method returns true, its parent styles context should not add it to its container.
XMLMarkerStyleContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
css::uno::Reference< css::io::XOutputStream > mxBase64Stream
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
css::uno::Reference< css::io::XOutputStream > GetStreamForGraphicObjectURLFromBase64() const
Definition: xmlimp.cxx:1390
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
virtual bool IsTransient() const override
if this method returns true, its parent styles context should not add it to its container.
XMLDashStyleContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Create a children element context.
virtual bool IsTransient() const override
if this method returns true, its parent styles context should not add it to its container.
virtual ~XMLBitmapStyleContext() override
XMLBitmapStyleContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &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.
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
XMLGradientStyleContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
virtual ~XMLTransGradientStyleContext() override
virtual bool IsTransient() const override
if this method returns true, its parent styles context should not add it to its container.
virtual void EndElement() override
EndElement is called before a context will be destructed, but after an elements context has been pars...
virtual ~XMLGradientStyleContext() override
Reference< XGraphic > xGraphic
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
Definition: xmlnmspe.hxx:29
XMLHatchStyleContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
virtual ~XMLDashStyleContext() override