Branch data 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 : : #include <DomainMapperTableManager.hxx>
20 : : #include <resourcemodel/WW8ResourceModel.hxx>
21 : : #include <BorderHandler.hxx>
22 : : #include <CellColorHandler.hxx>
23 : : #include <CellMarginHandler.hxx>
24 : : #include <ConversionHelper.hxx>
25 : : #include <MeasureHandler.hxx>
26 : : #include <TablePositionHandler.hxx>
27 : : #include <TDefTableHandler.hxx>
28 : : #include <com/sun/star/text/HoriOrientation.hpp>
29 : : #include <com/sun/star/text/SizeType.hpp>
30 : : #include <com/sun/star/text/TableColumnSeparator.hpp>
31 : : #include <com/sun/star/text/VertOrientation.hpp>
32 : : #include <ooxml/resourceids.hxx>
33 : : #include <doctok/sprmids.hxx>
34 : : #include <dmapperLoggers.hxx>
35 : :
36 : : namespace writerfilter {
37 : : namespace dmapper {
38 : :
39 : : using namespace ::com::sun::star;
40 : : using namespace ::std;
41 : :
42 : :
43 : 632 : DomainMapperTableManager::DomainMapperTableManager(bool bOOXML, bool bImplicitMerges) :
44 : : m_nRow(0),
45 : : m_nCell(0),
46 : : m_nGridSpan(1),
47 : : m_nCellBorderIndex(0),
48 : : m_nHeaderRepeat(0),
49 : : m_nTableWidth(0),
50 : : m_bOOXML( bOOXML ),
51 : : m_bImplicitMerges(bImplicitMerges),
52 [ + - ][ + - ]: 632 : m_pTablePropsHandler( new TablePropertiesHandler( bOOXML ) )
[ + - ][ + - ]
[ + - ][ + - ]
53 : : {
54 : 632 : m_pTablePropsHandler->SetTableManager( this );
55 : :
56 : : #ifdef DEBUG_DOMAINMAPPER
57 : : #ifdef DEBUG_TABLE
58 : : setTagLogger(dmapper_logger);
59 : : #endif
60 : : #endif
61 : 632 : }
62 : :
63 : :
64 [ + - ][ + - ]: 632 : DomainMapperTableManager::~DomainMapperTableManager()
65 : : {
66 [ + - ]: 632 : if ( m_pTablePropsHandler )
67 [ + - ][ + - ]: 632 : delete m_pTablePropsHandler, m_pTablePropsHandler = NULL;
68 [ - + ]: 1264 : }
69 : :
70 : :
71 : 60126 : bool DomainMapperTableManager::sprm(Sprm & rSprm)
72 : : {
73 : : #ifdef DEBUG_DOMAINMAPPER
74 : : dmapper_logger->startElement("tablemanager.sprm");
75 : : string sSprm = rSprm.toString();
76 : : dmapper_logger->chars(sSprm);
77 : : dmapper_logger->endElement();
78 : : #endif
79 : 60126 : bool bRet = DomainMapperTableManager_Base_t::sprm(rSprm);
80 [ + + ]: 60126 : if( !bRet )
81 : : {
82 : 58060 : bRet = m_pTablePropsHandler->sprm( rSprm );
83 : : }
84 : :
85 [ + + ]: 60126 : if ( !bRet )
86 : : {
87 : 57403 : bRet = true;
88 [ + - ]: 57403 : sal_uInt32 nSprmId = rSprm.getId();
89 [ + - ][ + - ]: 57403 : Value::Pointer_t pValue = rSprm.getValue();
90 [ + - ][ + - ]: 57403 : sal_Int32 nIntValue = ((pValue.get() != NULL) ? pValue->getInt() : 0);
91 [ + + - - : 57403 : switch ( nSprmId )
- - - - +
+ - - + +
+ - - - -
+ ]
92 : : {
93 : : case 0xf661: //sprmTTRLeft left table indent
94 : : case 0xf614: // sprmTTPreferredWidth - preferred table width
95 : : case NS_ooxml::LN_CT_TblPrBase_tblW: //90722;
96 : : case NS_ooxml::LN_CT_TblPrBase_tblInd: //90725
97 : : {
98 : : //contains unit and value
99 [ + - ]: 102 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
100 [ + - ]: 102 : if( pProperties.get())
101 : : { //contains attributes x2902 (LN_unit) and x17e2 (LN_trleft)
102 [ + - ][ + - ]: 102 : MeasureHandlerPtr pMeasureHandler( new MeasureHandler );
[ + - ]
103 [ + - ]: 102 : pProperties->resolve(*pMeasureHandler);
104 [ + - ][ + - ]: 102 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ + - ]
105 [ + - ][ - + ]: 102 : if( nSprmId == 0xf661 || nSprmId == sal_uInt32(NS_ooxml::LN_CT_TblPrBase_tblInd ))
106 : : {
107 [ # # ][ # # ]: 0 : pPropMap->setValue( TablePropertyMap::LEFT_MARGIN, pMeasureHandler->getMeasureValue() );
108 : : }
109 : : else
110 : : {
111 [ + - ]: 102 : m_nTableWidth = pMeasureHandler->getMeasureValue();
112 [ + + ]: 102 : if( m_nTableWidth )
113 [ + - ]: 70 : pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth );
114 : : }
115 : : #ifdef DEBUG_DOMAINMAPPER
116 : : pPropMap->dumpXml( dmapper_logger );
117 : : #endif
118 [ + - ][ + - ]: 102 : insertTableProps(pPropMap);
[ + - ][ + - ]
[ + - ]
119 [ + - ]: 102 : }
120 : : }
121 : 102 : break;
122 : : case 0x3404:// sprmTTableHeader
123 : : case NS_ooxml::LN_CT_TrPrBase_tblHeader: //90704
124 : : // if nIntValue == 1 then the row is a repeated header line
125 : : // to prevent later rows from increasing the repeating m_nHeaderRepeat is set to NULL when repeating stops
126 [ + - ][ + - ]: 6 : if( nIntValue > 0 && m_nHeaderRepeat >= 0 )
127 : : {
128 : 6 : ++m_nHeaderRepeat;
129 [ + - ][ + - ]: 6 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ + - ]
130 [ + - ][ + - ]: 6 : pPropMap->Insert( PROP_HEADER_ROW_COUNT, false, uno::makeAny( m_nHeaderRepeat ));
131 [ + - ][ + - ]: 6 : insertTableProps(pPropMap);
[ + - ][ + - ]
132 : : }
133 : : else
134 : 0 : m_nHeaderRepeat = -1;
135 : 6 : break;
136 : : case 0xd608: // TDefTable
137 : : {
138 [ # # ]: 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
139 [ # # ]: 0 : if( pProperties.get())
140 : : {
141 [ # # ][ # # ]: 0 : TDefTableHandlerPtr pTDefTableHandler( new TDefTableHandler(m_bOOXML) );
[ # # ]
142 [ # # ]: 0 : pProperties->resolve( *pTDefTableHandler );
143 : :
144 [ # # ][ # # ]: 0 : TablePropertyMapPtr pRowPropMap( new TablePropertyMap );
[ # # ]
145 [ # # ][ # # ]: 0 : pRowPropMap->insert( pTDefTableHandler->getRowProperties() );
[ # # ]
146 [ # # ][ # # ]: 0 : insertRowProps( pRowPropMap );
[ # # ]
147 [ # # ]: 0 : if( !m_nTableWidth )
148 : : {
149 [ # # ]: 0 : m_nTableWidth= pTDefTableHandler->getTableWidth();
150 [ # # ]: 0 : if( m_nTableWidth )
151 : : {
152 [ # # ][ # # ]: 0 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ # # ]
153 [ # # ]: 0 : pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth );
154 [ # # ][ # # ]: 0 : insertTableProps(pPropMap);
[ # # ][ # # ]
155 : : }
156 : : }
157 [ # # ][ # # ]: 0 : for( size_t nCell = 0; nCell < pTDefTableHandler->getCellCount(); ++nCell )
158 : : {
159 [ # # ][ # # ]: 0 : TablePropertyMapPtr pCellPropMap( new TablePropertyMap );
[ # # ]
160 [ # # ][ # # ]: 0 : pTDefTableHandler->fillCellProperties( nCell, pCellPropMap );
[ # # ]
161 [ # # ][ # # ]: 0 : cellPropsByCell( nCell, pCellPropMap );
[ # # ]
162 [ # # ][ # # ]: 0 : }
[ # # ]
163 [ # # ]: 0 : }
164 : : }
165 : 0 : break;
166 : : case 0xD605: // sprmTTableBorders
167 : : {
168 [ # # ]: 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
169 [ # # ]: 0 : if( pProperties.get())
170 : : {
171 [ # # ][ # # ]: 0 : BorderHandlerPtr pBorderHandler( new BorderHandler(m_bOOXML) );
[ # # ]
172 [ # # ]: 0 : pProperties->resolve(*pBorderHandler);
173 [ # # ][ # # ]: 0 : TablePropertyMapPtr pCellPropMap( new TablePropertyMap() );
[ # # ]
174 [ # # ][ # # ]: 0 : pCellPropMap->insert( pBorderHandler->getProperties() );
[ # # ]
175 [ # # ][ # # ]: 0 : cellPropsByCell( m_nCellBorderIndex, pCellPropMap );
[ # # ]
176 [ # # ][ # # ]: 0 : ++m_nCellBorderIndex;
177 [ # # ]: 0 : }
178 : : }
179 : 0 : break;
180 : : case 0xd632 : //sprmTNewSpacing
181 : : case 0xd634 : //sprmTNewSpacing
182 : : //TODO: sprms contain default (TNew) and actual border spacing of cells - not resolvable yet
183 : 0 : break;
184 : : case 0xd613: //sprmTGridLineProps
185 : : // TODO: needs a handler
186 : : /*contains:
187 : : GridLineProps">
188 : : rtf:LINEPROPSTOP
189 : : rtf:LINEPROPSLEFT
190 : : rtf:LINEPROPSBOTTOM
191 : : rtf:LINEPROPSRIGHT
192 : : rtf:LINEPROPSHORIZONTAL
193 : : rtf:LINEPROPSVERTICAL
194 : : rtf:LINECOLOR
195 : : rtf:LINEWIDTH
196 : : rtf:LINETYPE
197 : :
198 : : */
199 : 0 : break;
200 : : case 0x740a : //sprmTTlp
201 : : //TODO: Table look specifier
202 : 0 : break;
203 : : case 0x6816 : //unknown
204 : : case 0x3466 : //unknown
205 : : case 0x3615 : //unknown
206 : : case 0x646b : //unknown - expandable sprm - see ww8scan.cxx
207 : : case 0x7479 : //unknown
208 : : case 0xf617 : //unknown
209 : : case 0xf618 : //unknown
210 : 0 : bRet = false;
211 : 0 : break;
212 : : case NS_ooxml::LN_CT_TblPrBase_tblStyle: //table style name
213 : : {
214 [ + - ]: 36 : m_sTableStyleName = pValue->getString();
215 [ + - ][ + - ]: 36 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ + - ]
216 [ + - ][ + - ]: 36 : pPropMap->Insert( META_PROP_TABLE_STYLE_NAME, false, uno::makeAny( m_sTableStyleName ));
217 [ + - ][ + - ]: 36 : insertTableProps(pPropMap);
[ + - ][ + - ]
218 : : }
219 : 36 : break;
220 : : case NS_ooxml::LN_CT_TblGridBase_gridCol:
221 : : {
222 [ + - ][ + - ]: 489 : getCurrentGrid()->push_back( ConversionHelper::convertTwipToMM100( nIntValue ) );
[ + - ][ + - ]
223 : : }
224 : 489 : break;
225 : : case NS_ooxml::LN_CT_TcPrBase_vMerge : //vertical merge
226 : : {
227 : : // values can be: LN_Value_ST_Merge_restart, LN_Value_ST_Merge_continue, in reality the second one is a 0
228 [ # # ][ # # ]: 0 : TablePropertyMapPtr pMergeProps( new TablePropertyMap );
[ # # ]
229 [ # # ][ # # ]: 0 : pMergeProps->Insert( PROP_VERTICAL_MERGE, false, uno::makeAny( bool( sal::static_int_cast<Id>(nIntValue) == NS_ooxml::LN_Value_ST_Merge_restart )) );
230 [ # # ][ # # ]: 0 : cellProps( pMergeProps);
[ # # ][ # # ]
231 : : }
232 : 0 : break;
233 : : case NS_ooxml::LN_CT_TcPrBase_gridSpan: //number of grid positions spanned by this cell
234 : : {
235 : : #if DEBUG_DOMAINMAPPER
236 : : dmapper_logger->startElement("tablemanager.GridSpan");
237 : : dmapper_logger->attribute("gridSpan", nIntValue);
238 : : dmapper_logger->endElement();
239 : : #endif
240 : 0 : m_nGridSpan = nIntValue;
241 : : }
242 : 0 : break;
243 : : case NS_ooxml::LN_CT_TblPrBase_tblLook:
244 : 36 : break; //todo: table look specifier
245 : : case NS_ooxml::LN_CT_TcPrBase_textDirection:
246 : : {
247 [ + - ][ + - ]: 177 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ + - ]
248 : 177 : const sal_Int16 HORI_LEFT_TOP = 0;
249 : 177 : const sal_Int16 VERT_TOP_RIGHT = 2;
250 : 177 : bool bInsertCellProps = true;
251 [ - - - - : 177 : switch ( nIntValue )
+ ]
252 : : {
253 : : case 1: // tbRl
254 : : // Binary filter takes BiDirection into account ( but I have no idea about that here )
255 : : // or even what it is. But... here's where to handle it if it becomes an issue
256 [ # # ][ # # ]: 0 : pPropMap->Insert( PROP_FRM_DIRECTION, false, uno::makeAny( VERT_TOP_RIGHT ));
257 : : SAL_INFO( "writerfilter", "Have inserted textDirection " << nIntValue );
258 : 0 : break;
259 : : case 3: // btLr
260 : : // We have to fake this text direction
261 [ # # ][ # # ]: 0 : pPropMap->Insert( PROP_FRM_DIRECTION, false, uno::makeAny( HORI_LEFT_TOP ));
262 [ # # ][ # # ]: 0 : pPropMap->Insert( PROP_CHAR_ROTATION, false, uno::makeAny( sal_Int16( 900 ) ));
263 : : SAL_INFO( "writerfilter", "Have inserted textDirection " << nIntValue );
264 : 0 : break;
265 : : case 4: // lrTbV
266 [ # # ][ # # ]: 0 : pPropMap->Insert( PROP_FRM_DIRECTION, false, uno::makeAny( HORI_LEFT_TOP ));
267 : 0 : break;
268 : : case 5: // tbRlV
269 [ # # ][ # # ]: 0 : pPropMap->Insert( PROP_FRM_DIRECTION, false, uno::makeAny( VERT_TOP_RIGHT ));
270 : 0 : break;
271 : : case 0: // lrTb
272 : : case NS_ooxml::LN_Value_ST_TextDirection_tbLrV:
273 : : default:
274 : : // Ignore - we can't handle these
275 : 177 : bInsertCellProps = false;
276 : 177 : break;
277 : : }
278 [ - + ]: 177 : if ( bInsertCellProps )
279 [ # # ][ # # ]: 0 : cellProps( pPropMap );
[ # # ]
280 [ + - ]: 177 : break;
281 : : }
282 : : case NS_ooxml::LN_CT_TcPrBase_tcW:
283 : 229 : break; //fixed column width is not supported
284 : : case NS_ooxml::LN_CT_TrPrBase_cnfStyle:
285 : : {
286 [ # # ][ # # ]: 0 : TablePropertyMapPtr pProps( new TablePropertyMap );
[ # # ]
287 [ # # ][ # # ]: 0 : pProps->Insert( PROP_CNF_STYLE, true, uno::makeAny( pValue->getString( ) ) );
[ # # ]
288 [ # # ][ # # ]: 0 : insertRowProps( pProps );
[ # # ][ # # ]
289 : : }
290 : 0 : break;
291 : : case NS_ooxml::LN_CT_PPrBase_cnfStyle:
292 : : // TODO cnfStyle on a paragraph
293 : 0 : break;
294 : : case NS_ooxml::LN_CT_TcPrBase_cnfStyle:
295 : : {
296 [ # # ][ # # ]: 0 : TablePropertyMapPtr pProps( new TablePropertyMap );
[ # # ]
297 [ # # ][ # # ]: 0 : pProps->Insert( PROP_CNF_STYLE, true, uno::makeAny( pValue->getString( ) ) );
[ # # ]
298 [ # # ][ # # ]: 0 : cellProps( pProps );
[ # # ][ # # ]
299 : : }
300 : 0 : break;
301 : : case NS_ooxml::LN_CT_TblPrBase_tblpPr:
302 : : {
303 [ # # ]: 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
304 [ # # ]: 0 : if (pProperties.get())
305 : : {
306 [ # # ][ # # ]: 0 : TablePositionHandlerPtr pHandler( new TablePositionHandler );
[ # # ]
307 [ # # ]: 0 : pProperties->resolve(*pHandler);
308 [ # # ][ # # ]: 0 : m_sTableVertAnchor = pHandler->getVertAnchor();
309 [ # # ]: 0 : }
310 : : }
311 : 0 : break;
312 : : default:
313 : 56328 : bRet = false;
314 : :
315 : : #ifdef DEBUG_DOMAINMAPPER
316 : : dmapper_logger->element("unhandled");
317 : : #endif
318 [ + - ]: 57403 : }
319 : : }
320 : 60126 : return bRet;
321 : : }
322 : :
323 : 616 : boost::shared_ptr< vector<sal_Int32> > DomainMapperTableManager::getCurrentGrid( )
324 : : {
325 : 616 : return m_aTableGrid.back( );
326 : : }
327 : :
328 : 641 : boost::shared_ptr< vector< sal_Int32 > > DomainMapperTableManager::getCurrentSpans( )
329 : : {
330 : 641 : return m_aGridSpans.back( );
331 : : }
332 : :
333 : 108 : const OUString& DomainMapperTableManager::getTableVertAnchor() const
334 : : {
335 : 108 : return m_sTableVertAnchor;
336 : : }
337 : :
338 : 740 : void DomainMapperTableManager::startLevel( )
339 : : {
340 [ + - ]: 740 : DomainMapperTableManager_Base_t::startLevel( );
341 : :
342 [ + - ][ + - ]: 740 : IntVectorPtr pNewGrid( new vector<sal_Int32> );
[ + - ]
343 [ + - ][ + - ]: 740 : IntVectorPtr pNewSpans( new vector<sal_Int32> );
[ + - ]
344 [ + - ]: 740 : m_aTableGrid.push_back( pNewGrid );
345 [ + - ]: 740 : m_aGridSpans.push_back( pNewSpans );
346 [ + - ][ + - ]: 740 : m_nTableWidth = 0;
347 : 740 : }
348 : :
349 : 740 : void DomainMapperTableManager::endLevel( )
350 : : {
351 : 740 : m_aTableGrid.pop_back( );
352 : 740 : m_aGridSpans.pop_back( );
353 : 740 : m_nTableWidth = 0;
354 : :
355 : 740 : DomainMapperTableManager_Base_t::endLevel( );
356 : : #ifdef DEBUG_DOMAINMAPPER
357 : : dmapper_logger->startElement("dmappertablemanager.endLevel");
358 : : PropertyMapPtr pProps = getTableProps();
359 : : if (pProps.get() != NULL)
360 : : getTableProps()->dumpXml( dmapper_logger );
361 : :
362 : : dmapper_logger->endElement();
363 : : #endif
364 : 740 : }
365 : :
366 : :
367 : :
368 : 514 : void DomainMapperTableManager::endOfCellAction()
369 : : {
370 : : #ifdef DEBUG_DOMAINMAPPER
371 : : dmapper_logger->element("endOFCellAction");
372 : : #endif
373 : :
374 [ + - ][ + - ]: 514 : getCurrentSpans()->push_back(m_nGridSpan);
[ + - ]
375 : 514 : m_nGridSpan = 1;
376 : 514 : ++m_nCell;
377 : 514 : }
378 : :
379 : :
380 : 127 : void DomainMapperTableManager::endOfRowAction()
381 : : {
382 : : #ifdef DEBUG_DOMAINMAPPER
383 : : dmapper_logger->startElement("endOfRowAction");
384 : : #endif
385 : :
386 [ + - ]: 127 : IntVectorPtr pTableGrid = getCurrentGrid( );
387 [ + + ][ + + ]: 127 : if(!m_nTableWidth && pTableGrid->size())
[ + + ]
388 : : {
389 [ + - ]: 32 : ::std::vector<sal_Int32>::const_iterator aCellIter = pTableGrid->begin();
390 : :
391 : : #ifdef DEBUG_DOMAINMAPPER
392 : : dmapper_logger->startElement("tableWidth");
393 : : #endif
394 : :
395 [ + - ][ + + ]: 235 : while( aCellIter != pTableGrid->end() )
396 : : {
397 : : #ifdef DEBUG_DOMAINMAPPER
398 : : dmapper_logger->startElement("col");
399 : : dmapper_logger->attribute("width", *aCellIter);
400 : : dmapper_logger->endElement();
401 : : #endif
402 : :
403 [ + - ][ + - ]: 203 : m_nTableWidth += *aCellIter++;
404 : : }
405 : :
406 [ + - ]: 32 : if( m_nTableWidth > 0)
407 : : {
408 [ + - ][ + - ]: 32 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ + - ]
409 [ + - ]: 32 : pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth );
410 [ + - ][ + - ]: 32 : insertTableProps(pPropMap);
[ + - ][ + - ]
411 : : }
412 : :
413 : : #ifdef DEBUG_DOMAINMAPPER
414 : : dmapper_logger->endElement();
415 : : #endif
416 : : }
417 : :
418 [ + - ]: 127 : IntVectorPtr pCurrentSpans = getCurrentSpans( );
419 [ - + ]: 127 : if( pCurrentSpans->size() < m_nCell)
420 : : {
421 : : //fill missing elements with '1'
422 [ # # ]: 0 : pCurrentSpans->insert( pCurrentSpans->end( ), m_nCell - pCurrentSpans->size(), 1 );
423 : : }
424 : :
425 : : #ifdef DEBUG_DOMAINMAPPER
426 : : dmapper_logger->startElement("gridSpans");
427 : : {
428 : : ::std::vector<sal_Int32>::const_iterator aGridSpanIter = pCurrentSpans->begin();
429 : : ::std::vector<sal_Int32>::const_iterator aGridSpanIterEnd = pCurrentSpans->end();
430 : :
431 : : while (aGridSpanIter != aGridSpanIterEnd)
432 : : {
433 : : dmapper_logger->startElement("gridSpan");
434 : : dmapper_logger->attribute("span", *aGridSpanIter);
435 : : dmapper_logger->endElement();
436 : :
437 : : ++aGridSpanIter;
438 : : }
439 : : }
440 : : dmapper_logger->endElement();
441 : : #endif
442 : :
443 : : //calculate number of used grids - it has to match the size of m_aTableGrid
444 : 127 : size_t nGrids = 0;
445 [ + - ]: 127 : ::std::vector<sal_Int32>::const_iterator aGridSpanIter = pCurrentSpans->begin();
446 [ + - ][ + - ]: 641 : for( ; aGridSpanIter != pCurrentSpans->end(); ++aGridSpanIter)
[ + + ]
447 [ + - ]: 514 : nGrids += *aGridSpanIter;
448 : :
449 : : //determine table width
450 : 127 : double nFullWidth = m_nTableWidth;
451 : : //the positions have to be distibuted in a range of 10000
452 : 127 : const double nFullWidthRelative = 10000.;
453 [ + + ][ + + ]: 127 : if( pTableGrid->size() == nGrids && m_nCell > 0 )
[ + + ]
454 : : {
455 [ + - ]: 82 : uno::Sequence< text::TableColumnSeparator > aSeparators( m_nCell - 1 );
456 [ + - ]: 82 : text::TableColumnSeparator* pSeparators = aSeparators.getArray();
457 : 82 : sal_Int16 nLastRelPos = 0;
458 : 82 : sal_uInt32 nBorderGridIndex = 0;
459 : :
460 [ + - ]: 82 : ::std::vector< sal_Int32 >::const_iterator aSpansIter = pCurrentSpans->begin( );
461 [ + + ]: 436 : for( sal_uInt32 nBorder = 0; nBorder < m_nCell - 1; ++nBorder )
462 : : {
463 [ + - ]: 354 : sal_Int32 nGridCount = *aSpansIter;
464 : 354 : double fGridWidth = 0.;
465 [ - + ]: 354 : do
466 : : {
467 [ + - ]: 354 : fGridWidth += (*pTableGrid.get())[nBorderGridIndex++];
468 : : }while( --nGridCount );
469 : :
470 : : sal_Int16 nRelPos =
471 : 354 : sal::static_int_cast< sal_Int16 >(fGridWidth * nFullWidthRelative / nFullWidth );
472 : :
473 : 354 : pSeparators[nBorder].Position = nRelPos + nLastRelPos;
474 : 354 : pSeparators[nBorder].IsVisible = sal_True;
475 : 354 : nLastRelPos = nLastRelPos + nRelPos;
476 [ + - ]: 354 : ++aSpansIter;
477 : : }
478 [ + - ][ + - ]: 82 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ + - ]
479 [ + - ][ + - ]: 82 : pPropMap->Insert( PROP_TABLE_COLUMN_SEPARATORS, false, uno::makeAny( aSeparators ) );
480 : :
481 : : #ifdef DEBUG_DOMAINMAPPER
482 : : dmapper_logger->startElement("rowProperties");
483 : : pPropMap->dumpXml( dmapper_logger );
484 : : dmapper_logger->endElement();
485 : : #endif
486 [ + - ][ + - ]: 82 : insertRowProps(pPropMap);
[ + - ][ + - ]
[ + - ]
487 : : }
488 [ + - ][ + + ]: 45 : else if (m_bImplicitMerges && pTableGrid->size())
[ + + ]
489 : : {
490 : : // More grid than cells definitions? Then take the last ones.
491 : : // This feature is used by the RTF implicit horizontal cell merges.
492 [ + - ]: 24 : uno::Sequence< text::TableColumnSeparator > aSeparators(m_nCell - 1);
493 [ + - ]: 24 : text::TableColumnSeparator* pSeparators = aSeparators.getArray();
494 : :
495 : 24 : sal_Int16 nSum = 0;
496 : 24 : sal_uInt32 nPos = 0;
497 : 24 : sal_uInt32 nSizeTableGrid = pTableGrid->size();
498 : : // Ignoring the i=0 case means we assume that the width of the last cell matches the table width
499 [ + + ][ + + ]: 51 : for (sal_uInt32 i = m_nCell; i > 1 && nSizeTableGrid >= i; i--)
[ + + ]
500 : : {
501 [ + - ]: 27 : nSum += (*pTableGrid.get())[pTableGrid->size() - i]; // Size of the current cell
502 : 27 : pSeparators[nPos].Position = nSum * nFullWidthRelative / nFullWidth; // Relative position
503 : 27 : pSeparators[nPos].IsVisible = sal_True;
504 : 27 : nPos++;
505 : : }
506 : :
507 [ + - ][ + - ]: 24 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ + - ]
508 [ + - ][ + - ]: 24 : pPropMap->Insert( PROP_TABLE_COLUMN_SEPARATORS, false, uno::makeAny( aSeparators ) );
509 : : #ifdef DEBUG_DOMAINMAPPER
510 : : dmapper_logger->startElement("rowProperties");
511 : : pPropMap->dumpXml( dmapper_logger );
512 : : dmapper_logger->endElement();
513 : : #endif
514 [ + - ][ + - ]: 24 : insertRowProps(pPropMap);
[ + - ][ + - ]
[ + - ]
515 : : }
516 : :
517 : 127 : ++m_nRow;
518 : 127 : m_nCell = 0;
519 : 127 : m_nCellBorderIndex = 0;
520 [ + - ][ + - ]: 127 : pCurrentSpans->clear();
521 : :
522 : : #ifdef DEBUG_DOMAINMAPPER
523 : : dmapper_logger->endElement();
524 : : #endif
525 : 127 : }
526 : :
527 : :
528 : 671 : void DomainMapperTableManager::clearData()
529 : : {
530 : 671 : m_nRow = m_nCell = m_nCellBorderIndex = m_nHeaderRepeat = m_nTableWidth = 0;
531 : 671 : m_sTableStyleName = OUString();
532 : 671 : m_sTableVertAnchor = OUString();
533 : 671 : m_pTableStyleTextProperies.reset();
534 : 671 : }
535 : :
536 : :
537 : 36 : void lcl_CopyTextProperties(PropertyMapPtr pToFill,
538 : : const StyleSheetEntry* pStyleSheetEntry, StyleSheetTablePtr pStyleSheetTable)
539 : : {
540 [ - + ]: 36 : if( !pStyleSheetEntry )
541 : 36 : return;
542 : : //fill base style properties first, recursively
543 [ # # ]: 0 : if( !pStyleSheetEntry->sBaseStyleIdentifier.isEmpty())
544 : : {
545 : : const StyleSheetEntryPtr pParentStyleSheet =
546 [ # # ]: 0 : pStyleSheetTable->FindStyleSheetByISTD(pStyleSheetEntry->sBaseStyleIdentifier);
547 : : OSL_ENSURE( pParentStyleSheet, "table style not found" );
548 [ # # ][ # # ]: 0 : lcl_CopyTextProperties( pToFill, pParentStyleSheet.get( ), pStyleSheetTable);
[ # # ][ # # ]
[ # # ][ # # ]
549 : : }
550 : :
551 : 0 : PropertyMap::const_iterator aPropIter = pStyleSheetEntry->pProperties->begin();
552 [ # # ]: 36 : while(aPropIter != pStyleSheetEntry->pProperties->end())
553 : : {
554 : : //copy all text properties form the table style to the current run attributes
555 [ # # ]: 0 : if( aPropIter->first.bIsTextProperty )
556 [ # # ]: 0 : pToFill->insert(*aPropIter);
557 : 0 : ++aPropIter;
558 : : }
559 : : }
560 : 98 : void DomainMapperTableManager::CopyTextProperties(PropertyMapPtr pContext, StyleSheetTablePtr pStyleSheetTable)
561 : : {
562 [ + + ]: 98 : if( !m_pTableStyleTextProperies.get())
563 : : {
564 [ + - ][ + - ]: 36 : m_pTableStyleTextProperies.reset( new PropertyMap );
[ + - ]
565 : : const StyleSheetEntryPtr pStyleSheetEntry = pStyleSheetTable->FindStyleSheetByISTD(
566 [ + - ]: 36 : m_sTableStyleName);
567 : : OSL_ENSURE( pStyleSheetEntry, "table style not found" );
568 [ + - ][ + - ]: 36 : lcl_CopyTextProperties(m_pTableStyleTextProperies, pStyleSheetEntry.get( ), pStyleSheetTable);
[ + - ][ + - ]
[ + - ][ + - ]
569 : : }
570 [ + - ]: 98 : pContext->insert( m_pTableStyleTextProperies );
571 : 98 : }
572 : :
573 : :
574 [ + - ][ + - ]: 60 : }}
575 : :
576 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|