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