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 "BorderHandler.hxx"
21 #include "CellColorHandler.hxx"
22 #include "CellMarginHandler.hxx"
23 #include "ConversionHelper.hxx"
24 #include "MeasureHandler.hxx"
25 #include "TrackChangesHandler.hxx"
26 #include "TablePropertiesHandler.hxx"
27 #include "TDefTableHandler.hxx"
28 #include "DomainMapperTableManager.hxx"
30 #include <ooxml/resourceids.hxx>
32 #include <com/sun/star/text/SizeType.hpp>
33 #include <com/sun/star/text/VertOrientation.hpp>
34 #include <oox/token/tokens.hxx>
35 #include "DomainMapper.hxx"
37 using namespace com::sun::star
;
40 namespace writerfilter
{
43 TablePropertiesHandler::TablePropertiesHandler() :
44 m_pCurrentInteropGrabBag(nullptr),
45 m_pTableManager( nullptr )
49 bool TablePropertiesHandler::sprm(Sprm
& rSprm
)
51 #ifdef DEBUG_WRITERFILTER
52 TagLogger::getInstance().startElement("TablePropertiesHandler.sprm");
53 TagLogger::getInstance().attribute("sprm", rSprm
.toString());
57 sal_uInt32 nSprmId
= rSprm
.getId();
58 Value::Pointer_t pValue
= rSprm
.getValue();
59 sal_Int32 nIntValue
= ((pValue
.get() != nullptr) ? pValue
->getInt() : 0);
62 case NS_ooxml::LN_CT_TrPrBase_jc
:
63 case NS_ooxml::LN_CT_TblPrBase_jc
:
65 sal_Int16 nOrient
= ConversionHelper::convertTableJustification( nIntValue
);
66 TablePropertyMapPtr
pTableMap( new TablePropertyMap
);
67 pTableMap
->setValue( TablePropertyMap::HORI_ORIENT
, nOrient
);
68 insertTableProps( pTableMap
);
71 case NS_ooxml::LN_CT_TrPrBase_trHeight
:
73 //contains unit and value
74 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
75 if( pProperties
.get())
76 { //contains attributes x2902 (LN_unit) and x17e2 (LN_trleft)
77 MeasureHandlerPtr
pMeasureHandler( new MeasureHandler
);
78 pProperties
->resolve(*pMeasureHandler
);
79 TablePropertyMapPtr
pPropMap( new TablePropertyMap
);
81 DomainMapperTableManager
* pManager
= dynamic_cast<DomainMapperTableManager
*>(m_pTableManager
);
82 // In case any of the cells has the btLr cell direction, then an explicit minimal size will just hide the whole row, don't do that.
83 const int MINLAY
= 23; // sw/inc/swtypes.hxx, minimal possible size of frames.
84 if (!pManager
|| !pManager
->HasBtlrCell() || pMeasureHandler
->getMeasureValue() > ConversionHelper::convertTwipToMM100(MINLAY
))
86 bool bCantSplit
= false;
87 if (pManager
&& pManager
->getRowProps())
89 boost::optional
<PropertyMap::Property
> oIsSplitAllowed
= pManager
->getRowProps()->getProperty(PROP_IS_SPLIT_ALLOWED
);
90 bCantSplit
= oIsSplitAllowed
&& !oIsSplitAllowed
->second
.get
<bool>();
92 // In case a cell already wanted fixed size and the row has <w:cantSplit/>, we should not overwrite it here.
93 if (!pManager
|| !pManager
->IsRowSizeTypeInserted() || !bCantSplit
)
94 pPropMap
->Insert( PROP_SIZE_TYPE
, uno::makeAny( pMeasureHandler
->GetRowHeightSizeType() ), false);
96 pPropMap
->Insert( PROP_SIZE_TYPE
, uno::makeAny(text::SizeType::FIX
), false);
98 pPropMap
->Insert( PROP_HEIGHT
, uno::makeAny(pMeasureHandler
->getMeasureValue() ));
100 insertRowProps(pPropMap
);
104 case NS_ooxml::LN_CT_TrPr_ins
:
105 case NS_ooxml::LN_CT_TrPr_del
:
107 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
108 if( pProperties
.get())
110 sal_Int32 nToken
= sal_Int32();
113 case NS_ooxml::LN_CT_TrPr_ins
:
114 nToken
= XML_tableRowInsert
;
116 case NS_ooxml::LN_CT_TrPr_del
:
117 nToken
= XML_tableRowDelete
;
120 std::shared_ptr
<TrackChangesHandler
> pTrackChangesHandler( new TrackChangesHandler( nToken
) );
121 pProperties
->resolve(*pTrackChangesHandler
);
122 TablePropertyMapPtr
pPropMap( new TablePropertyMap
);
124 // Add the 'track changes' properties to the 'table row' via UNO.
125 // This way - in the SW core - when it receives this - it will create a new 'Table Redline' object for that row
126 uno::Sequence
<beans::PropertyValue
> aTableRedlineProperties
= pTrackChangesHandler
->getRedlineProperties();
127 pPropMap
->Insert( PROP_TABLE_REDLINE_PARAMS
, uno::makeAny( aTableRedlineProperties
));
128 insertRowProps(pPropMap
);
132 case NS_ooxml::LN_CT_TcPrBase_cellIns
:
133 case NS_ooxml::LN_CT_TcPrBase_cellDel
:
135 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
136 if( pProperties
.get())
141 case NS_ooxml::LN_CT_TcPrBase_cellIns
:
142 nToken
= XML_tableCellInsert
;
144 case NS_ooxml::LN_CT_TcPrBase_cellDel
:
145 nToken
= XML_tableCellDelete
;
148 throw lang::IllegalArgumentException("illegal redline token type", nullptr, 0);
151 std::shared_ptr
<TrackChangesHandler
> pTrackChangesHandler( new TrackChangesHandler( nToken
) );
152 pProperties
->resolve(*pTrackChangesHandler
);
153 TablePropertyMapPtr
pPropMap( new TablePropertyMap
);
155 // Add the 'track changes' properties to the 'table row' via UNO.
156 // This way - in the SW core - when it receives this - it will create a new 'Table Redline' object for that row
157 uno::Sequence
<beans::PropertyValue
> aTableRedlineProperties
= pTrackChangesHandler
->getRedlineProperties();
158 pPropMap
->Insert( PROP_TABLE_REDLINE_PARAMS
, uno::makeAny( aTableRedlineProperties
));
163 case NS_ooxml::LN_CT_TrPrBase_cantSplit
:
165 //row can't break across pages if nIntValue == 1
166 TablePropertyMapPtr
pPropMap( new TablePropertyMap
);
167 pPropMap
->Insert( PROP_IS_SPLIT_ALLOWED
, uno::makeAny( nIntValue
!= 1 ) );
168 insertRowProps(pPropMap
);
171 case NS_ooxml::LN_CT_TcPrBase_vAlign
:
173 sal_Int16 nVertOrient
= text::VertOrientation::NONE
;
176 case NS_ooxml::LN_Value_ST_VerticalJc_center
: nVertOrient
= text::VertOrientation::CENTER
; break;
177 case NS_ooxml::LN_Value_ST_VerticalJc_bottom
: nVertOrient
= text::VertOrientation::BOTTOM
; break;
180 TablePropertyMapPtr
pCellPropMap( new TablePropertyMap() );
181 pCellPropMap
->Insert( PROP_VERT_ORIENT
, uno::makeAny( nVertOrient
) );
182 //todo: in ooxml import the value of m_ncell is wrong
183 cellProps( pCellPropMap
);
184 if (m_pCurrentInteropGrabBag
)
186 OUString aVertOrient
;
189 case NS_ooxml::LN_Value_ST_VerticalJc_top
: aVertOrient
= "top"; break;
190 case NS_ooxml::LN_Value_ST_VerticalJc_center
: aVertOrient
= "center"; break;
191 case NS_ooxml::LN_Value_ST_VerticalJc_both
: aVertOrient
= "both"; break;
192 case NS_ooxml::LN_Value_ST_VerticalJc_bottom
: aVertOrient
= "bottom"; break;
194 if (!aVertOrient
.isEmpty())
196 beans::PropertyValue aValue
;
197 aValue
.Name
= "vAlign";
198 aValue
.Value
<<= aVertOrient
;
199 m_pCurrentInteropGrabBag
->push_back(aValue
);
204 case NS_ooxml::LN_CT_TblPrBase_tblBorders
: //table borders, might be defined in table style
206 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
207 if( pProperties
.get())
209 std::shared_ptr
<BorderHandler
> pBorderHandler(new BorderHandler(true));
210 if (m_pCurrentInteropGrabBag
)
211 pBorderHandler
->enableInteropGrabBag("tblBorders");
212 pProperties
->resolve(*pBorderHandler
);
213 if (m_pCurrentInteropGrabBag
)
214 m_pCurrentInteropGrabBag
->push_back(pBorderHandler
->getInteropGrabBag());
215 TablePropertyMapPtr
pTablePropMap( new TablePropertyMap
);
216 pTablePropMap
->InsertProps(pBorderHandler
->getProperties());
218 #ifdef DEBUG_WRITERFILTER
219 pTablePropMap
->dumpXml();
221 insertTableProps( pTablePropMap
);
225 case NS_ooxml::LN_CT_TblPrBase_tblLayout
:
227 DomainMapperTableManager
* pManager
= dynamic_cast<DomainMapperTableManager
*>(m_pTableManager
);
229 pManager
->SetLayoutType(static_cast<sal_uInt32
>(nIntValue
));
232 case NS_ooxml::LN_CT_TcPrBase_tcBorders
://cell borders
233 //contains CT_TcBorders_left, right, top, bottom
235 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
236 if( pProperties
.get())
238 //in OOXML there's one set of borders at each cell (if there is any)
239 tools::SvRef
< TDefTableHandler
> pTDefTableHandler( new TDefTableHandler());
240 if (m_pCurrentInteropGrabBag
)
241 pTDefTableHandler
->enableInteropGrabBag("tcBorders");
242 pProperties
->resolve( *pTDefTableHandler
);
243 if (m_pCurrentInteropGrabBag
)
244 m_pCurrentInteropGrabBag
->push_back(pTDefTableHandler
->getInteropGrabBag());
245 TablePropertyMapPtr
pCellPropMap( new TablePropertyMap
);
246 pTDefTableHandler
->fillCellProperties( pCellPropMap
);
247 cellProps( pCellPropMap
);
251 case NS_ooxml::LN_CT_TcPrBase_tcMar
:
254 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
255 if (pProperties
.get())
257 std::shared_ptr
<CellMarginHandler
> pCellMarginHandler(new CellMarginHandler
);
258 if (m_pCurrentInteropGrabBag
)
259 pCellMarginHandler
->enableInteropGrabBag("tcMar");
260 pProperties
->resolve(*pCellMarginHandler
);
261 if (m_pCurrentInteropGrabBag
)
262 m_pCurrentInteropGrabBag
->push_back(pCellMarginHandler
->getInteropGrabBag());
263 TablePropertyMapPtr
pCellProperties(new TablePropertyMap
);
264 if (pCellMarginHandler
->m_bTopMarginValid
)
265 pCellProperties
->Insert(PROP_TOP_BORDER_DISTANCE
, uno::makeAny(pCellMarginHandler
->m_nTopMargin
));
266 if (pCellMarginHandler
->m_bLeftMarginValid
)
267 pCellProperties
->Insert(PROP_LEFT_BORDER_DISTANCE
, uno::makeAny(pCellMarginHandler
->m_nLeftMargin
));
268 if (pCellMarginHandler
->m_bBottomMarginValid
)
269 pCellProperties
->Insert(PROP_BOTTOM_BORDER_DISTANCE
, uno::makeAny(pCellMarginHandler
->m_nBottomMargin
));
270 if (pCellMarginHandler
->m_bRightMarginValid
)
271 pCellProperties
->Insert(PROP_RIGHT_BORDER_DISTANCE
, uno::makeAny(pCellMarginHandler
->m_nRightMargin
));
272 cellProps(pCellProperties
);
276 case NS_ooxml::LN_CT_TblPrBase_shd
:
278 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
279 if( pProperties
.get())
281 std::shared_ptr
<CellColorHandler
> pCellColorHandler( new CellColorHandler
);
282 pProperties
->resolve( *pCellColorHandler
);
283 TablePropertyMapPtr
pTablePropMap( new TablePropertyMap
);
284 insertTableProps( pCellColorHandler
->getProperties() );
288 case NS_ooxml::LN_CT_TcPrBase_shd
:
290 // each color sprm contains as much colors as cells are in a row
291 //LN_CT_TcPrBase_shd: cell shading contains: LN_CT_Shd_val, LN_CT_Shd_fill, LN_CT_Shd_color
292 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
293 if( pProperties
.get())
295 std::shared_ptr
<CellColorHandler
> pCellColorHandler( new CellColorHandler
);
296 pCellColorHandler
->enableInteropGrabBag("shd"); //enable to store shd unsupported props in grab bag
297 pProperties
->resolve( *pCellColorHandler
);
298 TablePropertyMapPtr pPropertyMap
= pCellColorHandler
->getProperties();
299 beans::PropertyValue aGrabBag
= pCellColorHandler
->getInteropGrabBag();
300 if (m_pCurrentInteropGrabBag
)
301 m_pCurrentInteropGrabBag
->push_back(aGrabBag
);
302 pPropertyMap
->Insert( PROP_CELL_INTEROP_GRAB_BAG
, aGrabBag
.Value
);
303 cellProps( pPropertyMap
);
307 //OOXML table properties
308 case NS_ooxml::LN_CT_TblPrBase_tblCellMar
: //cell margins
310 //contains LN_CT_TblCellMar_top, LN_CT_TblCellMar_left, LN_CT_TblCellMar_bottom, LN_CT_TblCellMar_right
311 // LN_CT_TblCellMar_start, LN_CT_TblCellMar_end
312 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
313 if( pProperties
.get())
315 std::shared_ptr
<CellMarginHandler
> pCellMarginHandler( new CellMarginHandler
);
316 if (m_pCurrentInteropGrabBag
)
317 pCellMarginHandler
->enableInteropGrabBag("tblCellMar");
318 pProperties
->resolve( *pCellMarginHandler
);
319 if (m_pCurrentInteropGrabBag
)
320 m_pCurrentInteropGrabBag
->push_back(pCellMarginHandler
->getInteropGrabBag());
321 TablePropertyMapPtr
pMarginProps( new TablePropertyMap
);
322 if( pCellMarginHandler
->m_bTopMarginValid
)
323 pMarginProps
->setValue( TablePropertyMap::CELL_MAR_TOP
, pCellMarginHandler
->m_nTopMargin
);
324 if( pCellMarginHandler
->m_bBottomMarginValid
)
325 pMarginProps
->setValue( TablePropertyMap::CELL_MAR_BOTTOM
, pCellMarginHandler
->m_nBottomMargin
);
326 if( pCellMarginHandler
->m_bLeftMarginValid
)
327 pMarginProps
->setValue( TablePropertyMap::CELL_MAR_LEFT
, pCellMarginHandler
->m_nLeftMargin
);
328 if( pCellMarginHandler
->m_bRightMarginValid
)
329 pMarginProps
->setValue( TablePropertyMap::CELL_MAR_RIGHT
, pCellMarginHandler
->m_nRightMargin
);
330 insertTableProps(pMarginProps
);
334 case NS_ooxml::LN_CT_TblPrBase_tblInd
:
336 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
337 if (pProperties
.get())
339 MeasureHandlerPtr
pHandler(new MeasureHandler
);
340 if (m_pCurrentInteropGrabBag
)
341 pHandler
->enableInteropGrabBag("tblInd");
342 pProperties
->resolve( *pHandler
);
343 if (m_pCurrentInteropGrabBag
)
344 m_pCurrentInteropGrabBag
->push_back(pHandler
->getInteropGrabBag());
345 TablePropertyMapPtr
pTblIndMap(new TablePropertyMap
);
346 sal_uInt32 nTblInd
= pHandler
->getMeasureValue();
347 pTblIndMap
->setValue( TablePropertyMap::LEFT_MARGIN
, nTblInd
);
348 insertTableProps(pTblIndMap
);
352 case NS_ooxml::LN_CT_TcPrBase_hideMark
:
355 TablePropertyMapPtr
pPropMap(new TablePropertyMap());
356 pPropMap
->Insert(PROP_CELL_HIDE_MARK
, uno::makeAny(nIntValue
));
361 // Not handled here, give the next handler a chance.
363 // However, these logically belong here, so save the value if necessary.
366 case NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize
:
367 case NS_ooxml::LN_CT_TblPrBase_tblStyleColBandSize
:
368 if (m_pCurrentInteropGrabBag
)
370 beans::PropertyValue aValue
;
371 aValue
.Name
= (nSprmId
== NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize
? OUString("tblStyleRowBandSize") : OUString("tblStyleColBandSize"));
372 aValue
.Value
<<= nIntValue
;
373 m_pCurrentInteropGrabBag
->push_back(aValue
);
380 #ifdef DEBUG_WRITERFILTER
381 TagLogger::getInstance().endElement();
387 void TablePropertiesHandler::SetInteropGrabBag(std::vector
<beans::PropertyValue
>& rValue
)
389 m_pCurrentInteropGrabBag
= &rValue
;
393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */