Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/drawingml/table/tablecell.cxx
Line
Count
Source
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 <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>
41
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;
47
48
namespace oox::drawingml::table {
49
50
TableCell::TableCell()
51
2.61k
: mpTextBody( std::make_shared<TextBody>() )
52
2.61k
, mnRowSpan ( 1 )
53
2.61k
, mnGridSpan( 1 )
54
2.61k
, mbhMerge( false )
55
2.61k
, mbvMerge( false )
56
2.61k
, mnMarL( 91440 )
57
2.61k
, mnMarR( 91440 )
58
2.61k
, mnMarT( 45720 )
59
2.61k
, mnMarB( 45720 )
60
2.61k
, mnVertToken( XML_horz )
61
2.61k
, mnAnchorToken( XML_t )
62
2.61k
, mbAnchorCtr( false )
63
2.61k
, mnHorzOverflowToken( XML_clip )
64
2.61k
{
65
2.61k
}
66
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)
72
23.9k
{
73
23.9k
    BorderLine2 aBorderLine;
74
23.9k
    TableStyle& rTable(const_cast<TableStyle&>(rTableStyle));
75
23.9k
    if (!rTable.getStyleId().isEmpty())
76
6.01k
    {
77
6.01k
        Color aColor = rLineProperties.maLineFill.getBestSolidColor();
78
6.01k
        aBorderLine.Color = sal_Int32(aColor.getColor(rFilterBase.getGraphicHelper()));
79
6.01k
        aBorderLine.OuterLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(0)) / 4);
80
6.01k
        aBorderLine.InnerLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(0)) / 4);
81
6.01k
        aBorderLine.LineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(0)) / 2);
82
6.01k
        aBorderLine.LineDistance = 0;
83
6.01k
    }
84
17.9k
    else
85
17.9k
    {
86
17.9k
        if (rLineProperties.maLineFill.moFillType.has_value())
87
12
        {
88
12
            if (rLineProperties.maLineFill.moFillType.value() != XML_noFill)
89
0
            {
90
0
                Color aColor = rLineProperties.maLineFill.getBestSolidColor();
91
0
                aBorderLine.Color = sal_Int32(aColor.getColor(rFilterBase.getGraphicHelper()));
92
0
            }
93
12
            else
94
12
                aBorderLine.Color = sal_Int32(COL_AUTO);
95
12
        }
96
17.9k
        else
97
17.9k
            aBorderLine.Color = sal_Int32(COL_BLACK);
98
99
17.9k
        aBorderLine.OuterLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(12700)) / 4);
100
17.9k
        aBorderLine.InnerLineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(12700)) / 4);
101
17.9k
        aBorderLine.LineWidth = static_cast<sal_Int16>(GetCoordinate(rLineProperties.moLineWidth.value_or(12700)) / 2);
102
17.9k
        aBorderLine.LineDistance = 0;
103
17.9k
    }
104
105
23.9k
    if ( rLineProperties.moPresetDash.has_value() )
106
1.65k
    {
107
1.65k
        switch ( rLineProperties.moPresetDash.value() )
108
1.65k
        {
109
0
        case XML_dot:
110
0
        case XML_sysDot:
111
0
            aBorderLine.LineStyle = ::table::BorderLineStyle::DOTTED;
112
0
            break;
113
0
        case XML_dash:
114
0
        case XML_lgDash:
115
12
        case XML_sysDash:
116
12
            aBorderLine.LineStyle = ::table::BorderLineStyle::DASHED;
117
12
            break;
118
0
        case XML_dashDot:
119
0
        case XML_lgDashDot:
120
0
        case XML_sysDashDot:
121
0
            aBorderLine.LineStyle = ::table::BorderLineStyle::DASH_DOT;
122
0
            break;
123
0
        case XML_lgDashDotDot:
124
0
        case XML_sysDashDotDot:
125
0
            aBorderLine.LineStyle = ::table::BorderLineStyle::DASH_DOT_DOT;
126
0
            break;
127
1.64k
        case XML_solid:
128
1.64k
            aBorderLine.LineStyle = ::table::BorderLineStyle::SOLID;
129
1.64k
            break;
130
0
        default:
131
0
            aBorderLine.LineStyle = ::table::BorderLineStyle::DASHED;
132
0
            break;
133
1.65k
        }
134
1.65k
    }
135
22.2k
    else if ( !rLineProperties.maCustomDash.empty() )
136
0
    {
137
0
        aBorderLine.LineStyle = ::table::BorderLineStyle::DASHED;
138
0
    }
139
22.2k
    else
140
22.2k
    {
141
22.2k
        aBorderLine.LineStyle = ::table::BorderLineStyle::NONE;
142
22.2k
    }
143
144
23.9k
    PropertySet aPropSet( rxPropSet );
145
23.9k
    if (aPropSet.hasProperty(nPropId))
146
18.7k
        aPropSet.setProperty( nPropId, aBorderLine );
147
23.9k
}
148
149
static void applyBorder( const ::oox::core::XmlFilterBase& rFilterBase, TableStylePart& rTableStylePart, sal_Int32 nLineType, oox::drawingml::LineProperties& rLineProperties )
150
23.1k
{
151
23.1k
    std::map < sal_Int32, ::oox::drawingml::LinePropertiesPtr >& rPartLineBorders( rTableStylePart.getLineBorders() );
152
23.1k
    ::oox::drawingml::ShapeStyleRef& rLineStyleRef = rTableStylePart.getStyleRefs()[ nLineType ];
153
23.1k
    std::map < sal_Int32, ::oox::drawingml::LinePropertiesPtr >::const_iterator aIter( rPartLineBorders.find( nLineType ) );
154
23.1k
    if ( ( aIter != rPartLineBorders.end() ) && aIter->second )
155
2.23k
        rLineProperties.assignUsed( *aIter->second );
156
20.8k
    else if (rLineStyleRef.mnThemedIdx != 0)
157
0
    {
158
0
        if (const Theme* pTheme = rFilterBase.getCurrentTheme())
159
0
        {
160
0
            rLineProperties.assignUsed( *pTheme->getLineStyle(rLineStyleRef.mnThemedIdx) );
161
0
            ::Color nPhClr = rLineStyleRef.maPhClr.getColor( rFilterBase.getGraphicHelper() );
162
0
            rLineProperties.maLineFill.maFillColor.setSrgbClr( nPhClr );
163
0
        }
164
0
    }
165
23.1k
}
166
167
static void applyTableStylePart( const ::oox::core::XmlFilterBase& rFilterBase,
168
                          oox::drawingml::FillProperties& rFillProperties,
169
                          TextCharacterProperties& aTextCharProps,
170
                          oox::drawingml::LineProperties& rLeftBorder,
171
                          oox::drawingml::LineProperties& rRightBorder,
172
                          oox::drawingml::LineProperties& rTopBorder,
173
                          oox::drawingml::LineProperties& rBottomBorder,
174
                          oox::drawingml::LineProperties& rInsideHBorder,
175
                          oox::drawingml::LineProperties& rInsideVBorder,
176
                          oox::drawingml::LineProperties& rTopLeftToBottomRightBorder,
177
                          oox::drawingml::LineProperties& rBottomLeftToTopRightBorder,
178
                          TableStylePart& rTableStylePart,
179
                          bool bIsWholeTable = false,
180
                          sal_Int32 nCol = 0,
181
                          sal_Int32 nMaxCol = 0,
182
                          sal_Int32 nRow = 0,
183
                          sal_Int32 nMaxRow = 0)
184
3.92k
{
185
3.92k
    ::oox::drawingml::FillPropertiesPtr& rPartFillPropertiesPtr( rTableStylePart.getFillProperties() );
186
3.92k
    if ( rPartFillPropertiesPtr )
187
1.13k
        rFillProperties.assignUsed( *rPartFillPropertiesPtr );
188
2.78k
    else
189
2.78k
    {
190
2.78k
        ::oox::drawingml::ShapeStyleRef& rFillStyleRef = rTableStylePart.getStyleRefs()[ XML_fillRef ];
191
2.78k
        const Theme* pTheme = rFilterBase.getCurrentTheme();
192
2.78k
        if (pTheme && rFillStyleRef.mnThemedIdx != 0 )
193
0
        {
194
0
            rFillProperties.assignUsed( *pTheme->getFillStyle( rFillStyleRef.mnThemedIdx ) );
195
0
            ::Color nPhClr = rFillStyleRef.maPhClr.getColor( rFilterBase.getGraphicHelper() );
196
0
            rFillProperties.maFillColor.setSrgbClr( nPhClr );
197
0
        }
198
2.78k
    }
199
200
    // Left, right, top and bottom side of the whole table should be mean outer frame of the whole table.
201
    // Without this check it means left top right and bottom of whole cells of whole table.
202
3.92k
    if (bIsWholeTable)
203
2.61k
    {
204
2.61k
        if (nCol == 0)
205
540
            applyBorder( rFilterBase, rTableStylePart, XML_left, rLeftBorder );
206
2.61k
        if (nCol >= nMaxCol)
207
540
            applyBorder( rFilterBase, rTableStylePart, XML_right, rRightBorder );
208
2.61k
        if (nRow == 0)
209
556
            applyBorder( rFilterBase, rTableStylePart, XML_top, rTopBorder );
210
2.61k
        if (nRow >= nMaxRow)
211
556
            applyBorder( rFilterBase, rTableStylePart, XML_bottom, rBottomBorder );
212
213
2.61k
        applyBorder( rFilterBase, rTableStylePart, XML_insideH, rInsideHBorder );
214
2.61k
        applyBorder( rFilterBase, rTableStylePart, XML_insideV, rInsideVBorder );
215
2.61k
        applyBorder( rFilterBase, rTableStylePart, XML_tl2br, rTopLeftToBottomRightBorder );
216
2.61k
        applyBorder( rFilterBase, rTableStylePart, XML_tr2bl, rBottomLeftToTopRightBorder );
217
2.61k
    }
218
1.30k
    else
219
1.30k
    {
220
1.30k
        applyBorder( rFilterBase, rTableStylePart, XML_left, rLeftBorder );
221
1.30k
        applyBorder( rFilterBase, rTableStylePart, XML_right, rRightBorder );
222
1.30k
        applyBorder( rFilterBase, rTableStylePart, XML_top, rTopBorder );
223
1.30k
        applyBorder( rFilterBase, rTableStylePart, XML_bottom, rBottomBorder );
224
1.30k
        applyBorder( rFilterBase, rTableStylePart, XML_tl2br, rTopLeftToBottomRightBorder );
225
1.30k
        applyBorder( rFilterBase, rTableStylePart, XML_tr2bl, rBottomLeftToTopRightBorder );
226
1.30k
        applyBorder( rFilterBase, rTableStylePart, XML_insideH, rInsideHBorder );
227
1.30k
        applyBorder( rFilterBase, rTableStylePart, XML_insideV, rInsideVBorder );
228
1.30k
    }
229
230
3.92k
    aTextCharProps.maLatinFont = rTableStylePart.getLatinFont();
231
3.92k
    aTextCharProps.maAsianFont = rTableStylePart.getAsianFont();
232
3.92k
    aTextCharProps.maComplexFont = rTableStylePart.getComplexFont();
233
3.92k
    aTextCharProps.maSymbolFont = rTableStylePart.getSymbolFont();
234
3.92k
    if ( rTableStylePart.getTextColor().isUsed() )
235
891
    {
236
891
        aTextCharProps.maFillProperties.maFillColor = rTableStylePart.getTextColor();
237
891
        aTextCharProps.maFillProperties.moFillType = XML_solidFill;
238
891
    }
239
3.92k
    if( rTableStylePart.getTextBoldStyle() )
240
223
        aTextCharProps.moBold = *rTableStylePart.getTextBoldStyle();
241
3.92k
    if( rTableStylePart.getTextItalicStyle() )
242
0
        aTextCharProps.moItalic = *rTableStylePart.getTextItalicStyle();
243
3.92k
}
244
245
static void applyTableCellProperties( const Reference < css::table::XCell >& rxCell, const TableCell& rTableCell )
246
2.61k
{
247
2.61k
    Reference< XPropertySet > xPropSet( rxCell, UNO_QUERY_THROW );
248
2.61k
    xPropSet->setPropertyValue( u"TextUpperDistance"_ustr, Any( static_cast< sal_Int32 >( rTableCell.getTopMargin() / 360 ) ) );
249
2.61k
    xPropSet->setPropertyValue( u"TextRightDistance"_ustr, Any( static_cast< sal_Int32 >( rTableCell.getRightMargin() / 360 ) ) );
250
2.61k
    xPropSet->setPropertyValue( u"TextLeftDistance"_ustr, Any( static_cast< sal_Int32 >( rTableCell.getLeftMargin() / 360 ) ) );
251
2.61k
    xPropSet->setPropertyValue( u"TextLowerDistance"_ustr, Any( static_cast< sal_Int32 >( rTableCell.getBottomMargin() / 360 ) ) );
252
253
2.61k
    drawing::TextVerticalAdjust eVA;
254
2.61k
    switch( rTableCell.getAnchorToken() )
255
2.61k
    {
256
3
        case XML_ctr:   eVA = drawing::TextVerticalAdjust_CENTER; break;
257
0
        case XML_b:     eVA = drawing::TextVerticalAdjust_BOTTOM; break;
258
0
        case XML_just:
259
0
        case XML_dist:
260
0
        default:
261
2.61k
        case XML_t:     eVA = drawing::TextVerticalAdjust_TOP; break;
262
2.61k
    }
263
2.61k
    xPropSet->setPropertyValue( u"TextVerticalAdjust"_ustr, Any( eVA ) );
264
2.61k
}
265
266
void TableCell::pushToXCell( const ::oox::core::XmlFilterBase& rFilterBase, const ::oox::drawingml::TextListStylePtr& pMasterTextListStyle,
267
    const css::uno::Reference < css::table::XCell >& rxCell, const TableProperties& rTableProperties,
268
    const TableStyle& rTableStyle, sal_Int32 nColumn, sal_Int32 nMaxColumn, sal_Int32 nRow, sal_Int32 nMaxRow )
269
2.61k
{
270
2.61k
    TableStyle& rTable( const_cast< TableStyle& >( rTableStyle ) );
271
2.61k
    TableProperties& rProperties( const_cast< TableProperties& >( rTableProperties ) );
272
273
2.61k
    Reference< text::XText > xText( rxCell, UNO_QUERY_THROW );
274
2.61k
    Reference< text::XTextCursor > xAt = xText->createTextCursor();
275
276
2.61k
    applyTableCellProperties( rxCell, *this );
277
278
2.61k
    Reference<XPropertySet> xPropSet(rxCell, UNO_QUERY_THROW);
279
280
2.61k
    PropertyMap& rTextBodyPropertyMap = getTextBody()->getTextProperties().maPropertyMap;
281
2.61k
    if (rTextBodyPropertyMap.hasProperty(PROP_FontIndependentLineSpacing))
282
1.46k
    {
283
1.46k
        if (rTextBodyPropertyMap.getProperty(PROP_FontIndependentLineSpacing).get<bool>())
284
1.46k
            xPropSet->setPropertyValue(u"FontIndependentLineSpacing"_ustr, Any(true));
285
1.46k
    }
286
287
2.61k
    TextCharacterProperties aTextStyleProps;
288
2.61k
    xAt->gotoStart( true );
289
2.61k
    xAt->gotoEnd( true );
290
291
2.61k
    oox::drawingml::FillProperties aFillProperties;
292
2.61k
    oox::drawingml::LineProperties aLinePropertiesLeft;
293
2.61k
    oox::drawingml::LineProperties aLinePropertiesRight;
294
2.61k
    oox::drawingml::LineProperties aLinePropertiesTop;
295
2.61k
    oox::drawingml::LineProperties aLinePropertiesBottom;
296
2.61k
    oox::drawingml::LineProperties aLinePropertiesInsideH;
297
2.61k
    oox::drawingml::LineProperties aLinePropertiesInsideV;
298
2.61k
    oox::drawingml::LineProperties aLinePropertiesTopLeftToBottomRight;
299
2.61k
    oox::drawingml::LineProperties aLinePropertiesBottomLeftToTopRight;
300
301
2.61k
    applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
302
2.61k
        aLinePropertiesLeft,
303
2.61k
        aLinePropertiesRight,
304
2.61k
        aLinePropertiesTop,
305
2.61k
        aLinePropertiesBottom,
306
2.61k
        aLinePropertiesInsideH,
307
2.61k
        aLinePropertiesInsideV,
308
2.61k
        aLinePropertiesTopLeftToBottomRight,
309
2.61k
        aLinePropertiesBottomLeftToTopRight,
310
2.61k
        rTable.getWholeTbl(),
311
2.61k
        true,
312
2.61k
        nColumn,
313
2.61k
        nMaxColumn,
314
2.61k
        nRow,
315
2.61k
        nMaxRow );
316
317
2.61k
    if ( rProperties.isFirstRow() && ( nRow == 0 ) )
