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/namespacemap.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmlimp.hxx>
27 #include <xmloff/xmltkmap.hxx>
29 #include <editeng/brushitem.hxx>
30 #include <xmloff/xmluconv.hxx>
31 
32 #include "xmlbrshi.hxx"
33 #include "xmlbrshe.hxx"
34 #include "xmlexp.hxx"
35 #include "xmlimpit.hxx"
36 #include "xmlexpit.hxx"
37 
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::xmloff::token;
41 
43  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList,
44  const SvXMLUnitConverter& rUnitConv )
45 {
46  for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
47  {
48  const OUString sValue = aIter.toString();
49 
50  switch( aIter.getToken() )
51  {
52  case XML_ELEMENT(XLINK, XML_HREF):
54  break;
55  case XML_ELEMENT(XLINK, XML_TYPE):
56  case XML_ELEMENT(XLINK, XML_ACTUATE):
57  case XML_ELEMENT(XLINK, XML_SHOW):
58  break;
61  *pItem, sValue, MID_GRAPHIC_POSITION, rUnitConv );
62  break;
65  *pItem, sValue, MID_GRAPHIC_REPEAT, rUnitConv );
66  break;
69  *pItem, sValue, MID_GRAPHIC_FILTER, rUnitConv );
70  break;
71  default:
72  XMLOFF_WARN_UNKNOWN("sw", aIter);
73  }
74  }
75 
76 }
77 
78 css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLBrushItemImportContext::createFastChildContext(
79  sal_Int32 nElement,
80  const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
81 {
82  if ((nElement & TOKEN_MASK) == xmloff::token::XML_BINARY_DATA)
83  {
84  if (!m_xBase64Stream.is())
85  {
87  if (m_xBase64Stream.is())
89  }
90  }
91  XMLOFF_WARN_UNKNOWN_ELEMENT("sw", nElement);
92  return nullptr;
93 }
94 
96 {
97  if (m_xBase64Stream.is())
98  {
100  m_xBase64Stream = nullptr;
101  }
102 
103  if (m_xGraphic.is())
104  {
105  Graphic aGraphic(m_xGraphic);
106  SvxGraphicPosition eOldGraphicPos = pItem->GetGraphicPos();
107  pItem->SetGraphic(aGraphic);
108  if (GPOS_NONE == eOldGraphicPos && GPOS_NONE != pItem->GetGraphicPos())
109  pItem->SetGraphicPos(GPOS_TILED);
110  }
111 
112  if (!(pItem->GetGraphic()))
113  pItem->SetGraphicPos(GPOS_NONE);
114  else if (GPOS_NONE == pItem->GetGraphicPos())
115  pItem->SetGraphicPos(GPOS_TILED);
116 }
117 
119  SvXMLImport& rImport, sal_Int32 /*nElement*/,
120  const uno::Reference< xml::sax::XFastAttributeList >& xAttrList,
121  const SvXMLUnitConverter& rUnitConv,
122  const SvxBrushItem& rItem ) :
123  SvXMLImportContext( rImport ),
124  pItem( new SvxBrushItem( rItem ) )
125 {
126  // delete any graphic that is existing
127  pItem->SetGraphicPos( GPOS_NONE );
128 
129  ProcessAttrs( xAttrList, rUnitConv );
130 }
131 
133  SvXMLImport& rImport, sal_Int32 /*nElement*/,
134  const uno::Reference< xml::sax::XFastAttributeList > & xAttrList,
135  const SvXMLUnitConverter& rUnitConv,
136  sal_uInt16 nWhich ) :
137  SvXMLImportContext( rImport ),
138  pItem( new SvxBrushItem( nWhich ) )
139 {
140  ProcessAttrs( xAttrList, rUnitConv );
141 }
142 
144 {
145 }
146 
148  rExport( rExp )
149 {
150 }
151 
153 {
154 }
155 
157 {
159 
160  uno::Reference<graphic::XGraphic> xGraphic;
161 
162  const Graphic* pGraphic = rItem.GetGraphic();
163 
164  if (pGraphic)
165  xGraphic = pGraphic->GetXGraphic();
166 
167  if (xGraphic.is())
168  {
169  OUString sMimeType;
170  OUString sValue = GetExport().AddEmbeddedXGraphic(xGraphic, sMimeType);
171  if (!sValue.isEmpty())
172  {
176  }
177 
178  const SvXMLUnitConverter& rUnitConv = GetExport().GetTwipUnitConverter();
179  if (SvXMLExportItemMapper::QueryXMLValue(rItem, sValue, MID_GRAPHIC_POSITION, rUnitConv))
181 
182  if (SvXMLExportItemMapper::QueryXMLValue(rItem, sValue, MID_GRAPHIC_REPEAT, rUnitConv))
184 
185  if (SvXMLExportItemMapper::QueryXMLValue(rItem, sValue, MID_GRAPHIC_FILTER, rUnitConv))
187  }
188 
189  {
191  true, true );
192  if (xGraphic.is())
193  {
194  // optional office:binary-data
196  }
197  }
198 }
199 
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::graphic::XGraphic > loadGraphicFromBase64(css::uno::Reference< css::io::XOutputStream > const &rxOutputStream)
GPOS_NONE
css::uno::Reference< css::io::XOutputStream > m_xBase64Stream
Definition: xmlbrshi.hxx:40
void CheckAttrList()
SvXMLImport & GetImport()
XML_POSITION
constexpr sal_uInt16 XML_NAMESPACE_XLINK
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
SwXMLBrushItemExport(SwXMLExport &rExport)
Definition: xmlbrsh.cxx:147
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:78
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
virtual ~SwXMLBrushItemImportContext() override
Definition: xmlbrsh.cxx:143
XML_SHOW
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:95
XML_TYPE
#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
css::uno::Reference< css::io::XOutputStream > GetStreamForGraphicObjectURLFromBase64() const
OUString AddEmbeddedXGraphic(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic, OUString &rOutMimeType, OUString const &rRequestedName=OUString())
XML_ONLOAD
XML_BACKGROUND_IMAGE
std::unique_ptr< SvxBrushItem > pItem
Definition: xmlbrshi.hxx:43
SvxGraphicPosition
XML_HREF
const SvXMLUnitConverter & GetTwipUnitConverter() const
Definition: xmlexp.hxx:137
static bool QueryXMLValue(const SfxPoolItem &rItem, OUString &rValue, sal_uInt16 nMemberId, const SvXMLUnitConverter &rUnitConverter)
Definition: xmlexpit.cxx:349
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:156
#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_ACTUATE
XML_FILTER_NAME
XML_SIMPLE
#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:42
constexpr sal_Int32 TOKEN_MASK
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
css::uno::Any const SvXMLExport & rExport
Reference< XGraphic > xGraphic
constexpr sal_uInt16 XML_NAMESPACE_STYLE