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"
28 #include <xmloff/namespacemap.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 
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::xmloff::token;
41 
42 namespace {
43 
44 class SwXMLTableItemMapper_Impl: public SvXMLExportItemMapper
45 {
46  SwXMLBrushItemExport m_aBrushItemExport;
47 
48 protected:
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  SvXMLAttributeList& rAttrList );
56 
57 public:
58 
59  SwXMLTableItemMapper_Impl(
60  SvXMLItemMapEntriesRef rMapEntries,
61  SwXMLExport& rExp );
62 
63  virtual void handleSpecialItem( SvXMLAttributeList& 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 
79 SwXMLTableItemMapper_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 
88 void SwXMLTableItemMapper_Impl::AddAttribute( sal_uInt16 nPrefix,
89  enum XMLTokenEnum eLName,
90  const OUString& rValue,
91  const SvXMLNamespaceMap& rNamespaceMap,
92  SvXMLAttributeList& rAttrList )
93 {
94  OUString sName( rNamespaceMap.GetQNameByKey( nPrefix,
95  GetXMLToken(eLName) ) );
96  rAttrList.AddAttribute( sName, rValue );
97 }
98 
99 void SwXMLTableItemMapper_Impl::handleSpecialItem(
100  SvXMLAttributeList& 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  {
171  case MID_FRMSIZE_WIDTH:
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 
200 void 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 
215 inline 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 
239 void 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
constexpr TypedWhichId< SvxPrintItem > RES_PRINT(98)
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:323
SvXMLItemMapEntry const aXMLTableItemMap[]
Definition: xmlitemm.cxx:43
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
SvXMLItemMapEntriesRef m_xTableRowItemMap
Definition: xmlexp.hxx:57
sal_uInt16 nWhichId
Definition: xmlitmap.hxx:43
const SvXMLUnitConverter & GetMM100UnitConverter() const
#define MID_FRMSIZE_REL_WIDTH
Definition: unomid.h:72
void InitItemExport()
Definition: xmliteme.cxx:220
SvXMLItemMapEntriesRef m_xTableItemMap
Definition: xmlexp.hxx:56
SvXMLItemMapEntriesRef m_xTableCellItemMap
Definition: xmlexp.hxx:58
constexpr TypedWhichId< SwFormatHoriOrient > RES_HORI_ORIENT(103)
#define MID_SW_FLAG_MASK
Definition: xmlitmap.hxx:28
this class manages an array of SvXMLItemMapEntry.
Definition: xmlitmap.hxx:65
const char * sName
virtual void handleSpecialItem(SvXMLAttributeList &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:311
void FinitItemExport()
Definition: xmliteme.cxx:233
void ExportFormat(const SwFormat &rFormat, enum::xmloff::token::XMLTokenEnum eClass)
Definition: xmlfmte.cxx:49
#define MID_FRMSIZE_WIDTH
Definition: unomid.h:74
SvtSaveOptions::ODFSaneDefaultVersion getSaneDefaultVersion() const
#define MID_L_MARGIN
Style of a layout element.
Definition: frmfmt.hxx:59
enum::xmloff::token::XMLTokenEnum const eLocalName
Definition: xmlitmap.hxx:45
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
XML_TABLE
std::unique_ptr< SvXMLUnitConverter > m_pTwipUnitConverter
Definition: xmlexp.hxx:52
sal_Int16 GetHoriOrient() const
Definition: fmtornt.hxx:87
static bool QueryXMLValue(const SfxPoolItem &rItem, OUString &rValue, sal_uInt16 nMemberId, const SvXMLUnitConverter &rUnitConverter)
Definition: xmlexpit.cxx:350
void ExportTableFormat(const SwFrameFormat &rFormat, sal_uInt32 nAbsWidth)
Definition: xmliteme.cxx:239
#define MID_R_MARGIN
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
sal_uInt32 nMemberId
Definition: xmlitmap.hxx:48
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(105)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
XMLTokenEnum
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
sal_uInt16 nNameSpace
Definition: xmlitmap.hxx:41
SvXMLItemMapEntry const aXMLTableCellItemMap[]
Definition: xmlitemm.cxx:203
void AddAttribute(const OUString &sName, const OUString &sValue)
SvXMLItemMapEntry const aXMLTableRowItemMap[]
Definition: xmlitemm.cxx:130
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
std::unique_ptr< SvXMLExportItemMapper > m_pTableItemMapper
Definition: xmlexp.hxx:53