LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - DomainMapperTableManager.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 345 0.0 %
Date: 2014-04-14 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

          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 <boost/optional.hpp>
      20             : #include <DomainMapperTableManager.hxx>
      21             : #include <resourcemodel/WW8ResourceModel.hxx>
      22             : #include <BorderHandler.hxx>
      23             : #include <CellColorHandler.hxx>
      24             : #include <CellMarginHandler.hxx>
      25             : #include <ConversionHelper.hxx>
      26             : #include <MeasureHandler.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 <com/sun/star/text/WritingMode2.hpp>
      33             : #include <ooxml/resourceids.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           0 : DomainMapperTableManager::DomainMapperTableManager(bool bOOXML) :
      44             :     m_nRow(0),
      45             :     m_nCell(),
      46             :     m_nGridSpan(1),
      47             :     m_nGridBefore(0),
      48             :     m_nGridAfter(0),
      49             :     m_nCellBorderIndex(0),
      50             :     m_nHeaderRepeat(0),
      51             :     m_nTableWidth(0),
      52             :     m_bOOXML( bOOXML ),
      53             :     m_aTmpPosition(),
      54             :     m_aTmpTableProperties(),
      55             :     m_bPushCurrentWidth(false),
      56             :     m_bRowSizeTypeInserted(false),
      57             :     m_bHasBtlrCell(false),
      58             :     m_bTableSizeTypeInserted(false),
      59             :     m_nLayoutType(0),
      60             :     m_nMaxFixedWidth(0),
      61           0 :     m_pTablePropsHandler( new TablePropertiesHandler( bOOXML ) )
      62             : {
      63           0 :     m_pTablePropsHandler->SetTableManager( this );
      64             : 
      65             : #ifdef DEBUG_DOMAINMAPPER
      66             : #ifdef DEBUG_TABLE
      67             :     setTagLogger(dmapper_logger);
      68             : #endif
      69             : #endif
      70           0 : }
      71             : 
      72             : 
      73           0 : DomainMapperTableManager::~DomainMapperTableManager()
      74             : {
      75           0 :     if ( m_pTablePropsHandler )
      76           0 :         delete m_pTablePropsHandler, m_pTablePropsHandler = NULL;
      77           0 : }
      78             : 
      79             : 
      80           0 : bool DomainMapperTableManager::sprm(Sprm & rSprm)
      81             : {
      82             : #ifdef DEBUG_DOMAINMAPPER
      83             :     dmapper_logger->startElement("tablemanager.sprm");
      84             :     string sSprm = rSprm.toString();
      85             :     dmapper_logger->chars(sSprm);
      86             :     dmapper_logger->endElement();
      87             : #endif
      88           0 :     bool bRet = DomainMapperTableManager_Base_t::sprm(rSprm);
      89           0 :     if( !bRet )
      90             :     {
      91           0 :         bRet = m_pTablePropsHandler->sprm( rSprm );
      92             :     }
      93             : 
      94           0 :     if ( !bRet )
      95             :     {
      96           0 :         bRet = true;
      97           0 :         sal_uInt32 nSprmId = rSprm.getId();
      98           0 :         Value::Pointer_t pValue = rSprm.getValue();
      99           0 :         sal_Int32 nIntValue = ((pValue.get() != NULL) ? pValue->getInt() : 0);
     100           0 :         switch ( nSprmId )
     101             :         {
     102             :             case 0xf661: //sprmTTRLeft left table indent
     103             :             case 0xf614: // sprmTTPreferredWidth - preferred table width
     104             :             case NS_ooxml::LN_CT_TblPrBase_tblW:  //90722;
     105             :             case NS_ooxml::LN_CT_TblPrBase_tblInd: //90725
     106             :             {
     107             :                 //contains unit and value
     108           0 :                 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     109           0 :                 if( pProperties.get())
     110             :                 {   //contains attributes x2902 (LN_unit) and x17e2 (LN_trleft)
     111           0 :                     MeasureHandlerPtr pMeasureHandler( new MeasureHandler );
     112           0 :                     pProperties->resolve(*pMeasureHandler);
     113           0 :                     TablePropertyMapPtr pPropMap( new TablePropertyMap );
     114           0 :                     if( nSprmId == 0xf661 || nSprmId == sal_uInt32(NS_ooxml::LN_CT_TblPrBase_tblInd ))
     115             :                     {
     116           0 :                         pPropMap->setValue( TablePropertyMap::LEFT_MARGIN, pMeasureHandler->getMeasureValue() );
     117             :                     }
     118             :                     else
     119             :                     {
     120           0 :                         m_nTableWidth = pMeasureHandler->getMeasureValue();
     121           0 :                         if( m_nTableWidth )
     122             :                         {
     123           0 :                             pPropMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::FIX );
     124           0 :                             pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth );
     125             :                         }
     126           0 :                         else if( sal::static_int_cast<Id>(pMeasureHandler->getUnit()) == NS_ooxml::LN_Value_ST_TblWidth_pct )
     127             :                         {
     128           0 :                             sal_Int32 nPercent = pMeasureHandler->getValue() / 50;
     129           0 :                             if(nPercent > 100)
     130           0 :                                 nPercent = 100;
     131           0 :                             pPropMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::VARIABLE );
     132           0 :                             pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, nPercent );
     133             :                         }
     134           0 :                         else if( sal::static_int_cast<Id>(pMeasureHandler->getUnit()) == NS_ooxml::LN_Value_ST_TblWidth_auto )
     135             :                         {
     136             :                             /*
     137             :                             This attribute specifies the width type of table. This is used as part of the table layout
     138             :                             algorithm specified by the tblLayout element.(See 17.4.64 and 17.4.65 of the ISO/IEC 29500-1:2011.)
     139             :                             If this value is 'auto', the table layout has to use the preferred widths on the table items to generate
     140             :                             the final sizing of the table, but then must use the contents of each cell to determine final column widths.
     141             :                             (See 17.18.87 of the ISO/IEC 29500-1:2011.)
     142             :                             */
     143           0 :                             bool bFixed = true;
     144           0 :                             sal_Int32 nRowFixedWidth = 0;
     145           0 :                             IntVectorPtr pCellWidths = getCurrentCellWidths();
     146             :                             // Step 1. Check whether all cells have fixed widths in the given row of table.
     147           0 :                             for (std::vector<sal_Int32>::const_iterator aValIter = pCellWidths->begin(); aValIter != pCellWidths->end(); ++aValIter)
     148             :                             {
     149           0 :                                 if (*aValIter == -1)
     150             :                                 {
     151           0 :                                     bFixed = false;
     152           0 :                                     break;
     153             :                                 }
     154             :                                 // Sum the width of cells to find the total width of given row
     155           0 :                                 nRowFixedWidth += (*aValIter);
     156             :                             }
     157             : 
     158             :                             // Check whether the total width of given row is compared with the maximum value of rows (m_nMaxFixedWidth).
     159           0 :                             if (bFixed )
     160             :                             {
     161             :                                 // Check if total width
     162           0 :                                 if (m_nMaxFixedWidth < nRowFixedWidth)
     163           0 :                                     m_nMaxFixedWidth = nRowFixedWidth;
     164             : 
     165           0 :                                 pPropMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::FIX );
     166           0 :                                 pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nMaxFixedWidth );
     167             :                             }
     168             :                             else
     169             :                             {
     170             :                                 // Set the width type of table with 'Auto' and set the width value to 100(%)
     171           0 :                                 pPropMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::VARIABLE );
     172           0 :                                 pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, 0 );
     173           0 :                             }
     174             :                         }
     175           0 :                         m_bTableSizeTypeInserted = true;
     176             :                     }
     177             : #ifdef DEBUG_DOMAINMAPPER
     178             :                     pPropMap->dumpXml( dmapper_logger );
     179             : #endif
     180           0 :                     insertTableProps(pPropMap);
     181           0 :                 }
     182             :             }
     183           0 :             break;
     184             :             case 0x3404:// sprmTTableHeader
     185             :             case NS_ooxml::LN_CT_TrPrBase_tblHeader: //90704
     186             :                 // if nIntValue == 1 then the row is a repeated header line
     187             :                 // to prevent later rows from increasing the repeating m_nHeaderRepeat is set to NULL when repeating stops
     188           0 :                 if( nIntValue > 0 && m_nHeaderRepeat >= 0 )
     189             :                 {
     190           0 :                     ++m_nHeaderRepeat;
     191           0 :                     TablePropertyMapPtr pPropMap( new TablePropertyMap );
     192           0 :                     pPropMap->Insert( PROP_HEADER_ROW_COUNT, uno::makeAny( m_nHeaderRepeat ));
     193           0 :                     insertTableProps(pPropMap);
     194             :                 }
     195             :                 else
     196           0 :                     m_nHeaderRepeat = -1;
     197           0 :                 if (nIntValue)
     198             :                 {
     199             :                     // Store the info that this is a header, we'll need that when we apply table styles.
     200           0 :                     TablePropertyMapPtr pPropMap( new TablePropertyMap );
     201           0 :                     pPropMap->Insert( PROP_TBL_HEADER, uno::makeAny(nIntValue));
     202           0 :                     insertRowProps(pPropMap);
     203             :                 }
     204           0 :             break;
     205             :             case 0xd608: // TDefTable
     206             :             {
     207           0 :                 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     208           0 :                 if( pProperties.get())
     209             :                 {
     210           0 :                     TDefTableHandlerPtr pTDefTableHandler( new TDefTableHandler(m_bOOXML) );
     211           0 :                     pProperties->resolve( *pTDefTableHandler );
     212             : 
     213           0 :                     TablePropertyMapPtr pRowPropMap( new TablePropertyMap );
     214           0 :                     pRowPropMap->InsertProps(pTDefTableHandler->getRowProperties());
     215           0 :                     insertRowProps( pRowPropMap );
     216           0 :                     if( !m_nTableWidth )
     217             :                     {
     218           0 :                         m_nTableWidth= pTDefTableHandler->getTableWidth();
     219           0 :                         if( m_nTableWidth )
     220             :                         {
     221           0 :                             TablePropertyMapPtr pPropMap( new TablePropertyMap );
     222           0 :                             pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth );
     223           0 :                             insertTableProps(pPropMap);
     224             :                         }
     225             :                     }
     226           0 :                     for( size_t nCell = 0; nCell < pTDefTableHandler->getCellCount(); ++nCell )
     227             :                     {
     228           0 :                         TablePropertyMapPtr pCellPropMap( new TablePropertyMap );
     229           0 :                         pTDefTableHandler->fillCellProperties( nCell, pCellPropMap );
     230           0 :                         cellPropsByCell( nCell, pCellPropMap );
     231           0 :                     }
     232           0 :                 }
     233             :             }
     234           0 :             break;
     235             :             case 0xD605: // sprmTTableBorders
     236             :             {
     237           0 :                 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     238           0 :                 if( pProperties.get())
     239             :                 {
     240           0 :                     BorderHandlerPtr pBorderHandler( new BorderHandler(m_bOOXML) );
     241           0 :                     pProperties->resolve(*pBorderHandler);
     242           0 :                     TablePropertyMapPtr pCellPropMap( new TablePropertyMap() );
     243           0 :                     pCellPropMap->InsertProps(pBorderHandler->getProperties());
     244           0 :                     cellPropsByCell( m_nCellBorderIndex, pCellPropMap );
     245           0 :                     ++m_nCellBorderIndex;
     246           0 :                 }
     247             :             }
     248           0 :             break;
     249             :             case 0xd632 : //sprmTNewSpacing
     250             :             case 0xd634 : //sprmTNewSpacing
     251             :                 //TODO: sprms contain default (TNew) and actual border spacing of cells - not resolvable yet
     252           0 :             break;
     253             :             case 0xd613: //sprmTGridLineProps
     254             :                 // TODO: needs a handler
     255             :                 /*contains:
     256             :                  GridLineProps">
     257             :                     rtf:LINEPROPSTOP
     258             :                     rtf:LINEPROPSLEFT
     259             :                     rtf:LINEPROPSBOTTOM
     260             :                     rtf:LINEPROPSRIGHT
     261             :                     rtf:LINEPROPSHORIZONTAL
     262             :                     rtf:LINEPROPSVERTICAL
     263             :                         rtf:LINECOLOR
     264             :                         rtf:LINEWIDTH
     265             :                         rtf:LINETYPE
     266             : 
     267             :                 */
     268           0 :             break;
     269             :             case 0x740a : //sprmTTlp
     270             :                 //TODO: Table look specifier
     271           0 :             break;
     272             :             case 0x6816 : //unknown
     273             :             case 0x3466 : //unknown
     274             :             case 0x3615 : //unknown
     275             :             case 0x646b : //unknown - expandable sprm - see ww8scan.cxx
     276             :             case 0x7479 : //unknown
     277             :             case 0xf617 : //unknown
     278             :             case 0xf618 : //unknown
     279           0 :                 bRet = false;
     280           0 :             break;
     281             :             case NS_ooxml::LN_CT_TblPrBase_tblStyle: //table style name
     282             :             {
     283           0 :                 m_sTableStyleName = pValue->getString();
     284           0 :                 TablePropertyMapPtr pPropMap( new TablePropertyMap );
     285           0 :                 pPropMap->Insert( META_PROP_TABLE_STYLE_NAME, uno::makeAny( m_sTableStyleName ));
     286           0 :                 insertTableProps(pPropMap);
     287             :             }
     288           0 :             break;
     289             :             case NS_ooxml::LN_CT_TblGridBase_gridCol:
     290             :             {
     291           0 :                 if (nIntValue == -1)
     292           0 :                     getCurrentGrid()->clear();
     293             :                 else
     294           0 :                     getCurrentGrid()->push_back( ConversionHelper::convertTwipToMM100( nIntValue ) );
     295             :             }
     296           0 :             break;
     297             :             case NS_ooxml::LN_CT_TcPrBase_vMerge : //vertical merge
     298             :             {
     299             :                 // values can be: LN_Value_ST_Merge_restart, LN_Value_ST_Merge_continue, in reality the second one is a 0
     300           0 :                 TablePropertyMapPtr pMergeProps( new TablePropertyMap );
     301           0 :                 pMergeProps->Insert( PROP_VERTICAL_MERGE, uno::makeAny( bool( sal::static_int_cast<Id>(nIntValue) == NS_ooxml::LN_Value_ST_Merge_restart )) );
     302           0 :                 cellProps( pMergeProps);
     303             :             }
     304           0 :             break;
     305             :             case NS_ooxml::LN_CT_TcPrBase_hMerge:
     306             :             {
     307             :                 // values can be: LN_Value_ST_Merge_restart, LN_Value_ST_Merge_continue, in reality the second one is a 0
     308           0 :                 TablePropertyMapPtr pMergeProps(new TablePropertyMap());
     309           0 :                 pMergeProps->Insert(PROP_HORIZONTAL_MERGE, uno::makeAny(bool(sal::static_int_cast<Id>(nIntValue) == NS_ooxml::LN_Value_ST_Merge_restart)));
     310           0 :                 cellProps(pMergeProps);
     311             :             }
     312           0 :             break;
     313             :             case NS_ooxml::LN_CT_TcPrBase_gridSpan: //number of grid positions spanned by this cell
     314             :             {
     315             : #ifdef DEBUG_DOMAINMAPPER
     316             :                 dmapper_logger->startElement("tablemanager.GridSpan");
     317             :                 dmapper_logger->attribute("gridSpan", nIntValue);
     318             :                 dmapper_logger->endElement();
     319             : #endif
     320           0 :                 m_nGridSpan = nIntValue;
     321             :             }
     322           0 :             break;
     323             :             case NS_ooxml::LN_CT_TblPrBase_tblLook:
     324             :             {
     325           0 :                 TablePropertyMapPtr pPropMap( new TablePropertyMap );
     326           0 :                 pPropMap->Insert( PROP_TBL_LOOK, uno::makeAny( nIntValue ));
     327           0 :                 insertTableProps(pPropMap);
     328             :             }
     329           0 :             break;
     330             :             case NS_ooxml::LN_CT_TcPrBase_textDirection:
     331             :             {
     332           0 :                 TablePropertyMapPtr pPropMap( new TablePropertyMap );
     333           0 :                 bool bInsertCellProps = true;
     334           0 :                 switch ( nIntValue )
     335             :                 {
     336             :                     case 1:  // tbRl
     337             :                     // Binary filter takes BiDirection into account ( but I have no idea about that here )
     338             :                     // or even what it is. But... here's where to handle it if it becomes an issue
     339           0 :                         pPropMap->Insert( PROP_FRM_DIRECTION, uno::makeAny( text::WritingMode2::TB_RL ));
     340             :                         SAL_INFO( "writerfilter", "Have inserted textDirection " << nIntValue );
     341           0 :                         break;
     342             :                     case 3:  // btLr
     343             :                         {
     344             :                         // We have to fake this text direction
     345           0 :                          pPropMap->Insert( PROP_FRM_DIRECTION, uno::makeAny( text::WritingMode2::LR_TB ));
     346           0 :                          pPropMap->Insert( PROP_CHAR_ROTATION, uno::makeAny( sal_Int16( 900 ) ));
     347             :                         SAL_INFO( "writerfilter", "Have inserted textDirection " << nIntValue );
     348             : 
     349             :                         // We're faking a text direction, so don't allow multiple lines.
     350           0 :                         if (!getCellProps() || getCellProps()->find(PROP_VERTICAL_MERGE) == getCellProps()->end())
     351             :                         {
     352             :                             // Though in case there will be a vertical merge, don't do this, it hides text that is supposed to be visible.
     353           0 :                             TablePropertyMapPtr pRowPropMap( new TablePropertyMap );
     354           0 :                             pRowPropMap->Insert(PROP_SIZE_TYPE, uno::makeAny(text::SizeType::FIX));
     355           0 :                             m_bRowSizeTypeInserted = true;
     356           0 :                             insertRowProps(pRowPropMap);
     357             :                         }
     358           0 :                         m_bHasBtlrCell = true;
     359             :                         }
     360           0 :                         break;
     361             :                     case 4: // lrTbV
     362           0 :                         pPropMap->Insert( PROP_FRM_DIRECTION, uno::makeAny( text::WritingMode2::LR_TB ));
     363           0 :                         break;
     364             :                     case 5: // tbRlV
     365           0 :                         pPropMap->Insert( PROP_FRM_DIRECTION, uno::makeAny( text::WritingMode2::TB_RL ));
     366           0 :                         break;
     367             :                     case 0: // lrTb
     368             :                     case NS_ooxml::LN_Value_ST_TextDirection_tbLrV:
     369             :                     default:
     370             :                        // Ignore - we can't handle these
     371           0 :                        bInsertCellProps = false;
     372           0 :                        break;
     373             :                 }
     374           0 :                 if ( bInsertCellProps )
     375           0 :                     cellProps( pPropMap );
     376           0 :                 break;
     377             :             }
     378             :             case NS_ooxml::LN_CT_TcPrBase_tcW:
     379             :                 {
     380             :                     // Contains unit and value, but unit is not interesting for
     381             :                     // us, later we'll just distribute these values in a
     382             :                     // 0..10000 scale.
     383           0 :                     writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     384           0 :                     if( pProperties.get())
     385             :                     {
     386           0 :                         MeasureHandlerPtr pMeasureHandler(new MeasureHandler());
     387           0 :                         pProperties->resolve(*pMeasureHandler);
     388           0 :                         if (sal::static_int_cast<Id>(pMeasureHandler->getUnit()) == NS_ooxml::LN_Value_ST_TblWidth_auto)
     389           0 :                             getCurrentCellWidths()->push_back(sal_Int32(-1));
     390             :                         else
     391           0 :                             getCurrentCellWidths()->push_back(pMeasureHandler->getMeasureValue());
     392           0 :                         if (getTableDepthDifference() > 0)
     393           0 :                             m_bPushCurrentWidth = true;
     394           0 :                     }
     395             :                 }
     396           0 :                 break;
     397             :             case NS_ooxml::LN_CT_TrPrBase_cnfStyle:
     398           0 :                 break;  // the cnfStyle doesn't matter, instead the tblLook property is used to specify conditional styles that are to be used
     399             :             case NS_ooxml::LN_CT_PPrBase_cnfStyle:
     400             :                 // TODO cnfStyle on a paragraph
     401           0 :                 break;
     402             :             case NS_ooxml::LN_CT_TcPrBase_cnfStyle:
     403           0 :                 break;  // the cnfStyle doesn't matter, instead the tblLook property is used to specify conditional styles that are to be used
     404             :             case NS_ooxml::LN_CT_TblPrBase_tblpPr:
     405             :                 {
     406           0 :                     writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
     407           0 :                     if (pProperties.get())
     408             :                     {
     409           0 :                         TablePositionHandlerPtr pHandler = m_aTmpPosition.back();
     410           0 :                         if ( !pHandler )
     411             :                         {
     412           0 :                             m_aTmpPosition.pop_back();
     413           0 :                             pHandler.reset( new TablePositionHandler );
     414           0 :                             m_aTmpPosition.push_back( pHandler );
     415             :                         }
     416           0 :                         pProperties->resolve(*m_aTmpPosition.back());
     417           0 :                     }
     418             :                 }
     419           0 :                 break;
     420             :             case NS_ooxml::LN_CT_TrPrBase_gridBefore:
     421           0 :                 m_nGridBefore = nIntValue;
     422           0 :                 break;
     423             :             case NS_ooxml::LN_CT_TrPrBase_gridAfter:
     424           0 :                 m_nGridAfter = nIntValue;
     425           0 :                 break;
     426             :             default:
     427           0 :                 bRet = false;
     428             : 
     429             : #ifdef DEBUG_DOMAINMAPPER
     430             :                 dmapper_logger->element("unhandled");
     431             : #endif
     432           0 :         }
     433             :     }
     434           0 :     return bRet;
     435             : }
     436             : 
     437           0 : boost::shared_ptr< vector<sal_Int32> > DomainMapperTableManager::getCurrentGrid( )
     438             : {
     439           0 :     return m_aTableGrid.back( );
     440             : }
     441             : 
     442           0 : boost::shared_ptr< vector< sal_Int32 > > DomainMapperTableManager::getCurrentSpans( )
     443             : {
     444           0 :     return m_aGridSpans.back( );
     445             : }
     446             : 
     447           0 : boost::shared_ptr< vector< sal_Int32 > > DomainMapperTableManager::getCurrentCellWidths( )
     448             : {
     449           0 :     return m_aCellWidths.back( );
     450             : }
     451             : 
     452           0 : const uno::Sequence<beans::PropertyValue> DomainMapperTableManager::getCurrentTablePosition( )
     453             : {
     454           0 :     if ( !m_aTablePositions.empty( ) && m_aTablePositions.back() )
     455           0 :         return m_aTablePositions.back( )->getTablePosition();
     456             :     else
     457           0 :         return uno::Sequence< beans::PropertyValue >( 0 );
     458             : }
     459             : 
     460           0 : void DomainMapperTableManager::startLevel( )
     461             : {
     462           0 :     DomainMapperTableManager_Base_t::startLevel( );
     463             : 
     464             :     // If requested, pop the value that was pushed too early.
     465           0 :     boost::optional<sal_Int32> oCurrentWidth;
     466           0 :     if (m_bPushCurrentWidth && !m_aCellWidths.empty() && !m_aCellWidths.back()->empty())
     467             :     {
     468           0 :         oCurrentWidth.reset(m_aCellWidths.back()->back());
     469           0 :         m_aCellWidths.back()->pop_back();
     470             :     }
     471             : 
     472           0 :     IntVectorPtr pNewGrid( new vector<sal_Int32> );
     473           0 :     IntVectorPtr pNewSpans( new vector<sal_Int32> );
     474           0 :     IntVectorPtr pNewCellWidths( new vector<sal_Int32> );
     475           0 :     TablePositionHandlerPtr pNewPositionHandler;
     476           0 :     m_aTableGrid.push_back( pNewGrid );
     477           0 :     m_aGridSpans.push_back( pNewSpans );
     478           0 :     m_aCellWidths.push_back( pNewCellWidths );
     479           0 :     m_aTablePositions.push_back( pNewPositionHandler );
     480             : 
     481           0 :     TablePositionHandlerPtr pTmpPosition;
     482           0 :     TablePropertyMapPtr pTmpProperties( new TablePropertyMap( ) );
     483           0 :     m_aTmpPosition.push_back( pTmpPosition );
     484           0 :     m_aTmpTableProperties.push_back( pTmpProperties );
     485           0 :     m_nCell.push_back( 0 );
     486           0 :     m_nTableWidth = 0;
     487           0 :     m_nLayoutType = 0;
     488           0 :     m_nMaxFixedWidth = 0;
     489             : 
     490             :     // And push it back to the right level.
     491           0 :     if (oCurrentWidth)
     492           0 :         m_aCellWidths.back()->push_back(*oCurrentWidth);
     493           0 : }
     494             : 
     495           0 : void DomainMapperTableManager::endLevel( )
     496             : {
     497           0 :     m_aTableGrid.pop_back( );
     498           0 :     m_aGridSpans.pop_back( );
     499             : 
     500             :     // Do the same trick as in startLevel(): pop the value that was pushed too early.
     501           0 :     boost::optional<sal_Int32> oCurrentWidth;
     502           0 :     if (m_bPushCurrentWidth && !m_aCellWidths.empty() && !m_aCellWidths.back()->empty())
     503           0 :         oCurrentWidth.reset(m_aCellWidths.back()->back());
     504           0 :     m_aCellWidths.pop_back( );
     505             :     // And push it back to the right level.
     506           0 :     if (oCurrentWidth)
     507           0 :         m_aCellWidths.back()->push_back(*oCurrentWidth);
     508             : 
     509           0 :     m_nCell.pop_back( );
     510           0 :     m_nTableWidth = 0;
     511           0 :     m_nLayoutType = 0;
     512           0 :     m_nMaxFixedWidth = 0;
     513             : 
     514           0 :     m_aTmpPosition.pop_back( );
     515           0 :     m_aTmpTableProperties.pop_back( );
     516             : 
     517           0 :     DomainMapperTableManager_Base_t::endLevel( );
     518             : #ifdef DEBUG_DOMAINMAPPER
     519             :     dmapper_logger->startElement("dmappertablemanager.endLevel");
     520             :     PropertyMapPtr pProps = getTableProps();
     521             :     if (pProps.get() != NULL)
     522             :         getTableProps()->dumpXml( dmapper_logger );
     523             : 
     524             :     dmapper_logger->endElement();
     525             : #endif
     526             : 
     527             :     // Pop back the table position after endLevel as it's used
     528             :     // in the endTable method called in endLevel.
     529           0 :     m_aTablePositions.pop_back();
     530           0 : }
     531             : 
     532             : 
     533             : 
     534           0 : void DomainMapperTableManager::endOfCellAction()
     535             : {
     536             : #ifdef DEBUG_DOMAINMAPPER
     537             :     dmapper_logger->element("endOFCellAction");
     538             : #endif
     539             : 
     540           0 :     getCurrentSpans()->push_back(m_nGridSpan);
     541           0 :     m_nGridSpan = 1;
     542           0 :     ++m_nCell.back( );
     543           0 : }
     544             : 
     545             : 
     546           0 : void DomainMapperTableManager::endOfRowAction()
     547             : {
     548             : #ifdef DEBUG_DOMAINMAPPER
     549             :     dmapper_logger->startElement("endOfRowAction");
     550             : #endif
     551             : 
     552             :     // Compare the table position with the previous ones. We may need to split
     553             :     // into two tables if those are different. We surely don't want to do anything
     554             :     // if we don't have any row yet.
     555           0 :     TablePositionHandlerPtr pTmpPosition = m_aTmpPosition.back();
     556           0 :     TablePropertyMapPtr pTmpTableProperties = m_aTmpTableProperties.back( );
     557           0 :     TablePositionHandlerPtr pCurrentPosition = m_aTablePositions.back();
     558           0 :     bool bSamePosition = ( pTmpPosition == pCurrentPosition ) ||
     559           0 :                          ( pTmpPosition && pCurrentPosition && *pTmpPosition == *pCurrentPosition );
     560           0 :     if ( !bSamePosition && m_nRow > 0 )
     561             :     {
     562             :         // Save the grid infos to have them survive the end/start level
     563           0 :         IntVectorPtr pTmpTableGrid = m_aTableGrid.back();
     564           0 :         IntVectorPtr pTmpGridSpans = m_aGridSpans.back();
     565           0 :         IntVectorPtr pTmpCellWidths = m_aCellWidths.back();
     566             : 
     567             :         // endLevel and startLevel are taking care of the non finished row
     568             :         // to carry it over to the next table
     569           0 :         setKeepUnfinishedRow( true );
     570           0 :         endLevel();
     571           0 :         setKeepUnfinishedRow( false );
     572           0 :         startLevel();
     573             : 
     574           0 :         m_aTableGrid.pop_back();
     575           0 :         m_aGridSpans.pop_back();
     576           0 :         m_aCellWidths.pop_back();
     577           0 :         m_aTableGrid.push_back(pTmpTableGrid);
     578           0 :         m_aGridSpans.push_back(pTmpGridSpans);
     579           0 :         m_aCellWidths.push_back(pTmpCellWidths);
     580             :     }
     581             : 
     582             :     // Push the tmp position now that we compared it
     583           0 :     m_aTablePositions.pop_back();
     584           0 :     m_aTablePositions.push_back( pTmpPosition );
     585           0 :     m_aTmpPosition.back().reset( );
     586             : 
     587             : 
     588           0 :     IntVectorPtr pTableGrid = getCurrentGrid( );
     589           0 :     IntVectorPtr pCellWidths = getCurrentCellWidths( );
     590           0 :     if(!m_nTableWidth && pTableGrid->size())
     591             :     {
     592           0 :         ::std::vector<sal_Int32>::const_iterator aCellIter = pTableGrid->begin();
     593             : 
     594             : #ifdef DEBUG_DOMAINMAPPER
     595             :         dmapper_logger->startElement("tableWidth");
     596             : #endif
     597             : 
     598           0 :         while( aCellIter != pTableGrid->end() )
     599             :         {
     600             : #ifdef DEBUG_DOMAINMAPPER
     601             :             dmapper_logger->startElement("col");
     602             :             dmapper_logger->attribute("width", *aCellIter);
     603             :             dmapper_logger->endElement();
     604             : #endif
     605             : 
     606           0 :              m_nTableWidth += *aCellIter++;
     607             :         }
     608             : 
     609           0 :         if (m_nTableWidth > 0 && !m_bTableSizeTypeInserted)
     610             :         {
     611           0 :             TablePropertyMapPtr pPropMap( new TablePropertyMap );
     612           0 :             pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth );
     613           0 :             insertTableProps(pPropMap);
     614             :         }
     615             : 
     616             : #ifdef DEBUG_DOMAINMAPPER
     617             :         dmapper_logger->endElement();
     618             : #endif
     619             :     }
     620             : 
     621           0 :     IntVectorPtr pCurrentSpans = getCurrentSpans( );
     622           0 :     if( pCurrentSpans->size() < m_nCell.back( ) )
     623             :     {
     624             :         //fill missing elements with '1'
     625           0 :         pCurrentSpans->insert( pCurrentSpans->end( ), m_nCell.back( ) - pCurrentSpans->size(), 1 );
     626             :     }
     627             : 
     628             : #ifdef DEBUG_DOMAINMAPPER
     629             :     dmapper_logger->startElement("gridSpans");
     630             :     {
     631             :         ::std::vector<sal_Int32>::const_iterator aGridSpanIter = pCurrentSpans->begin();
     632             :         ::std::vector<sal_Int32>::const_iterator aGridSpanIterEnd = pCurrentSpans->end();
     633             : 
     634             :         while (aGridSpanIter != aGridSpanIterEnd)
     635             :         {
     636             :             dmapper_logger->startElement("gridSpan");
     637             :             dmapper_logger->attribute("span", *aGridSpanIter);
     638             :             dmapper_logger->endElement();
     639             : 
     640             :             ++aGridSpanIter;
     641             :         }
     642             :     }
     643             :     dmapper_logger->endElement();
     644             : #endif
     645             : 
     646             :     //calculate number of used grids - it has to match the size of m_aTableGrid
     647           0 :     size_t nGrids = 0;
     648           0 :     ::std::vector<sal_Int32>::const_iterator aGridSpanIter = pCurrentSpans->begin();
     649           0 :     for( ; aGridSpanIter != pCurrentSpans->end(); ++aGridSpanIter)
     650           0 :         nGrids += *aGridSpanIter;
     651             : 
     652             :     // sj: the grid is having no units... they is containing only relative values.
     653             :     // a table with a grid of "1:2:1" looks identical as if the table is having
     654             :     // a grid of "20:40:20" and it doesn't have to do something with the tableWidth
     655             :     // -> so we have get the sum of each grid entry for the fullWidthRelative:
     656           0 :     int nFullWidthRelative = 0;
     657           0 :     for (unsigned int i = 0 ; i < (*pTableGrid.get()).size(); i++ )
     658           0 :         nFullWidthRelative += (*pTableGrid.get())[ i ];
     659             : 
     660           0 :     if( pTableGrid->size() == ( m_nGridBefore + nGrids + m_nGridAfter ) && m_nCell.back( ) > 0 )
     661             :     {
     662             :         /*
     663             :          * If table width property set earlier is smaller than the current table width,
     664             :          * then replace the TABLE_WIDTH property, set earlier.
     665             :          */
     666           0 :         TablePropertyMapPtr propMap = m_aTmpTableProperties.back();
     667             :         sal_Int32 nTableWidth;
     668             :         sal_Int32 nTableWidthType;
     669           0 :         propMap->getValue( TablePropertyMap::TABLE_WIDTH, nTableWidth );
     670           0 :         propMap->getValue( TablePropertyMap::TABLE_WIDTH_TYPE, nTableWidthType );
     671           0 :         if ((nTableWidthType == text::SizeType::FIX) && (nTableWidth < m_nTableWidth))
     672             :         {
     673           0 :             propMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth );
     674             :         }
     675           0 :         if (nTableWidthType == text::SizeType::VARIABLE )
     676             :         {
     677           0 :             if(nTableWidth > 100 || nTableWidth <= 0)
     678             :             {
     679           0 :                 propMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth);
     680           0 :                 propMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::FIX);
     681             :             }
     682             :         }
     683           0 :         uno::Sequence< text::TableColumnSeparator > aSeparators( m_nCell.back( ) - 1 );
     684           0 :         text::TableColumnSeparator* pSeparators = aSeparators.getArray();
     685           0 :         sal_Int16 nLastRelPos = 0;
     686           0 :         sal_uInt32 nBorderGridIndex = m_nGridBefore;
     687             : 
     688           0 :         ::std::vector< sal_Int32 >::const_iterator aSpansIter = pCurrentSpans->begin( );
     689           0 :         for( sal_uInt32 nBorder = 0; nBorder < m_nCell.back( ) - 1; ++nBorder )
     690             :         {
     691           0 :             double fGridWidth = 0.;
     692           0 :             for ( sal_Int32 nGridCount = *aSpansIter; nGridCount > 0; --nGridCount )
     693           0 :                 fGridWidth += (*pTableGrid.get())[nBorderGridIndex++];
     694             : 
     695             :             sal_Int16 nRelPos =
     696           0 :                 sal::static_int_cast< sal_Int16 >((fGridWidth * 10000) / nFullWidthRelative);
     697             : 
     698           0 :             pSeparators[nBorder].Position =  nRelPos + nLastRelPos;
     699           0 :             pSeparators[nBorder].IsVisible = sal_True;
     700           0 :             nLastRelPos = nLastRelPos + nRelPos;
     701           0 :             ++aSpansIter;
     702             :         }
     703           0 :         TablePropertyMapPtr pPropMap( new TablePropertyMap );
     704           0 :         pPropMap->Insert( PROP_TABLE_COLUMN_SEPARATORS, uno::makeAny( aSeparators ) );
     705             : 
     706             : #ifdef DEBUG_DOMAINMAPPER
     707             :         dmapper_logger->startElement("rowProperties");
     708             :         pPropMap->dumpXml( dmapper_logger );
     709             :         dmapper_logger->endElement();
     710             : #endif
     711           0 :         insertRowProps(pPropMap);
     712             :     }
     713           0 :     else if ( pCellWidths->size() > 0 &&
     714           0 :                ( m_nLayoutType == NS_ooxml::LN_Value_wordprocessingml_ST_TblLayout_fixed
     715           0 :                  || pCellWidths->size() == ( m_nGridBefore + nGrids + m_nGridAfter ) )
     716             :              )
     717             :     {
     718             :         // If we're here, then the number of cells does not equal to the amount
     719             :         // defined by the grid, even after taking care of
     720             :         // gridSpan/gridBefore/gridAfter. Handle this by ignoring the grid and
     721             :         // providing the separators based on the provided cell widths, as long
     722             :         // as we have a fixed layout;
     723             :         // On the other hand even if the layout is not fixed, but the cell widths
     724             :         // provided equal the total number of cells, and there are no after/before cells
     725             :         // then use the cell widths to calculate the column separators.
     726           0 :         uno::Sequence< text::TableColumnSeparator > aSeparators(pCellWidths->size() - 1);
     727           0 :         text::TableColumnSeparator* pSeparators = aSeparators.getArray();
     728           0 :         sal_Int16 nSum = 0;
     729           0 :         sal_uInt32 nPos = 0;
     730             :         // Avoid divide by zero (if there's no grid, position using cell widths).
     731           0 :         if( nFullWidthRelative == 0 )
     732           0 :             for (sal_uInt32 i = 0; i < pCellWidths->size(); ++i)
     733           0 :                 nFullWidthRelative += (*pCellWidths.get())[i];
     734             : 
     735           0 :         for (sal_uInt32 i = 0; i < pCellWidths->size() - 1; ++i)
     736             :         {
     737           0 :             nSum += (*pCellWidths.get())[i];
     738           0 :             pSeparators[nPos].Position = (nSum * 10000) / nFullWidthRelative; // Relative position
     739           0 :             pSeparators[nPos].IsVisible = sal_True;
     740           0 :             nPos++;
     741             :         }
     742             : 
     743           0 :         TablePropertyMapPtr pPropMap( new TablePropertyMap );
     744           0 :         pPropMap->Insert( PROP_TABLE_COLUMN_SEPARATORS, uno::makeAny( aSeparators ) );
     745             : #ifdef DEBUG_DOMAINMAPPER
     746             :         dmapper_logger->startElement("rowProperties");
     747             :         pPropMap->dumpXml( dmapper_logger );
     748             :         dmapper_logger->endElement();
     749             : #endif
     750           0 :         insertRowProps(pPropMap);
     751             :     }
     752             : 
     753             :     // Now that potentially opened table is closed, save the table properties
     754           0 :     DomainMapperTableManager_Base_t::insertTableProps( pTmpTableProperties );
     755             : 
     756           0 :     m_aTmpTableProperties.pop_back();
     757           0 :     TablePropertyMapPtr pEmptyTableProps( new TablePropertyMap() );
     758           0 :     m_aTmpTableProperties.push_back( pEmptyTableProps );
     759             : 
     760           0 :     ++m_nRow;
     761           0 :     m_nCell.back( ) = 0;
     762           0 :     m_nCellBorderIndex = 0;
     763           0 :     getCurrentGrid()->clear();
     764           0 :     pCurrentSpans->clear();
     765           0 :     pCellWidths->clear();
     766             : 
     767           0 :     m_nGridBefore = m_nGridAfter = 0;
     768           0 :     m_bRowSizeTypeInserted = false;
     769           0 :     m_bHasBtlrCell = false;
     770           0 :     m_bTableSizeTypeInserted = false;
     771             : 
     772             : #ifdef DEBUG_DOMAINMAPPER
     773             :     dmapper_logger->endElement();
     774             : #endif
     775           0 : }
     776             : 
     777             : 
     778           0 : void DomainMapperTableManager::clearData()
     779             : {
     780           0 :     m_nRow = m_nCellBorderIndex = m_nHeaderRepeat = m_nTableWidth = m_nLayoutType = 0;
     781           0 :     m_sTableStyleName = OUString();
     782           0 :     m_pTableStyleTextProperies.reset();
     783           0 : }
     784             : 
     785             : 
     786             : }}
     787             : 
     788             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10