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 #include <xmloff/xmlnamespace.hxx>
38 
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using namespace ::xmloff::token;
42 
43 namespace {
44 
45 class SwXMLTableItemMapper_Impl: public SvXMLExportItemMapper
46 {
47  SwXMLBrushItemExport m_aBrushItemExport;
48 
49 protected:
50 
51  sal_uInt32 m_nAbsWidth;
52 
53  static void AddAttribute( sal_uInt16 nPrefix, enum XMLTokenEnum eLName,
54  const OUString& rValue,
55  const SvXMLNamespaceMap& rNamespaceMap,
56  SvXMLAttributeList& rAttrList );
57 
58 public:
59 
60  SwXMLTableItemMapper_Impl(
61  SvXMLItemMapEntriesRef rMapEntries,
62  SwXMLExport& rExp );
63 
64  virtual void handleSpecialItem( SvXMLAttributeList& rAttrList,
65  const SvXMLItemMapEntry& rEntry,
66  const SfxPoolItem& rItem,
67  const SvXMLUnitConverter& rUnitConverter,
68  const SvXMLNamespaceMap& rNamespaceMap,
69  const SfxItemSet *pSet ) const override;
70 
71  virtual void handleElementItem(
72  const SvXMLItemMapEntry& rEntry,
73  const SfxPoolItem& rItem ) const override;
74 
75  inline void SetAbsWidth( sal_uInt32 nAbs );
76 };
77 
78 }
79 
80 SwXMLTableItemMapper_Impl::SwXMLTableItemMapper_Impl(
81  SvXMLItemMapEntriesRef rMapEntries,
82  SwXMLExport& rExp ) :
83  SvXMLExportItemMapper( std::move(rMapEntries) ),
84  m_aBrushItemExport( rExp ),
85  m_nAbsWidth( USHRT_MAX )
86 {
87 }
88 
89 void SwXMLTableItemMapper_Impl::AddAttribute( sal_uInt16 nPrefix,
90  enum XMLTokenEnum eLName,
91  const OUString& rValue,
92  const SvXMLNamespaceMap& rNamespaceMap,
93  SvXMLAttributeList& rAttrList )
94 {
95  OUString sName( rNamespaceMap.GetQNameByKey( nPrefix,
96  GetXMLToken(eLName) ) );
97  rAttrList.AddAttribute( sName, rValue );
98 }
99 
100 void SwXMLTableItemMapper_Impl::handleSpecialItem(
101  SvXMLAttributeList& rAttrList,
102  const SvXMLItemMapEntry& rEntry,
103  const SfxPoolItem& rItem,
104  const SvXMLUnitConverter& rUnitConverter,
105  const SvXMLNamespaceMap& rNamespaceMap,
106  const SfxItemSet *pSet ) const
107 {
108  switch( rEntry.nWhichId )
109  {
110 
111  case RES_PRINT:
112  {
113  const SfxPoolItem *pItem;
114  if( pSet &&
115  SfxItemState::SET == pSet->GetItemState( RES_PRINT, true,
116  &pItem ) )
117  {
118  bool bHasTextChangesOnly =
119  static_cast<const SvxPrintItem *>(pItem)->GetValue();
120  if ( !bHasTextChangesOnly )
121  {
122  OUString sValue;
123  sal_uInt16 nMemberId =
124  static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
125 
127  rItem, sValue, nMemberId, rUnitConverter ) )
128  {
129  AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
130  sValue, rNamespaceMap, rAttrList );
131  }
132  }
133  }
134  }
135  break;
136 
137  case RES_LR_SPACE:
138  {
139  const SfxPoolItem *pItem;
140  if( pSet &&
141  SfxItemState::SET == pSet->GetItemState( RES_HORI_ORIENT, true,
142  &pItem ) )
143  {
144  sal_Int16 eHoriOrient =
145  static_cast<const SwFormatHoriOrient *>(pItem)->GetHoriOrient();
146  bool bExport = false;
147  sal_uInt16 nMemberId =
148  o3tl::narrowing<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
149  switch( nMemberId )
150  {
151  case MID_L_MARGIN:
152  bExport = text::HoriOrientation::NONE == eHoriOrient ||
153  text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient;
154  break;
155  case MID_R_MARGIN:
156  bExport = text::HoriOrientation::NONE == eHoriOrient;
157  break;
158  }
159  OUString sValue;
161  rItem, sValue, nMemberId, rUnitConverter ) )
162  {
163  AddAttribute( rEntry.nNameSpace, rEntry.eLocalName, sValue,
164  rNamespaceMap, rAttrList );
165  }
166  }
167  }
168  break;
169 
170  case RES_FRM_SIZE:
171  {
172  sal_uInt16 nMemberId =
173  o3tl::narrowing<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
174  switch( nMemberId )
175  {
176  case MID_FRMSIZE_WIDTH:
177  if( m_nAbsWidth )
178  {
179  OUStringBuffer sBuffer;
180  rUnitConverter.convertMeasureToXML( sBuffer, m_nAbsWidth );
181  AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
182  sBuffer.makeStringAndClear(),
183  rNamespaceMap, rAttrList );
184  }
185  break;
187  {
188  OUString sValue;
190  rItem, sValue, nMemberId, rUnitConverter ) )
191  {
192  AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
193  sValue, rNamespaceMap, rAttrList );
194  }
195  }
196  break;
197  }
198  }
199  break;
200  }
201 }
202 
205 void SwXMLTableItemMapper_Impl::handleElementItem(
206  const SvXMLItemMapEntry& rEntry,
207  const SfxPoolItem& rItem ) const
208 {
209  switch( rEntry.nWhichId )
210  {
211  case RES_BACKGROUND:
212  {
213  const_cast<SwXMLTableItemMapper_Impl *>(this)->m_aBrushItemExport.exportXML(
214  static_cast<const SvxBrushItem&>(rItem) );
215  }
216  break;
217  }
218 }
219 
220 inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs )
221 {
222  m_nAbsWidth = nAbs;
223 }
224 
226 {
228  util::MeasureUnit::TWIP, GetMM100UnitConverter().GetXMLMeasureUnit(),
230 
234 
235  m_pTableItemMapper.reset(new SwXMLTableItemMapper_Impl( m_xTableItemMap, *this ));
236 }
237 
239 {
240  m_pTableItemMapper.reset();
241  m_pTwipUnitConverter.reset();
242 }
243 
244 void SwXMLExport::ExportTableFormat( const SwFrameFormat& rFormat, sal_uInt32 nAbsWidth )
245 {
246  static_cast<SwXMLTableItemMapper_Impl *>(m_pTableItemMapper.get())
247  ->SetAbsWidth( nAbsWidth );
248  ExportFormat( rFormat, XML_TABLE );
249 }
250 
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< SvxPrintItem > RES_PRINT(98)
std::string GetValue
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:225
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:238
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
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
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
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:244
#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