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 
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::xmloff::token;
40 
41 namespace {
42 
43 class SwXMLTableItemMapper_Impl: public SvXMLExportItemMapper
44 {
45  SwXMLBrushItemExport aBrushItemExport;
46 
47 protected:
48 
49  sal_uInt32 nAbsWidth;
50 
51  static void AddAttribute( sal_uInt16 nPrefix, enum XMLTokenEnum eLName,
52  const OUString& rValue,
53  const SvXMLNamespaceMap& rNamespaceMap,
54  SvXMLAttributeList& rAttrList );
55 
56 public:
57 
58  SwXMLTableItemMapper_Impl(
59  SvXMLItemMapEntriesRef rMapEntries,
60  SwXMLExport& rExp );
61 
62  virtual void handleSpecialItem( SvXMLAttributeList& rAttrList,
63  const SvXMLItemMapEntry& rEntry,
64  const SfxPoolItem& rItem,
65  const SvXMLUnitConverter& rUnitConverter,
66  const SvXMLNamespaceMap& rNamespaceMap,
67  const SfxItemSet *pSet ) const override;
68 
69  virtual void handleElementItem(
70  const SvXMLItemMapEntry& rEntry,
71  const SfxPoolItem& rItem ) const override;
72 
73  inline void SetAbsWidth( sal_uInt32 nAbs );
74 };
75 
76 }
77 
78 SwXMLTableItemMapper_Impl::SwXMLTableItemMapper_Impl(
79  SvXMLItemMapEntriesRef rMapEntries,
80  SwXMLExport& rExp ) :
81  SvXMLExportItemMapper( std::move(rMapEntries) ),
82  aBrushItemExport( rExp ),
83  nAbsWidth( USHRT_MAX )
84 {
85 }
86 
87 void SwXMLTableItemMapper_Impl::AddAttribute( sal_uInt16 nPrefix,
88  enum XMLTokenEnum eLName,
89  const OUString& rValue,
90  const SvXMLNamespaceMap& rNamespaceMap,
91  SvXMLAttributeList& rAttrList )
92 {
93  OUString sName( rNamespaceMap.GetQNameByKey( nPrefix,
94  GetXMLToken(eLName) ) );
95  rAttrList.AddAttribute( sName, rValue );
96 }
97 
98 void SwXMLTableItemMapper_Impl::handleSpecialItem(
99  SvXMLAttributeList& rAttrList,
100  const SvXMLItemMapEntry& rEntry,
101  const SfxPoolItem& rItem,
102  const SvXMLUnitConverter& rUnitConverter,
103  const SvXMLNamespaceMap& rNamespaceMap,
104  const SfxItemSet *pSet ) const
105 {
106  switch( rEntry.nWhichId )
107  {
108  case RES_LR_SPACE:
109  {
110  const SfxPoolItem *pItem;
111  if( pSet &&
112  SfxItemState::SET == pSet->GetItemState( RES_HORI_ORIENT, true,
113  &pItem ) )
114  {
115  sal_Int16 eHoriOrient =
116  static_cast<const SwFormatHoriOrient *>(pItem)->GetHoriOrient();
117  bool bExport = false;
118  sal_uInt16 nMemberId =
119  static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
120  switch( nMemberId )
121  {
122  case MID_L_MARGIN:
123  bExport = text::HoriOrientation::NONE == eHoriOrient ||
124  text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient;
125  break;
126  case MID_R_MARGIN:
127  bExport = text::HoriOrientation::NONE == eHoriOrient;
128  break;
129  }
130  OUString sValue;
132  rItem, sValue, nMemberId, rUnitConverter ) )
133  {
134  AddAttribute( rEntry.nNameSpace, rEntry.eLocalName, sValue,
135  rNamespaceMap, rAttrList );
136  }
137  }
138  }
139  break;
140 
141  case RES_FRM_SIZE:
142  {
143  sal_uInt16 nMemberId =
144  static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
145  switch( nMemberId )
146  {
147  case MID_FRMSIZE_WIDTH:
148  if( nAbsWidth )
149  {
150  OUStringBuffer sBuffer;
151  rUnitConverter.convertMeasureToXML( sBuffer, nAbsWidth );
152  AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
153  sBuffer.makeStringAndClear(),
154  rNamespaceMap, rAttrList );
155  }
156  break;
158  {
159  OUString sValue;
161  rItem, sValue, nMemberId, rUnitConverter ) )
162  {
163  AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
164  sValue, rNamespaceMap, rAttrList );
165  }
166  }
167  break;
168  }
169  }
170  break;
171  }
172 }
173 
176 void SwXMLTableItemMapper_Impl::handleElementItem(
177  const SvXMLItemMapEntry& rEntry,
178  const SfxPoolItem& rItem ) const
179 {
180  switch( rEntry.nWhichId )
181  {
182  case RES_BACKGROUND:
183  {
184  const_cast<SwXMLTableItemMapper_Impl *>(this)->aBrushItemExport.exportXML(
185  static_cast<const SvxBrushItem&>(rItem) );
186  }
187  break;
188  }
189 }
190 
191 inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs )
192 {
193  nAbsWidth = nAbs;
194 }
195 
197 {
199  util::MeasureUnit::TWIP, GetMM100UnitConverter().GetXMLMeasureUnit()));
200 
204 
205  m_pTableItemMapper.reset(new SwXMLTableItemMapper_Impl( m_xTableItemMap, *this ));
206 }
207 
209 {
210  m_pTableItemMapper.reset();
211  m_pTwipUnitConverter.reset();
212 }
213 
214 void SwXMLExport::ExportTableFormat( const SwFrameFormat& rFormat, sal_uInt32 nAbsWidth )
215 {
216  static_cast<SwXMLTableItemMapper_Impl *>(m_pTableItemMapper.get())
217  ->SetAbsWidth( nAbsWidth );
218  ExportFormat( rFormat, XML_TABLE );
219 }
220 
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:322
SvXMLItemMapEntry const aXMLTableItemMap[]
Definition: xmlitemm.cxx:43
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
SvXMLItemMapEntriesRef m_xTableRowItemMap
Definition: xmlexp.hxx:55
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:196
SvXMLItemMapEntriesRef m_xTableItemMap
Definition: xmlexp.hxx:54
SvXMLItemMapEntriesRef m_xTableCellItemMap
Definition: xmlexp.hxx:56
constexpr TypedWhichId< SwFormatHoriOrient > RES_HORI_ORIENT(103)
XML_TABLE
#define MID_SW_FLAG_MASK
Definition: xmlitmap.hxx:28
this class manages an array of SvXMLItemMapEntry.
Definition: xmlitmap.hxx:65
const char * sName
XMLTokenEnum
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:310
void FinitItemExport()
Definition: xmliteme.cxx:208
void ExportFormat(const SwFormat &rFormat, enum::xmloff::token::XMLTokenEnum eClass)
Definition: xmlfmte.cxx:49
#define MID_FRMSIZE_WIDTH
Definition: unomid.h:74
#define MID_L_MARGIN
Style of a layout element.
Definition: frmfmt.hxx:58
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
std::unique_ptr< SvXMLUnitConverter > m_pTwipUnitConverter
Definition: xmlexp.hxx:50
static bool QueryXMLValue(const SfxPoolItem &rItem, OUString &rValue, sal_uInt16 nMemberId, const SvXMLUnitConverter &rUnitConverter)
Definition: xmlexpit.cxx:349
void ExportTableFormat(const SwFrameFormat &rFormat, sal_uInt32 nAbsWidth)
Definition: xmliteme.cxx:214
#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)
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:254
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
sal_uInt16 nNameSpace
Definition: xmlitmap.hxx:41
SvXMLItemMapEntry const aXMLTableCellItemMap[]
Definition: xmlitemm.cxx:202
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:51