cid#1640468 Dereference after null check
[LibreOffice.git] / oox / source / drawingml / table / tablecell.cxx
blobe6fd01bf43fc8e9967bb9795a5c8e2c2b0b572b7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <drawingml/table/tablecell.hxx>
21 #include <drawingml/table/tableproperties.hxx>
22 #include <basegfx/color/bcolor.hxx>
23 #include <oox/drawingml/shapepropertymap.hxx>
24 #include <drawingml/textbody.hxx>
25 #include <drawingml/textcharacterproperties.hxx>
26 #include <drawingml/textparagraph.hxx>
27 #include <oox/drawingml/theme.hxx>
28 #include <oox/core/xmlfilterbase.hxx>
29 #include <oox/helper/propertyset.hxx>
30 #include <oox/token/properties.hxx>
31 #include <oox/token/tokens.hxx>
32 #include <oox/token/tokenmap.hxx>
33 #include <tools/color.hxx>
34 #include <com/sun/star/table/BorderLineStyle.hpp>
35 #include <com/sun/star/table/BorderLine2.hpp>
36 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
37 #include <com/sun/star/text/XText.hpp>
38 #include <com/sun/star/text/WritingMode.hpp>
39 #include <comphelper/propertysequence.hxx>
40 #include <comphelper/propertyvalue.hxx>
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::BorderLine2;
48 namespace oox::drawingml::table {
50 TableCell::TableCell()
51 : mpTextBody( std::make_shared<TextBody>() )
52 , mnRowSpan ( 1 )
53 , mnGridSpan( 1 )
54 , mbhMerge( false )
55 , mbvMerge( false )
56 , mnMarL( 91440 )
57 , mnMarR( 91440 )
58 , mnMarT( 45720 )
59 , mnMarB( 45720 )
60 , mnVertToken( XML_horz )
61 , mnAnchorToken( XML_t )
62 , mbAnchorCtr( false )
63 , mnHorzOverflowToken( XML_clip )
67 static void applyLineAttributes(const ::oox::core::XmlFilterBase& rFilterBase,
68 Reference<XPropertySet> const& rxPropSet,
69 oox::drawingml::table::TableStyle const& rTableStyle,
70 oox::drawingml::LineProperties const& rLineProperties,
71 sal_Int32 nPropId)
73 BorderLine2 aBorderLine;
74 TableStyle& rTable(const_cast<TableStyle&>(rTableStyle));
75 if (!rTable.getStyleId().isEmpty())
77 Color aColor = rLineProperties.maLineFill.getBestSolidColor();
78 aBorderLine.Color = sal_Int32(aColor.getColor(rFilterBase.getGraphicHelper()));
79 aBorderLine.OuterLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(0)) / 4);
80 aBorderLine.InnerLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(0)) / 4);
81 aBorderLine.LineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(0)) / 2);
82 aBorderLine.LineDistance = 0;
84 else
86 if (rLineProperties.maLineFill.moFillType.has_value())
88 if (rLineProperties.maLineFill.moFillType.value() != XML_noFill)
90 Color aColor = rLineProperties.maLineFill.getBestSolidColor();
91 aBorderLine.Color = sal_Int32(aColor.getColor(rFilterBase.getGraphicHelper()));
93 else
94 aBorderLine.Color = sal_Int32(COL_AUTO);
96 else
97 aBorderLine.Color = sal_Int32(COL_BLACK);
99 aBorderLine.OuterLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(12700)) / 4);
100 aBorderLine.InnerLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(12700)) / 4);
101 aBorderLine.LineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(12700)) / 2);
102 aBorderLine.LineDistance = 0;
105 if ( rLineProperties.moPresetDash.has_value() )
107 switch ( rLineProperties.moPresetDash.value() )
109 case XML_dot:
110 case XML_sysDot:
111 aBorderLine.LineStyle = ::table::BorderLineStyle::DOTTED;
112 break;
113 case XML_dash:
114 case XML_lgDash:
115 case XML_sysDash:
116 aBorderLine.LineStyle = ::table::BorderLineStyle::DASHED;
117 break;
118 case XML_dashDot:
119 case XML_lgDashDot:
120 case XML_sysDashDot:
121 aBorderLine.LineStyle = ::table::BorderLineStyle::DASH_DOT;
122 break;
123 case XML_lgDashDotDot:
124 case XML_sysDashDotDot:
125 aBorderLine.LineStyle = ::table::BorderLineStyle::DASH_DOT_DOT;
126 break;
127 case XML_solid:
128 aBorderLine.LineStyle = ::table::BorderLineStyle::SOLID;
129 break;
130 default:
131 aBorderLine.LineStyle = ::table::BorderLineStyle::DASHED;
132 break;
135 else if ( !rLineProperties.maCustomDash.empty() )
137 aBorderLine.LineStyle = ::table::BorderLineStyle::DASHED;
139 else
141 aBorderLine.LineStyle = ::table::BorderLineStyle::NONE;
144 PropertySet aPropSet( rxPropSet );
145 aPropSet.setProperty( nPropId, aBorderLine );
148 static void applyBorder( const ::oox::core::XmlFilterBase& rFilterBase, TableStylePart& rTableStylePart, sal_Int32 nLineType, oox::drawingml::LineProperties& rLineProperties )
150 std::map < sal_Int32, ::oox::drawingml::LinePropertiesPtr >& rPartLineBorders( rTableStylePart.getLineBorders() );
151 ::oox::drawingml::ShapeStyleRef& rLineStyleRef = rTableStylePart.getStyleRefs()[ nLineType ];
152 std::map < sal_Int32, ::oox::drawingml::LinePropertiesPtr >::const_iterator aIter( rPartLineBorders.find( nLineType ) );
153 if ( ( aIter != rPartLineBorders.end() ) && aIter->second )
154 rLineProperties.assignUsed( *aIter->second );
155 else if (rLineStyleRef.mnThemedIdx != 0)
157 if (const Theme* pTheme = rFilterBase.getCurrentTheme())
159 rLineProperties.assignUsed( *pTheme->getLineStyle(rLineStyleRef.mnThemedIdx) );
160 ::Color nPhClr = rLineStyleRef.maPhClr.getColor( rFilterBase.getGraphicHelper() );
161 rLineProperties.maLineFill.maFillColor.setSrgbClr( nPhClr );
166 static void applyTableStylePart( const ::oox::core::XmlFilterBase& rFilterBase,
167 oox::drawingml::FillProperties& rFillProperties,
168 TextCharacterProperties& aTextCharProps,
169 oox::drawingml::LineProperties& rLeftBorder,
170 oox::drawingml::LineProperties& rRightBorder,
171 oox::drawingml::LineProperties& rTopBorder,
172 oox::drawingml::LineProperties& rBottomBorder,
173 oox::drawingml::LineProperties& rInsideHBorder,
174 oox::drawingml::LineProperties& rInsideVBorder,
175 oox::drawingml::LineProperties& rTopLeftToBottomRightBorder,
176 oox::drawingml::LineProperties& rBottomLeftToTopRightBorder,
177 TableStylePart& rTableStylePart,
178 bool bIsWholeTable = false,
179 sal_Int32 nCol = 0,
180 sal_Int32 nMaxCol = 0,
181 sal_Int32 nRow = 0,
182 sal_Int32 nMaxRow = 0)
184 ::oox::drawingml::FillPropertiesPtr& rPartFillPropertiesPtr( rTableStylePart.getFillProperties() );
185 if ( rPartFillPropertiesPtr )
186 rFillProperties.assignUsed( *rPartFillPropertiesPtr );
187 else
189 ::oox::drawingml::ShapeStyleRef& rFillStyleRef = rTableStylePart.getStyleRefs()[ XML_fillRef ];
190 const Theme* pTheme = rFilterBase.getCurrentTheme();
191 if (pTheme && rFillStyleRef.mnThemedIdx != 0 )
193 rFillProperties.assignUsed( *pTheme->getFillStyle( rFillStyleRef.mnThemedIdx ) );
194 ::Color nPhClr = rFillStyleRef.maPhClr.getColor( rFilterBase.getGraphicHelper() );
195 rFillProperties.maFillColor.setSrgbClr( nPhClr );
199 // Left, right, top and bottom side of the whole table should be mean outer frame of the whole table.
200 // Without this check it means left top right and bottom of whole cells of whole table.
201 if (bIsWholeTable)
203 if (nCol == 0)
204 applyBorder( rFilterBase, rTableStylePart, XML_left, rLeftBorder );
205 if (nCol >= nMaxCol)
206 applyBorder( rFilterBase, rTableStylePart, XML_right, rRightBorder );
207 if (nRow == 0)
208 applyBorder( rFilterBase, rTableStylePart, XML_top, rTopBorder );
209 if (nRow >= nMaxRow)
210 applyBorder( rFilterBase, rTableStylePart, XML_bottom, rBottomBorder );
212 applyBorder( rFilterBase, rTableStylePart, XML_insideH, rInsideHBorder );
213 applyBorder( rFilterBase, rTableStylePart, XML_insideV, rInsideVBorder );
214 applyBorder( rFilterBase, rTableStylePart, XML_tl2br, rTopLeftToBottomRightBorder );
215 applyBorder( rFilterBase, rTableStylePart, XML_tr2bl, rBottomLeftToTopRightBorder );
217 else
219 applyBorder( rFilterBase, rTableStylePart, XML_left, rLeftBorder );
220 applyBorder( rFilterBase, rTableStylePart, XML_right, rRightBorder );
221 applyBorder( rFilterBase, rTableStylePart, XML_top, rTopBorder );
222 applyBorder( rFilterBase, rTableStylePart, XML_bottom, rBottomBorder );
223 applyBorder( rFilterBase, rTableStylePart, XML_tl2br, rTopLeftToBottomRightBorder );
224 applyBorder( rFilterBase, rTableStylePart, XML_tr2bl, rBottomLeftToTopRightBorder );
225 applyBorder( rFilterBase, rTableStylePart, XML_insideH, rInsideHBorder );
226 applyBorder( rFilterBase, rTableStylePart, XML_insideV, rInsideVBorder );
229 aTextCharProps.maLatinFont = rTableStylePart.getLatinFont();
230 aTextCharProps.maAsianFont = rTableStylePart.getAsianFont();
231 aTextCharProps.maComplexFont = rTableStylePart.getComplexFont();
232 aTextCharProps.maSymbolFont = rTableStylePart.getSymbolFont();
233 if ( rTableStylePart.getTextColor().isUsed() )
235 aTextCharProps.maFillProperties.maFillColor = rTableStylePart.getTextColor();
236 aTextCharProps.maFillProperties.moFillType = XML_solidFill;
238 if( rTableStylePart.getTextBoldStyle() )
239 aTextCharProps.moBold = *rTableStylePart.getTextBoldStyle();
240 if( rTableStylePart.getTextItalicStyle() )
241 aTextCharProps.moItalic = *rTableStylePart.getTextItalicStyle();
244 static void applyTableCellProperties( const Reference < css::table::XCell >& rxCell, const TableCell& rTableCell )
246 Reference< XPropertySet > xPropSet( rxCell, UNO_QUERY_THROW );
247 xPropSet->setPropertyValue( u"TextUpperDistance"_ustr, Any( static_cast< sal_Int32 >( rTableCell.getTopMargin() / 360 ) ) );
248 xPropSet->setPropertyValue( u"TextRightDistance"_ustr, Any( static_cast< sal_Int32 >( rTableCell.getRightMargin() / 360 ) ) );
249 xPropSet->setPropertyValue( u"TextLeftDistance"_ustr, Any( static_cast< sal_Int32 >( rTableCell.getLeftMargin() / 360 ) ) );
250 xPropSet->setPropertyValue( u"TextLowerDistance"_ustr, Any( static_cast< sal_Int32 >( rTableCell.getBottomMargin() / 360 ) ) );
252 drawing::TextVerticalAdjust eVA;
253 switch( rTableCell.getAnchorToken() )
255 case XML_ctr: eVA = drawing::TextVerticalAdjust_CENTER; break;
256 case XML_b: eVA = drawing::TextVerticalAdjust_BOTTOM; break;
257 case XML_just:
258 case XML_dist:
259 default:
260 case XML_t: eVA = drawing::TextVerticalAdjust_TOP; break;
262 xPropSet->setPropertyValue( u"TextVerticalAdjust"_ustr, Any( eVA ) );
265 void TableCell::pushToXCell( const ::oox::core::XmlFilterBase& rFilterBase, const ::oox::drawingml::TextListStylePtr& pMasterTextListStyle,
266 const css::uno::Reference < css::table::XCell >& rxCell, const TableProperties& rTableProperties,
267 const TableStyle& rTableStyle, sal_Int32 nColumn, sal_Int32 nMaxColumn, sal_Int32 nRow, sal_Int32 nMaxRow )
269 TableStyle& rTable( const_cast< TableStyle& >( rTableStyle ) );
270 TableProperties& rProperties( const_cast< TableProperties& >( rTableProperties ) );
272 Reference< text::XText > xText( rxCell, UNO_QUERY_THROW );
273 Reference< text::XTextCursor > xAt = xText->createTextCursor();
275 applyTableCellProperties( rxCell, *this );
276 TextCharacterProperties aTextStyleProps;
277 xAt->gotoStart( true );
278 xAt->gotoEnd( true );
280 Reference< XPropertySet > xPropSet( rxCell, UNO_QUERY_THROW );
281 oox::drawingml::FillProperties aFillProperties;
282 oox::drawingml::LineProperties aLinePropertiesLeft;
283 oox::drawingml::LineProperties aLinePropertiesRight;
284 oox::drawingml::LineProperties aLinePropertiesTop;
285 oox::drawingml::LineProperties aLinePropertiesBottom;
286 oox::drawingml::LineProperties aLinePropertiesInsideH;
287 oox::drawingml::LineProperties aLinePropertiesInsideV;
288 oox::drawingml::LineProperties aLinePropertiesTopLeftToBottomRight;
289 oox::drawingml::LineProperties aLinePropertiesBottomLeftToTopRight;
291 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
292 aLinePropertiesLeft,
293 aLinePropertiesRight,
294 aLinePropertiesTop,
295 aLinePropertiesBottom,
296 aLinePropertiesInsideH,
297 aLinePropertiesInsideV,
298 aLinePropertiesTopLeftToBottomRight,
299 aLinePropertiesBottomLeftToTopRight,
300 rTable.getWholeTbl(),
301 true,
302 nColumn,
303 nMaxColumn,
304 nRow,
305 nMaxRow );
307 if ( rProperties.isFirstRow() && ( nRow == 0 ) )
309 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
310 aLinePropertiesLeft,
311 aLinePropertiesRight,
312 aLinePropertiesTop,
313 aLinePropertiesBottom,
314 aLinePropertiesInsideH,
315 aLinePropertiesInsideV,
316 aLinePropertiesTopLeftToBottomRight,
317 aLinePropertiesBottomLeftToTopRight,
318 rTable.getFirstRow() );
320 if ( rProperties.isLastRow() && ( nRow == nMaxRow ) )
322 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
323 aLinePropertiesLeft,
324 aLinePropertiesRight,
325 aLinePropertiesTop,
326 aLinePropertiesBottom,
327 aLinePropertiesInsideH,
328 aLinePropertiesInsideV,
329 aLinePropertiesTopLeftToBottomRight,
330 aLinePropertiesBottomLeftToTopRight,
331 rTable.getLastRow() );
333 if ( rProperties.isFirstCol() && ( nColumn == 0 ) )
335 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
336 aLinePropertiesLeft,
337 aLinePropertiesRight,
338 aLinePropertiesTop,
339 aLinePropertiesBottom,
340 aLinePropertiesInsideH,
341 aLinePropertiesInsideV,
342 aLinePropertiesTopLeftToBottomRight,
343 aLinePropertiesBottomLeftToTopRight,
344 rTable.getFirstCol() );
346 if ( rProperties.isLastCol() && ( nColumn == nMaxColumn ) )
348 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
349 aLinePropertiesLeft,
350 aLinePropertiesRight,
351 aLinePropertiesTop,
352 aLinePropertiesBottom,
353 aLinePropertiesInsideH,
354 aLinePropertiesInsideV,
355 aLinePropertiesTopLeftToBottomRight,
356 aLinePropertiesBottomLeftToTopRight,
357 rTable.getLastCol() );
359 if ( rProperties.isBandRow() )
361 bool bHasFirstColFillColor
362 = (rProperties.isFirstCol() && rTable.getFirstCol().getFillProperties()
363 && rTable.getFirstCol().getFillProperties()->maFillColor.isUsed());
365 bool bHasLastColFillColor
366 = (rProperties.isLastCol() && rTable.getLastCol().getFillProperties()
367 && rTable.getLastCol().getFillProperties()->maFillColor.isUsed());
369 if ( ( !rProperties.isFirstRow() || ( nRow != 0 ) ) &&
370 ( !rProperties.isLastRow() || ( nRow != nMaxRow ) ) &&
371 ( !rProperties.isFirstCol() || ( nColumn != 0 ) || !bHasFirstColFillColor ) &&
372 ( !rProperties.isLastCol() || ( nColumn != nMaxColumn ) || !bHasLastColFillColor ) )
374 sal_Int32 nBand = nRow;
375 if ( rProperties.isFirstRow() )
376 nBand++;
377 if ( nBand & 1 )
379 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
380 aLinePropertiesLeft,
381 aLinePropertiesRight,
382 aLinePropertiesTop,
383 aLinePropertiesBottom,
384 aLinePropertiesInsideH,
385 aLinePropertiesInsideV,
386 aLinePropertiesTopLeftToBottomRight,
387 aLinePropertiesBottomLeftToTopRight,
388 rTable.getBand2H() );
390 else
392 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
393 aLinePropertiesLeft,
394 aLinePropertiesRight,
395 aLinePropertiesTop,
396 aLinePropertiesBottom,
397 aLinePropertiesInsideH,
398 aLinePropertiesInsideV,
399 aLinePropertiesTopLeftToBottomRight,
400 aLinePropertiesBottomLeftToTopRight,
401 rTable.getBand1H() );
405 if ( ( nRow == 0 ) && ( nColumn == 0 ) )
407 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
408 aLinePropertiesLeft,
409 aLinePropertiesRight,
410 aLinePropertiesTop,
411 aLinePropertiesBottom,
412 aLinePropertiesInsideH,
413 aLinePropertiesInsideV,
414 aLinePropertiesTopLeftToBottomRight,
415 aLinePropertiesBottomLeftToTopRight,
416 rTable.getNwCell() );
418 if ( ( nRow == nMaxRow ) && ( nColumn == 0 ) )
420 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
421 aLinePropertiesLeft,
422 aLinePropertiesRight,
423 aLinePropertiesTop,
424 aLinePropertiesBottom,
425 aLinePropertiesInsideH,
426 aLinePropertiesInsideV,
427 aLinePropertiesTopLeftToBottomRight,
428 aLinePropertiesBottomLeftToTopRight,
429 rTable.getSwCell() );
431 if ( ( nRow == 0 ) && ( nColumn == nMaxColumn ) )
433 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
434 aLinePropertiesLeft,
435 aLinePropertiesRight,
436 aLinePropertiesTop,
437 aLinePropertiesBottom,
438 aLinePropertiesInsideH,
439 aLinePropertiesInsideV,
440 aLinePropertiesTopLeftToBottomRight,
441 aLinePropertiesBottomLeftToTopRight,
442 rTable.getNeCell() );
444 if ( ( nRow == nMaxRow ) && ( nColumn == nMaxColumn ) )
446 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
447 aLinePropertiesLeft,
448 aLinePropertiesRight,
449 aLinePropertiesTop,
450 aLinePropertiesBottom,
451 aLinePropertiesInsideH,
452 aLinePropertiesInsideV,
453 aLinePropertiesTopLeftToBottomRight,
454 aLinePropertiesBottomLeftToTopRight,
455 rTable.getSeCell() );
457 if ( rProperties.isBandCol() )
459 if ( ( !rProperties.isFirstRow() || ( nRow != 0 ) ) &&
460 ( !rProperties.isLastRow() || ( nRow != nMaxRow ) ) &&
461 ( !rProperties.isFirstCol() || ( nColumn != 0 ) ) &&
462 ( !rProperties.isLastCol() || ( nColumn != nMaxColumn ) ) )
464 sal_Int32 nBand = nColumn;
465 if ( rProperties.isFirstCol() )
466 nBand++;
467 if ( nBand & 1 )
469 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
470 aLinePropertiesLeft,
471 aLinePropertiesRight,
472 aLinePropertiesTop,
473 aLinePropertiesBottom,
474 aLinePropertiesInsideH,
475 aLinePropertiesInsideV,
476 aLinePropertiesTopLeftToBottomRight,
477 aLinePropertiesBottomLeftToTopRight,
478 rTable.getBand2V() );
480 else
482 applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
483 aLinePropertiesLeft,
484 aLinePropertiesRight,
485 aLinePropertiesTop,
486 aLinePropertiesBottom,
487 aLinePropertiesInsideH,
488 aLinePropertiesInsideV,
489 aLinePropertiesTopLeftToBottomRight,
490 aLinePropertiesBottomLeftToTopRight,
491 rTable.getBand1V() );
495 aLinePropertiesLeft.assignUsed( maLinePropertiesLeft );
496 aLinePropertiesRight.assignUsed( maLinePropertiesRight );
497 aLinePropertiesTop.assignUsed( maLinePropertiesTop );
498 aLinePropertiesBottom.assignUsed( maLinePropertiesBottom );
499 aLinePropertiesInsideH.assignUsed( maLinePropertiesInsideH );
500 aLinePropertiesInsideV.assignUsed( maLinePropertiesInsideV );
501 aLinePropertiesTopLeftToBottomRight.assignUsed( maLinePropertiesTopLeftToBottomRight );
502 aLinePropertiesBottomLeftToTopRight.assignUsed( maLinePropertiesBottomLeftToTopRight );
504 applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesLeft, PROP_LeftBorder );
505 applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesRight, PROP_RightBorder );
506 applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesTop, PROP_TopBorder );
507 applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesBottom, PROP_BottomBorder );
508 applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesTopLeftToBottomRight, PROP_DiagonalTLBR );
509 applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesBottomLeftToTopRight, PROP_DiagonalBLTR );
511 // Convert insideH to Top and Bottom, InsideV to Left and Right. Exclude the outer borders.
512 if(nRow != 0)
514 aLinePropertiesInsideH.assignUsed( aLinePropertiesTop );
515 applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideH, PROP_TopBorder );
517 if(nRow != nMaxRow)
519 aLinePropertiesInsideH.assignUsed( aLinePropertiesBottom );
520 applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideH, PROP_BottomBorder );
522 if(nColumn != 0)
524 aLinePropertiesInsideV.assignUsed( aLinePropertiesLeft );
525 applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideV, PROP_LeftBorder );
527 if(nColumn != nMaxColumn)
529 aLinePropertiesInsideV.assignUsed( aLinePropertiesRight );
530 applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideV, PROP_RightBorder );
533 if (rProperties.getBgColor().isUsed() && !maFillProperties.maFillColor.isUsed() &&
534 maFillProperties.moFillType.value_or(0) == XML_noFill)
536 maFillProperties.moFillType = XML_solidFill;
537 maFillProperties.maFillColor = rProperties.getBgColor();
540 aFillProperties.assignUsed( maFillProperties );
541 ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
543 Color aBgColor;
544 ::Color nPhClr = API_RGB_TRANSPARENT;
545 std::shared_ptr< ::oox::drawingml::FillProperties >& rBackgroundFillPropertiesPtr( rTable.getBackgroundFillProperties() );
546 ::oox::drawingml::ShapeStyleRef& rBackgroundFillStyle( rTable.getBackgroundFillStyleRef() );
547 if (rBackgroundFillPropertiesPtr)
548 aBgColor = rBackgroundFillPropertiesPtr->getBestSolidColor();
549 else if (rBackgroundFillStyle.mnThemedIdx != 0)
551 if (const Theme* pTheme = rFilterBase.getCurrentTheme())
553 aBgColor = pTheme->getFillStyle(rBackgroundFillStyle.mnThemedIdx)->getBestSolidColor();
554 nPhClr = rBackgroundFillStyle.maPhClr.getColor(rFilterBase.getGraphicHelper());
557 if (aBgColor.isUsed())
559 const Color aCellColor = aFillProperties.getBestSolidColor();
560 const double fTransparency = aCellColor.isUsed() ? 0.01 * aCellColor.getTransparency() : 1.0;
561 ::Color nBgColor( aBgColor.getColor(rFilterBase.getGraphicHelper(), nPhClr) );
562 ::Color nCellColor( aCellColor.getColor(rFilterBase.getGraphicHelper()) );
563 ::Color aResult( basegfx::interpolate(nBgColor.getBColor(), nCellColor.getBColor(), 1.0 - fTransparency) );
564 aFillProperties.maFillColor.clearTransformations();
565 aFillProperties.maFillColor.setSrgbClr(sal_Int32(aResult.GetRGBColor()));
566 aFillProperties.moFillType = XML_solidFill;
568 if (!aFillProperties.moFillType.has_value())
569 aFillProperties.moFillType = XML_noFill;
571 // TODO: phClr?
572 aFillProperties.pushToPropMap( aPropMap, rFilterBase.getGraphicHelper() );
573 PropertySet aPropSet{xPropSet};
574 aPropSet.setProperties( aPropMap );
576 if ( getVertToken() == XML_eaVert )
578 xPropSet->setPropertyValue(u"TextWritingMode"_ustr, Any(css::text::WritingMode_TB_RL));
581 getTextBody()->insertAt( rFilterBase, xText, xAt, aTextStyleProps, pMasterTextListStyle );
583 // tdf#144092 For empty cells push character styles & endParaRPr to the Cell's properties
584 const TextParagraphVector& rParagraphs = getTextBody()->getParagraphs();
585 if (rParagraphs.size() == 1)
587 const auto pFirstParagraph = rParagraphs.at(0);
588 if (pFirstParagraph->getRuns().empty())
590 TextCharacterProperties aTextCharacterProps{ pFirstParagraph->getCharacterStyle(
591 aTextStyleProps, *pMasterTextListStyle, getTextBody()->getTextListStyle()) };
592 aTextCharacterProps.assignUsed(pFirstParagraph->getEndProperties());
593 aTextCharacterProps.pushToPropSet(aPropSet, rFilterBase);
597 if ( getVertToken() == XML_vert )
599 xPropSet->setPropertyValue(u"RotateAngle"_ustr, Any(short(27000)));
601 else if ( getVertToken() == XML_vert270 )
603 xPropSet->setPropertyValue(u"RotateAngle"_ustr, Any(short(9000)));
605 else if ( getVertToken() != XML_horz && getVertToken() != XML_eaVert )
607 // put the vert value in the grab bag for roundtrip
608 const OUString aTokenName(TokenMap::getUnicodeTokenName(getVertToken()));
609 Sequence<PropertyValue> aGrabBag;
610 xPropSet->getPropertyValue(u"CellInteropGrabBag"_ustr) >>= aGrabBag;
611 PropertyValue aPropertyValue = comphelper::makePropertyValue(u"mso-tcPr-vert-value"_ustr, aTokenName);
612 if (aGrabBag.hasElements())
614 sal_Int32 nLength = aGrabBag.getLength();
615 aGrabBag.realloc(nLength + 1);
616 aGrabBag.getArray()[nLength] = std::move(aPropertyValue);
618 else
620 aGrabBag = { std::move(aPropertyValue) };
622 xPropSet->setPropertyValue(u"CellInteropGrabBag"_ustr, Any(aGrabBag));
628 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */