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 : :
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 : :
28 : : #include <ooxml/resourceids.hxx>
29 : : #include <doctok/sprmids.hxx>
30 : :
31 : : #include <com/sun/star/text/SizeType.hpp>
32 : : #include <com/sun/star/text/VertOrientation.hpp>
33 : : #include <dmapperLoggers.hxx>
34 : :
35 : :
36 : : namespace writerfilter {
37 : : namespace dmapper {
38 : :
39 : 5519 : TablePropertiesHandler::TablePropertiesHandler( bool bOOXML ) :
40 : : m_pTableManager( NULL ),
41 [ + - ]: 5519 : m_bOOXML( bOOXML )
42 : : {
43 : 5519 : }
44 : :
45 : :
46 [ + - ]: 5519 : TablePropertiesHandler::~TablePropertiesHandler( )
47 : : {
48 : : // Do not delete the table manager... this will be done somewhere else
49 : 5519 : m_pTableManager = NULL;
50 [ - + ]: 11038 : }
51 : :
52 : 63055 : bool TablePropertiesHandler::sprm(Sprm & rSprm)
53 : : {
54 : : #ifdef DEBUG_DOMAINMAPPER
55 : : dmapper_logger->startElement("TablePropertiesHandler.sprm");
56 : : dmapper_logger->attribute("sprm", rSprm.toString());
57 : : #endif
58 : :
59 : 63055 : bool bRet = true;
60 [ + - ]: 63055 : sal_uInt32 nSprmId = rSprm.getId();
61 [ + - ][ + - ]: 63055 : Value::Pointer_t pValue = rSprm.getValue();
62 [ + - ][ + - ]: 63055 : sal_Int32 nIntValue = ((pValue.get() != NULL) ? pValue->getInt() : 0);
63 [ - - - + : 63055 : switch( nSprmId )
+ - + + +
- - + +
+ ]
64 : : {
65 : : case NS_ooxml::LN_CT_TrPrBase_jc: //90706
66 : : case NS_ooxml::LN_CT_TblPrBase_jc:
67 : : case 0x5400: // sprmTJc
68 : : {
69 : : //table justification 0: left, 1: center, 2: right
70 [ # # ]: 0 : sal_Int16 nOrient = ConversionHelper::convertTableJustification( nIntValue );
71 [ # # ][ # # ]: 0 : TablePropertyMapPtr pTableMap( new TablePropertyMap );
[ # # ]
72 [ # # ]: 0 : pTableMap->setValue( TablePropertyMap::HORI_ORIENT, nOrient );
73 [ # # ][ # # ]: 0 : insertTableProps( pTableMap );
[ # # ][ # # ]
74 : : }
75 : 0 : break;
76 : : case 0x9601: // sprmTDxaLeft
77 : 0 : break;
78 : : case 0x9602: // sprmTDxaGapHalf
79 : : {
80 : : //m_nGapHalf = ConversionHelper::convertTwipToMM100( nIntValue );
81 [ # # ][ # # ]: 0 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ # # ]
82 [ # # ][ # # ]: 0 : pPropMap->setValue( TablePropertyMap::GAP_HALF, ConversionHelper::convertTwipToMM100( nIntValue ) );
83 [ # # ][ # # ]: 0 : insertTableProps(pPropMap);
[ # # ][ # # ]
84 : : }
85 : 0 : break;
86 : : case NS_ooxml::LN_CT_TrPrBase_trHeight: //90703
87 : : {
88 : : //contains unit and value
89 [ + - ]: 11 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
90 [ + - ]: 11 : if( pProperties.get())
91 : : { //contains attributes x2902 (LN_unit) and x17e2 (LN_trleft)
92 [ + - ][ + - ]: 11 : MeasureHandlerPtr pMeasureHandler( new MeasureHandler );
[ + - ]
93 [ + - ]: 11 : pProperties->resolve(*pMeasureHandler);
94 [ + - ][ + - ]: 11 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ + - ]
95 [ + - ][ + - ]: 11 : pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny( pMeasureHandler->GetRowHeightSizeType() ));
96 [ + - ][ + - ]: 11 : pPropMap->Insert( PROP_HEIGHT, false, uno::makeAny(pMeasureHandler->getMeasureValue() ));
[ + - ]
97 [ + - ][ + - ]: 11 : insertRowProps(pPropMap);
[ + - ][ + - ]
[ + - ]
98 [ + - ]: 11 : }
99 : : }
100 : 11 : break;
101 : : case 0x3403: // sprmTFCantSplit
102 : : case NS_sprm::LN_TCantSplit: // 0x3644
103 : : {
104 : : //row can't break across pages if nIntValue == 1
105 [ + - ][ + - ]: 2 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ + - ]
106 [ + - ][ + - ]: 2 : pPropMap->Insert( PROP_IS_SPLIT_ALLOWED, false, uno::makeAny(sal_Bool( nIntValue == 1 ? sal_False : sal_True ) ));
107 [ + - ][ + - ]: 2 : insertRowProps(pPropMap);
[ + - ][ + - ]
108 : : }
109 : 2 : break;
110 : : case 0x9407: // sprmTDyaRowHeight
111 : : {
112 : : // table row height - negative values indicate 'exact height' - positive 'at least'
113 [ # # ][ # # ]: 0 : TablePropertyMapPtr pPropMap( new TablePropertyMap );
[ # # ]
114 : 0 : bool bMinHeight = true;
115 : 0 : sal_Int16 nHeight = static_cast<sal_Int16>( nIntValue );
116 [ # # ]: 0 : if( nHeight < 0 )
117 : : {
118 : 0 : bMinHeight = false;
119 : 0 : nHeight *= -1;
120 : : }
121 [ # # ][ # # ]: 0 : pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny(bMinHeight ? text::SizeType::MIN : text::SizeType::FIX ));
[ # # ]
122 [ # # ][ # # ]: 0 : pPropMap->Insert( PROP_HEIGHT, false, uno::makeAny(ConversionHelper::convertTwipToMM100( nHeight )));
[ # # ]
123 [ # # ][ # # ]: 0 : insertRowProps(pPropMap);
[ # # ][ # # ]
124 : : }
125 : 0 : break;
126 : : case NS_ooxml::LN_CT_TcPrBase_vAlign://90694
127 : : {
128 : 259 : sal_Int16 nVertOrient = text::VertOrientation::NONE;
129 [ - + + ]: 259 : switch( nIntValue ) //0 - top 1 - center 3 - bottom
130 : : {
131 : 0 : case 1: nVertOrient = text::VertOrientation::CENTER; break;
132 : 4 : case 3: nVertOrient = text::VertOrientation::BOTTOM; break;
133 : : default:;
134 : : };
135 [ + - ][ + - ]: 259 : TablePropertyMapPtr pCellPropMap( new TablePropertyMap() );
[ + - ]
136 [ + - ][ + - ]: 259 : pCellPropMap->Insert( PROP_VERT_ORIENT, false, uno::makeAny( nVertOrient ) );
137 : : //todo: in ooxml import the value of m_ncell is wrong
138 [ + - ][ + - ]: 259 : cellProps( pCellPropMap );
[ + - ][ + - ]
139 : : }
140 : 259 : break;
141 : : case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style
142 : : {
143 [ + - ]: 35 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
144 [ + - ]: 35 : if( pProperties.get())
145 : : {
146 [ + - ][ + - ]: 35 : BorderHandlerPtr pBorderHandler( new BorderHandler(m_bOOXML) );
[ + - ]
147 [ + - ]: 35 : pProperties->resolve(*pBorderHandler);
148 [ + - ][ + - ]: 35 : TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
[ + - ]
149 [ + - ][ + - ]: 35 : pTablePropMap->insert( pBorderHandler->getProperties() );
[ + - ]
150 : :
151 : : #ifdef DEBUG_DOMAINMAPPER
152 : : pTablePropMap->dumpXml( dmapper_logger );
153 : : #endif
154 [ + - ][ + - ]: 35 : insertTableProps( pTablePropMap );
[ + - ][ + - ]
[ + - ]
155 [ + - ]: 35 : }
156 : : }
157 : 35 : break;
158 : : case NS_ooxml::LN_CT_TcPrBase_tcBorders ://cell borders
159 : : //contains CT_TcBorders_left, right, top, bottom
160 : : {
161 [ + - ]: 364 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
162 [ + - ]: 364 : if( pProperties.get())
163 : : {
164 : : //in OOXML there's one set of borders at each cell (if there is any)
165 [ + - ][ + - ]: 364 : TDefTableHandlerPtr pTDefTableHandler( new TDefTableHandler( m_bOOXML ));
[ + - ]
166 [ + - ]: 364 : pProperties->resolve( *pTDefTableHandler );
167 [ + - ][ + - ]: 364 : TablePropertyMapPtr pCellPropMap( new TablePropertyMap );
[ + - ]
168 [ + - ][ + - ]: 364 : pTDefTableHandler->fillCellProperties( 0, pCellPropMap );
[ + - ]
169 [ + - ][ + - ]: 364 : cellProps( pCellPropMap );
[ + - ][ + - ]
[ + - ]
170 [ + - ]: 364 : }
171 : : }
172 : 364 : break;
173 : : case NS_ooxml::LN_CT_TblPrBase_shd:
174 : : {
175 [ # # ]: 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
176 [ # # ]: 0 : if( pProperties.get())
177 : : {
178 [ # # ][ # # ]: 0 : CellColorHandlerPtr pCellColorHandler( new CellColorHandler);
[ # # ]
179 [ # # ]: 0 : pProperties->resolve( *pCellColorHandler );
180 [ # # ][ # # ]: 0 : TablePropertyMapPtr pTablePropMap( new TablePropertyMap );
[ # # ]
181 [ # # ][ # # ]: 0 : insertTableProps( pCellColorHandler->getProperties() );
[ # # ][ # # ]
[ # # ]
182 [ # # ]: 0 : }
183 : : }
184 : 0 : break;
185 : : case 0xd61a : // sprmTCellTopColor
186 : : case 0xd61b : // sprmTCellLeftColor
187 : : case 0xd61c : // sprmTCellBottomColor
188 : : case 0xd61d : // sprmTCellRightColor
189 : : case NS_ooxml::LN_CT_TcPrBase_shd:
190 : : {
191 : : // each color sprm contains as much colors as cells are in a row
192 : : //LN_CT_TcPrBase_shd: cell shading contains: LN_CT_Shd_val, LN_CT_Shd_fill, LN_CT_Shd_color
193 [ # # ]: 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
194 [ # # ]: 0 : if( pProperties.get())
195 : : {
196 [ # # ][ # # ]: 0 : CellColorHandlerPtr pCellColorHandler( new CellColorHandler );
[ # # ]
197 [ # # ]: 0 : pProperties->resolve( *pCellColorHandler );
198 [ # # ][ # # ]: 0 : cellProps( pCellColorHandler->getProperties());
[ # # ][ # # ]
199 [ # # ]: 0 : }
200 : : }
201 : 0 : break;
202 : : //OOXML table properties
203 : : case NS_ooxml::LN_CT_TblPrBase_tblCellMar: //cell margins
204 : : {
205 : : //contains LN_CT_TblCellMar_top, LN_CT_TblCellMar_left, LN_CT_TblCellMar_bottom, LN_CT_TblCellMar_right
206 : : // LN_CT_TblCellMar_start, LN_CT_TblCellMar_end
207 [ + - ]: 94 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
208 [ + - ]: 94 : if( pProperties.get())
209 : : {
210 [ + - ][ + - ]: 94 : CellMarginHandlerPtr pCellMarginHandler( new CellMarginHandler );
[ + - ]
211 [ + - ]: 94 : pProperties->resolve( *pCellMarginHandler );
212 [ + - ][ + - ]: 94 : TablePropertyMapPtr pMarginProps( new TablePropertyMap );
[ + - ]
213 [ + - ]: 94 : if( pCellMarginHandler->m_bTopMarginValid )
214 [ + - ]: 94 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_TOP, pCellMarginHandler->m_nTopMargin );
215 [ + - ]: 94 : if( pCellMarginHandler->m_bBottomMarginValid )
216 [ + - ]: 94 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_BOTTOM, pCellMarginHandler->m_nBottomMargin );
217 [ + - ]: 94 : if( pCellMarginHandler->m_bLeftMarginValid )
218 [ + - ]: 94 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_LEFT, pCellMarginHandler->m_nLeftMargin );
219 [ + - ]: 94 : if( pCellMarginHandler->m_bRightMarginValid )
220 [ + - ]: 94 : pMarginProps->setValue( TablePropertyMap::CELL_MAR_RIGHT, pCellMarginHandler->m_nRightMargin );
221 [ + - ][ + - ]: 94 : insertTableProps(pMarginProps);
[ + - ][ + - ]
[ + - ]
222 [ + - ]: 94 : }
223 : : }
224 : 94 : break;
225 : : case NS_ooxml::LN_CT_TblPrBase_tblInd:
226 : : {
227 [ + - ]: 94 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
228 [ + - ]: 94 : if (pProperties.get())
229 : : {
230 [ + - ][ + - ]: 94 : MeasureHandlerPtr pHandler(new MeasureHandler);
[ + - ]
231 [ + - ]: 94 : pProperties->resolve( *pHandler );
232 [ + - ][ + - ]: 94 : TablePropertyMapPtr pTblIndMap(new TablePropertyMap);
[ + - ]
233 [ + - ]: 94 : sal_uInt32 nTblInd = pHandler->getMeasureValue();
234 [ + - ]: 94 : pTblIndMap->setValue( TablePropertyMap::LEFT_MARGIN, nTblInd);
235 [ + - ][ + - ]: 94 : insertTableProps(pTblIndMap);
[ + - ][ + - ]
[ + - ]
236 [ + - ]: 94 : }
237 : : }
238 : 94 : break;
239 : 62196 : default: bRet = false;
240 : : }
241 : :
242 : : #ifdef DEBUG_DOMAINMAPPER
243 : : dmapper_logger->endElement();
244 : : #endif
245 : :
246 [ + - ]: 63055 : return bRet;
247 : : }
248 [ + - ][ + - ]: 60 : }}
249 : :
250 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|