Line data Source code
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 <xmloff/xmluconv.hxx>
26 : #include "xmlexpit.hxx"
27 : #include <xmloff/nmspmap.hxx>
28 : #include <xmloff/xmltabe.hxx>
29 : #include "xmlbrshe.hxx"
30 : #include <editeng/tstpitem.hxx>
31 : #include <editeng/brushitem.hxx>
32 : #include <tools/fldunit.hxx>
33 : #include <swmodule.hxx>
34 : #include <doc.hxx>
35 : #include "fmtornt.hxx"
36 : #include <unomid.h>
37 : #include "frmfmt.hxx"
38 : #include "fmtfsize.hxx"
39 : #include "swrect.hxx"
40 : #include "xmlexp.hxx"
41 : #include <editeng/memberids.hrc>
42 : #include <comphelper/processfactory.hxx>
43 :
44 : using namespace ::com::sun::star;
45 : using namespace ::com::sun::star::uno;
46 : using namespace ::xmloff::token;
47 :
48 : extern SvXMLItemMapEntry aXMLTableItemMap[];
49 : extern SvXMLItemMapEntry aXMLTableRowItemMap[];
50 : extern SvXMLItemMapEntry aXMLTableCellItemMap[];
51 :
52 : class SwXMLTableItemMapper_Impl: public SvXMLExportItemMapper
53 : {
54 : SwXMLBrushItemExport aBrushItemExport;
55 :
56 : protected:
57 :
58 : sal_uInt32 nAbsWidth;
59 :
60 : static void AddAttribute( sal_uInt16 nPrefix, enum XMLTokenEnum eLName,
61 : const OUString& rValue,
62 : const SvXMLNamespaceMap& rNamespaceMap,
63 : SvXMLAttributeList& rAttrList );
64 :
65 : public:
66 :
67 : SwXMLTableItemMapper_Impl(
68 : SvXMLItemMapEntriesRef rMapEntries,
69 : SwXMLExport& rExp );
70 :
71 : virtual ~SwXMLTableItemMapper_Impl();
72 :
73 : virtual void handleSpecialItem( SvXMLAttributeList& rAttrList,
74 : const SvXMLItemMapEntry& rEntry,
75 : const SfxPoolItem& rItem,
76 : const SvXMLUnitConverter& rUnitConverter,
77 : const SvXMLNamespaceMap& rNamespaceMap,
78 : const SfxItemSet *pSet = NULL ) const SAL_OVERRIDE;
79 :
80 : virtual void handleElementItem(
81 : SvXMLExport& rExport,
82 : const SvXMLItemMapEntry& rEntry,
83 : const SfxPoolItem& rItem,
84 : const SvXMLUnitConverter& rUnitConverter,
85 : const SfxItemSet& rSet,
86 : SvXmlExportFlags nFlags ) const SAL_OVERRIDE;
87 :
88 : inline void SetAbsWidth( sal_uInt32 nAbs );
89 : };
90 :
91 286 : SwXMLTableItemMapper_Impl::SwXMLTableItemMapper_Impl(
92 : SvXMLItemMapEntriesRef rMapEntries,
93 : SwXMLExport& rExp ) :
94 : SvXMLExportItemMapper( rMapEntries ),
95 : aBrushItemExport( rExp ),
96 286 : nAbsWidth( USHRT_MAX )
97 : {
98 286 : }
99 :
100 572 : SwXMLTableItemMapper_Impl::~SwXMLTableItemMapper_Impl()
101 : {
102 572 : }
103 :
104 24 : void SwXMLTableItemMapper_Impl::AddAttribute( sal_uInt16 nPrefix,
105 : enum XMLTokenEnum eLName,
106 : const OUString& rValue,
107 : const SvXMLNamespaceMap& rNamespaceMap,
108 : SvXMLAttributeList& rAttrList )
109 : {
110 : OUString sName( rNamespaceMap.GetQNameByKey( nPrefix,
111 24 : GetXMLToken(eLName) ) );
112 24 : rAttrList.AddAttribute( sName, rValue );
113 24 : }
114 :
115 88 : void SwXMLTableItemMapper_Impl::handleSpecialItem(
116 : SvXMLAttributeList& rAttrList,
117 : const SvXMLItemMapEntry& rEntry,
118 : const SfxPoolItem& rItem,
119 : const SvXMLUnitConverter& rUnitConverter,
120 : const SvXMLNamespaceMap& rNamespaceMap,
121 : const SfxItemSet *pSet ) const
122 : {
123 88 : switch( rEntry.nWhichId )
124 : {
125 : case RES_LR_SPACE:
126 : {
127 : const SfxPoolItem *pItem;
128 40 : if( pSet &&
129 : SfxItemState::SET == pSet->GetItemState( RES_HORI_ORIENT, true,
130 20 : &pItem ) )
131 : {
132 : sal_Int16 eHoriOrient =
133 20 : static_cast<const SwFormatHoriOrient *>(pItem)->GetHoriOrient();
134 20 : bool bExport = false;
135 : sal_uInt16 nMemberId =
136 20 : static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
137 20 : switch( nMemberId )
138 : {
139 : case MID_L_MARGIN:
140 10 : bExport = text::HoriOrientation::NONE == eHoriOrient ||
141 10 : text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient;
142 10 : break;
143 : case MID_R_MARGIN:
144 10 : bExport = text::HoriOrientation::NONE == eHoriOrient;
145 10 : break;
146 : }
147 20 : OUString sValue;
148 30 : if( bExport && SvXMLExportItemMapper::QueryXMLValue(
149 10 : rItem, sValue, nMemberId, rUnitConverter ) )
150 : {
151 : AddAttribute( rEntry.nNameSpace, rEntry.eLocalName, sValue,
152 10 : rNamespaceMap, rAttrList );
153 20 : }
154 : }
155 : }
156 20 : break;
157 :
158 : case RES_FRM_SIZE:
159 : {
160 : sal_uInt16 nMemberId =
161 28 : static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
162 28 : switch( nMemberId )
163 : {
164 : case MID_FRMSIZE_WIDTH:
165 14 : if( nAbsWidth )
166 : {
167 14 : OUStringBuffer sBuffer;
168 14 : rUnitConverter.convertMeasureToXML( sBuffer, nAbsWidth );
169 : AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
170 : sBuffer.makeStringAndClear(),
171 14 : rNamespaceMap, rAttrList );
172 : }
173 14 : break;
174 : case MID_FRMSIZE_REL_WIDTH:
175 : {
176 14 : OUString sValue;
177 14 : if( SvXMLExportItemMapper::QueryXMLValue(
178 14 : rItem, sValue, nMemberId, rUnitConverter ) )
179 : {
180 : AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
181 0 : sValue, rNamespaceMap, rAttrList );
182 14 : }
183 : }
184 14 : break;
185 : }
186 : }
187 28 : break;
188 : }
189 88 : }
190 :
191 : /** this method is called for every item that has the
192 : MID_SW_FLAG_ELEMENT_EXPORT flag set */
193 10 : void SwXMLTableItemMapper_Impl::handleElementItem(
194 : SvXMLExport& /*rExport*/,
195 : const SvXMLItemMapEntry& rEntry,
196 : const SfxPoolItem& rItem,
197 : const SvXMLUnitConverter& /*rUnitConverter*/,
198 : const SfxItemSet&,
199 : SvXmlExportFlags ) const
200 : {
201 10 : switch( rEntry.nWhichId )
202 : {
203 : case RES_BACKGROUND:
204 : {
205 : const_cast<SwXMLTableItemMapper_Impl *>(this)->aBrushItemExport.exportXML(
206 10 : static_cast<const SvxBrushItem&>(rItem) );
207 : }
208 10 : break;
209 : }
210 10 : }
211 :
212 14 : inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs )
213 : {
214 14 : nAbsWidth = nAbs;
215 14 : }
216 :
217 286 : void SwXMLExport::_InitItemExport()
218 : {
219 : pTwipUnitConv = new SvXMLUnitConverter(getComponentContext(),
220 286 : util::MeasureUnit::TWIP, GetMM100UnitConverter().GetXMLMeasureUnit());
221 :
222 286 : xTableItemMap = new SvXMLItemMapEntries( aXMLTableItemMap );
223 286 : xTableRowItemMap = new SvXMLItemMapEntries( aXMLTableRowItemMap );
224 286 : xTableCellItemMap = new SvXMLItemMapEntries( aXMLTableCellItemMap );
225 :
226 286 : pTableItemMapper = new SwXMLTableItemMapper_Impl( xTableItemMap, *this );
227 286 : }
228 :
229 286 : void SwXMLExport::_FinitItemExport()
230 : {
231 286 : delete pTableItemMapper;
232 286 : delete pTwipUnitConv;
233 286 : }
234 :
235 14 : void SwXMLExport::ExportTableFormat( const SwFrameFormat& rFormat, sal_uInt32 nAbsWidth )
236 : {
237 : static_cast<SwXMLTableItemMapper_Impl *>(pTableItemMapper)
238 14 : ->SetAbsWidth( nAbsWidth );
239 14 : ExportFormat( rFormat, XML_TABLE );
240 191 : }
241 :
242 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|