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>
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
36using namespace ::com::sun::star;
37using namespace ::com::sun::star::uno;
38using 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):
51 m_xGraphic = GetImport().loadGraphicByURL(sValue);
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
76css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLBrushItemImportContext::createFastChildContext(
77 sal_Int32 nElement,
78 const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ )
79{
81 {
82 if (!m_xBase64Stream.is())
83 {
84 m_xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
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 {
97 m_xGraphic = GetImport().loadGraphicFromBase64(m_xBase64Stream);
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{
153
154 uno::Reference<graphic::XGraphic> xGraphic;
155
156 const Graphic* pGraphic = rItem.GetGraphic();
157
158 if (pGraphic)
159 xGraphic = pGraphic->GetXGraphic();
160
161 if (xGraphic.is())
162 {
163 OUString sMimeType;
164 OUString sValue = GetExport().AddEmbeddedXGraphic(xGraphic, sMimeType);
165 if (!sValue.isEmpty())
166 {
170 }
171
173 if (SvXMLExportItemMapper::QueryXMLValue(rItem, sValue, MID_GRAPHIC_POSITION, rUnitConv))
175
176 if (SvXMLExportItemMapper::QueryXMLValue(rItem, sValue, MID_GRAPHIC_REPEAT, rUnitConv))
178
179 if (SvXMLExportItemMapper::QueryXMLValue(rItem, sValue, MID_GRAPHIC_FILTER, rUnitConv))
181 }
182
183 {
185 true, true );
186 if (xGraphic.is())
187 {
188 // optional office:binary-data
190 }
191 }
192}
193
194/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvxGraphicPosition
GPOS_NONE
GPOS_TILED
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
static bool QueryXMLValue(const SfxPoolItem &rItem, OUString &rValue, sal_uInt16 nMemberId, const SvXMLUnitConverter &rUnitConverter)
Definition: xmlexpit.cxx:360
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
bool AddEmbeddedXGraphicAsBase64(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic)
void CheckAttrList()
OUString AddEmbeddedXGraphic(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic, OUString &rOutMimeType, OUString const &rRequestedName=OUString())
SvXMLImport & GetImport()
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
const Graphic * GetGraphic(OUString const &referer=OUString()) const
SwXMLExport & GetExport()
Definition: xmlbrshe.hxx:30
void exportXML(const SvxBrushItem &rItem)
Definition: xmlbrsh.cxx:150
SwXMLBrushItemExport(SwXMLExport &rExport)
Definition: xmlbrsh.cxx:145
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
std::unique_ptr< SvxBrushItem > m_pItem
Definition: xmlbrshi.hxx:43
SwXMLBrushItemImportContext(SvXMLImport &rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, const SvXMLUnitConverter &rUnitConv, const SvxBrushItem &rItem)
css::uno::Reference< css::graphic::XGraphic > m_xGraphic
Definition: xmlbrshi.hxx:41
void ProcessAttrs(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, const SvXMLUnitConverter &rUnitConv)
Definition: xmlbrsh.cxx:40
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmlbrsh.cxx:93
virtual ~SwXMLBrushItemImportContext() override
Definition: xmlbrsh.cxx:141
css::uno::Reference< css::io::XOutputStream > m_xBase64Stream
Definition: xmlbrshi.hxx:40
const SvXMLUnitConverter & GetTwipUnitConverter() const
Definition: xmlexp.hxx:140
#define MID_GRAPHIC_REPEAT
#define MID_GRAPHIC_POSITION
#define MID_GRAPHIC_FILTER
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XML_REPEAT
XML_ACTUATE
XML_HREF
XML_SHOW
XML_ONLOAD
XML_SIMPLE
XML_BACKGROUND_IMAGE
XML_POSITION
XML_FILTER_NAME
XML_TYPE
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)
constexpr sal_Int32 TOKEN_MASK
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_STYLE