1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "oox/drawingml/table/tablecell.hxx"
25 #include "oox/drawingml/table/tableproperties.hxx"
26 #include "oox/drawingml/shapepropertymap.hxx"
27 #include "oox/drawingml/textbody.hxx"
28 #include "oox/core/xmlfilterbase.hxx"
29 #include "oox/helper/propertyset.hxx"
30 #include <com/sun/star/container/XNameContainer.hpp>
31 #include <com/sun/star/beans/XMultiPropertySet.hpp>
32 #include <com/sun/star/table/XTable.hpp>
33 #include <com/sun/star/table/XMergeableCellRange.hpp>
34 #include <com/sun/star/table/BorderLine.hpp>
35 #include <com/sun/star/drawing/LineStyle.hpp>
36 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
37 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
38 #include <com/sun/star/text/XText.hpp>
39 #include <com/sun/star/text/WritingMode.hpp>
40
41 using rtl::OUString;
42 using namespace ::oox::core;
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::beans;
46 using ::com::sun::star::table::BorderLine;
47 using ::com::sun::star::drawing::LineStyle;
48
49 namespace oox { namespace drawingml { namespace table {
50
TableCell()51 TableCell::TableCell()
52 : mnRowSpan ( 1 )
53 , mnGridSpan( 1 )
54 , mbhMerge( sal_False )
55 , mbvMerge( sal_False )
56 , mnMarL( 91440 )
57 , mnMarR( 91440 )
58 , mnMarT( 45720 )
59 , mnMarB( 45720 )
60 , mnVertToken( XML_horz )
61 , mnAnchorToken( XML_t )
62 , mbAnchorCtr( sal_False )
63 , mnHorzOverflowToken( XML_clip )
64 {
65 }
~TableCell()66 TableCell::~TableCell()
67 {
68 }
69
applyLineAttributes(const::oox::core::XmlFilterBase & rFilterBase,Reference<XPropertySet> & rxPropSet,oox::drawingml::LineProperties & rLineProperties,sal_Int32 nPropId)70 void applyLineAttributes( const ::oox::core::XmlFilterBase& rFilterBase,
71 Reference< XPropertySet >& rxPropSet, oox::drawingml::LineProperties& rLineProperties,
72 sal_Int32 nPropId )
73 {
74 BorderLine aBorderLine( 0, 0, 0, 0 );
75 if( rLineProperties.maLineFill.moFillType.differsFrom( XML_noFill ) )
76 {
77 Color aColor = rLineProperties.maLineFill.getBestSolidColor();
78 aBorderLine.Color = aColor.getColor( rFilterBase.getGraphicHelper() );
79 aBorderLine.OuterLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.get( 0 ) ) / 4 );
80 aBorderLine.InnerLineWidth = static_cast< sal_Int16 >( GetCoordinate( rLineProperties.moLineWidth.get( 0 ) ) / 4 );
81 aBorderLine.LineDistance = 0;
82 }
83
84 PropertySet aPropSet( rxPropSet );
85 aPropSet.setProperty( nPropId, aBorderLine );
86 }
87
applyBorder(TableStylePart & rTableStylePart,sal_Int32 nLineType,oox::drawingml::LineProperties & rLineProperties)88 void applyBorder( TableStylePart& rTableStylePart, sal_Int32 nLineType, oox::drawingml::LineProperties& rLineProperties )
89 {
90 std::map < sal_Int32, ::oox::drawingml::LinePropertiesPtr >& rPartLineBorders( rTableStylePart.getLineBorders() );
91 std::map < sal_Int32, ::oox::drawingml::LinePropertiesPtr >::const_iterator aIter( rPartLineBorders.find( nLineType ) );
92 if ( ( aIter != rPartLineBorders.end() ) && aIter->second.get() )
93 rLineProperties.assignUsed( *aIter->second );
94 }
95
applyTableStylePart(const::oox::core::XmlFilterBase & rFilterBase,const Reference<::com::sun::star::table::XCell> & rxCell,oox::drawingml::FillProperties & rFillProperties,oox::drawingml::LineProperties & rLeftBorder,oox::drawingml::LineProperties & rRightBorder,oox::drawingml::LineProperties & rTopBorder,oox::drawingml::LineProperties & rBottomBorder,oox::drawingml::LineProperties & rTopLeftToBottomRightBorder,oox::drawingml::LineProperties & rBottomLeftToTopRightBorder,TableStylePart & rTableStylePart)96 void applyTableStylePart( const ::oox::core::XmlFilterBase& rFilterBase, const Reference < ::com::sun::star::table::XCell >& rxCell, oox::drawingml::FillProperties& rFillProperties,
97 oox::drawingml::LineProperties& rLeftBorder,
98 oox::drawingml::LineProperties& rRightBorder,
99 oox::drawingml::LineProperties& rTopBorder,
100 oox::drawingml::LineProperties& rBottomBorder,
101 oox::drawingml::LineProperties& rTopLeftToBottomRightBorder,
102 oox::drawingml::LineProperties& rBottomLeftToTopRightBorder,
103 TableStylePart& rTableStylePart )
104 {
105 boost::shared_ptr< ::oox::drawingml::FillProperties >& rPartFillPropertiesPtr( rTableStylePart.getFillProperties() );
106 if ( rPartFillPropertiesPtr.get() )
107 rFillProperties.assignUsed( *rPartFillPropertiesPtr );
108
109 applyBorder( rTableStylePart, XML_left, rLeftBorder );
110 applyBorder( rTableStylePart, XML_right, rRightBorder );
111 applyBorder( rTableStylePart, XML_top, rTopBorder );
112 applyBorder( rTableStylePart, XML_bottom, rBottomBorder );
113 applyBorder( rTableStylePart, XML_tl2br, rTopLeftToBottomRightBorder );
114 applyBorder( rTableStylePart, XML_tr2bl, rBottomLeftToTopRightBorder );
115
116 TextCharacterProperties aTextCharProps;
117 aTextCharProps.maLatinFont = rTableStylePart.getLatinFont();
118 aTextCharProps.maAsianFont = rTableStylePart.getAsianFont();
119 aTextCharProps.maComplexFont = rTableStylePart.getComplexFont();
120 aTextCharProps.maSymbolFont = rTableStylePart.getSymbolFont();
121 aTextCharProps.maCharColor = rTableStylePart.getTextColor();
122
123 PropertySet aPropSet( rxCell );
124 aTextCharProps.pushToPropSet( aPropSet, rFilterBase );
125 }
126
applyTableCellProperties(const Reference<::com::sun::star::table::XCell> & rxCell,const TableCell & rTableCell)127 void applyTableCellProperties( const Reference < ::com::sun::star::table::XCell >& rxCell, const TableCell& rTableCell )
128 {
129 static const rtl::OUString sTopBorder( RTL_CONSTASCII_USTRINGPARAM( "TextUpperDistance" ) );
130 static const rtl::OUString sBottomBorder( RTL_CONSTASCII_USTRINGPARAM( "TextLowerDistance" ) );
131 static const rtl::OUString sLeftBorder( RTL_CONSTASCII_USTRINGPARAM( "TextLeftDistance" ) );
132 static const rtl::OUString sRightBorder( RTL_CONSTASCII_USTRINGPARAM( "TextRightDistance" ) );
133 static const rtl::OUString sVerticalAdjust( RTL_CONSTASCII_USTRINGPARAM( "TextVerticalAdjust" ) );
134
135 Reference< XPropertySet > xPropSet( rxCell, UNO_QUERY_THROW );
136 xPropSet->setPropertyValue( sTopBorder, Any( static_cast< sal_Int32 >( rTableCell.getTopMargin() / 360 ) ) );
137 xPropSet->setPropertyValue( sRightBorder, Any( static_cast< sal_Int32 >( rTableCell.getRightMargin() / 360 ) ) );
138 xPropSet->setPropertyValue( sLeftBorder, Any( static_cast< sal_Int32 >( rTableCell.getLeftMargin() / 360 ) ) );
139 xPropSet->setPropertyValue( sBottomBorder, Any( static_cast< sal_Int32 >( rTableCell.getBottomMargin() / 360 ) ) );
140
141 drawing::TextVerticalAdjust eVA;
142 switch( rTableCell.getAnchorToken() )
143 {
144 case XML_ctr: eVA = drawing::TextVerticalAdjust_CENTER; break;
145 case XML_b: eVA = drawing::TextVerticalAdjust_BOTTOM; break;
146 case XML_just:
147 case XML_dist:
148 default:
149 case XML_t: eVA = drawing::TextVerticalAdjust_TOP; break;
150 }
151 xPropSet->setPropertyValue( sVerticalAdjust, Any( eVA ) );
152 }
153
154 // save char color from tblstyle for combination later
lcl_getCharPropFromTblStylePart(TextCharacterProperties & rDstCharProp,const TableStylePart & rSrcTblStyle)155 void lcl_getCharPropFromTblStylePart(TextCharacterProperties& rDstCharProp, const TableStylePart& rSrcTblStyle)
156 {
157 const Color& clr = const_cast<TableStylePart&>(rSrcTblStyle).getTextColor();
158 if (clr.isUsed())
159 rDstCharProp.maCharColor = clr;
160 // TODO: there may be other similar properties from tblstyle which need combination later
161 }
162
pushToXCell(const::oox::core::XmlFilterBase & rFilterBase,::oox::drawingml::TextListStylePtr pMasterTextListStyle,const::com::sun::star::uno::Reference<::com::sun::star::table::XCell> & rxCell,const TableProperties & rTableProperties,const TableStyle & rTableStyle,sal_Int32 nColumn,sal_Int32 nMaxColumn,sal_Int32 nRow,sal_Int32 nMaxRow)163 void TableCell::pushToXCell( const ::oox::core::XmlFilterBase& rFilterBase, ::oox::drawingml::TextListStylePtr pMasterTextListStyle,
164 const ::com::sun::star::uno::Reference < ::com::sun::star::table::XCell >& rxCell, const TableProperties& rTableProperties,
165 const TableStyle& rTableStyle, sal_Int32 nColumn, sal_Int32 nMaxColumn, sal_Int32 nRow, sal_Int32 nMaxRow )
166 {
167 TableStyle& rTable( const_cast< TableStyle& >( rTableStyle ) );
168 TableProperties& rProperties( const_cast< TableProperties& >( rTableProperties ) );
169
170 Reference< text::XText > xText( rxCell, UNO_QUERY_THROW );
171 Reference< text::XTextCursor > xAt = xText->createTextCursor();
172
173 applyTableCellProperties( rxCell, *this );
174
175 Reference< XPropertySet > xPropSet( rxCell, UNO_QUERY_THROW );
176 oox::drawingml::FillProperties aFillProperties;
177 oox::drawingml::LineProperties aLinePropertiesLeft;
178 oox::drawingml::LineProperties aLinePropertiesRight;
179 oox::drawingml::LineProperties aLinePropertiesTop;
180 oox::drawingml::LineProperties aLinePropertiesBottom;
181 oox::drawingml::LineProperties aLinePropertiesTopLeftToBottomRight;
182 oox::drawingml::LineProperties aLinePropertiesBottomLeftToTopRight;
183
184 boost::shared_ptr< ::oox::drawingml::FillProperties >& rBackgroundFillPropertiesPtr( rTable.getBackgroundFillProperties() );
185 if ( rBackgroundFillPropertiesPtr.get() )
186 aFillProperties.assignUsed( *rBackgroundFillPropertiesPtr );
187
188 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
189 aLinePropertiesLeft,
190 aLinePropertiesRight,
191 aLinePropertiesTop,
192 aLinePropertiesBottom,
193 aLinePropertiesTopLeftToBottomRight,
194 aLinePropertiesBottomLeftToTopRight,
195 rTable.getWholeTbl() );
196
197 // get char color from tblstyle for combination later
198 TextCharacterProperties aTextCharProps;
199 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getWholeTbl());
200
201 if ( rProperties.isFirstRow() && ( nRow == 0 ) )
202 {
203 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
204 aLinePropertiesLeft,
205 aLinePropertiesRight,
206 aLinePropertiesTop,
207 aLinePropertiesBottom,
208 aLinePropertiesTopLeftToBottomRight,
209 aLinePropertiesBottomLeftToTopRight,
210 rTable.getFirstRow() );
211 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getFirstRow());
212 }
213 if ( rProperties.isLastRow() && ( nRow == nMaxRow ) )
214 {
215 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
216 aLinePropertiesLeft,
217 aLinePropertiesRight,
218 aLinePropertiesTop,
219 aLinePropertiesBottom,
220 aLinePropertiesTopLeftToBottomRight,
221 aLinePropertiesBottomLeftToTopRight,
222 rTable.getLastRow() );
223 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getLastRow());
224 }
225 if ( rProperties.isFirstCol() && ( nColumn == 0 ) )
226 {
227 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
228 aLinePropertiesLeft,
229 aLinePropertiesRight,
230 aLinePropertiesTop,
231 aLinePropertiesBottom,
232 aLinePropertiesTopLeftToBottomRight,
233 aLinePropertiesBottomLeftToTopRight,
234 rTable.getFirstCol() );
235 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getFirstCol());
236 }
237 if ( rProperties.isLastCol() && ( nColumn == nMaxColumn ) )
238 {
239 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
240 aLinePropertiesLeft,
241 aLinePropertiesRight,
242 aLinePropertiesTop,
243 aLinePropertiesBottom,
244 aLinePropertiesTopLeftToBottomRight,
245 aLinePropertiesBottomLeftToTopRight,
246 rTable.getLastCol() );
247 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getLastCol());
248 }
249 if ( rProperties.isBandRow() )
250 {
251 if ( ( !rProperties.isFirstRow() || ( nRow != 0 ) ) &&
252 ( !rProperties.isLastRow() || ( nRow != nMaxRow ) ) )
253 {
254 sal_Int32 nBand = nRow;
255 if ( rProperties.isFirstRow() )
256 nBand++;
257 if ( nBand & 1 )
258 {
259 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
260 aLinePropertiesLeft,
261 aLinePropertiesRight,
262 aLinePropertiesTop,
263 aLinePropertiesBottom,
264 aLinePropertiesTopLeftToBottomRight,
265 aLinePropertiesBottomLeftToTopRight,
266 rTable.getBand2H() );
267 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getBand2H());
268 }
269 else
270 {
271 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
272 aLinePropertiesLeft,
273 aLinePropertiesRight,
274 aLinePropertiesTop,
275 aLinePropertiesBottom,
276 aLinePropertiesTopLeftToBottomRight,
277 aLinePropertiesBottomLeftToTopRight,
278 rTable.getBand1H() );
279 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getBand1H());
280 }
281 }
282 }
283 if ( ( nRow == 0 ) && ( nColumn == 0 ) )
284 {
285 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
286 aLinePropertiesLeft,
287 aLinePropertiesRight,
288 aLinePropertiesTop,
289 aLinePropertiesBottom,
290 aLinePropertiesTopLeftToBottomRight,
291 aLinePropertiesBottomLeftToTopRight,
292 rTable.getNwCell() );
293 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getNwCell());
294 }
295 if ( ( nRow == nMaxRow ) && ( nColumn == 0 ) )
296 {
297 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
298 aLinePropertiesLeft,
299 aLinePropertiesRight,
300 aLinePropertiesTop,
301 aLinePropertiesBottom,
302 aLinePropertiesTopLeftToBottomRight,
303 aLinePropertiesBottomLeftToTopRight,
304 rTable.getSwCell() );
305 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getSwCell());
306 }
307 if ( ( nRow == 0 ) && ( nColumn == nMaxColumn ) )
308 {
309 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
310 aLinePropertiesLeft,
311 aLinePropertiesRight,
312 aLinePropertiesTop,
313 aLinePropertiesBottom,
314 aLinePropertiesTopLeftToBottomRight,
315 aLinePropertiesBottomLeftToTopRight,
316 rTable.getNeCell() );
317 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getNeCell());
318 }
319 if ( ( nRow == nMaxColumn ) && ( nColumn == nMaxColumn ) )
320 {
321 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
322 aLinePropertiesLeft,
323 aLinePropertiesRight,
324 aLinePropertiesTop,
325 aLinePropertiesBottom,
326 aLinePropertiesTopLeftToBottomRight,
327 aLinePropertiesBottomLeftToTopRight,
328 rTable.getSeCell() );
329 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getSeCell());
330 }
331 if ( rProperties.isBandCol() )
332 {
333 if ( ( !rProperties.isFirstCol() || ( nColumn != 0 ) ) &&
334 ( !rProperties.isLastCol() || ( nColumn != nMaxColumn ) ) )
335 {
336 sal_Int32 nBand = nColumn;
337 if ( rProperties.isFirstCol() )
338 nBand++;
339 if ( nBand & 1 )
340 {
341 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
342 aLinePropertiesLeft,
343 aLinePropertiesRight,
344 aLinePropertiesTop,
345 aLinePropertiesBottom,
346 aLinePropertiesTopLeftToBottomRight,
347 aLinePropertiesBottomLeftToTopRight,
348 rTable.getBand2V() );
349 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getBand2V());
350 }
351 else
352 {
353 applyTableStylePart( rFilterBase, rxCell, aFillProperties,
354 aLinePropertiesLeft,
355 aLinePropertiesRight,
356 aLinePropertiesTop,
357 aLinePropertiesBottom,
358 aLinePropertiesTopLeftToBottomRight,
359 aLinePropertiesBottomLeftToTopRight,
360 rTable.getBand1V() );
361 lcl_getCharPropFromTblStylePart(aTextCharProps, rTable.getBand1V());
362 }
363 }
364 }
365
366 getTextBody()->insertAt( rFilterBase, xText, xAt, aTextCharProps, pMasterTextListStyle );
367
368 aLinePropertiesLeft.assignUsed( maLinePropertiesLeft );
369 aLinePropertiesRight.assignUsed( maLinePropertiesRight );
370 aLinePropertiesTop.assignUsed( maLinePropertiesTop );
371 aLinePropertiesBottom.assignUsed( maLinePropertiesBottom );
372 aLinePropertiesTopLeftToBottomRight.assignUsed( maLinePropertiesTopLeftToBottomRight );
373 aLinePropertiesBottomLeftToTopRight.assignUsed( maLinePropertiesBottomLeftToTopRight );
374 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesLeft, PROP_LeftBorder );
375 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesRight, PROP_RightBorder );
376 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesTop, PROP_TopBorder );
377 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesBottom, PROP_BottomBorder );
378 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesTopLeftToBottomRight, PROP_DiagonalTLBR );
379 applyLineAttributes( rFilterBase, xPropSet, aLinePropertiesBottomLeftToTopRight, PROP_DiagonalBLTR );
380
381 aFillProperties.assignUsed( maFillProperties );
382 ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
383 // TODO: phClr?
384 aFillProperties.pushToPropMap( aPropMap, rFilterBase.getGraphicHelper() );
385 PropertySet( xPropSet ).setProperties( aPropMap );
386
387 if ( getVertToken() == XML_eaVert )
388 {
389 xPropSet->setPropertyValue(::rtl::OUString::createFromAscii( "TextWritingMode" ) , Any(com::sun::star::text::WritingMode_TB_RL) );
390 }
391 }
392
393 } } }
394