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 "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"
29 :
30 : #include <ooxml/resourceids.hxx>
31 :
32 : #include <com/sun/star/text/SizeType.hpp>
33 : #include <com/sun/star/text/VertOrientation.hpp>
34 : #include <dmapperLoggers.hxx>
35 : #include <ooxml/OOXMLFastTokens.hxx>
36 :
37 :
38 : namespace writerfilter {
39 : namespace dmapper {
40 :
41 0 : TablePropertiesHandler::TablePropertiesHandler( bool bOOXML ) :
42 : m_pCurrentInteropGrabBag(0),
43 : m_pTableManager( NULL ),
44 0 : m_bOOXML( bOOXML )
45 : {
46 0 : }
47 :
48 :
49 0 : TablePropertiesHandler::~TablePropertiesHandler( )
50 : {
51 : // Do not delete the table manager... this will be done somewhere else
52 0 : m_pTableManager = NULL;
53 0 : }
54 :
55 0 : bool TablePropertiesHandler::sprm(Sprm & rSprm)
56 : {
57 : #ifdef DEBUG_DOMAINMAPPER
58 : dmapper_logger->startElement("TablePropertiesHandler.sprm");
59 : dmapper_logger->attribute("sprm", rSprm.toString());
60 : #endif
61 :
62 0 : bool bRet = true;
63 0 : sal_uInt32 nSprmId = rSprm.getId();
64 0 : Value::Pointer_t pValue = rSprm.getValue();
65 0 : sal_Int32 nIntValue = ((pValue.get() != NULL) ? pValue->getInt() : 0);
66 0 : switch( nSprmId )
67 : {
68 : case NS_ooxml::LN_CT_TrPrBase_jc: //90706
69 : case NS_ooxml::LN_CT_TblPrBase_jc:
70 : case 0x5400: // sprmTJc
71 : {
72 : //table justification 0: left, 1: center, 2: right
73 0 : sal_Int16 nOrient = ConversionHelper::convertTableJustification( nIntValue );
74 0 : TablePropertyMapPtr pTableMap( new TablePropertyMap );
75 0 : pTableMap->setValue( TablePropertyMap::HORI_ORIENT, nOrient );
76 0 : insertTableProps( pTableMap );
77 : }
78 0 : break;
79 : case 0x9601: // sprmTDxaLeft
80 0 : break;
81 : case 0x9602: // sprmTDxaGapHalf
82 : {
83 : //m_nGapHalf = ConversionHelper::convertTwipToMM100( nIntValue );
84 0 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
85 0 : pPropMap->setValue( TablePropertyMap::GAP_HALF, ConversionHelper::convertTwipToMM100( nIntValue ) );
86 0 : insertTableProps(pPropMap);
87 : }
88 0 : break;
89 : case NS_ooxml::LN_CT_TrPrBase_trHeight: //90703
90 : {
91 : //contains unit and value
92 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
93 0 : if( pProperties.get())
94 : { //contains attributes x2902 (LN_unit) and x17e2 (LN_trleft)
95 0 : MeasureHandlerPtr pMeasureHandler( new MeasureHandler );
96 0 : pProperties->resolve(*pMeasureHandler);
97 0 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
98 :
99 0 : DomainMapperTableManager* pManager = dynamic_cast<DomainMapperTableManager*>(m_pTableManager);
100 : // 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.
101 0 : if (pMeasureHandler->GetRowHeightSizeType() != text::SizeType::MIN || !pManager || !pManager->HasBtlrCell())
102 : {
103 : // In case a cell already wanted fixed size, we should not overwrite it here.
104 0 : if (!pManager || !pManager->IsRowSizeTypeInserted())
105 0 : pPropMap->Insert( PROP_SIZE_TYPE, uno::makeAny( pMeasureHandler->GetRowHeightSizeType() ), false);
106 :
107 0 : pPropMap->Insert( PROP_HEIGHT, uno::makeAny(pMeasureHandler->getMeasureValue() ));
108 : }
109 0 : insertRowProps(pPropMap);
110 0 : }
111 : }
112 0 : break;
113 : case NS_ooxml::LN_CT_TrPr_ins:
114 : case NS_ooxml::LN_CT_TrPr_del:
115 : {
116 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
117 0 : if( pProperties.get())
118 : {
119 0 : sal_Int32 nToken = sal_Int32();
120 0 : switch( nSprmId )
121 : {
122 : case NS_ooxml::LN_CT_TrPr_ins:
123 0 : nToken = OOXML_tableRowInsert;
124 0 : break;
125 : case NS_ooxml::LN_CT_TrPr_del:
126 0 : nToken = OOXML_tableRowDelete;
127 0 : break;
128 : };
129 0 : TrackChangesHandlerPtr pTrackChangesHandler( new TrackChangesHandler( nToken ) );
130 0 : pProperties->resolve(*pTrackChangesHandler);
131 0 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
132 :
133 : // Add the 'track changes' properties to the 'table row' via UNO.
134 : // This way - in the SW core - when it receives this - it will create a new 'Table Redline' object for that row
135 0 : uno::Sequence<beans::PropertyValue> aTableRedlineProperties = pTrackChangesHandler->getRedlineProperties();
136 0 : pPropMap->Insert( PROP_TABLE_REDLINE_PARAMS , uno::makeAny( aTableRedlineProperties ));
137 0 : insertRowProps(pPropMap);
138 0 : }
139 : }
140 0 : break;
141 : case NS_ooxml::LN_CT_TcPrBase_cellIns:
142 : case NS_ooxml::LN_CT_TcPrBase_cellDel:
143 : {
144 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
145 0 : if( pProperties.get())
146 : {
147 : sal_Int32 nToken;
148 0 : switch( nSprmId )
149 : {
150 : case NS_ooxml::LN_CT_TcPrBase_cellIns:
151 0 : nToken = OOXML_tableCellInsert;
152 0 : break;
153 : case NS_ooxml::LN_CT_TcPrBase_cellDel:
154 0 : nToken = OOXML_tableCellDelete;
155 0 : break;
156 : default:
157 0 : throw ::com::sun::star::lang::IllegalArgumentException("illegal redline token type", NULL, 0);
158 : break;
159 : };
160 0 : TrackChangesHandlerPtr pTrackChangesHandler( new TrackChangesHandler( nToken ) );
161 0 : pProperties->resolve(*pTrackChangesHandler);
162 0 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
163 :
164 : // Add the 'track changes' properties to the 'table row' via UNO.
165 : // This way - in the SW core - when it receives this - it will create a new 'Table Redline' object for that row
166 0 : uno::Sequence<beans::PropertyValue> aTableRedlineProperties = pTrackChangesHandler->getRedlineProperties();
167 0 : pPropMap->Insert( PROP_TABLE_REDLINE_PARAMS , uno::makeAny( aTableRedlineProperties ));
168 0 : cellProps(pPropMap);
169 0 : }
170 : }
171 0 : break;
172 : case NS_ooxml::LN_CT_TrPrBase_cantSplit:
173 : {
174 : //row can't break across pages if nIntValue == 1
175 0 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
176 0 : pPropMap->Insert( PROP_IS_SPLIT_ALLOWED, uno::makeAny(sal_Bool( nIntValue == 1 ? sal_False : sal_True ) ));
177 0 : insertRowProps(pPropMap);
178 : }
179 0 : break;
180 : case 0x9407: // sprmTDyaRowHeight
181 : {
182 : // table row height - negative values indicate 'exact height' - positive 'at least'
183 0 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
184 0 : bool bMinHeight = true;
185 0 : sal_Int16 nHeight = static_cast<sal_Int16>( nIntValue );
186 0 : if( nHeight < 0 )
187 : {
188 0 : bMinHeight = false;
189 0 : nHeight *= -1;
190 : }
191 0 : pPropMap->Insert( PROP_SIZE_TYPE, uno::makeAny(bMinHeight ? text::SizeType::MIN : text::SizeType::FIX ));
192 0 : pPropMap->Insert( PROP_HEIGHT, uno::makeAny(ConversionHelper::convertTwipToMM100( nHeight )));
193 0 : insertRowProps(pPropMap);
194 : }
195 0 : break;
196 : case NS_ooxml::LN_CT_TcPrBase_vAlign://90694
197 : {
198 0 : sal_Int16 nVertOrient = text::VertOrientation::NONE;
199 0 : switch( nIntValue ) //0 - top 1 - center 3 - bottom (ST_VerticalJc)
200 : {
201 0 : case 1: nVertOrient = text::VertOrientation::CENTER; break;
202 0 : case 3: nVertOrient = text::VertOrientation::BOTTOM; break;
203 : default:;
204 : };
205 0 : TablePropertyMapPtr pCellPropMap( new TablePropertyMap() );
206 0 : pCellPropMap->Insert( PROP_VERT_ORIENT, uno::makeAny( nVertOrient ) );
207 : //todo: in ooxml import the value of m_ncell is wrong
208 0 : cellProps( pCellPropMap );
209 0 : if (m_pCurrentInteropGrabBag)
210 : {
211 0 : OUString aVertOrient;
212 0 : switch( nIntValue )
213 : {
214 0 : case 0: aVertOrient = "top"; break;
215 0 : case 1: aVertOrient = "center"; break;
216 0 : case 2: aVertOrient = "both"; break;
217 0 : case 3: aVertOrient = "bottom"; break;
218 : };
219 0 : if (!aVertOrient.isEmpty())
220 : {
221 0 : beans::PropertyValue aValue;
222 0 : aValue.Name = "vAlign";
223 0 : aValue.Value = uno::makeAny(aVertOrient);
224 0 : m_pCurrentInteropGrabBag->push_back(aValue);
225 0 : }
226 0 : }
227 : }
228 0 : break;
229 : case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style
230 : {
231 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
232 0 : if( pProperties.get())
233 : {
234 0 : BorderHandlerPtr pBorderHandler( new BorderHandler(m_bOOXML) );
235 0 : if (m_pCurrentInteropGrabBag)
236 0 : pBorderHandler->enableInteropGrabBag("tblBorders");
237 0 : pProperties->resolve(*pBorderHandler);
238 0 : if (m_pCurrentInteropGrabBag)
239 0 : m_pCurrentInteropGrabBag->push_back(pBorderHandler->getInteropGrabBag());
240 0 : TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
241 0 : pTablePropMap->InsertProps(pBorderHandler->getProperties());
242 :
243 : #ifdef DEBUG_DOMAINMAPPER
244 : pTablePropMap->dumpXml( dmapper_logger );
245 : #endif
246 0 : insertTableProps( pTablePropMap );
247 0 : }
248 : }
249 0 : break;
250 : case NS_ooxml::LN_CT_TblPrBase_tblLayout:
251 : {
252 0 : DomainMapperTableManager* pManager = dynamic_cast<DomainMapperTableManager*>(m_pTableManager);
253 0 : if (pManager)
254 0 : pManager->SetLayoutType(static_cast<sal_uInt32>(nIntValue));
255 : }
256 0 : break;
257 : case NS_ooxml::LN_CT_TcPrBase_tcBorders ://cell borders
258 : //contains CT_TcBorders_left, right, top, bottom
259 : {
260 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
261 0 : if( pProperties.get())
262 : {
263 : //in OOXML there's one set of borders at each cell (if there is any)
264 0 : TDefTableHandlerPtr pTDefTableHandler( new TDefTableHandler( m_bOOXML ));
265 0 : if (m_pCurrentInteropGrabBag)
266 0 : pTDefTableHandler->enableInteropGrabBag("tcBorders");
267 0 : pProperties->resolve( *pTDefTableHandler );
268 0 : if (m_pCurrentInteropGrabBag)
269 0 : m_pCurrentInteropGrabBag->push_back(pTDefTableHandler->getInteropGrabBag());
270 0 : TablePropertyMapPtr pCellPropMap( new TablePropertyMap );
271 0 : pTDefTableHandler->fillCellProperties( 0, pCellPropMap );
272 0 : cellProps( pCellPropMap );
273 0 : }
274 : }
275 0 : break;
276 : case NS_ooxml::LN_CT_TcPrBase_tcMar:
277 :
278 : {
279 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
280 0 : if (pProperties.get())
281 : {
282 0 : CellMarginHandlerPtr pCellMarginHandler(new CellMarginHandler);
283 0 : if (m_pCurrentInteropGrabBag)
284 0 : pCellMarginHandler->enableInteropGrabBag("tcMar");
285 0 : pProperties->resolve(*pCellMarginHandler);
286 0 : if (m_pCurrentInteropGrabBag)
287 0 : m_pCurrentInteropGrabBag->push_back(pCellMarginHandler->getInteropGrabBag());
288 0 : TablePropertyMapPtr pCellProperties(new TablePropertyMap);
289 0 : if (pCellMarginHandler->m_bTopMarginValid)
290 0 : pCellProperties->Insert(PROP_TOP_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nTopMargin));
291 0 : if (pCellMarginHandler->m_bLeftMarginValid)
292 0 : pCellProperties->Insert(PROP_LEFT_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nLeftMargin));
293 0 : if (pCellMarginHandler->m_bBottomMarginValid)
294 0 : pCellProperties->Insert(PROP_BOTTOM_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nBottomMargin));
295 0 : if (pCellMarginHandler->m_bRightMarginValid)
296 0 : pCellProperties->Insert(PROP_RIGHT_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nRightMargin));
297 0 : cellProps(pCellProperties);
298 0 : }
299 : }
300 0 : break;
301 : case NS_ooxml::LN_CT_TblPrBase_shd:
302 : {
303 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
304 0 : if( pProperties.get())
305 : {
306 0 : CellColorHandlerPtr pCellColorHandler( new CellColorHandler);
307 0 : pProperties->resolve( *pCellColorHandler );
308 0 : TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
309 0 : insertTableProps( pCellColorHandler->getProperties() );
310 0 : }
311 : }
312 0 : break;
313 : case 0xd61a : // sprmTCellTopColor
314 : case 0xd61b : // sprmTCellLeftColor
315 : case 0xd61c : // sprmTCellBottomColor
316 : case 0xd61d : // sprmTCellRightColor
317 : case NS_ooxml::LN_CT_TcPrBase_shd:
318 : {
319 : // each color sprm contains as much colors as cells are in a row
320 : //LN_CT_TcPrBase_shd: cell shading contains: LN_CT_Shd_val, LN_CT_Shd_fill, LN_CT_Shd_color
321 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
322 0 : if( pProperties.get())
323 : {
324 0 : CellColorHandlerPtr pCellColorHandler( new CellColorHandler );
325 0 : pCellColorHandler->enableInteropGrabBag("shd"); //enable to store shd unsupported props in grab bag
326 0 : pProperties->resolve( *pCellColorHandler );
327 0 : beans::PropertyValue aGrabBag = pCellColorHandler->getInteropGrabBag();
328 0 : if (m_pCurrentInteropGrabBag)
329 0 : m_pCurrentInteropGrabBag->push_back(aGrabBag);
330 0 : TablePropertyMapPtr pPropertyMap = pCellColorHandler->getProperties();
331 0 : pPropertyMap->Insert( PROP_CELL_INTEROP_GRAB_BAG, aGrabBag.Value );
332 0 : cellProps( pPropertyMap );
333 0 : }
334 : }
335 0 : break;
336 : //OOXML table properties
337 : case NS_ooxml::LN_CT_TblPrBase_tblCellMar: //cell margins
338 : {
339 : //contains LN_CT_TblCellMar_top, LN_CT_TblCellMar_left, LN_CT_TblCellMar_bottom, LN_CT_TblCellMar_right
340 : // LN_CT_TblCellMar_start, LN_CT_TblCellMar_end
341 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
342 0 : if( pProperties.get())
343 : {
344 0 : CellMarginHandlerPtr pCellMarginHandler( new CellMarginHandler );
345 0 : if (m_pCurrentInteropGrabBag)
346 0 : pCellMarginHandler->enableInteropGrabBag("tblCellMar");
347 0 : pProperties->resolve( *pCellMarginHandler );
348 0 : if (m_pCurrentInteropGrabBag)
349 0 : m_pCurrentInteropGrabBag->push_back(pCellMarginHandler->getInteropGrabBag());
350 0 : TablePropertyMapPtr pMarginProps( new TablePropertyMap );
351 0 : if( pCellMarginHandler->m_bTopMarginValid )
352 0 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_TOP, pCellMarginHandler->m_nTopMargin );
353 0 : if( pCellMarginHandler->m_bBottomMarginValid )
354 0 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_BOTTOM, pCellMarginHandler->m_nBottomMargin );
355 0 : if( pCellMarginHandler->m_bLeftMarginValid )
356 0 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_LEFT, pCellMarginHandler->m_nLeftMargin );
357 0 : if( pCellMarginHandler->m_bRightMarginValid )
358 0 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_RIGHT, pCellMarginHandler->m_nRightMargin );
359 0 : insertTableProps(pMarginProps);
360 0 : }
361 : }
362 0 : break;
363 : case NS_ooxml::LN_CT_TblPrBase_tblInd:
364 : {
365 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
366 0 : if (pProperties.get())
367 : {
368 0 : MeasureHandlerPtr pHandler(new MeasureHandler);
369 0 : if (m_pCurrentInteropGrabBag)
370 0 : pHandler->enableInteropGrabBag("tblInd");
371 0 : pProperties->resolve( *pHandler );
372 0 : if (m_pCurrentInteropGrabBag)
373 0 : m_pCurrentInteropGrabBag->push_back(pHandler->getInteropGrabBag());
374 0 : TablePropertyMapPtr pTblIndMap(new TablePropertyMap);
375 0 : sal_uInt32 nTblInd = pHandler->getMeasureValue();
376 0 : pTblIndMap->setValue( TablePropertyMap::LEFT_MARGIN, nTblInd);
377 0 : insertTableProps(pTblIndMap);
378 0 : }
379 : }
380 0 : break;
381 : default:
382 : // Not handled here, give the next handler a chance.
383 0 : bRet = false;
384 : // However, these logically belong here, so save the value if necessary.
385 0 : switch (nSprmId)
386 : {
387 : case NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize:
388 : case NS_ooxml::LN_CT_TblPrBase_tblStyleColBandSize:
389 0 : if (m_pCurrentInteropGrabBag)
390 : {
391 0 : beans::PropertyValue aValue;
392 0 : aValue.Name = (nSprmId == NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize ? OUString("tblStyleRowBandSize") : OUString("tblStyleColBandSize"));
393 0 : aValue.Value = uno::makeAny(nIntValue);
394 0 : m_pCurrentInteropGrabBag->push_back(aValue);
395 : }
396 0 : break;
397 : }
398 0 : break;
399 : }
400 :
401 : #ifdef DEBUG_DOMAINMAPPER
402 : dmapper_logger->endElement();
403 : #endif
404 :
405 0 : return bRet;
406 : }
407 :
408 0 : void TablePropertiesHandler::SetInteropGrabBag(std::vector<beans::PropertyValue>& rValue)
409 : {
410 0 : m_pCurrentInteropGrabBag = &rValue;
411 0 : }
412 : }}
413 :
414 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|