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 25519 : TablePropertiesHandler::TablePropertiesHandler( bool bOOXML ) :
42 : m_pCurrentInteropGrabBag(0),
43 : m_pTableManager( NULL ),
44 25519 : m_bOOXML( bOOXML )
45 : {
46 25519 : }
47 :
48 :
49 76557 : TablePropertiesHandler::~TablePropertiesHandler( )
50 : {
51 : // Do not delete the table manager... this will be done somewhere else
52 25519 : m_pTableManager = NULL;
53 51038 : }
54 :
55 308288 : 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 308288 : bool bRet = true;
63 308288 : sal_uInt32 nSprmId = rSprm.getId();
64 308288 : Value::Pointer_t pValue = rSprm.getValue();
65 308288 : sal_Int32 nIntValue = ((pValue.get() != NULL) ? pValue->getInt() : 0);
66 308288 : 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 617 : sal_Int16 nOrient = ConversionHelper::convertTableJustification( nIntValue );
74 617 : TablePropertyMapPtr pTableMap( new TablePropertyMap );
75 617 : pTableMap->setValue( TablePropertyMap::HORI_ORIENT, nOrient );
76 617 : insertTableProps( pTableMap );
77 : }
78 617 : 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 1220 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
93 1220 : if( pProperties.get())
94 : { //contains attributes x2902 (LN_unit) and x17e2 (LN_trleft)
95 1220 : MeasureHandlerPtr pMeasureHandler( new MeasureHandler );
96 1220 : pProperties->resolve(*pMeasureHandler);
97 2440 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
98 :
99 1220 : 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 1220 : 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 1197 : if (!pManager || !pManager->IsRowSizeTypeInserted())
105 1197 : pPropMap->Insert( PROP_SIZE_TYPE, uno::makeAny( pMeasureHandler->GetRowHeightSizeType() ), false);
106 :
107 1197 : pPropMap->Insert( PROP_HEIGHT, uno::makeAny(pMeasureHandler->getMeasureValue() ));
108 : }
109 2440 : insertRowProps(pPropMap);
110 1220 : }
111 : }
112 1220 : break;
113 : case NS_ooxml::LN_CT_TrPr_ins:
114 : case NS_ooxml::LN_CT_TrPr_del:
115 : {
116 28 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
117 28 : if( pProperties.get())
118 : {
119 28 : sal_Int32 nToken = sal_Int32();
120 28 : switch( nSprmId )
121 : {
122 : case NS_ooxml::LN_CT_TrPr_ins:
123 3 : nToken = OOXML_tableRowInsert;
124 3 : break;
125 : case NS_ooxml::LN_CT_TrPr_del:
126 25 : nToken = OOXML_tableRowDelete;
127 25 : break;
128 : };
129 28 : TrackChangesHandlerPtr pTrackChangesHandler( new TrackChangesHandler( nToken ) );
130 28 : pProperties->resolve(*pTrackChangesHandler);
131 56 : 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 56 : uno::Sequence<beans::PropertyValue> aTableRedlineProperties = pTrackChangesHandler->getRedlineProperties();
136 28 : pPropMap->Insert( PROP_TABLE_REDLINE_PARAMS , uno::makeAny( aTableRedlineProperties ));
137 56 : insertRowProps(pPropMap);
138 28 : }
139 : }
140 28 : break;
141 : case NS_ooxml::LN_CT_TcPrBase_cellIns:
142 : case NS_ooxml::LN_CT_TcPrBase_cellDel:
143 : {
144 6 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
145 6 : if( pProperties.get())
146 : {
147 : sal_Int32 nToken;
148 6 : switch( nSprmId )
149 : {
150 : case NS_ooxml::LN_CT_TcPrBase_cellIns:
151 3 : nToken = OOXML_tableCellInsert;
152 3 : break;
153 : case NS_ooxml::LN_CT_TcPrBase_cellDel:
154 3 : nToken = OOXML_tableCellDelete;
155 3 : break;
156 : default:
157 0 : throw ::com::sun::star::lang::IllegalArgumentException("illegal redline token type", NULL, 0);
158 : break;
159 : };
160 6 : TrackChangesHandlerPtr pTrackChangesHandler( new TrackChangesHandler( nToken ) );
161 6 : pProperties->resolve(*pTrackChangesHandler);
162 12 : 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 12 : uno::Sequence<beans::PropertyValue> aTableRedlineProperties = pTrackChangesHandler->getRedlineProperties();
167 6 : pPropMap->Insert( PROP_TABLE_REDLINE_PARAMS , uno::makeAny( aTableRedlineProperties ));
168 12 : cellProps(pPropMap);
169 6 : }
170 : }
171 6 : break;
172 : case NS_ooxml::LN_CT_TrPrBase_cantSplit:
173 : {
174 : //row can't break across pages if nIntValue == 1
175 124 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
176 124 : pPropMap->Insert( PROP_IS_SPLIT_ALLOWED, uno::makeAny(sal_Bool( nIntValue == 1 ? sal_False : sal_True ) ));
177 124 : insertRowProps(pPropMap);
178 : }
179 124 : 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 1855 : sal_Int16 nVertOrient = text::VertOrientation::NONE;
199 1855 : switch( nIntValue ) //0 - top 1 - center 3 - bottom (ST_VerticalJc)
200 : {
201 980 : case 1: nVertOrient = text::VertOrientation::CENTER; break;
202 735 : case 3: nVertOrient = text::VertOrientation::BOTTOM; break;
203 : default:;
204 : };
205 1855 : TablePropertyMapPtr pCellPropMap( new TablePropertyMap() );
206 1855 : pCellPropMap->Insert( PROP_VERT_ORIENT, uno::makeAny( nVertOrient ) );
207 : //todo: in ooxml import the value of m_ncell is wrong
208 1855 : cellProps( pCellPropMap );
209 1855 : if (m_pCurrentInteropGrabBag)
210 : {
211 21 : OUString aVertOrient;
212 21 : switch( nIntValue )
213 : {
214 6 : case 0: aVertOrient = "top"; break;
215 12 : case 1: aVertOrient = "center"; break;
216 0 : case 2: aVertOrient = "both"; break;
217 3 : case 3: aVertOrient = "bottom"; break;
218 : };
219 21 : if (!aVertOrient.isEmpty())
220 : {
221 21 : beans::PropertyValue aValue;
222 21 : aValue.Name = "vAlign";
223 21 : aValue.Value = uno::makeAny(aVertOrient);
224 21 : m_pCurrentInteropGrabBag->push_back(aValue);
225 21 : }
226 1855 : }
227 : }
228 1855 : break;
229 : case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style
230 : {
231 1386 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
232 1386 : if( pProperties.get())
233 : {
234 1386 : BorderHandlerPtr pBorderHandler( new BorderHandler(m_bOOXML) );
235 1386 : if (m_pCurrentInteropGrabBag)
236 367 : pBorderHandler->enableInteropGrabBag("tblBorders");
237 1386 : pProperties->resolve(*pBorderHandler);
238 1386 : if (m_pCurrentInteropGrabBag)
239 367 : m_pCurrentInteropGrabBag->push_back(pBorderHandler->getInteropGrabBag());
240 2772 : TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
241 1386 : pTablePropMap->InsertProps(pBorderHandler->getProperties());
242 :
243 : #ifdef DEBUG_DOMAINMAPPER
244 : pTablePropMap->dumpXml( dmapper_logger );
245 : #endif
246 2772 : insertTableProps( pTablePropMap );
247 1386 : }
248 : }
249 1386 : break;
250 : case NS_ooxml::LN_CT_TblPrBase_tblLayout:
251 : {
252 259 : DomainMapperTableManager* pManager = dynamic_cast<DomainMapperTableManager*>(m_pTableManager);
253 259 : if (pManager)
254 259 : pManager->SetLayoutType(static_cast<sal_uInt32>(nIntValue));
255 : }
256 259 : break;
257 : case NS_ooxml::LN_CT_TcPrBase_tcBorders ://cell borders
258 : //contains CT_TcBorders_left, right, top, bottom
259 : {
260 3891 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
261 3891 : if( pProperties.get())
262 : {
263 : //in OOXML there's one set of borders at each cell (if there is any)
264 3891 : TDefTableHandlerPtr pTDefTableHandler( new TDefTableHandler( m_bOOXML ));
265 3891 : if (m_pCurrentInteropGrabBag)
266 701 : pTDefTableHandler->enableInteropGrabBag("tcBorders");
267 3891 : pProperties->resolve( *pTDefTableHandler );
268 3891 : if (m_pCurrentInteropGrabBag)
269 701 : m_pCurrentInteropGrabBag->push_back(pTDefTableHandler->getInteropGrabBag());
270 7782 : TablePropertyMapPtr pCellPropMap( new TablePropertyMap );
271 3891 : pTDefTableHandler->fillCellProperties( 0, pCellPropMap );
272 7782 : cellProps( pCellPropMap );
273 3891 : }
274 : }
275 3891 : break;
276 : case NS_ooxml::LN_CT_TcPrBase_tcMar:
277 :
278 : {
279 1458 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
280 1458 : if (pProperties.get())
281 : {
282 1458 : CellMarginHandlerPtr pCellMarginHandler(new CellMarginHandler);
283 1458 : if (m_pCurrentInteropGrabBag)
284 15 : pCellMarginHandler->enableInteropGrabBag("tcMar");
285 1458 : pProperties->resolve(*pCellMarginHandler);
286 1458 : if (m_pCurrentInteropGrabBag)
287 15 : m_pCurrentInteropGrabBag->push_back(pCellMarginHandler->getInteropGrabBag());
288 2916 : TablePropertyMapPtr pCellProperties(new TablePropertyMap);
289 1458 : if (pCellMarginHandler->m_bTopMarginValid)
290 413 : pCellProperties->Insert(PROP_TOP_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nTopMargin));
291 1458 : if (pCellMarginHandler->m_bLeftMarginValid)
292 144 : pCellProperties->Insert(PROP_LEFT_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nLeftMargin));
293 1458 : if (pCellMarginHandler->m_bBottomMarginValid)
294 101 : pCellProperties->Insert(PROP_BOTTOM_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nBottomMargin));
295 1458 : if (pCellMarginHandler->m_bRightMarginValid)
296 391 : pCellProperties->Insert(PROP_RIGHT_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nRightMargin));
297 2916 : cellProps(pCellProperties);
298 1458 : }
299 : }
300 1458 : break;
301 : case NS_ooxml::LN_CT_TblPrBase_shd:
302 : {
303 90 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
304 90 : if( pProperties.get())
305 : {
306 90 : CellColorHandlerPtr pCellColorHandler( new CellColorHandler);
307 90 : pProperties->resolve( *pCellColorHandler );
308 180 : TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
309 180 : insertTableProps( pCellColorHandler->getProperties() );
310 90 : }
311 : }
312 90 : 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 2862 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
322 2862 : if( pProperties.get())
323 : {
324 2862 : CellColorHandlerPtr pCellColorHandler( new CellColorHandler );
325 2862 : pCellColorHandler->enableInteropGrabBag("shd"); //enable to store shd unsupported props in grab bag
326 2862 : pProperties->resolve( *pCellColorHandler );
327 5724 : beans::PropertyValue aGrabBag = pCellColorHandler->getInteropGrabBag();
328 2862 : if (m_pCurrentInteropGrabBag)
329 443 : m_pCurrentInteropGrabBag->push_back(aGrabBag);
330 5724 : TablePropertyMapPtr pPropertyMap = pCellColorHandler->getProperties();
331 2862 : pPropertyMap->Insert( PROP_CELL_INTEROP_GRAB_BAG, aGrabBag.Value );
332 5724 : cellProps( pPropertyMap );
333 2862 : }
334 : }
335 2862 : 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 1969 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
342 1969 : if( pProperties.get())
343 : {
344 1969 : CellMarginHandlerPtr pCellMarginHandler( new CellMarginHandler );
345 1969 : if (m_pCurrentInteropGrabBag)
346 1210 : pCellMarginHandler->enableInteropGrabBag("tblCellMar");
347 1969 : pProperties->resolve( *pCellMarginHandler );
348 1969 : if (m_pCurrentInteropGrabBag)
349 1210 : m_pCurrentInteropGrabBag->push_back(pCellMarginHandler->getInteropGrabBag());
350 3938 : TablePropertyMapPtr pMarginProps( new TablePropertyMap );
351 1969 : if( pCellMarginHandler->m_bTopMarginValid )
352 1760 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_TOP, pCellMarginHandler->m_nTopMargin );
353 1969 : if( pCellMarginHandler->m_bBottomMarginValid )
354 1760 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_BOTTOM, pCellMarginHandler->m_nBottomMargin );
355 1969 : if( pCellMarginHandler->m_bLeftMarginValid )
356 1967 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_LEFT, pCellMarginHandler->m_nLeftMargin );
357 1969 : if( pCellMarginHandler->m_bRightMarginValid )
358 1942 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_RIGHT, pCellMarginHandler->m_nRightMargin );
359 3938 : insertTableProps(pMarginProps);
360 1969 : }
361 : }
362 1969 : break;
363 : case NS_ooxml::LN_CT_TblPrBase_tblInd:
364 : {
365 1940 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
366 1940 : if (pProperties.get())
367 : {
368 1940 : MeasureHandlerPtr pHandler(new MeasureHandler);
369 1940 : if (m_pCurrentInteropGrabBag)
370 1213 : pHandler->enableInteropGrabBag("tblInd");
371 1940 : pProperties->resolve( *pHandler );
372 1940 : if (m_pCurrentInteropGrabBag)
373 1213 : m_pCurrentInteropGrabBag->push_back(pHandler->getInteropGrabBag());
374 3880 : TablePropertyMapPtr pTblIndMap(new TablePropertyMap);
375 1940 : sal_uInt32 nTblInd = pHandler->getMeasureValue();
376 1940 : pTblIndMap->setValue( TablePropertyMap::LEFT_MARGIN, nTblInd);
377 3880 : insertTableProps(pTblIndMap);
378 1940 : }
379 : }
380 1940 : break;
381 : default:
382 : // Not handled here, give the next handler a chance.
383 290583 : bRet = false;
384 : // However, these logically belong here, so save the value if necessary.
385 290583 : switch (nSprmId)
386 : {
387 : case NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize:
388 : case NS_ooxml::LN_CT_TblPrBase_tblStyleColBandSize:
389 282 : if (m_pCurrentInteropGrabBag)
390 : {
391 138 : beans::PropertyValue aValue;
392 138 : aValue.Name = (nSprmId == NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize ? OUString("tblStyleRowBandSize") : OUString("tblStyleColBandSize"));
393 138 : aValue.Value = uno::makeAny(nIntValue);
394 138 : m_pCurrentInteropGrabBag->push_back(aValue);
395 : }
396 282 : break;
397 : }
398 290583 : break;
399 : }
400 :
401 : #ifdef DEBUG_DOMAINMAPPER
402 : dmapper_logger->endElement();
403 : #endif
404 :
405 308288 : return bRet;
406 : }
407 :
408 5657 : void TablePropertiesHandler::SetInteropGrabBag(std::vector<beans::PropertyValue>& rValue)
409 : {
410 5657 : m_pCurrentInteropGrabBag = &rValue;
411 5657 : }
412 : }}
413 :
414 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|