318
282
    {
319
282
        applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
320
282
            aLinePropertiesLeft,
321
282
            aLinePropertiesRight,
322
282
            aLinePropertiesTop,
323
282
            aLinePropertiesBottom,
324
282
            aLinePropertiesInsideH,
325
282
            aLinePropertiesInsideV,
326
282
            aLinePropertiesTopLeftToBottomRight,
327
282
            aLinePropertiesBottomLeftToTopRight,
328
282
            rTable.getFirstRow() );
329
282
    }
330
2.61k
    if ( rProperties.isLastRow() && ( nRow == nMaxRow ) )
331
0
    {
332
0
        applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
333
0
            aLinePropertiesLeft,
334
0
            aLinePropertiesRight,
335
0
            aLinePropertiesTop,
336
0
            aLinePropertiesBottom,
337
0
            aLinePropertiesInsideH,
338
0
            aLinePropertiesInsideV,
339
0
            aLinePropertiesTopLeftToBottomRight,
340
0
            aLinePropertiesBottomLeftToTopRight,
341
0
            rTable.getLastRow() );
342
0
    }
343
2.61k
    if ( rProperties.isFirstCol() && ( nColumn == 0 ) )
344
0
    {
345
0
        applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
346
0
            aLinePropertiesLeft,
347
0
            aLinePropertiesRight,
348
0
            aLinePropertiesTop,
349
0
            aLinePropertiesBottom,
350
0
            aLinePropertiesInsideH,
351
0
            aLinePropertiesInsideV,
352
0
            aLinePropertiesTopLeftToBottomRight,
353
0
            aLinePropertiesBottomLeftToTopRight,
354
0
            rTable.getFirstCol() );
355
0
    }
356
2.61k
    if ( rProperties.isLastCol() && ( nColumn == nMaxColumn ) )
357
0
    {
358
0
        applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
359
0
            aLinePropertiesLeft,
360
0
            aLinePropertiesRight,
361
0
            aLinePropertiesTop,
362
0
            aLinePropertiesBottom,
363
0
            aLinePropertiesInsideH,
364
0
            aLinePropertiesInsideV,
365
0
            aLinePropertiesTopLeftToBottomRight,
366
0
            aLinePropertiesBottomLeftToTopRight,
367
0
            rTable.getLastCol() );
368
0
    }
369
2.61k
    if ( rProperties.isBandRow() )
370
840
    {
371
840
        bool bHasFirstColFillColor
372
840
            = (rProperties.isFirstCol() && rTable.getFirstCol().getFillProperties()
373
0
               && rTable.getFirstCol().getFillProperties()->maFillColor.isUsed());
374
375
840
        bool bHasLastColFillColor
376
840
            = (rProperties.isLastCol() && rTable.getLastCol().getFillProperties()
377
0
               && rTable.getLastCol().getFillProperties()->maFillColor.isUsed());
378
379
840
        if ( ( !rProperties.isFirstRow() || ( nRow != 0 ) ) &&
380
558
            ( !rProperties.isLastRow() || ( nRow != nMaxRow ) ) &&
381
558
            ( !rProperties.isFirstCol() || ( nColumn != 0 ) || !bHasFirstColFillColor ) &&
382
558
            ( !rProperties.isLastCol() || ( nColumn != nMaxColumn ) || !bHasLastColFillColor ) )
383
558
        {
384
558
            sal_Int32 nBand = nRow;
385
558
            if ( rProperties.isFirstRow() )
386
558
                nBand++;
387
558
            if ( nBand & 1 )
388
279
            {
389
279
                applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
390
279
                    aLinePropertiesLeft,
391
279
                    aLinePropertiesRight,
392
279
                    aLinePropertiesTop,
393
279
                    aLinePropertiesBottom,
394
279
                    aLinePropertiesInsideH,
395
279
                    aLinePropertiesInsideV,
396
279
                    aLinePropertiesTopLeftToBottomRight,
397
279
                    aLinePropertiesBottomLeftToTopRight,
398
279
                    rTable.getBand2H() );
399
279
            }
400
279
            else
401
279
            {
402
279
                applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
403
279
                    aLinePropertiesLeft,
404
279
                    aLinePropertiesRight,
405
279
                    aLinePropertiesTop,
406
279
                    aLinePropertiesBottom,
407
279
                    aLinePropertiesInsideH,
408
279
                    aLinePropertiesInsideV,
409
279
                    aLinePropertiesTopLeftToBottomRight,
410
279
                    aLinePropertiesBottomLeftToTopRight,
411
279
                    rTable.getBand1H() );
412
279
            }
413
558
        }
414
840
    }
415
2.61k
    if ( ( nRow == 0 ) && ( nColumn == 0 ) )
416
117
    {
417
117
        applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
418
117
            aLinePropertiesLeft,
419
117
            aLinePropertiesRight,
420
117
            aLinePropertiesTop,
421
117
            aLinePropertiesBottom,
422
117
            aLinePropertiesInsideH,
423
117
            aLinePropertiesInsideV,
424
117
            aLinePropertiesTopLeftToBottomRight,
425
117
            aLinePropertiesBottomLeftToTopRight,
426
117
            rTable.getNwCell() );
427
117
    }
428
2.61k
    if ( ( nRow == nMaxRow ) && ( nColumn == 0 ) )
429
117
    {
430
117
        applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
431
117
            aLinePropertiesLeft,
432
117
            aLinePropertiesRight,
433
117
            aLinePropertiesTop,
434
117
            aLinePropertiesBottom,
435
117
            aLinePropertiesInsideH,
436
117
            aLinePropertiesInsideV,
437
117
            aLinePropertiesTopLeftToBottomRight,
438
117
            aLinePropertiesBottomLeftToTopRight,
439
117
            rTable.getSwCell() );
440
117
    }
441
2.61k
    if ( ( nRow == 0 ) && ( nColumn == nMaxColumn ) )
442
117
    {
443
117
        applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
444
117
            aLinePropertiesLeft,
445
117
            aLinePropertiesRight,
446
117
            aLinePropertiesTop,
447
117
            aLinePropertiesBottom,
448
117
            aLinePropertiesInsideH,
449
117
            aLinePropertiesInsideV,
450
117
            aLinePropertiesTopLeftToBottomRight,
451
117
            aLinePropertiesBottomLeftToTopRight,
452
117
            rTable.getNeCell() );
453
117
    }
454
2.61k
    if ( ( nRow == nMaxRow ) && ( nColumn == nMaxColumn ) )
455
117
    {
456
117
        applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
457
117
            aLinePropertiesLeft,
458
117
            aLinePropertiesRight,
459
117
            aLinePropertiesTop,
460
117
            aLinePropertiesBottom,
461
117
            aLinePropertiesInsideH,
462
117
            aLinePropertiesInsideV,
463
117
            aLinePropertiesTopLeftToBottomRight,
464
117
            aLinePropertiesBottomLeftToTopRight,
465
117
            rTable.getSeCell() );
466
117
    }
467
2.61k
    if ( rProperties.isBandCol() )
468
0
    {
469
0
        if ( ( !rProperties.isFirstRow() || ( nRow != 0 ) ) &&
470
0
            ( !rProperties.isLastRow() || ( nRow != nMaxRow ) ) &&
471
0
            ( !rProperties.isFirstCol() || ( nColumn != 0 ) ) &&
472
0
            ( !rProperties.isLastCol() || ( nColumn != nMaxColumn ) ) )
473
0
        {
474
0
            sal_Int32 nBand = nColumn;
475
0
            if ( rProperties.isFirstCol() )
476
0
                nBand++;
477
0
            if ( nBand & 1 )
478
0
            {
479
0
                applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
480
0
                    aLinePropertiesLeft,
481
0
                    aLinePropertiesRight,
482
0
                    aLinePropertiesTop,
483
0
                    aLinePropertiesBottom,
484
0
                    aLinePropertiesInsideH,
485
0
                    aLinePropertiesInsideV,
486
0
                    aLinePropertiesTopLeftToBottomRight,
487
0
                    aLinePropertiesBottomLeftToTopRight,
488
0
                    rTable.getBand2V() );
489
0
            }
490
0
            else
491
0
            {
492
0
                applyTableStylePart( rFilterBase, aFillProperties, aTextStyleProps,
493
0
                    aLinePropertiesLeft,
494
0
                    aLinePropertiesRight,
495
0
                    aLinePropertiesTop,
496
0
                    aLinePropertiesBottom,
497
0
                    aLinePropertiesInsideH,
498
0
                    aLinePropertiesInsideV,
499
0
                    aLinePropertiesTopLeftToBottomRight,
500
0
                    aLinePropertiesBottomLeftToTopRight,
501
0
                    rTable.getBand1V() );
502
0
            }
503
0
        }
504
0
    }
505
2.61k
    aLinePropertiesLeft.assignUsed( maLinePropertiesLeft );
506
2.61k
    aLinePropertiesRight.assignUsed( maLinePropertiesRight );
507
2.61k
    aLinePropertiesTop.assignUsed( maLinePropertiesTop );
508
2.61k
    aLinePropertiesBottom.assignUsed( maLinePropertiesBottom );
509
2.61k
    aLinePropertiesInsideH.assignUsed( maLinePropertiesInsideH );
510
2.61k
    aLinePropertiesInsideV.assignUsed( maLinePropertiesInsideV );
511
2.61k
    aLinePropertiesTopLeftToBottomRight.assignUsed( maLinePropertiesTopLeftToBottomRight );
512
2.61k
    aLinePropertiesBottomLeftToTopRight.assignUsed( maLinePropertiesBottomLeftToTopRight );
513
514
2.61k
    applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesLeft, PROP_LeftBorder );
515
2.61k
    applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesRight, PROP_RightBorder );
516
2.61k
    applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesTop, PROP_TopBorder );
517
2.61k
    applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesBottom, PROP_BottomBorder );
518
2.61k
    applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesTopLeftToBottomRight, PROP_DiagonalTLBR );
519
2.61k
    applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesBottomLeftToTopRight, PROP_DiagonalBLTR );
520
521
    // Convert insideH to Top and Bottom, InsideV to Left and Right. Exclude the outer borders.
522
2.61k
    if(nRow != 0)
523
2.05k
    {
524
2.05k
        aLinePropertiesInsideH.assignUsed( aLinePropertiesTop );
525
2.05k
        applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideH, PROP_TopBorder );
526
2.05k
    }
527
2.61k
    if(nRow != nMaxRow)
528
2.05k
    {
529
2.05k
        aLinePropertiesInsideH.assignUsed( aLinePropertiesBottom );
530
2.05k
        applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideH, PROP_BottomBorder );
531
2.05k
    }
532
2.61k
    if(nColumn != 0)
533
2.07k
    {
534
2.07k
        aLinePropertiesInsideV.assignUsed( aLinePropertiesLeft );
535
2.07k
        applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideV, PROP_LeftBorder );
536
2.07k
    }
537
2.61k
    if(nColumn != nMaxColumn)
538
2.07k
    {
539
2.07k
        aLinePropertiesInsideV.assignUsed( aLinePropertiesRight );
540
2.07k
        applyLineAttributes( rFilterBase, xPropSet, rTable, aLinePropertiesInsideV, PROP_RightBorder );
541
2.07k
    }
542
543
2.61k
    if (rProperties.getBgColor().isUsed() && !maFillProperties.maFillColor.isUsed() &&
544
0
        maFillProperties.moFillType.value_or(0) == XML_noFill)
545
0
    {
546
0
        maFillProperties.moFillType = XML_solidFill;
547
0
        maFillProperties.maFillColor = rProperties.getBgColor();
548
0
    }
549
550
2.61k
    aFillProperties.assignUsed( maFillProperties );
551
2.61k
    ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
552
553
2.61k
    Color aBgColor;
554
2.61k
    ::Color nPhClr = API_RGB_TRANSPARENT;
555
2.61k
    std::shared_ptr< ::oox::drawingml::FillProperties >& rBackgroundFillPropertiesPtr( rTable.getBackgroundFillProperties() );
556
2.61k
    ::oox::drawingml::ShapeStyleRef& rBackgroundFillStyle( rTable.getBackgroundFillStyleRef() );
557
2.61k
    if (rBackgroundFillPropertiesPtr)
558
73
        aBgColor = rBackgroundFillPropertiesPtr->getBestSolidColor();
559
2.54k
    else if (rBackgroundFillStyle.mnThemedIdx != 0)
560
0
    {
561
0
        if (const Theme* pTheme = rFilterBase.getCurrentTheme())
562
0
        {
563
0
            aBgColor = pTheme->getFillStyle(rBackgroundFillStyle.mnThemedIdx)->getBestSolidColor();
564
0
            nPhClr = rBackgroundFillStyle.maPhClr.getColor(rFilterBase.getGraphicHelper());
565
0
        }
566
0
    }
567
2.61k
    if (aBgColor.isUsed())
568
0
    {
569
0
        const Color aCellColor = aFillProperties.getBestSolidColor();
570
0
        const double fTransparency = aCellColor.isUsed() ? 0.01 * aCellColor.getTransparency() : 1.0;
571
0
        ::Color nBgColor( aBgColor.getColor(rFilterBase.getGraphicHelper(), nPhClr) );
572
0
        ::Color nCellColor( aCellColor.getColor(rFilterBase.getGraphicHelper()) );
573
0
        ::Color aResult( basegfx::interpolate(nBgColor.getBColor(), nCellColor.getBColor(), 1.0 - fTransparency) );
574
0
        aFillProperties.maFillColor.clearTransformations();
575
0
        aFillProperties.maFillColor.setSrgbClr(sal_Int32(aResult.GetRGBColor()));
576
0
        aFillProperties.moFillType = XML_solidFill;
577
0
    }
578
2.61k
    if (!aFillProperties.moFillType.has_value())
579
1.94k
        aFillProperties.moFillType = XML_noFill;
580
581
    // TODO: phClr?
582
2.61k
    aFillProperties.pushToPropMap( aPropMap, rFilterBase.getGraphicHelper() );
583
2.61k
    PropertySet aPropSet{xPropSet};
584
2.61k
    aPropSet.setProperties( aPropMap );
585
586
2.61k
    if ( getVertToken() == XML_eaVert )
587
0
    {
588
0
        xPropSet->setPropertyValue(u"TextWritingMode"_ustr, Any(css::text::WritingMode_TB_RL));
589
0
    }
590
591
2.61k
    getTextBody()->insertAt( rFilterBase, xText, xAt, aTextStyleProps, pMasterTextListStyle );
592
593
    // tdf#144092 For empty cells push character styles & endParaRPr to the Cell's properties
594
2.61k
    const TextParagraphVector& rParagraphs = getTextBody()->getParagraphs();
595
2.61k
    if (rParagraphs.size() == 1)
596
1.45k
    {
597
1.45k
        const auto pFirstParagraph = rParagraphs.at(0);
598
1.45k
        if (pFirstParagraph->getRuns().empty())
599
837
        {
600
837
            TextCharacterProperties aTextCharacterProps{ pFirstParagraph->getCharacterStyle(
601
837
                aTextStyleProps, *pMasterTextListStyle, getTextBody()->getTextListStyle()) };
602
837
            aTextCharacterProps.assignUsed(pFirstParagraph->getEndProperties());
603
837
            aTextCharacterProps.pushToPropSet(aPropSet, rFilterBase);
604
837
        }
605
1.45k
    }
606
607
2.61k
    if ( getVertToken() == XML_vert )
608
0
    {
609
0
        xPropSet->setPropertyValue(u"RotateAngle"_ustr, Any(short(27000)));
610
0
    }
611
2.61k
    else if ( getVertToken() == XML_vert270 )
612
0
    {
613
0
        xPropSet->setPropertyValue(u"RotateAngle"_ustr, Any(short(9000)));
614
0
    }
615
2.61k
    else if ( getVertToken() != XML_horz && getVertToken() != XML_eaVert )
616
0
    {
617
        // put the vert value in the grab bag for roundtrip
618
0
        const OUString aTokenName(TokenMap::getUnicodeTokenName(getVertToken()));
619
0
        Sequence<PropertyValue> aGrabBag;
620
0
        xPropSet->getPropertyValue(u"CellInteropGrabBag"_ustr) >>= aGrabBag;
621
0
        PropertyValue aPropertyValue = comphelper::makePropertyValue(u"mso-tcPr-vert-value"_ustr, aTokenName);
622
0
        if (aGrabBag.hasElements())
623
0
        {
624
0
            sal_Int32 nLength = aGrabBag.getLength();
625
0
            aGrabBag.realloc(nLength + 1);
626
0
            aGrabBag.getArray()[nLength] = std::move(aPropertyValue);
627
0
        }
628
0
        else
629
0
        {
630
0
            aGrabBag = { std::move(aPropertyValue) };
631
0
        }
632
0
        xPropSet->setPropertyValue(u"CellInteropGrabBag"_ustr, Any(aGrabBag));
633
0
    }
634
2.61k
}
635
636
}
637
638
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */