1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28 #include <hintids.hxx>
29 #include <rtl/ustring.hxx>
30 #include <rtl/ustrbuf.hxx>
31 #include <tools/shl.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include "xmlexpit.hxx"
34 #include <xmloff/nmspmap.hxx>
35 #include <xmloff/xmlnmspe.hxx>
36 #include <xmloff/xmltabe.hxx>
37 #include "xmlbrshe.hxx"
38 #include <editeng/tstpitem.hxx>
39 #include <editeng/brshitem.hxx>
40 #include <tools/fldunit.hxx>
41 #include <swmodule.hxx>
42 #include <doc.hxx>
43 #include "fmtornt.hxx"
44 #include <unomid.h>
45 #include "frmfmt.hxx"
46 #include "fmtfsize.hxx"
47 #include "swrect.hxx"
48 #include "xmlexp.hxx"
49 #include <editeng/memberids.hrc>
50
51 using ::rtl::OUString;
52 using ::rtl::OUStringBuffer;
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::uno;
55 using namespace ::xmloff::token;
56
57 extern SvXMLItemMapEntry aXMLTableItemMap[];
58 extern SvXMLItemMapEntry aXMLTableRowItemMap[];
59 extern SvXMLItemMapEntry aXMLTableCellItemMap[];
60
61
62 class SwXMLTableItemMapper_Impl: public SvXMLExportItemMapper
63 {
64 SwXMLBrushItemExport aBrushItemExport;
65
66 protected:
67
68 sal_uInt32 nAbsWidth;
69
70 void AddAttribute( sal_uInt16 nPrefix, enum XMLTokenEnum eLName,
71 const OUString& rValue,
72 const SvXMLNamespaceMap& rNamespaceMap,
73 SvXMLAttributeList& rAttrList ) const;
74
75 public:
76
77 SwXMLTableItemMapper_Impl(
78 SvXMLItemMapEntriesRef rMapEntries,
79 SwXMLExport& rExp );
80
81 virtual ~SwXMLTableItemMapper_Impl();
82
83 virtual void handleSpecialItem( SvXMLAttributeList& rAttrList,
84 const SvXMLItemMapEntry& rEntry,
85 const SfxPoolItem& rItem,
86 const SvXMLUnitConverter& rUnitConverter,
87 const SvXMLNamespaceMap& rNamespaceMap,
88 const SfxItemSet *pSet = NULL ) const;
89
90 virtual void handleElementItem(
91 SvXMLExport& rExport,
92 const SvXMLItemMapEntry& rEntry,
93 const SfxPoolItem& rItem,
94 const SvXMLUnitConverter& rUnitConverter,
95 const SfxItemSet& rSet,
96 sal_uInt16 nFlags ) const;
97
98 inline void SetAbsWidth( sal_uInt32 nAbs );
99 };
100
SwXMLTableItemMapper_Impl(SvXMLItemMapEntriesRef rMapEntries,SwXMLExport & rExp)101 SwXMLTableItemMapper_Impl::SwXMLTableItemMapper_Impl(
102 SvXMLItemMapEntriesRef rMapEntries,
103 SwXMLExport& rExp ) :
104 SvXMLExportItemMapper( rMapEntries ),
105 aBrushItemExport( rExp ),
106 nAbsWidth( USHRT_MAX )
107 {
108 }
109
~SwXMLTableItemMapper_Impl()110 SwXMLTableItemMapper_Impl::~SwXMLTableItemMapper_Impl()
111 {
112 }
113
AddAttribute(sal_uInt16 nPrefix,enum XMLTokenEnum eLName,const OUString & rValue,const SvXMLNamespaceMap & rNamespaceMap,SvXMLAttributeList & rAttrList) const114 void SwXMLTableItemMapper_Impl::AddAttribute( sal_uInt16 nPrefix,
115 enum XMLTokenEnum eLName,
116 const OUString& rValue,
117 const SvXMLNamespaceMap& rNamespaceMap,
118 SvXMLAttributeList& rAttrList ) const
119 {
120 OUString sName( rNamespaceMap.GetQNameByKey( nPrefix,
121 GetXMLToken(eLName) ) );
122 rAttrList.AddAttribute( sName, rValue );
123 }
124
handleSpecialItem(SvXMLAttributeList & rAttrList,const SvXMLItemMapEntry & rEntry,const SfxPoolItem & rItem,const SvXMLUnitConverter & rUnitConverter,const SvXMLNamespaceMap & rNamespaceMap,const SfxItemSet * pSet) const125 void SwXMLTableItemMapper_Impl::handleSpecialItem(
126 SvXMLAttributeList& rAttrList,
127 const SvXMLItemMapEntry& rEntry,
128 const SfxPoolItem& rItem,
129 const SvXMLUnitConverter& rUnitConverter,
130 const SvXMLNamespaceMap& rNamespaceMap,
131 const SfxItemSet *pSet ) const
132 {
133 switch( rEntry.nWhichId )
134 {
135 case RES_LR_SPACE:
136 {
137 const SfxPoolItem *pItem;
138 if( pSet &&
139 SFX_ITEM_SET == pSet->GetItemState( RES_HORI_ORIENT, sal_True,
140 &pItem ) )
141 {
142 sal_Int16 eHoriOrient =
143 ((const SwFmtHoriOrient *)pItem)->GetHoriOrient();
144 sal_Bool bExport = sal_False;
145 sal_uInt16 nMemberId =
146 static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
147 switch( nMemberId )
148 {
149 case MID_L_MARGIN:
150 bExport = text::HoriOrientation::NONE == eHoriOrient ||
151 text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient;
152 break;
153 case MID_R_MARGIN:
154 bExport = text::HoriOrientation::NONE == eHoriOrient;
155 break;
156 }
157 OUString sValue;
158 if( bExport && SvXMLExportItemMapper::QueryXMLValue(
159 rItem, sValue, nMemberId, rUnitConverter ) )
160 {
161 AddAttribute( rEntry.nNameSpace, rEntry.eLocalName, sValue,
162 rNamespaceMap, rAttrList );
163 }
164 }
165 }
166 break;
167
168 case RES_FRM_SIZE:
169 {
170 sal_uInt16 nMemberId =
171 static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
172 switch( nMemberId )
173 {
174 case MID_FRMSIZE_WIDTH:
175 if( nAbsWidth )
176 {
177 OUStringBuffer sBuffer;
178 rUnitConverter.convertMeasure( sBuffer, nAbsWidth );
179 AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
180 sBuffer.makeStringAndClear(),
181 rNamespaceMap, rAttrList );
182 }
183 break;
184 case MID_FRMSIZE_REL_WIDTH:
185 {
186 OUString sValue;
187 if( SvXMLExportItemMapper::QueryXMLValue(
188 rItem, sValue, nMemberId, rUnitConverter ) )
189 {
190 AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
191 sValue, rNamespaceMap, rAttrList );
192 }
193 }
194 break;
195 }
196 }
197 break;
198 }
199 }
200
201 /** this method is called for every item that has the
202 MID_SW_FLAG_ELEMENT_EXPORT flag set */
handleElementItem(SvXMLExport &,const SvXMLItemMapEntry & rEntry,const SfxPoolItem & rItem,const SvXMLUnitConverter &,const SfxItemSet &,sal_uInt16) const203 void SwXMLTableItemMapper_Impl::handleElementItem(
204 SvXMLExport& /*rExport*/,
205 const SvXMLItemMapEntry& rEntry,
206 const SfxPoolItem& rItem,
207 const SvXMLUnitConverter& /*rUnitConverter*/,
208 const SfxItemSet&,
209 sal_uInt16 ) const
210 {
211 switch( rEntry.nWhichId )
212 {
213 case RES_BACKGROUND:
214 {
215 ((SwXMLTableItemMapper_Impl *)this)->aBrushItemExport.exportXML(
216 (const SvxBrushItem&)rItem );
217 }
218 break;
219 }
220 }
221
SetAbsWidth(sal_uInt32 nAbs)222 inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs )
223 {
224 nAbsWidth = nAbs;
225 }
226
227 // ----------------------------------------------------------------------------
228
_InitItemExport()229 void SwXMLExport::_InitItemExport()
230 {
231 // #110680#
232 pTwipUnitConv = new SvXMLUnitConverter( MAP_TWIP,
233 GetMM100UnitConverter().getXMLMeasureUnit(), getServiceFactory() );
234
235 xTableItemMap = new SvXMLItemMapEntries( aXMLTableItemMap );
236 xTableRowItemMap = new SvXMLItemMapEntries( aXMLTableRowItemMap );
237 xTableCellItemMap = new SvXMLItemMapEntries( aXMLTableCellItemMap );
238
239 pTableItemMapper = new SwXMLTableItemMapper_Impl( xTableItemMap, *this );
240
241 if( getDefaultVersion() > SvtSaveOptions::ODFVER_012 )
242 {
243 _GetNamespaceMap().Add(
244 GetXMLToken(XML_NP_TEXT_EXT),
245 GetXMLToken(XML_N_TEXT_EXT),
246 XML_NAMESPACE_TEXT_EXT);
247 }
248 }
249
_FinitItemExport()250 void SwXMLExport::_FinitItemExport()
251 {
252 delete pTableItemMapper;
253 delete pTwipUnitConv;
254 }
255
ExportTableFmt(const SwFrmFmt & rFmt,sal_uInt32 nAbsWidth)256 void SwXMLExport::ExportTableFmt( const SwFrmFmt& rFmt, sal_uInt32 nAbsWidth )
257 {
258 ((SwXMLTableItemMapper_Impl *)pTableItemMapper)
259 ->SetAbsWidth( nAbsWidth );
260 ExportFmt( rFmt, XML_TABLE );
261 }
262