LibreOffice Module sw (master) 1
xmliteme.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/util/MeasureUnit.hpp>
21
22#include <hintids.hxx>
23#include <rtl/ustring.hxx>
24#include <rtl/ustrbuf.hxx>
25#include <utility>
26#include <xmloff/xmluconv.hxx>
27#include "xmlexpit.hxx"
29#include "xmlbrshe.hxx"
30#include <editeng/brushitem.hxx>
31#include <fmtornt.hxx>
32#include <unomid.h>
33#include <frmfmt.hxx>
34#include "xmlexp.hxx"
35#include <editeng/memberids.h>
36#include <editeng/prntitem.hxx>
37
38using namespace ::com::sun::star;
39using namespace ::com::sun::star::uno;
40using namespace ::xmloff::token;
41
42namespace {
43
44class SwXMLTableItemMapper_Impl: public SvXMLExportItemMapper
45{
46 SwXMLBrushItemExport m_aBrushItemExport;
47
48protected:
49
50 sal_uInt32 m_nAbsWidth;
51
52 static void AddAttribute( sal_uInt16 nPrefix, enum XMLTokenEnum eLName,
53 const OUString& rValue,
54 const SvXMLNamespaceMap& rNamespaceMap,
55 comphelper::AttributeList& rAttrList );
56
57public:
58
59 SwXMLTableItemMapper_Impl(
60 SvXMLItemMapEntriesRef rMapEntries,
61 SwXMLExport& rExp );
62
63 virtual void handleSpecialItem( comphelper::AttributeList& rAttrList,
64 const SvXMLItemMapEntry& rEntry,
65 const SfxPoolItem& rItem,
66 const SvXMLUnitConverter& rUnitConverter,
67 const SvXMLNamespaceMap& rNamespaceMap,
68 const SfxItemSet *pSet ) const override;
69
70 virtual void handleElementItem(
71 const SvXMLItemMapEntry& rEntry,
72 const SfxPoolItem& rItem ) const override;
73
74 inline void SetAbsWidth( sal_uInt32 nAbs );
75};
76
77}
78
79SwXMLTableItemMapper_Impl::SwXMLTableItemMapper_Impl(
80 SvXMLItemMapEntriesRef rMapEntries,
81 SwXMLExport& rExp ) :
82 SvXMLExportItemMapper( std::move(rMapEntries) ),
83 m_aBrushItemExport( rExp ),
84 m_nAbsWidth( USHRT_MAX )
85{
86}
87
88void SwXMLTableItemMapper_Impl::AddAttribute( sal_uInt16 nPrefix,
89 enum XMLTokenEnum eLName,
90 const OUString& rValue,
91 const SvXMLNamespaceMap& rNamespaceMap,
92 comphelper::AttributeList& rAttrList )
93{
94 OUString sName( rNamespaceMap.GetQNameByKey( nPrefix,
95 GetXMLToken(eLName) ) );
96 rAttrList.AddAttribute( sName, rValue );
97}
98
99void SwXMLTableItemMapper_Impl::handleSpecialItem(
100 comphelper::AttributeList& rAttrList,
101 const SvXMLItemMapEntry& rEntry,
102 const SfxPoolItem& rItem,
103 const SvXMLUnitConverter& rUnitConverter,
104 const SvXMLNamespaceMap& rNamespaceMap,
105 const SfxItemSet *pSet ) const
106{
107 switch( rEntry.nWhichId )
108 {
109
110 case RES_PRINT:
111 {
112 const SvxPrintItem *pItem;
113 if( pSet &&
114 (pItem = pSet->GetItemIfSet( RES_PRINT )) )
115 {
116 bool bHasTextChangesOnly = pItem->GetValue();
117 if ( !bHasTextChangesOnly )
118 {
119 OUString sValue;
120 sal_uInt16 nMemberId =
121 static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
122
124 rItem, sValue, nMemberId, rUnitConverter ) )
125 {
126 AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
127 sValue, rNamespaceMap, rAttrList );
128 }
129 }
130 }
131 }
132 break;
133
134 case RES_LR_SPACE:
135 {
136 const SwFormatHoriOrient *pItem;
137 if( pSet &&
138 (pItem = pSet->GetItemIfSet( RES_HORI_ORIENT )) )
139 {
140 sal_Int16 eHoriOrient = pItem->GetHoriOrient();
141 bool bExport = false;
142 sal_uInt16 nMemberId =
143 o3tl::narrowing<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
144 switch( nMemberId )
145 {
146 case MID_L_MARGIN:
147 bExport = text::HoriOrientation::NONE == eHoriOrient ||
148 text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient;
149 break;
150 case MID_R_MARGIN:
151 bExport = text::HoriOrientation::NONE == eHoriOrient;
152 break;
153 }
154 OUString sValue;
156 rItem, sValue, nMemberId, rUnitConverter ) )
157 {
158 AddAttribute( rEntry.nNameSpace, rEntry.eLocalName, sValue,
159 rNamespaceMap, rAttrList );
160 }
161 }
162 }
163 break;
164
165 case RES_FRM_SIZE:
166 {
167 sal_uInt16 nMemberId =
168 o3tl::narrowing<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
169 switch( nMemberId )
170 {
172 if( m_nAbsWidth )
173 {
174 OUStringBuffer sBuffer;
175 rUnitConverter.convertMeasureToXML( sBuffer, m_nAbsWidth );
176 AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
177 sBuffer.makeStringAndClear(),
178 rNamespaceMap, rAttrList );
179 }
180 break;
182 {
183 OUString sValue;
185 rItem, sValue, nMemberId, rUnitConverter ) )
186 {
187 AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
188 sValue, rNamespaceMap, rAttrList );
189 }
190 }
191 break;
192 }
193 }
194 break;
195 }
196}
197
200void SwXMLTableItemMapper_Impl::handleElementItem(
201 const SvXMLItemMapEntry& rEntry,
202 const SfxPoolItem& rItem ) const
203{
204 switch( rEntry.nWhichId )
205 {
206 case RES_BACKGROUND:
207 {
208 const_cast<SwXMLTableItemMapper_Impl *>(this)->m_aBrushItemExport.exportXML(
209 static_cast<const SvxBrushItem&>(rItem) );
210 }
211 break;
212 }
213}
214
215inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs )
216{
217 m_nAbsWidth = nAbs;
218}
219
221{
223 util::MeasureUnit::TWIP, GetMM100UnitConverter().GetXMLMeasureUnit(),
225
229
230 m_pTableItemMapper.reset(new SwXMLTableItemMapper_Impl( m_xTableItemMap, *this ));
231}
232
234{
235 m_pTableItemMapper.reset();
236 m_pTwipUnitConverter.reset();
237}
238
239void SwXMLExport::ExportTableFormat( const SwFrameFormat& rFormat, sal_uInt32 nAbsWidth )
240{
241 static_cast<SwXMLTableItemMapper_Impl *>(m_pTableItemMapper.get())
242 ->SetAbsWidth( nAbsWidth );
243 ExportFormat(rFormat, XML_TABLE, {});
244}
245
246/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
static bool QueryXMLValue(const SfxPoolItem &rItem, OUString &rValue, sal_uInt16 nMemberId, const SvXMLUnitConverter &rUnitConverter)
Definition: xmlexpit.cxx:360
virtual void handleElementItem(const SvXMLItemMapEntry &rEntry, const SfxPoolItem &rItem) const
this method is called for every item that has the MID_SW_FLAG_ELEMENT_EXPORT flag set
Definition: xmlexpit.cxx:333
virtual void handleSpecialItem(comphelper::AttributeList &rAttrList, const SvXMLItemMapEntry &rEntry, const SfxPoolItem &rItem, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap, const SfxItemSet *pSet) const
this method is called for every item that has the MID_SW_FLAG_SPECIAL_ITEM_EXPORT flag set
Definition: xmlexpit.cxx:321
SvtSaveOptions::ODFSaneDefaultVersion getSaneDefaultVersion() const
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
const SvXMLUnitConverter & GetMM100UnitConverter() const
this class manages an array of SvXMLItemMapEntry.
Definition: xmlitmap.hxx:65
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
Defines the horizontal position of a fly frame.
Definition: fmtornt.hxx:73
sal_Int16 GetHoriOrient() const
Definition: fmtornt.hxx:94
Style of a layout element.
Definition: frmfmt.hxx:62
SvXMLItemMapEntriesRef m_xTableCellItemMap
Definition: xmlexp.hxx:59
SvXMLItemMapEntriesRef m_xTableItemMap
Definition: xmlexp.hxx:57
void ExportTableFormat(const SwFrameFormat &rFormat, sal_uInt32 nAbsWidth)
Definition: xmliteme.cxx:239
void ExportFormat(const SwFormat &rFormat, enum ::xmloff::token::XMLTokenEnum eClass, ::std::optional< OUString > const oStyleName)
Definition: xmlfmte.cxx:48
SvXMLItemMapEntriesRef m_xTableRowItemMap
Definition: xmlexp.hxx:58
void FinitItemExport()
Definition: xmliteme.cxx:233
std::unique_ptr< SvXMLUnitConverter > m_pTwipUnitConverter
Definition: xmlexp.hxx:53
void InitItemExport()
Definition: xmliteme.cxx:220
std::unique_ptr< SvXMLExportItemMapper > m_pTableItemMapper
Definition: xmlexp.hxx:54
void AddAttribute(const OUString &sName, const OUString &sValue)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
constexpr TypedWhichId< SwFormatHoriOrient > RES_HORI_ORIENT(103)
constexpr TypedWhichId< SvxPrintItem > RES_PRINT(98)
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(105)
#define MID_R_MARGIN
#define MID_L_MARGIN
const char * sName
XMLTokenEnum
XML_TABLE
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
enum::xmloff::token::XMLTokenEnum const eLocalName
Definition: xmlitmap.hxx:46
sal_uInt16 nWhichId
Definition: xmlitmap.hxx:44
sal_uInt16 nNameSpace
Definition: xmlitmap.hxx:42
sal_uInt32 nMemberId
Definition: xmlitmap.hxx:49
#define MID_FRMSIZE_REL_WIDTH
Definition: unomid.h:72
#define MID_FRMSIZE_WIDTH
Definition: unomid.h:74
const o3tl::span< SvXMLItemMapEntry const > aXMLTableCellItemMap(aTableCellItemMap)
const o3tl::span< SvXMLItemMapEntry const > aXMLTableItemMap(aTableItemMap)
const o3tl::span< SvXMLItemMapEntry const > aXMLTableRowItemMap(aTableRowItemMap)
#define MID_SW_FLAG_MASK
Definition: xmlitmap.hxx:29