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 "oox/drawingml/table/tablecell.hxx"
21 : : #include "oox/drawingml/table/tableproperties.hxx"
22 : : #include "oox/drawingml/shapepropertymap.hxx"
23 : : #include "oox/drawingml/textbody.hxx"
24 : : #include "oox/core/xmlfilterbase.hxx"
25 : : #include "oox/helper/propertyset.hxx"
26 : : #include <com/sun/star/container/XNameContainer.hpp>
27 : : #include <com/sun/star/beans/XMultiPropertySet.hpp>
28 : : #include <com/sun/star/table/XTable.hpp>
29 : : #include <com/sun/star/table/XMergeableCellRange.hpp>
30 : : #include <com/sun/star/table/BorderLine2.hpp>
31 : : #include <com/sun/star/drawing/LineStyle.hpp>
32 : : #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
33 : : #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
34 : : #include <com/sun/star/text/XText.hpp>
35 : :
36 : : using rtl::OUString;
37 : : using namespace ::oox::core;
38 : : using namespace ::com::sun::star;
39 : : using namespace ::com::sun::star::uno;
40 : : using namespace ::com::sun::star::beans;
41 : : using ::com::sun::star::table::BorderLine2;
42 : : using ::com::sun::star::drawing::LineStyle;
43 : :
44 : : namespace oox { namespace drawingml { namespace table {
45 : :
46 : 0 : TableCell::TableCell()
47 : 0 : : mpTextBody( new TextBody() )
48 : : , mnRowSpan ( 1 )
49 : : , mnGridSpan( 1 )
50 : : , mbhMerge( sal_False )
51 : : , mbvMerge( sal_False )
52 : : , mnMarL( 91440 )
53 : : , mnMarR( 91440 )
54 : : , mnMarT( 45720 )
55 : : , mnMarB( 45720 )
56 : : , mnVertToken( XML_horz )
57 : : , mnAnchorToken( XML_t )
58 : : , mbAnchorCtr( sal_False )
59 [ # # ][ # # ]: 0 : , mnHorzOverflowToken( XML_clip )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
60 : : {
61 : 0 : }
62 [ # # ][ # # ]: 0 : TableCell::~TableCell()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
63 : : {
64 : 0 : }
65 : :
66 : 0 : void applyLineAttributes( const ::oox::core::XmlFilterBase& rFilterBase,
67 : : Reference< XPropertySet >& rxPropSet, oox::drawingml::LineProperties& rLineProperties,
68 : : sal_Int32 nPropId )
69 : : {
70 : 0 : BorderLine2 aBorderLine;
71 [ # # ]: 0 : if( rLineProperties.maLineFill.moFillType.differsFrom( XML_noFill ) )
72 : : {
73 [ # # ]: 0 : Color aColor = rLineProperties.maLineFill.getBestSolidColor();
74 [ # # ][ # # ]: 0 : aBorderLine.Color = aColor.getColor( rFilterBase.getGraphicHelper() );
75 [ # # ]: 0 : aBorderLine.OuterLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.get( 0 ) ) / 4 );
76 [ # # ]: 0 : aBorderLine.InnerLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.get( 0 ) ) / 4 );
77 [ # # ]: 0 : aBorderLine.LineDistance = 0;
78 : : }
79 : :
80 [ # # ]: 0 : PropertySet aPropSet( rxPropSet );
81 [ # # ][ # # ]: 0 : aPropSet.setProperty( nPropId, aBorderLine );
82 : 0 : }
83 : :
84 : 0 : void applyBorder( TableStylePart& rTableStylePart, sal_Int32 nLineType, oox::drawingml::LineProperties& rLineProperties )
85 : : {
86 : 0 : std::map < sal_Int32, ::oox::drawingml::LinePropertiesPtr >& rPartLineBorders( rTableStylePart.getLineBorders() );
87 [ # # ]: 0 : std::map < sal_Int32, ::oox::drawingml::LinePropertiesPtr >::const_iterator aIter( rPartLineBorders.find( nLineType ) );
88 [ # # ][ # # ]: 0 : if ( ( aIter != rPartLineBorders.end() ) && aIter->second.get() )
[ # # ][ # # ]
[ # # ]
89 [ # # ]: 0 : rLineProperties.assignUsed( *aIter->second );
90 : 0 : }
91 : :
92 : 0 : void applyTableStylePart( oox::drawingml::FillProperties& rFillProperties,
93 : : TextCharacterProperties& aTextCharProps,
94 : : oox::drawingml::LineProperties& rLeftBorder,
95 : : oox::drawingml::LineProperties& rRightBorder,
96 : : oox::drawingml::LineProperties& rTopBorder,
97 : : oox::drawingml::LineProperties& rBottomBorder,
98 : : oox::drawingml::LineProperties& rTopLeftToBottomRightBorder,
99 : : oox::drawingml::LineProperties& rBottomLeftToTopRightBorder,
100 : : TableStylePart& rTableStylePart )
101 : : {
102 : 0 : boost::shared_ptr< ::oox::drawingml::FillProperties >& rPartFillPropertiesPtr( rTableStylePart.getFillProperties() );
103 [ # # ]: 0 : if ( rPartFillPropertiesPtr.get() )
104 : 0 : rFillProperties.assignUsed( *rPartFillPropertiesPtr );
105 : :
106 : 0 : applyBorder( rTableStylePart, XML_left, rLeftBorder );
107 : 0 : applyBorder( rTableStylePart, XML_right, rRightBorder );
108 : 0 : applyBorder( rTableStylePart, XML_top, rTopBorder );
109 : 0 : applyBorder( rTableStylePart, XML_bottom, rBottomBorder );
110 : 0 : applyBorder( rTableStylePart, XML_tl2br, rTopLeftToBottomRightBorder );
111 : 0 : applyBorder( rTableStylePart, XML_tr2bl, rBottomLeftToTopRightBorder );
112 : :
113 : 0 : aTextCharProps.maLatinFont = rTableStylePart.getLatinFont();
114 : 0 : aTextCharProps.maAsianFont = rTableStylePart.getAsianFont();
115 : 0 : aTextCharProps.maComplexFont = rTableStylePart.getComplexFont();
116 : 0 : aTextCharProps.maSymbolFont = rTableStylePart.getSymbolFont();
117 [ # # ]: 0 : if (rTableStylePart.getTextColor().isUsed())
118 : 0 : aTextCharProps.maCharColor = rTableStylePart.getTextColor();
119 [ # # ]: 0 : if( rTableStylePart.getTextBoldStyle().is_initialized() )
120 [ # # ]: 0 : aTextCharProps.moBold = rTableStylePart.getTextBoldStyle();
121 [ # # ]: 0 : if( rTableStylePart.getTextItalicStyle().is_initialized() )
122 [ # # ]: 0 : aTextCharProps.moItalic = rTableStylePart.getTextItalicStyle();
123 : 0 : }
124 : :
125 : 0 : void applyTableCellProperties( const Reference < ::com::sun::star::table::XCell >& rxCell, const TableCell& rTableCell )
126 : : {
127 [ # # ][ # # ]: 0 : static const rtl::OUString sTopBorder( RTL_CONSTASCII_USTRINGPARAM( "TextUpperDistance" ) );
[ # # ][ # # ]
128 [ # # ][ # # ]: 0 : static const rtl::OUString sBottomBorder( RTL_CONSTASCII_USTRINGPARAM( "TextLowerDistance" ) );
[ # # ][ # # ]
129 [ # # ][ # # ]: 0 : static const rtl::OUString sLeftBorder( RTL_CONSTASCII_USTRINGPARAM( "TextLeftDistance" ) );
[ # # ][ # # ]
130 [ # # ][ # # ]: 0 : static const rtl::OUString sRightBorder( RTL_CONSTASCII_USTRINGPARAM( "TextRightDistance" ) );
[ # # ][ # # ]
131 [ # # ][ # # ]: 0 : static const rtl::OUString sVerticalAdjust( RTL_CONSTASCII_USTRINGPARAM( "TextVerticalAdjust" ) );
[ # # ][ # # ]
132 : :
133 [ # # ]: 0 : Reference< XPropertySet > xPropSet( rxCell, UNO_QUERY_THROW );
134 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( sTopBorder, Any( static_cast< sal_Int32 >( rTableCell.getTopMargin() / 360 ) ) );
[ # # ]
135 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( sRightBorder, Any( static_cast< sal_Int32 >( rTableCell.getRightMargin() / 360 ) ) );
[ # # ]
136 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( sLeftBorder, Any( static_cast< sal_Int32 >( rTableCell.getLeftMargin() / 360 ) ) );
[ # # ]
137 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( sBottomBorder, Any( static_cast< sal_Int32 >( rTableCell.getBottomMargin() / 360 ) ) );
[ # # ]
138 : :
139 : : drawing::TextVerticalAdjust eVA;
140 [ # # # ]: 0 : switch( rTableCell.getAnchorToken() )
141 : : {
142 : 0 : case XML_ctr: eVA = drawing::TextVerticalAdjust_CENTER; break;
143 : 0 : case XML_b: eVA = drawing::TextVerticalAdjust_BOTTOM; break;
144 : : case XML_just:
145 : : case XML_dist:
146 : : default:
147 : 0 : case XML_t: eVA = drawing::TextVerticalAdjust_TOP; break;
148 : : }
149 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( sVerticalAdjust, Any( eVA ) );
[ # # ]
150 : 0 : }
151 : :
152 : 0 : void TableCell::pushToXCell( const ::oox::core::XmlFilterBase& rFilterBase, ::oox::drawingml::TextListStylePtr pMasterTextListStyle,
153 : : const ::com::sun::star::uno::Reference < ::com::sun::star::table::XCell >& rxCell, const TableProperties& rTableProperties,
154 : : const TableStyle& rTableStyle, sal_Int32 nColumn, sal_Int32 nMaxColumn, sal_Int32 nRow, sal_Int32 nMaxRow )
155 : : {
156 : 0 : TableStyle& rTable( const_cast< TableStyle& >( rTableStyle ) );
157 : 0 : TableProperties& rProperties( const_cast< TableProperties& >( rTableProperties ) );
158 : :
159 [ # # ]: 0 : Reference< text::XText > xText( rxCell, UNO_QUERY_THROW );
160 [ # # ][ # # ]: 0 : Reference< text::XTextCursor > xAt = xText->createTextCursor();
161 : :
162 [ # # ]: 0 : applyTableCellProperties( rxCell, *this );
163 [ # # ]: 0 : TextCharacterProperties aTextStyleProps;
164 [ # # ][ # # ]: 0 : xAt->gotoStart( sal_True );
165 [ # # ]: 0 : Reference< text::XTextRange > xStart( xAt, UNO_QUERY );
166 [ # # ][ # # ]: 0 : xAt->gotoEnd( sal_True );
167 : :
168 [ # # ]: 0 : Reference< XPropertySet > xPropSet( rxCell, UNO_QUERY_THROW );
169 [ # # ]: 0 : oox::drawingml::FillProperties aFillProperties;
170 [ # # ]: 0 : oox::drawingml::LineProperties aLinePropertiesLeft;
171 [ # # ]: 0 : oox::drawingml::LineProperties aLinePropertiesRight;
172 [ # # ]: 0 : oox::drawingml::LineProperties aLinePropertiesTop;
173 [ # # ]: 0 : oox::drawingml::LineProperties aLinePropertiesBottom;
174 [ # # ]: 0 : oox::drawingml::LineProperties aLinePropertiesTopLeftToBottomRight;
175 [ # # ]: 0 : oox::drawingml::LineProperties aLinePropertiesBottomLeftToTopRight;
176 : :
177 : 0 : boost::shared_ptr< ::oox::drawingml::FillProperties >& rBackgroundFillPropertiesPtr( rTable.getBackgroundFillProperties() );
178 [ # # ]: 0 : if ( rBackgroundFillPropertiesPtr.get() )
179 [ # # ]: 0 : aFillProperties.assignUsed( *rBackgroundFillPropertiesPtr );
180 : :
181 : : applyTableStylePart( aFillProperties, aTextStyleProps,
182 : : aLinePropertiesLeft,
183 : : aLinePropertiesRight,
184 : : aLinePropertiesTop,
185 : : aLinePropertiesBottom,
186 : : aLinePropertiesTopLeftToBottomRight,
187 : : aLinePropertiesBottomLeftToTopRight,
188 [ # # ]: 0 : rTable.getWholeTbl() );
189 : :
190 [ # # ][ # # ]: 0 : if ( rProperties.isFirstRow() && ( nRow == 0 ) )
[ # # ]
191 : : {
192 : : applyTableStylePart( aFillProperties, aTextStyleProps,
193 : : aLinePropertiesLeft,
194 : : aLinePropertiesRight,
195 : : aLinePropertiesTop,
196 : : aLinePropertiesBottom,
197 : : aLinePropertiesTopLeftToBottomRight,
198 : : aLinePropertiesBottomLeftToTopRight,
199 [ # # ]: 0 : rTable.getFirstRow() );
200 : : }
201 [ # # ][ # # ]: 0 : if ( rProperties.isLastRow() && ( nRow == nMaxRow ) )
[ # # ]
202 : : {
203 : : applyTableStylePart( aFillProperties, aTextStyleProps,
204 : : aLinePropertiesLeft,
205 : : aLinePropertiesRight,
206 : : aLinePropertiesTop,
207 : : aLinePropertiesBottom,
208 : : aLinePropertiesTopLeftToBottomRight,
209 : : aLinePropertiesBottomLeftToTopRight,
210 [ # # ]: 0 : rTable.getLastRow() );
211 : : }
212 [ # # ][ # # ]: 0 : if ( rProperties.isFirstCol() && ( nColumn == 0 ) )
[ # # ]
213 : : {
214 : : applyTableStylePart( aFillProperties, aTextStyleProps,
215 : : aLinePropertiesLeft,
216 : : aLinePropertiesRight,
217 : : aLinePropertiesTop,
218 : : aLinePropertiesBottom,
219 : : aLinePropertiesTopLeftToBottomRight,
220 : : aLinePropertiesBottomLeftToTopRight,
221 [ # # ]: 0 : rTable.getFirstCol() );
222 : : }
223 [ # # ][ # # ]: 0 : if ( rProperties.isLastCol() && ( nColumn == nMaxColumn ) )
[ # # ]
224 : : {
225 : : applyTableStylePart( aFillProperties, aTextStyleProps,
226 : : aLinePropertiesLeft,
227 : : aLinePropertiesRight,
228 : : aLinePropertiesTop,
229 : : aLinePropertiesBottom,
230 : : aLinePropertiesTopLeftToBottomRight,
231 : : aLinePropertiesBottomLeftToTopRight,
232 [ # # ]: 0 : rTable.getLastCol() );
233 : : }
234 [ # # ]: 0 : if ( rProperties.isBandRow() )
235 : : {
236 [ # # ]: 0 : if ( ( !rProperties.isFirstRow() || ( nRow != 0 ) ) &&
[ # # # # ]
[ # # ][ # # ]
237 : 0 : ( !rProperties.isLastRow() || ( nRow != nMaxRow ) ) )
238 : : {
239 : 0 : sal_Int32 nBand = nRow;
240 [ # # ]: 0 : if ( rProperties.isFirstRow() )
241 : 0 : nBand++;
242 [ # # ]: 0 : if ( nBand & 1 )
243 : : {
244 : : applyTableStylePart( aFillProperties, aTextStyleProps,
245 : : aLinePropertiesLeft,
246 : : aLinePropertiesRight,
247 : : aLinePropertiesTop,
248 : : aLinePropertiesBottom,
249 : : aLinePropertiesTopLeftToBottomRight,
250 : : aLinePropertiesBottomLeftToTopRight,
251 [ # # ]: 0 : rTable.getBand2H() );
252 : : }
253 : : else
254 : : {
255 : : applyTableStylePart( aFillProperties, aTextStyleProps,
256 : : aLinePropertiesLeft,
257 : : aLinePropertiesRight,
258 : : aLinePropertiesTop,
259 : : aLinePropertiesBottom,
260 : : aLinePropertiesTopLeftToBottomRight,
261 : : aLinePropertiesBottomLeftToTopRight,
262 [ # # ]: 0 : rTable.getBand1H() );
263 : : }
264 : : }
265 : : }
266 [ # # ][ # # ]: 0 : if ( ( nRow == 0 ) && ( nColumn == 0 ) )
267 : : {
268 : : applyTableStylePart( aFillProperties, aTextStyleProps,
269 : : aLinePropertiesLeft,
270 : : aLinePropertiesRight,
271 : : aLinePropertiesTop,
272 : : aLinePropertiesBottom,
273 : : aLinePropertiesTopLeftToBottomRight,
274 : : aLinePropertiesBottomLeftToTopRight,
275 [ # # ]: 0 : rTable.getNwCell() );
276 : : }
277 [ # # ][ # # ]: 0 : if ( ( nRow == nMaxRow ) && ( nColumn == 0 ) )
278 : : {
279 : : applyTableStylePart( aFillProperties, aTextStyleProps,
280 : : aLinePropertiesLeft,
281 : : aLinePropertiesRight,
282 : : aLinePropertiesTop,
283 : : aLinePropertiesBottom,
284 : : aLinePropertiesTopLeftToBottomRight,
285 : : aLinePropertiesBottomLeftToTopRight,
286 [ # # ]: 0 : rTable.getSwCell() );
287 : : }
288 [ # # ][ # # ]: 0 : if ( ( nRow == 0 ) && ( nColumn == nMaxColumn ) )
289 : : {
290 : : applyTableStylePart( aFillProperties, aTextStyleProps,
291 : : aLinePropertiesLeft,
292 : : aLinePropertiesRight,
293 : : aLinePropertiesTop,
294 : : aLinePropertiesBottom,
295 : : aLinePropertiesTopLeftToBottomRight,
296 : : aLinePropertiesBottomLeftToTopRight,
297 [ # # ]: 0 : rTable.getNeCell() );
298 : : }
299 [ # # ][ # # ]: 0 : if ( ( nRow == nMaxColumn ) && ( nColumn == nMaxColumn ) )
300 : : {
301 : : applyTableStylePart( aFillProperties, aTextStyleProps,
302 : : aLinePropertiesLeft,
303 : : aLinePropertiesRight,
304 : : aLinePropertiesTop,
305 : : aLinePropertiesBottom,
306 : : aLinePropertiesTopLeftToBottomRight,
307 : : aLinePropertiesBottomLeftToTopRight,
308 [ # # ]: 0 : rTable.getSeCell() );
309 : : }
310 [ # # ]: 0 : if ( rProperties.isBandCol() )
311 : : {
312 [ # # ]: 0 : if ( ( !rProperties.isFirstCol() || ( nColumn != 0 ) ) &&
[ # # # # ]
[ # # ][ # # ]
313 : 0 : ( !rProperties.isLastCol() || ( nColumn != nMaxColumn ) ) )
314 : : {
315 : 0 : sal_Int32 nBand = nColumn;
316 [ # # ]: 0 : if ( rProperties.isFirstCol() )
317 : 0 : nBand++;
318 [ # # ]: 0 : if ( nBand & 1 )
319 : : {
320 : : applyTableStylePart( aFillProperties, aTextStyleProps,
321 : : aLinePropertiesLeft,
322 : : aLinePropertiesRight,
323 : : aLinePropertiesTop,
324 : : aLinePropertiesBottom,
325 : : aLinePropertiesTopLeftToBottomRight,
326 : : aLinePropertiesBottomLeftToTopRight,
327 [ # # ]: 0 : rTable.getBand2V() );
328 : : }
329 : : else
330 : : {
331 : : applyTableStylePart( aFillProperties, aTextStyleProps,
332 : : aLinePropertiesLeft,
333 : : aLinePropertiesRight,
334 : : aLinePropertiesTop,
335 : : aLinePropertiesBottom,
336 : : aLinePropertiesTopLeftToBottomRight,
337 : : aLinePropertiesBottomLeftToTopRight,
338 [ # # ]: 0 : rTable.getBand1V() );
339 : : }
340 : : }
341 : : }
342 [ # # ]: 0 : aLinePropertiesLeft.assignUsed( maLinePropertiesLeft );
343 [ # # ]: 0 : aLinePropertiesRight.assignUsed( maLinePropertiesRight );
344 [ # # ]: 0 : aLinePropertiesTop.assignUsed( maLinePropertiesTop );
345 [ # # ]: 0 : aLinePropertiesBottom.assignUsed( maLinePropertiesBottom );
346 [ # # ]: 0 : aLinePropertiesTopLeftToBottomRight.assignUsed( maLinePropertiesTopLeftToBottomRight );
347 [ # # ]: 0 : aLinePropertiesBottomLeftToTopRight.assignUsed( maLinePropertiesBottomLeftToTopRight );
348 [ # # ]: 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesLeft, PROP_LeftBorder );
349 [ # # ]: 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesRight, PROP_RightBorder );
350 [ # # ]: 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesTop, PROP_TopBorder );
351 [ # # ]: 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesBottom, PROP_BottomBorder );
352 [ # # ]: 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesTopLeftToBottomRight, PROP_DiagonalTLBR );
353 [ # # ]: 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesBottomLeftToTopRight, PROP_DiagonalBLTR );
354 : :
355 [ # # ]: 0 : aFillProperties.assignUsed( maFillProperties );
356 [ # # ][ # # ]: 0 : ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
357 : : // TODO: phClr?
358 [ # # ][ # # ]: 0 : aFillProperties.pushToPropMap( aPropMap, rFilterBase.getGraphicHelper() );
359 [ # # ][ # # ]: 0 : PropertySet( xPropSet ).setProperties( aPropMap );
[ # # ]
360 : :
361 [ # # ][ # # ]: 0 : getTextBody()->insertAt( rFilterBase, xText, xAt, aTextStyleProps, pMasterTextListStyle );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
362 : 0 : }
363 : :
364 [ + - ][ + - ]: 285 : } } }
365 : :
366 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|