1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/util/MeasureUnit.hpp>
22 #include <hintids.hxx>
23 #include <rtl/ustring.hxx>
24 #include <rtl/ustrbuf.hxx>
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>
35 #include <editeng/memberids.h>
36 #include <editeng/prntitem.hxx>
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::xmloff::token
;
44 class SwXMLTableItemMapper_Impl
: public SvXMLExportItemMapper
46 SwXMLBrushItemExport m_aBrushItemExport
;
50 sal_uInt32 m_nAbsWidth
;
52 static void AddAttribute( sal_uInt16 nPrefix
, enum XMLTokenEnum eLName
,
53 const OUString
& rValue
,
54 const SvXMLNamespaceMap
& rNamespaceMap
,
55 comphelper::AttributeList
& rAttrList
);
59 SwXMLTableItemMapper_Impl(
60 SvXMLItemMapEntriesRef rMapEntries
,
63 virtual void handleSpecialItem( comphelper::AttributeList
& rAttrList
,
64 const SvXMLItemMapEntry
& rEntry
,
65 const SfxPoolItem
& rItem
,
66 const SvXMLUnitConverter
& rUnitConverter
,
67 const SvXMLNamespaceMap
& rNamespaceMap
,
68 const SfxItemSet
*pSet
) const override
;
70 virtual void handleElementItem(
71 const SvXMLItemMapEntry
& rEntry
,
72 const SfxPoolItem
& rItem
) const override
;
74 inline void SetAbsWidth( sal_uInt32 nAbs
);
79 SwXMLTableItemMapper_Impl::SwXMLTableItemMapper_Impl(
80 SvXMLItemMapEntriesRef rMapEntries
,
82 SvXMLExportItemMapper( std::move(rMapEntries
) ),
83 m_aBrushItemExport( rExp
),
84 m_nAbsWidth( USHRT_MAX
)
88 void SwXMLTableItemMapper_Impl::AddAttribute( sal_uInt16 nPrefix
,
89 enum XMLTokenEnum eLName
,
90 const OUString
& rValue
,
91 const SvXMLNamespaceMap
& rNamespaceMap
,
92 comphelper::AttributeList
& rAttrList
)
94 OUString
sName( rNamespaceMap
.GetQNameByKey( nPrefix
,
95 GetXMLToken(eLName
) ) );
96 rAttrList
.AddAttribute( sName
, rValue
);
99 void SwXMLTableItemMapper_Impl::handleSpecialItem(
100 comphelper::AttributeList
& rAttrList
,
101 const SvXMLItemMapEntry
& rEntry
,
102 const SfxPoolItem
& rItem
,
103 const SvXMLUnitConverter
& rUnitConverter
,
104 const SvXMLNamespaceMap
& rNamespaceMap
,
105 const SfxItemSet
*pSet
) const
107 switch( rEntry
.nWhichId
)
112 const SvxPrintItem
*pItem
;
114 (pItem
= pSet
->GetItemIfSet( RES_PRINT
)) )
116 bool bHasTextChangesOnly
= pItem
->GetValue();
117 if ( !bHasTextChangesOnly
)
120 sal_uInt16 nMemberId
=
121 static_cast<sal_uInt16
>( rEntry
.nMemberId
& MID_SW_FLAG_MASK
);
123 if( SvXMLExportItemMapper::QueryXMLValue(
124 rItem
, sValue
, nMemberId
, rUnitConverter
) )
126 AddAttribute( rEntry
.nNameSpace
, rEntry
.eLocalName
,
127 sValue
, rNamespaceMap
, rAttrList
);
136 const SwFormatHoriOrient
*pItem
;
138 (pItem
= pSet
->GetItemIfSet( RES_HORI_ORIENT
)) )
140 sal_Int16 eHoriOrient
= pItem
->GetHoriOrient();
141 bool bExport
= false;
142 sal_uInt16 nMemberId
=
143 o3tl::narrowing
<sal_uInt16
>( rEntry
.nMemberId
& MID_SW_FLAG_MASK
);
147 bExport
= text::HoriOrientation::NONE
== eHoriOrient
||
148 text::HoriOrientation::LEFT_AND_WIDTH
== eHoriOrient
;
151 bExport
= text::HoriOrientation::NONE
== eHoriOrient
;
155 if( bExport
&& SvXMLExportItemMapper::QueryXMLValue(
156 rItem
, sValue
, nMemberId
, rUnitConverter
) )
158 AddAttribute( rEntry
.nNameSpace
, rEntry
.eLocalName
, sValue
,
159 rNamespaceMap
, rAttrList
);
167 sal_uInt16 nMemberId
=
168 o3tl::narrowing
<sal_uInt16
>( rEntry
.nMemberId
& MID_SW_FLAG_MASK
);
171 case MID_FRMSIZE_WIDTH
:
174 OUStringBuffer sBuffer
;
175 rUnitConverter
.convertMeasureToXML( sBuffer
, m_nAbsWidth
);
176 AddAttribute( rEntry
.nNameSpace
, rEntry
.eLocalName
,
177 sBuffer
.makeStringAndClear(),
178 rNamespaceMap
, rAttrList
);
181 case MID_FRMSIZE_REL_WIDTH
:
184 if( SvXMLExportItemMapper::QueryXMLValue(
185 rItem
, sValue
, nMemberId
, rUnitConverter
) )
187 AddAttribute( rEntry
.nNameSpace
, rEntry
.eLocalName
,
188 sValue
, rNamespaceMap
, rAttrList
);
198 /** this method is called for every item that has the
199 MID_SW_FLAG_ELEMENT_EXPORT flag set */
200 void SwXMLTableItemMapper_Impl::handleElementItem(
201 const SvXMLItemMapEntry
& rEntry
,
202 const SfxPoolItem
& rItem
) const
204 switch( rEntry
.nWhichId
)
208 const_cast<SwXMLTableItemMapper_Impl
*>(this)->m_aBrushItemExport
.exportXML(
209 static_cast<const SvxBrushItem
&>(rItem
) );
215 inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs
)
220 void SwXMLExport::InitItemExport()
222 m_pTwipUnitConverter
.reset(new SvXMLUnitConverter(getComponentContext(),
223 util::MeasureUnit::TWIP
, GetMM100UnitConverter().GetXMLMeasureUnit(),
224 getSaneDefaultVersion()));
226 m_xTableItemMap
= new SvXMLItemMapEntries( aXMLTableItemMap
);
227 m_xTableRowItemMap
= new SvXMLItemMapEntries( aXMLTableRowItemMap
);
228 m_xTableCellItemMap
= new SvXMLItemMapEntries( aXMLTableCellItemMap
);
230 m_pTableItemMapper
.reset(new SwXMLTableItemMapper_Impl( m_xTableItemMap
, *this ));
233 void SwXMLExport::FinitItemExport()
235 m_pTableItemMapper
.reset();
236 m_pTwipUnitConverter
.reset();
239 void SwXMLExport::ExportTableFormat( const SwFrameFormat
& rFormat
, sal_uInt32 nAbsWidth
)
241 static_cast<SwXMLTableItemMapper_Impl
*>(m_pTableItemMapper
.get())
242 ->SetAbsWidth( nAbsWidth
);
243 ExportFormat(rFormat
, XML_TABLE
, {});
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */