Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/drawingml/theme.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 <oox/drawingml/theme.hxx>
21
#include <oox/token/tokens.hxx>
22
#include <drawingml/textcharacterproperties.hxx>
23
#include <com/sun/star/beans/PropertyValues.hpp>
24
#include <com/sun/star/beans/XPropertySet.hpp>
25
#include <com/sun/star/drawing/XDrawPage.hpp>
26
#include <comphelper/propertyvalue.hxx>
27
#include <sal/log.hxx>
28
#include <svx/unopage.hxx>
29
#include <svx/svdpage.hxx>
30
#include <docmodel/theme/ColorSet.hxx>
31
#include <docmodel/theme/Theme.hxx>
32
#include <svx/unoapi.hxx>
33
34
using namespace com::sun::star;
35
36
namespace oox::drawingml {
37
38
namespace {
39
40
template< typename Type >
41
const Type* lclGetStyleElement( const RefVector< Type >& rVector, sal_Int32 nIndex )
42
16.2k
{
43
16.2k
    return (rVector.empty() || (nIndex < 1)) ? nullptr :
44
16.2k
        rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get();
45
16.2k
}
theme.cxx:oox::drawingml::FillProperties const* oox::drawingml::(anonymous namespace)::lclGetStyleElement<oox::drawingml::FillProperties>(oox::RefVector<oox::drawingml::FillProperties> const&, int)
Line
Count
Source
42
6.78k
{
43
6.78k
    return (rVector.empty() || (nIndex < 1)) ? nullptr :
44
6.78k
        rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get();
45
6.78k
}
theme.cxx:oox::drawingml::LineProperties const* oox::drawingml::(anonymous namespace)::lclGetStyleElement<oox::drawingml::LineProperties>(oox::RefVector<oox::drawingml::LineProperties> const&, int)
Line
Count
Source
42
6.32k
{
43
6.32k
    return (rVector.empty() || (nIndex < 1)) ? nullptr :
44
6.32k
        rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get();
45
6.32k
}
theme.cxx:oox::drawingml::EffectProperties const* oox::drawingml::(anonymous namespace)::lclGetStyleElement<oox::drawingml::EffectProperties>(oox::RefVector<oox::drawingml::EffectProperties> const&, int)
Line
Count
Source
42
3.16k
{
43
3.16k
    return (rVector.empty() || (nIndex < 1)) ? nullptr :
44
3.16k
        rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get();
45
3.16k
}
46
47
} // namespace
48
49
const FillProperties* Theme::getFillStyle( sal_Int32 nIndex ) const
50
6.78k
{
51
6.78k
    return (nIndex >= 1000) ?
52
3.62k
        lclGetStyleElement( maBgFillStyleList, nIndex - 1000 ) :
53
6.78k
        lclGetStyleElement( maFillStyleList, nIndex );
54
6.78k
}
55
56
const LineProperties* Theme::getLineStyle( sal_Int32 nIndex ) const
57
6.32k
{
58
6.32k
     return lclGetStyleElement( maLineStyleList, nIndex );
59
6.32k
}
60
61
const EffectProperties* Theme::getEffectStyle( sal_Int32 nIndex ) const
62
3.16k
{
63
3.16k
    return lclGetStyleElement( maEffectStyleList, nIndex );
64
3.16k
}
65
66
const TextCharacterProperties* Theme::getFontStyle( sal_Int32 nSchemeType ) const
67
1.31k
{
68
1.31k
    return maFontScheme.get( nSchemeType ).get();
69
1.31k
}
70
71
const TextFont* Theme::resolveFont( std::u16string_view rName ) const
72
2.43M
{
73
2.43M
    const TextCharacterProperties* pCharProps = nullptr;
74
    /*  Resolves the following names:
75
        +mj-lt, +mj-ea, +mj-cs  --  major Latin, Asian, Complex font
76
        +mn-lt, +mn-ea, +mn-cs  --  minor Latin, Asian, Complex font
77
     */
78
2.43M
    if( (rName.size() == 6) && (rName[ 0 ] == '+') && (rName[ 3 ] == '-') )
79
468k
    {
80
468k
        if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'j') )
81
41.6k
            pCharProps = maFontScheme.get( XML_major ).get();
82
426k
        else if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'n') )
83
426k
            pCharProps = maFontScheme.get( XML_minor ).get();
84
468k
        if( pCharProps )
85
466k
        {
86
466k
            if( (rName[ 4 ] == 'l') && (rName[ 5 ] == 't') )
87
148k
                return &pCharProps->maLatinFont;
88
317k
            if( (rName[ 4 ] == 'e') && (rName[ 5 ] == 'a') )
89
157k
                return &pCharProps->maAsianFont;
90
159k
            if( (rName[ 4 ] == 'c') && (rName[ 5 ] == 's') )
91
159k
                return &pCharProps->maComplexFont;
92
159k
        }
93
468k
    }
94
95
    // See writerfilter::dmapper::ThemeTable::getFontNameForTheme().
96
1.96M
    if (rName == u"majorHAnsi" || rName == u"majorAscii" || rName == u"majorBidi" || rName == u"majorEastAsia")
97
0
        pCharProps = maFontScheme.get(XML_major).get();
98
1.96M
    else if (rName == u"minorHAnsi" || rName == u"minorAscii" || rName == u"minorBidi" || rName == u"minorEastAsia")
99
0
        pCharProps = maFontScheme.get(XML_minor).get();
100
1.96M
    if (pCharProps)
101
0
    {
102
0
        if (rName == u"majorAscii" || rName == u"majorHAnsi" || rName == u"minorAscii" || rName == u"minorHAnsi")
103
0
            return &pCharProps->maLatinFont;
104
0
        else if (rName == u"minorBidi" || rName == u"majorBidi")
105
0
            return &pCharProps->maComplexFont;
106
0
        else if (rName == u"minorEastAsia" || rName == u"majorEastAsia")
107
0
            return &pCharProps->maAsianFont;
108
0
    }
109
1.96M
    return nullptr;
110
1.96M
}
111
112
void Theme::addTheme(const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage) const
113
16.2k
{
114
16.2k
    SAL_WARN_IF(!xDrawPage.is(), "oox", "DrawPage is not set");
115
116
16.2k
    SdrPage* pPage = GetSdrPageFromXDrawPage(xDrawPage);
117
118
16.2k
    SAL_WARN_IF(!pPage, "oox", "Can't get SdrPage from XDrawPage");
119
120
16.2k
    if (!pPage)
121
0
        return;
122
123
16.2k
    pPage->getSdrPageProperties().setTheme(getTheme());
124
16.2k
}
125
126
} // namespace oox::drawingml
127
128
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */