LibreOffice Module sw (master)  1
xmlbrsh.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 <editeng/memberids.h>
21 #include <vcl/graph.hxx>
22 
23 #include <sal/log.hxx>
24 #include <xmloff/xmlnamespace.hxx>
25 #include <xmloff/xmlimp.hxx>
27 #include <editeng/brushitem.hxx>
28 #include <xmloff/xmluconv.hxx>
29 
30 #include "xmlbrshi.hxx"
31 #include "xmlbrshe.hxx"
32 #include "xmlexp.hxx"
33 #include "xmlimpit.hxx"
34 #include "xmlexpit.hxx"
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::xmloff::token;
39 
41  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList,
42  const SvXMLUnitConverter& rUnitConv )
43 {
44  for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
45  {
46  const OUString sValue = aIter.toString();
47 
48  switch( aIter.getToken() )
49  {
50  case XML_ELEMENT(XLINK, XML_HREF):
52  break;
53  case XML_ELEMENT(XLINK, XML_TYPE):
54  case XML_ELEMENT(XLINK, XML_ACTUATE):
55  case XML_ELEMENT(XLINK, XML_SHOW):
56  break;
59  *m_pItem, sValue, MID_GRAPHIC_POSITION, rUnitConv );
60  break;
63  *m_pItem, sValue, MID_GRAPHIC_REPEAT, rUnitConv );
64  break;
67  *m_pItem, sValue, MID_GRAPHIC_FILTER, rUnitConv );
68  break;
69  default:
70  XMLOFF_WARN_UNKNOWN("sw", aIter);
71  }
72  }
73 
74 }
75 
76 css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLBrushItemImportContext::createFastChildContext(
77  sal_Int32 nElement,
78  const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
79 {
80  if ((nElement & TOKEN_MASK) == xmloff::token::XML_BINARY_DATA)
81  {
82  if (!m_xBase64Stream.is())
83  {
85  if (m_xBase64Stream.is())
87  }
88  }
89  XMLOFF_WARN_UNKNOWN_ELEMENT("sw", nElement);
90  return nullptr;
91 }
92 
94 {
95  if (m_xBase64Stream.is())
96  {
98  m_xBase64Stream = nullptr;
99  }
100 
101  if (m_xGraphic.is())
102  {
103  Graphic aGraphic(m_xGraphic);
104  SvxGraphicPosition eOldGraphicPos = m_pItem->GetGraphicPos();
105  m_pItem->SetGraphic(aGraphic);
106  if (GPOS_NONE == eOldGraphicPos && GPOS_NONE != m_pItem->GetGraphicPos())
107  m_pItem->SetGraphicPos(GPOS_TILED);
108  }
109 
110  if (!(m_pItem->GetGraphic()))
111  m_pItem->SetGraphicPos(GPOS_NONE);
112  else if (GPOS_NONE == m_pItem->GetGraphicPos())
113  m_pItem->SetGraphicPos(GPOS_TILED);
114 }
115 
117  SvXMLImport& rImport, sal_Int32 /*nElement*/,
118  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList,
119  const SvXMLUnitConverter& rUnitConv,
120  const SvxBrushItem& rItem ) :
121  SvXMLImportContext( rImport ),
122  m_pItem( new SvxBrushItem( rItem ) )
123 {
124  // delete any graphic that is existing
125  m_pItem->SetGraphicPos( GPOS_NONE );
126 
127  ProcessAttrs( xAttrList, rUnitConv );
128 }
129 
131  SvXMLImport& rImport, sal_Int32 /*nElement*/,
132  const uno::Reference< xml::sax::XFastAttributeList > & xAttrList,
133  const SvXMLUnitConverter& rUnitConv,
134  sal_uInt16 nWhich ) :
135  SvXMLImportContext( rImport ),
136  m_pItem( new SvxBrushItem( nWhich ) )
137 {
138  ProcessAttrs( xAttrList, rUnitConv );
139 }
140 
142 {
143 }
144 
146  m_rExport( rExp )
147 {
148 }
149 
151 {
152 }
153 
155 {
157 
158  uno::Reference<graphic::XGraphic> xGraphic;
159 
160  const Graphic* pGraphic = rItem.GetGraphic();
161 
162  if (pGraphic)
163  xGraphic = pGraphic->GetXGraphic();
164 
165  if (xGraphic.is())
166  {
167  OUString sMimeType;
168  OUString sValue = GetExport().AddEmbeddedXGraphic(xGraphic, sMimeType);
169  if (!sValue.isEmpty())
170  {
174  }
175 
176  const SvXMLUnitConverter& rUnitConv = GetExport().GetTwipUnitConverter();
177  if (SvXMLExportItemMapper::QueryXMLValue(rItem, sValue, MID_GRAPHIC_POSITION, rUnitConv))
179 
180  if (SvXMLExportItemMapper::QueryXMLValue(rItem, sValue, MID_GRAPHIC_REPEAT, rUnitConv))
182 
183  if (SvXMLExportItemMapper::QueryXMLValue(rItem, sValue, MID_GRAPHIC_FILTER, rUnitConv))
185  }
186 
187  {
189  true, true );
190  if (xGraphic.is())
191  {
192  // optional office:binary-data
194  }
195  }
196 }
197 
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::graphic::XGraphic > loadGraphicFromBase64(css::uno::Reference< css::io::XOutputStream > const &rxOutputStream)
XML_POSITION
GPOS_NONE
css::uno::Reference< css::io::XOutputStream > m_xBase64Stream
Definition: xmlbrshi.hxx:40
void CheckAttrList()
SvXMLImport & GetImport()
constexpr sal_uInt16 XML_NAMESPACE_XLINK
std::unique_ptr< SvxBrushItem > m_pItem
Definition: xmlbrshi.hxx:43
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
SwXMLBrushItemExport(SwXMLExport &rExport)
Definition: xmlbrsh.cxx:145
css::uno::Reference< css::graphic::XGraphic > loadGraphicByURL(OUString const &rURL)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: xmlbrsh.cxx:76
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
virtual ~SwXMLBrushItemImportContext() override
Definition: xmlbrsh.cxx:141
GPOS_TILED
css::uno::Reference< css::graphic::XGraphic > m_xGraphic
Definition: xmlbrshi.hxx:41
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlbrsh.cxx:93
#define XMLOFF_WARN_UNKNOWN(area, rIter)
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
#define MID_GRAPHIC_REPEAT
const Graphic * GetGraphic(OUString const &referer=OUString()) const
XML_REPEAT
XML_HREF
css::uno::Reference< css::io::XOutputStream > GetStreamForGraphicObjectURLFromBase64() const
OUString AddEmbeddedXGraphic(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic, OUString &rOutMimeType, OUString const &rRequestedName=OUString())
SvxGraphicPosition
const SvXMLUnitConverter & GetTwipUnitConverter() const
Definition: xmlexp.hxx:139
XML_FILTER_NAME
XML_SIMPLE
static bool QueryXMLValue(const SfxPoolItem &rItem, OUString &rValue, sal_uInt16 nMemberId, const SvXMLUnitConverter &rUnitConverter)
Definition: xmlexpit.cxx:350
XML_ONLOAD
SwXMLBrushItemImportContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, const SvXMLUnitConverter &rUnitConv, const SvxBrushItem &rItem)
void exportXML(const SvxBrushItem &rItem)
Definition: xmlbrsh.cxx:154
#define MID_GRAPHIC_POSITION
static bool PutXMLValue(SfxPoolItem &rItem, const OUString &rValue, sal_uInt16 nMemberId, const SvXMLUnitConverter &rUnitConverter)
This method is called for every item that should be set based upon an XML attribute value...
Definition: xmlimpit.cxx:310
SwXMLExport & GetExport()
Definition: xmlbrshe.hxx:30
XML_BACKGROUND_IMAGE
XML_SHOW
XML_TYPE
#define XML_ELEMENT(prefix, name)
#define MID_GRAPHIC_FILTER
bool AddEmbeddedXGraphicAsBase64(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic)
void ProcessAttrs(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, const SvXMLUnitConverter &rUnitConv)
Definition: xmlbrsh.cxx:40
constexpr sal_Int32 TOKEN_MASK
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
XML_ACTUATE
constexpr sal_uInt16 XML_NAMESPACE_STYLE