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 : #include <com/sun/star/text/WritingMode.hpp>
36 :
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 :
43 : namespace oox { namespace drawingml { namespace table {
44 :
45 0 : TableCell::TableCell()
46 0 : : mpTextBody( new TextBody() )
47 : , mnRowSpan ( 1 )
48 : , mnGridSpan( 1 )
49 : , mbhMerge( false )
50 : , mbvMerge( false )
51 : , mnMarL( 91440 )
52 : , mnMarR( 91440 )
53 : , mnMarT( 45720 )
54 : , mnMarB( 45720 )
55 : , mnVertToken( XML_horz )
56 : , mnAnchorToken( XML_t )
57 : , mbAnchorCtr( false )
58 0 : , mnHorzOverflowToken( XML_clip )
59 : {
60 0 : }
61 0 : TableCell::~TableCell()
62 : {
63 0 : }
64 :
65 0 : void applyLineAttributes( const ::oox::core::XmlFilterBase& rFilterBase,
66 : Reference< XPropertySet >& rxPropSet, oox::drawingml::LineProperties& rLineProperties,
67 : sal_Int32 nPropId )
68 : {
69 0 : BorderLine2 aBorderLine;
70 0 : if( rLineProperties.maLineFill.moFillType.differsFrom( XML_noFill ) )
71 : {
72 0 : Color aColor = rLineProperties.maLineFill.getBestSolidColor();
73 0 : aBorderLine.Color = aColor.getColor( rFilterBase.getGraphicHelper() );
74 0 : aBorderLine.OuterLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.get( 0 ) ) / 4 );
75 0 : aBorderLine.InnerLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.get( 0 ) ) / 4 );
76 0 : aBorderLine.LineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.get( 0 ) ) / 2 );
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 : Reference< XPropertySet > xPropSet( rxCell, UNO_QUERY_THROW );
128 0 : xPropSet->setPropertyValue( "TextUpperDistance", Any( static_cast< sal_Int32 >( rTableCell.getTopMargin() / 360 ) ) );
129 0 : xPropSet->setPropertyValue( "TextRightDistance", Any( static_cast< sal_Int32 >( rTableCell.getRightMargin() / 360 ) ) );
130 0 : xPropSet->setPropertyValue( "TextLeftDistance", Any( static_cast< sal_Int32 >( rTableCell.getLeftMargin() / 360 ) ) );
131 0 : xPropSet->setPropertyValue( "TextLowerDistance", Any( static_cast< sal_Int32 >( rTableCell.getBottomMargin() / 360 ) ) );
132 :
133 : drawing::TextVerticalAdjust eVA;
134 0 : switch( rTableCell.getAnchorToken() )
135 : {
136 0 : case XML_ctr: eVA = drawing::TextVerticalAdjust_CENTER; break;
137 0 : case XML_b: eVA = drawing::TextVerticalAdjust_BOTTOM; break;
138 : case XML_just:
139 : case XML_dist:
140 : default:
141 0 : case XML_t: eVA = drawing::TextVerticalAdjust_TOP; break;
142 : }
143 0 : xPropSet->setPropertyValue( "TextVerticalAdjust", Any( eVA ) );
144 0 : }
145 :
146 0 : void TableCell::pushToXCell( const ::oox::core::XmlFilterBase& rFilterBase, ::oox::drawingml::TextListStylePtr pMasterTextListStyle,
147 : const ::com::sun::star::uno::Reference < ::com::sun::star::table::XCell >& rxCell, const TableProperties& rTableProperties,
148 : const TableStyle& rTableStyle, sal_Int32 nColumn, sal_Int32 nMaxColumn, sal_Int32 nRow, sal_Int32 nMaxRow )
149 : {
150 0 : TableStyle& rTable( const_cast< TableStyle& >( rTableStyle ) );
151 0 : TableProperties& rProperties( const_cast< TableProperties& >( rTableProperties ) );
152 :
153 0 : Reference< text::XText > xText( rxCell, UNO_QUERY_THROW );
154 0 : Reference< text::XTextCursor > xAt = xText->createTextCursor();
155 :
156 0 : applyTableCellProperties( rxCell, *this );
157 0 : TextCharacterProperties aTextStyleProps;
158 0 : xAt->gotoStart( sal_True );
159 0 : Reference< text::XTextRange > xStart( xAt, UNO_QUERY );
160 0 : xAt->gotoEnd( sal_True );
161 :
162 0 : Reference< XPropertySet > xPropSet( rxCell, UNO_QUERY_THROW );
163 0 : oox::drawingml::FillProperties aFillProperties;
164 0 : oox::drawingml::LineProperties aLinePropertiesLeft;
165 0 : oox::drawingml::LineProperties aLinePropertiesRight;
166 0 : oox::drawingml::LineProperties aLinePropertiesTop;
167 0 : oox::drawingml::LineProperties aLinePropertiesBottom;
168 0 : oox::drawingml::LineProperties aLinePropertiesTopLeftToBottomRight;
169 0 : oox::drawingml::LineProperties aLinePropertiesBottomLeftToTopRight;
170 :
171 0 : boost::shared_ptr< ::oox::drawingml::FillProperties >& rBackgroundFillPropertiesPtr( rTable.getBackgroundFillProperties() );
172 0 : if ( rBackgroundFillPropertiesPtr.get() )
173 0 : aFillProperties.assignUsed( *rBackgroundFillPropertiesPtr );
174 :
175 : applyTableStylePart( aFillProperties, aTextStyleProps,
176 : aLinePropertiesLeft,
177 : aLinePropertiesRight,
178 : aLinePropertiesTop,
179 : aLinePropertiesBottom,
180 : aLinePropertiesTopLeftToBottomRight,
181 : aLinePropertiesBottomLeftToTopRight,
182 0 : rTable.getWholeTbl() );
183 :
184 0 : if ( rProperties.isFirstRow() && ( nRow == 0 ) )
185 : {
186 : applyTableStylePart( aFillProperties, aTextStyleProps,
187 : aLinePropertiesLeft,
188 : aLinePropertiesRight,
189 : aLinePropertiesTop,
190 : aLinePropertiesBottom,
191 : aLinePropertiesTopLeftToBottomRight,
192 : aLinePropertiesBottomLeftToTopRight,
193 0 : rTable.getFirstRow() );
194 : }
195 0 : if ( rProperties.isLastRow() && ( nRow == nMaxRow ) )
196 : {
197 : applyTableStylePart( aFillProperties, aTextStyleProps,
198 : aLinePropertiesLeft,
199 : aLinePropertiesRight,
200 : aLinePropertiesTop,
201 : aLinePropertiesBottom,
202 : aLinePropertiesTopLeftToBottomRight,
203 : aLinePropertiesBottomLeftToTopRight,
204 0 : rTable.getLastRow() );
205 : }
206 0 : if ( rProperties.isFirstCol() && ( nColumn == 0 ) )
207 : {
208 : applyTableStylePart( aFillProperties, aTextStyleProps,
209 : aLinePropertiesLeft,
210 : aLinePropertiesRight,
211 : aLinePropertiesTop,
212 : aLinePropertiesBottom,
213 : aLinePropertiesTopLeftToBottomRight,
214 : aLinePropertiesBottomLeftToTopRight,
215 0 : rTable.getFirstCol() );
216 : }
217 0 : if ( rProperties.isLastCol() && ( nColumn == nMaxColumn ) )
218 : {
219 : applyTableStylePart( aFillProperties, aTextStyleProps,
220 : aLinePropertiesLeft,
221 : aLinePropertiesRight,
222 : aLinePropertiesTop,
223 : aLinePropertiesBottom,
224 : aLinePropertiesTopLeftToBottomRight,
225 : aLinePropertiesBottomLeftToTopRight,
226 0 : rTable.getLastCol() );
227 : }
228 0 : if ( rProperties.isBandRow() )
229 : {
230 0 : if ( ( !rProperties.isFirstRow() || ( nRow != 0 ) ) &&
231 0 : ( !rProperties.isLastRow() || ( nRow != nMaxRow ) ) )
232 : {
233 0 : sal_Int32 nBand = nRow;
234 0 : if ( rProperties.isFirstRow() )
235 0 : nBand++;
236 0 : if ( nBand & 1 )
237 : {
238 : applyTableStylePart( aFillProperties, aTextStyleProps,
239 : aLinePropertiesLeft,
240 : aLinePropertiesRight,
241 : aLinePropertiesTop,
242 : aLinePropertiesBottom,
243 : aLinePropertiesTopLeftToBottomRight,
244 : aLinePropertiesBottomLeftToTopRight,
245 0 : rTable.getBand2H() );
246 : }
247 : else
248 : {
249 : applyTableStylePart( aFillProperties, aTextStyleProps,
250 : aLinePropertiesLeft,
251 : aLinePropertiesRight,
252 : aLinePropertiesTop,
253 : aLinePropertiesBottom,
254 : aLinePropertiesTopLeftToBottomRight,
255 : aLinePropertiesBottomLeftToTopRight,
256 0 : rTable.getBand1H() );
257 : }
258 : }
259 : }
260 0 : if ( ( nRow == 0 ) && ( nColumn == 0 ) )
261 : {
262 : applyTableStylePart( aFillProperties, aTextStyleProps,
263 : aLinePropertiesLeft,
264 : aLinePropertiesRight,
265 : aLinePropertiesTop,
266 : aLinePropertiesBottom,
267 : aLinePropertiesTopLeftToBottomRight,
268 : aLinePropertiesBottomLeftToTopRight,
269 0 : rTable.getNwCell() );
270 : }
271 0 : if ( ( nRow == nMaxRow ) && ( nColumn == 0 ) )
272 : {
273 : applyTableStylePart( aFillProperties, aTextStyleProps,
274 : aLinePropertiesLeft,
275 : aLinePropertiesRight,
276 : aLinePropertiesTop,
277 : aLinePropertiesBottom,
278 : aLinePropertiesTopLeftToBottomRight,
279 : aLinePropertiesBottomLeftToTopRight,
280 0 : rTable.getSwCell() );
281 : }
282 0 : if ( ( nRow == 0 ) && ( nColumn == nMaxColumn ) )
283 : {
284 : applyTableStylePart( aFillProperties, aTextStyleProps,
285 : aLinePropertiesLeft,
286 : aLinePropertiesRight,
287 : aLinePropertiesTop,
288 : aLinePropertiesBottom,
289 : aLinePropertiesTopLeftToBottomRight,
290 : aLinePropertiesBottomLeftToTopRight,
291 0 : rTable.getNeCell() );
292 : }
293 0 : if ( ( nRow == nMaxColumn ) && ( nColumn == nMaxColumn ) )
294 : {
295 : applyTableStylePart( aFillProperties, aTextStyleProps,
296 : aLinePropertiesLeft,
297 : aLinePropertiesRight,
298 : aLinePropertiesTop,
299 : aLinePropertiesBottom,
300 : aLinePropertiesTopLeftToBottomRight,
301 : aLinePropertiesBottomLeftToTopRight,
302 0 : rTable.getSeCell() );
303 : }
304 0 : if ( rProperties.isBandCol() )
305 : {
306 0 : if ( ( !rProperties.isFirstCol() || ( nColumn != 0 ) ) &&
307 0 : ( !rProperties.isLastCol() || ( nColumn != nMaxColumn ) ) )
308 : {
309 0 : sal_Int32 nBand = nColumn;
310 0 : if ( rProperties.isFirstCol() )
311 0 : nBand++;
312 0 : if ( nBand & 1 )
313 : {
314 : applyTableStylePart( aFillProperties, aTextStyleProps,
315 : aLinePropertiesLeft,
316 : aLinePropertiesRight,
317 : aLinePropertiesTop,
318 : aLinePropertiesBottom,
319 : aLinePropertiesTopLeftToBottomRight,
320 : aLinePropertiesBottomLeftToTopRight,
321 0 : rTable.getBand2V() );
322 : }
323 : else
324 : {
325 : applyTableStylePart( aFillProperties, aTextStyleProps,
326 : aLinePropertiesLeft,
327 : aLinePropertiesRight,
328 : aLinePropertiesTop,
329 : aLinePropertiesBottom,
330 : aLinePropertiesTopLeftToBottomRight,
331 : aLinePropertiesBottomLeftToTopRight,
332 0 : rTable.getBand1V() );
333 : }
334 : }
335 : }
336 0 : aLinePropertiesLeft.assignUsed( maLinePropertiesLeft );
337 0 : aLinePropertiesRight.assignUsed( maLinePropertiesRight );
338 0 : aLinePropertiesTop.assignUsed( maLinePropertiesTop );
339 0 : aLinePropertiesBottom.assignUsed( maLinePropertiesBottom );
340 0 : aLinePropertiesTopLeftToBottomRight.assignUsed( maLinePropertiesTopLeftToBottomRight );
341 0 : aLinePropertiesBottomLeftToTopRight.assignUsed( maLinePropertiesBottomLeftToTopRight );
342 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesLeft, PROP_LeftBorder );
343 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesRight, PROP_RightBorder );
344 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesTop, PROP_TopBorder );
345 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesBottom, PROP_BottomBorder );
346 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesTopLeftToBottomRight, PROP_DiagonalTLBR );
347 0 : applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesBottomLeftToTopRight, PROP_DiagonalBLTR );
348 :
349 0 : aFillProperties.assignUsed( maFillProperties );
350 0 : ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
351 : // TODO: phClr?
352 0 : aFillProperties.pushToPropMap( aPropMap, rFilterBase.getGraphicHelper() );
353 0 : PropertySet( xPropSet ).setProperties( aPropMap );
354 :
355 0 : if ( getVertToken() == XML_eaVert )
356 : {
357 0 : xPropSet->setPropertyValue("TextWritingMode", Any(com::sun::star::text::WritingMode_TB_RL));
358 : }
359 :
360 0 : getTextBody()->insertAt( rFilterBase, xText, xAt, aTextStyleProps, pMasterTextListStyle );
361 0 : }
362 :
363 0 : } } }
364 :
365 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|