Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / dmapper / TablePropertiesHandler.cxx
blob4023a2134abb28e05951e4d4bb046618c4cdc1aa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "BorderHandler.hxx"
21 #include "CellColorHandler.hxx"
22 #include "CellMarginHandler.hxx"
23 #include "ConversionHelper.hxx"
24 #include "MeasureHandler.hxx"
25 #include "TablePropertiesHandler.hxx"
26 #include "TDefTableHandler.hxx"
27 #include "DomainMapperTableManager.hxx"
29 #include <ooxml/resourceids.hxx>
30 #include <doctok/sprmids.hxx>
32 #include <com/sun/star/text/SizeType.hpp>
33 #include <com/sun/star/text/VertOrientation.hpp>
34 #include <dmapperLoggers.hxx>
37 namespace writerfilter {
38 namespace dmapper {
40 TablePropertiesHandler::TablePropertiesHandler( bool bOOXML ) :
41 m_pTableManager( NULL ),
42 m_bOOXML( bOOXML )
47 TablePropertiesHandler::~TablePropertiesHandler( )
49 // Do not delete the table manager... this will be done somewhere else
50 m_pTableManager = NULL;
53 bool TablePropertiesHandler::sprm(Sprm & rSprm)
55 #ifdef DEBUG_DOMAINMAPPER
56 dmapper_logger->startElement("TablePropertiesHandler.sprm");
57 dmapper_logger->attribute("sprm", rSprm.toString());
58 #endif
60 bool bRet = true;
61 sal_uInt32 nSprmId = rSprm.getId();
62 Value::Pointer_t pValue = rSprm.getValue();
63 sal_Int32 nIntValue = ((pValue.get() != NULL) ? pValue->getInt() : 0);
64 switch( nSprmId )
66 case NS_ooxml::LN_CT_TrPrBase_jc: //90706
67 case NS_ooxml::LN_CT_TblPrBase_jc:
68 case 0x5400: // sprmTJc
70 //table justification 0: left, 1: center, 2: right
71 sal_Int16 nOrient = ConversionHelper::convertTableJustification( nIntValue );
72 TablePropertyMapPtr pTableMap( new TablePropertyMap );
73 pTableMap->setValue( TablePropertyMap::HORI_ORIENT, nOrient );
74 insertTableProps( pTableMap );
76 break;
77 case 0x9601: // sprmTDxaLeft
78 break;
79 case 0x9602: // sprmTDxaGapHalf
81 //m_nGapHalf = ConversionHelper::convertTwipToMM100( nIntValue );
82 TablePropertyMapPtr pPropMap( new TablePropertyMap );
83 pPropMap->setValue( TablePropertyMap::GAP_HALF, ConversionHelper::convertTwipToMM100( nIntValue ) );
84 insertTableProps(pPropMap);
86 break;
87 case NS_ooxml::LN_CT_TrPrBase_trHeight: //90703
89 //contains unit and value
90 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
91 if( pProperties.get())
92 { //contains attributes x2902 (LN_unit) and x17e2 (LN_trleft)
93 MeasureHandlerPtr pMeasureHandler( new MeasureHandler );
94 pProperties->resolve(*pMeasureHandler);
95 TablePropertyMapPtr pPropMap( new TablePropertyMap );
97 // In case a cell already wanted fixed size, we should not overwrite it here.
98 DomainMapperTableManager* pManager = dynamic_cast<DomainMapperTableManager*>(m_pTableManager);
99 if (!pManager || !pManager->IsRowSizeTypeInserted())
100 pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny( pMeasureHandler->GetRowHeightSizeType() ), false);
102 pPropMap->Insert( PROP_HEIGHT, false, uno::makeAny(pMeasureHandler->getMeasureValue() ));
103 insertRowProps(pPropMap);
106 break;
107 case 0x3403: // sprmTFCantSplit
108 case NS_sprm::LN_TCantSplit: // 0x3644
110 //row can't break across pages if nIntValue == 1
111 TablePropertyMapPtr pPropMap( new TablePropertyMap );
112 pPropMap->Insert( PROP_IS_SPLIT_ALLOWED, false, uno::makeAny(sal_Bool( nIntValue == 1 ? sal_False : sal_True ) ));
113 insertRowProps(pPropMap);
115 break;
116 case 0x9407: // sprmTDyaRowHeight
118 // table row height - negative values indicate 'exact height' - positive 'at least'
119 TablePropertyMapPtr pPropMap( new TablePropertyMap );
120 bool bMinHeight = true;
121 sal_Int16 nHeight = static_cast<sal_Int16>( nIntValue );
122 if( nHeight < 0 )
124 bMinHeight = false;
125 nHeight *= -1;
127 pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny(bMinHeight ? text::SizeType::MIN : text::SizeType::FIX ));
128 pPropMap->Insert( PROP_HEIGHT, false, uno::makeAny(ConversionHelper::convertTwipToMM100( nHeight )));
129 insertRowProps(pPropMap);
131 break;
132 case NS_ooxml::LN_CT_TcPrBase_vAlign://90694
134 sal_Int16 nVertOrient = text::VertOrientation::NONE;
135 switch( nIntValue ) //0 - top 1 - center 3 - bottom
137 case 1: nVertOrient = text::VertOrientation::CENTER; break;
138 case 3: nVertOrient = text::VertOrientation::BOTTOM; break;
139 default:;
141 TablePropertyMapPtr pCellPropMap( new TablePropertyMap() );
142 pCellPropMap->Insert( PROP_VERT_ORIENT, false, uno::makeAny( nVertOrient ) );
143 //todo: in ooxml import the value of m_ncell is wrong
144 cellProps( pCellPropMap );
146 break;
147 case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style
149 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
150 if( pProperties.get())
152 BorderHandlerPtr pBorderHandler( new BorderHandler(m_bOOXML) );
153 pProperties->resolve(*pBorderHandler);
154 TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
155 pTablePropMap->InsertProps(pBorderHandler->getProperties());
157 #ifdef DEBUG_DOMAINMAPPER
158 pTablePropMap->dumpXml( dmapper_logger );
159 #endif
160 insertTableProps( pTablePropMap );
163 break;
164 case NS_ooxml::LN_CT_TblPrBase_tblLayout:
166 DomainMapperTableManager* pManager = dynamic_cast<DomainMapperTableManager*>(m_pTableManager);
167 if (pManager)
168 pManager->SetLayoutType(static_cast<sal_uInt32>(nIntValue));
170 break;
171 case NS_ooxml::LN_CT_TcPrBase_tcBorders ://cell borders
172 //contains CT_TcBorders_left, right, top, bottom
174 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
175 if( pProperties.get())
177 //in OOXML there's one set of borders at each cell (if there is any)
178 TDefTableHandlerPtr pTDefTableHandler( new TDefTableHandler( m_bOOXML ));
179 pProperties->resolve( *pTDefTableHandler );
180 TablePropertyMapPtr pCellPropMap( new TablePropertyMap );
181 pTDefTableHandler->fillCellProperties( 0, pCellPropMap );
182 cellProps( pCellPropMap );
185 break;
186 case NS_ooxml::LN_CT_TcPrBase_tcMar:
188 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
189 if (pProperties.get())
191 CellMarginHandlerPtr pCellMarginHandler(new CellMarginHandler);
192 pProperties->resolve(*pCellMarginHandler);
193 TablePropertyMapPtr pCellProperties(new TablePropertyMap);
194 if (pCellMarginHandler->m_bTopMarginValid)
195 pCellProperties->Insert(PROP_TOP_BORDER_DISTANCE, false, uno::makeAny(pCellMarginHandler->m_nTopMargin));
196 if (pCellMarginHandler->m_bLeftMarginValid)
197 pCellProperties->Insert(PROP_LEFT_BORDER_DISTANCE, false, uno::makeAny(pCellMarginHandler->m_nLeftMargin));
198 if (pCellMarginHandler->m_bBottomMarginValid)
199 pCellProperties->Insert(PROP_BOTTOM_BORDER_DISTANCE, false, uno::makeAny(pCellMarginHandler->m_nBottomMargin));
200 if (pCellMarginHandler->m_bRightMarginValid)
201 pCellProperties->Insert(PROP_RIGHT_BORDER_DISTANCE, false, uno::makeAny(pCellMarginHandler->m_nRightMargin));
202 cellProps(pCellProperties);
205 break;
206 case NS_ooxml::LN_CT_TblPrBase_shd:
208 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
209 if( pProperties.get())
211 CellColorHandlerPtr pCellColorHandler( new CellColorHandler);
212 pProperties->resolve( *pCellColorHandler );
213 TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
214 insertTableProps( pCellColorHandler->getProperties() );
217 break;
218 case 0xd61a : // sprmTCellTopColor
219 case 0xd61b : // sprmTCellLeftColor
220 case 0xd61c : // sprmTCellBottomColor
221 case 0xd61d : // sprmTCellRightColor
222 case NS_ooxml::LN_CT_TcPrBase_shd:
224 // each color sprm contains as much colors as cells are in a row
225 //LN_CT_TcPrBase_shd: cell shading contains: LN_CT_Shd_val, LN_CT_Shd_fill, LN_CT_Shd_color
226 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
227 if( pProperties.get())
229 CellColorHandlerPtr pCellColorHandler( new CellColorHandler );
230 pProperties->resolve( *pCellColorHandler );
231 cellProps( pCellColorHandler->getProperties());
234 break;
235 //OOXML table properties
236 case NS_ooxml::LN_CT_TblPrBase_tblCellMar: //cell margins
238 //contains LN_CT_TblCellMar_top, LN_CT_TblCellMar_left, LN_CT_TblCellMar_bottom, LN_CT_TblCellMar_right
239 // LN_CT_TblCellMar_start, LN_CT_TblCellMar_end
240 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
241 if( pProperties.get())
243 CellMarginHandlerPtr pCellMarginHandler( new CellMarginHandler );
244 pProperties->resolve( *pCellMarginHandler );
245 TablePropertyMapPtr pMarginProps( new TablePropertyMap );
246 if( pCellMarginHandler->m_bTopMarginValid )
247 pMarginProps->setValue( TablePropertyMap::CELL_MAR_TOP, pCellMarginHandler->m_nTopMargin );
248 if( pCellMarginHandler->m_bBottomMarginValid )
249 pMarginProps->setValue( TablePropertyMap::CELL_MAR_BOTTOM, pCellMarginHandler->m_nBottomMargin );
250 if( pCellMarginHandler->m_bLeftMarginValid )
251 pMarginProps->setValue( TablePropertyMap::CELL_MAR_LEFT, pCellMarginHandler->m_nLeftMargin );
252 if( pCellMarginHandler->m_bRightMarginValid )
253 pMarginProps->setValue( TablePropertyMap::CELL_MAR_RIGHT, pCellMarginHandler->m_nRightMargin );
254 insertTableProps(pMarginProps);
257 break;
258 case NS_ooxml::LN_CT_TblPrBase_tblInd:
260 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
261 if (pProperties.get())
263 MeasureHandlerPtr pHandler(new MeasureHandler);
264 pProperties->resolve( *pHandler );
265 TablePropertyMapPtr pTblIndMap(new TablePropertyMap);
266 sal_uInt32 nTblInd = pHandler->getMeasureValue();
267 pTblIndMap->setValue( TablePropertyMap::LEFT_MARGIN, nTblInd);
268 insertTableProps(pTblIndMap);
271 break;
272 default: bRet = false;
275 #ifdef DEBUG_DOMAINMAPPER
276 dmapper_logger->endElement();
277 #endif
279 return bRet;
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */