/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.9k | { |
43 | 16.9k | return (rVector.empty() || (nIndex < 1)) ? nullptr : |
44 | 16.9k | rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get(); |
45 | 16.9k | } 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.63k | { | 43 | 6.63k | return (rVector.empty() || (nIndex < 1)) ? nullptr : | 44 | 6.63k | rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get(); | 45 | 6.63k | } |
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.87k | { | 43 | 6.87k | return (rVector.empty() || (nIndex < 1)) ? nullptr : | 44 | 6.87k | rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get(); | 45 | 6.87k | } |
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.43k | { | 43 | 3.43k | return (rVector.empty() || (nIndex < 1)) ? nullptr : | 44 | 3.43k | rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get(); | 45 | 3.43k | } |
|
46 | | |
47 | | } // namespace |
48 | | |
49 | | const FillProperties* Theme::getFillStyle( sal_Int32 nIndex ) const |
50 | 6.63k | { |
51 | 6.63k | return (nIndex >= 1000) ? |
52 | 3.20k | lclGetStyleElement( maBgFillStyleList, nIndex - 1000 ) : |
53 | 6.63k | lclGetStyleElement( maFillStyleList, nIndex ); |
54 | 6.63k | } |
55 | | |
56 | | const LineProperties* Theme::getLineStyle( sal_Int32 nIndex ) const |
57 | 6.87k | { |
58 | 6.87k | return lclGetStyleElement( maLineStyleList, nIndex ); |
59 | 6.87k | } |
60 | | |
61 | | const EffectProperties* Theme::getEffectStyle( sal_Int32 nIndex ) const |
62 | 3.43k | { |
63 | 3.43k | return lclGetStyleElement( maEffectStyleList, nIndex ); |
64 | 3.43k | } |
65 | | |
66 | | const TextCharacterProperties* Theme::getFontStyle( sal_Int32 nSchemeType ) const |
67 | 1.23k | { |
68 | 1.23k | return maFontScheme.get( nSchemeType ).get(); |
69 | 1.23k | } |
70 | | |
71 | | const TextFont* Theme::resolveFont( std::u16string_view rName ) const |
72 | 2.23M | { |
73 | 2.23M | 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.23M | if( (rName.size() == 6) && (rName[ 0 ] == '+') && (rName[ 3 ] == '-') ) |
79 | 403k | { |
80 | 403k | if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'j') ) |
81 | 35.6k | pCharProps = maFontScheme.get( XML_major ).get(); |
82 | 367k | else if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'n') ) |
83 | 367k | pCharProps = maFontScheme.get( XML_minor ).get(); |
84 | 403k | if( pCharProps ) |
85 | 403k | { |
86 | 403k | if( (rName[ 4 ] == 'l') && (rName[ 5 ] == 't') ) |
87 | 129k | return &pCharProps->maLatinFont; |
88 | 273k | if( (rName[ 4 ] == 'e') && (rName[ 5 ] == 'a') ) |
89 | 135k | return &pCharProps->maAsianFont; |
90 | 138k | if( (rName[ 4 ] == 'c') && (rName[ 5 ] == 's') ) |
91 | 138k | return &pCharProps->maComplexFont; |
92 | 138k | } |
93 | 403k | } |
94 | | |
95 | | // See writerfilter::dmapper::ThemeTable::getFontNameForTheme(). |
96 | 1.83M | if (rName == u"majorHAnsi" || rName == u"majorAscii" || rName == u"majorBidi" || rName == u"majorEastAsia") |
97 | 0 | pCharProps = maFontScheme.get(XML_major).get(); |
98 | 1.83M | else if (rName == u"minorHAnsi" || rName == u"minorAscii" || rName == u"minorBidi" || rName == u"minorEastAsia") |
99 | 0 | pCharProps = maFontScheme.get(XML_minor).get(); |
100 | 1.83M | 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.83M | return nullptr; |
110 | 1.83M | } |
111 | | |
112 | | void Theme::addTheme(const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage) const |
113 | 15.2k | { |
114 | 15.2k | SAL_WARN_IF(!xDrawPage.is(), "oox", "DrawPage is not set"); |
115 | | |
116 | 15.2k | SdrPage* pPage = GetSdrPageFromXDrawPage(xDrawPage); |
117 | | |
118 | 15.2k | SAL_WARN_IF(!pPage, "oox", "Can't get SdrPage from XDrawPage"); |
119 | | |
120 | 15.2k | if (!pPage) |
121 | 0 | return; |
122 | | |
123 | 15.2k | pPage->getSdrPageProperties().setTheme(getTheme()); |
124 | 15.2k | } |
125 | | |
126 | | } // namespace oox::drawingml |
127 | | |
128 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |