Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/drawingml/textliststyle.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/textliststyle.hxx>
21
#include <sal/log.hxx>
22
#include <comphelper/sequenceashashmap.hxx>
23
24
using namespace css;
25
26
namespace oox::drawingml {
27
28
TextListStyle::TextListStyle()
29
541k
    : mbHasListStyleOnImport(false)
30
541k
{
31
541k
}
32
33
TextListStyle::~TextListStyle()
34
592k
{
35
592k
}
36
37
TextListStyle::TextListStyle(const TextListStyle& rStyle)
38
50.3k
    : mbHasListStyleOnImport(false)
39
50.3k
{
40
503k
    for ( size_t i = 0; i < NUM_TEXT_LIST_STYLE_ENTRIES; i++ )
41
453k
    {
42
453k
        maListStyle[i] = rStyle.maListStyle[i];
43
453k
        maAggregationListStyle[i] = rStyle.maAggregationListStyle[i];
44
453k
    }
45
50.3k
}
46
47
TextListStyle& TextListStyle::operator=(const TextListStyle& rStyle)
48
25.1k
{
49
25.1k
    if(this != &rStyle)
50
25.1k
    {
51
251k
        for ( size_t i = 0; i < NUM_TEXT_LIST_STYLE_ENTRIES; i++ )
52
226k
        {
53
226k
            maListStyle[i] = rStyle.maListStyle[i];
54
226k
            maAggregationListStyle[i] = rStyle.maAggregationListStyle[i];
55
226k
        }
56
25.1k
    }
57
25.1k
    return *this;
58
25.1k
}
59
60
static void applyStyleList( const TextParagraphPropertiesArray& rSourceListStyle, TextParagraphPropertiesArray& rDestListStyle )
61
647k
{
62
6.47M
    for ( size_t i = 0; i < NUM_TEXT_LIST_STYLE_ENTRIES; i++ )
63
5.82M
        rDestListStyle[i].apply(rSourceListStyle[i]);
64
647k
}
65
66
void TextListStyle::apply( const TextListStyle& rTextListStyle )
67
323k
{
68
323k
    applyStyleList( rTextListStyle.getAggregationListStyle(), getAggregationListStyle() );
69
323k
    applyStyleList( rTextListStyle.getListStyle(), getListStyle() );
70
323k
}
71
72
void TextListStyle::pushToNumberingRules(const uno::Reference<container::XIndexReplace>& xNumRules,
73
                                         std::optional<size_t> oIgnoreLevel)
74
99.4k
{
75
99.4k
    TextParagraphPropertiesArray& rListStyle = getListStyle();
76
99.4k
    size_t nLevels = xNumRules->getCount();
77
99.4k
    if (rListStyle.size() < nLevels)
78
99.4k
    {
79
99.4k
        nLevels = rListStyle.size();
80
99.4k
    }
81
82
994k
    for (size_t nLevel = 0; nLevel < nLevels; ++nLevel)
83
894k
    {
84
894k
        if (oIgnoreLevel && nLevel == *oIgnoreLevel)
85
62.7k
        {
86
62.7k
            continue;
87
62.7k
        }
88
89
832k
        comphelper::SequenceAsHashMap aMap(xNumRules->getByIndex(nLevel));
90
832k
        TextParagraphProperties& rLevel = rListStyle[nLevel];
91
832k
        bool bChanged = false;
92
832k
        if (rLevel.getParaLeftMargin())
93
257k
        {
94
257k
            aMap["LeftMargin"] <<= *rLevel.getParaLeftMargin();
95
257k
            bChanged = true;
96
257k
        }
97
832k
        if (rLevel.getFirstLineIndentation())
98
138k
        {
99
138k
            sal_Int32 nFirstLineIndentation = *rLevel.getFirstLineIndentation();
100
138k
            if (nFirstLineIndentation > 0)
101
0
            {
102
                // The opposite of this would be exported as <style:list-level-properties
103
                // text:min-label-width="..."> to ODF, where negative values are not allowed.
104
0
                nFirstLineIndentation = 0;
105
0
            }
106
138k
            aMap["FirstLineOffset"] <<= nFirstLineIndentation;
107
138k
            bChanged = true;
108
138k
        }
109
110
832k
        if (bChanged)
111
257k
        {
112
257k
            xNumRules->replaceByIndex(nLevel, aMap.getAsConstAny(true));
113
257k
        }
114
832k
    }
115
99.4k
}
116
117
#ifdef DBG_UTIL
118
void TextListStyle::dump() const
119
{
120
    for ( int i = 0; i < NUM_TEXT_LIST_STYLE_ENTRIES; i++ )
121
    {
122
        SAL_INFO("oox.drawingml", "text list style level: " << i);
123
        maListStyle[i].dump();
124
    }
125
}
126
#endif
127
}
128
129
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */