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/nmspmap.hxx>
29 #include <xmloff/xmltabe.hxx>
30 #include "xmlbrshe.hxx"
31 #include <editeng/tstpitem.hxx>
32 #include <editeng/brushitem.hxx>
33 #include <tools/fldunit.hxx>
34 #include <swmodule.hxx>
35 #include <doc.hxx>
36 #include <fmtornt.hxx>
37 #include <unomid.h>
38 #include <frmfmt.hxx>
39 #include <fmtfsize.hxx>
40 #include <swrect.hxx>
41 #include "xmlexp.hxx"
42 #include <editeng/memberids.h>
44 
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::uno;
47 using namespace ::xmloff::token;
48 
50 {
52 
53 protected:
54 
55  sal_uInt32 nAbsWidth;
56 
57  static void AddAttribute( sal_uInt16 nPrefix, enum XMLTokenEnum eLName,
58  const OUString& rValue,
59  const SvXMLNamespaceMap& rNamespaceMap,
60  SvXMLAttributeList& rAttrList );
61 
62 public:
63 
65  SvXMLItemMapEntriesRef rMapEntries,
66  SwXMLExport& rExp );
67 
68  virtual void handleSpecialItem( SvXMLAttributeList& rAttrList,
69  const SvXMLItemMapEntry& rEntry,
70  const SfxPoolItem& rItem,
71  const SvXMLUnitConverter& rUnitConverter,
72  const SvXMLNamespaceMap& rNamespaceMap,
73  const SfxItemSet *pSet ) const override;
74 
75  virtual void handleElementItem(
76  SvXMLExport& rExport,
77  const SvXMLItemMapEntry& rEntry,
78  const SfxPoolItem& rItem,
79  const SvXMLUnitConverter& rUnitConverter,
80  const SfxItemSet& rSet,
81  SvXmlExportFlags nFlags ) const override;
82 
83  inline void SetAbsWidth( sal_uInt32 nAbs );
84 };
85 
87  SvXMLItemMapEntriesRef rMapEntries,
88  SwXMLExport& rExp ) :
89  SvXMLExportItemMapper( std::move(rMapEntries) ),
90  aBrushItemExport( rExp ),
91  nAbsWidth( USHRT_MAX )
92 {
93 }
94 
95 void SwXMLTableItemMapper_Impl::AddAttribute( sal_uInt16 nPrefix,
96  enum XMLTokenEnum eLName,
97  const OUString& rValue,
98  const SvXMLNamespaceMap& rNamespaceMap,
99  SvXMLAttributeList& rAttrList )
100 {
101  OUString sName( rNamespaceMap.GetQNameByKey( nPrefix,
102  GetXMLToken(eLName) ) );
103  rAttrList.AddAttribute( sName, rValue );
104 }
105 
107  SvXMLAttributeList& rAttrList,
108  const SvXMLItemMapEntry& rEntry,
109  const SfxPoolItem& rItem,
110  const SvXMLUnitConverter& rUnitConverter,
111  const SvXMLNamespaceMap& rNamespaceMap,
112  const SfxItemSet *pSet ) const
113 {
114  switch( rEntry.nWhichId )
115  {
116  case RES_LR_SPACE:
117  {
118  const SfxPoolItem *pItem;
119  if( pSet &&
120  SfxItemState::SET == pSet->GetItemState( RES_HORI_ORIENT, true,
121  &pItem ) )
122  {
123  sal_Int16 eHoriOrient =
124  static_cast<const SwFormatHoriOrient *>(pItem)->GetHoriOrient();
125  bool bExport = false;
126  sal_uInt16 nMemberId =
127  static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
128  switch( nMemberId )
129  {
130  case MID_L_MARGIN:
131  bExport = text::HoriOrientation::NONE == eHoriOrient ||
132  text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient;
133  break;
134  case MID_R_MARGIN:
135  bExport = text::HoriOrientation::NONE == eHoriOrient;
136  break;
137  }
138  OUString sValue;
140  rItem, sValue, nMemberId, rUnitConverter ) )
141  {
142  AddAttribute( rEntry.nNameSpace, rEntry.eLocalName, sValue,
143  rNamespaceMap, rAttrList );
144  }
145  }
146  }
147  break;
148 
149  case RES_FRM_SIZE:
150  {
151  sal_uInt16 nMemberId =
152  static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
153  switch( nMemberId )
154  {
155  case MID_FRMSIZE_WIDTH:
156  if( nAbsWidth )
157  {
158  OUStringBuffer sBuffer;
159  rUnitConverter.convertMeasureToXML( sBuffer, nAbsWidth );
160  AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
161  sBuffer.makeStringAndClear(),
162  rNamespaceMap, rAttrList );
163  }
164  break;
166  {
167  OUString sValue;
169  rItem, sValue, nMemberId, rUnitConverter ) )
170  {
171  AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
172  sValue, rNamespaceMap, rAttrList );
173  }
174  }
175  break;
176  }
177  }
178  break;
179  }
180 }
181 
185  SvXMLExport& /*rExport*/,
186  const SvXMLItemMapEntry& rEntry,
187  const SfxPoolItem& rItem,
188  const SvXMLUnitConverter& /*rUnitConverter*/,
189  const SfxItemSet&,
190  SvXmlExportFlags ) const
191 {
192  switch( rEntry.nWhichId )
193  {
194  case RES_BACKGROUND:
195  {
197  static_cast<const SvxBrushItem&>(rItem) );
198  }
199  break;
200  }
201 }
202 
203 inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs )
204 {
205  nAbsWidth = nAbs;
206 }
207 
209 {
211  util::MeasureUnit::TWIP, GetMM100UnitConverter().GetXMLMeasureUnit()));
212 
216 
218 }
219 
221 {
222  m_pTableItemMapper.reset();
223  m_pTwipUnitConverter.reset();
224 }
225 
226 void SwXMLExport::ExportTableFormat( const SwFrameFormat& rFormat, sal_uInt32 nAbsWidth )
227 {
228  static_cast<SwXMLTableItemMapper_Impl *>(m_pTableItemMapper.get())
229  ->SetAbsWidth( nAbsWidth );
230  ExportFormat( rFormat, XML_TABLE );
231 }
232 
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define RES_FRM_SIZE
Definition: hintids.hxx:194
void SetAbsWidth(sal_uInt32 nAbs)
Definition: xmliteme.cxx:203
#define RES_HORI_ORIENT
Definition: hintids.hxx:208
SvXMLItemMapEntry const aXMLTableItemMap[]
Definition: xmlitemm.cxx:44
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:208
SvXMLItemMapEntriesRef m_xTableItemMap
Definition: xmlexp.hxx:54
SvXMLItemMapEntriesRef m_xTableCellItemMap
Definition: xmlexp.hxx:56
XML_TABLE
#define MID_SW_FLAG_MASK
Definition: xmlitmap.hxx:28
SwXMLBrushItemExport aBrushItemExport
Definition: xmliteme.cxx:51
this class manages an array of SvXMLItemMapEntry.
Definition: xmlitmap.hxx:65
XMLTokenEnum
void FinitItemExport()
Definition: xmliteme.cxx:220
void ExportFormat(const SwFormat &rFormat, enum::xmloff::token::XMLTokenEnum eClass)
Definition: xmlfmte.cxx:49
#define RES_BACKGROUND
Definition: hintids.hxx:210
#define MID_FRMSIZE_WIDTH
Definition: unomid.h:74
#define MID_L_MARGIN
Style of a layout element.
Definition: frmfmt.hxx:57
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
enum::xmloff::token::XMLTokenEnum const eLocalName
Definition: xmlitmap.hxx:45
OUString sName
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:367
void exportXML(const SvxBrushItem &rItem)
Definition: xmlbrsh.cxx:194
void ExportTableFormat(const SwFrameFormat &rFormat, sal_uInt32 nAbsWidth)
Definition: xmliteme.cxx:226
#define MID_R_MARGIN
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
#define RES_LR_SPACE
Definition: hintids.hxx:196
virtual void handleElementItem(SvXMLExport &rExport, const SvXMLItemMapEntry &rEntry, const SfxPoolItem &rItem, const SvXMLUnitConverter &rUnitConverter, const SfxItemSet &rSet, SvXmlExportFlags nFlags) const override
this method is called for every item that has the MID_SW_FLAG_ELEMENT_EXPORT flag set ...
Definition: xmliteme.cxx:184
static void AddAttribute(sal_uInt16 nPrefix, enum XMLTokenEnum eLName, const OUString &rValue, const SvXMLNamespaceMap &rNamespaceMap, SvXMLAttributeList &rAttrList)
Definition: xmliteme.cxx:95
SvXmlExportFlags
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext()
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
sal_uInt32 const nMemberId
Definition: xmlitmap.hxx:48
SvXMLItemMapEntry const aXMLTableCellItemMap[]
Definition: xmlitemm.cxx:203
void AddAttribute(const OUString &sName, const OUString &sValue)
sal_uInt16 const nNameSpace
Definition: xmlitmap.hxx:41
SwXMLTableItemMapper_Impl(SvXMLItemMapEntriesRef rMapEntries, SwXMLExport &rExp)
Definition: xmliteme.cxx:86
SvXMLItemMapEntry const aXMLTableRowItemMap[]
Definition: xmlitemm.cxx:131
void convertMeasureToXML(OUStringBuffer &rBuffer, sal_Int32 nMeasure) const
virtual void handleSpecialItem(SvXMLAttributeList &rAttrList, const SvXMLItemMapEntry &rEntry, const SfxPoolItem &rItem, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap, const SfxItemSet *pSet) const override
this method is called for every item that has the MID_SW_FLAG_SPECIAL_ITEM_EXPORT flag set ...
Definition: xmliteme.cxx:106
std::unique_ptr< SvXMLExportItemMapper > m_pTableItemMapper
Definition: xmlexp.hxx:51