1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <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>
34 using namespace com::sun::star
;
36 namespace oox::drawingml
{
40 template< typename Type
>
41 const Type
* lclGetStyleElement( const RefVector
< Type
>& rVector
, sal_Int32 nIndex
)
43 return (rVector
.empty() || (nIndex
< 1)) ? nullptr :
44 rVector
.get( ::std::min( static_cast< sal_Int32
>( nIndex
- 1 ), static_cast< sal_Int32
>( rVector
.size() - 1 ) ) ).get();
49 const FillProperties
* Theme::getFillStyle( sal_Int32 nIndex
) const
51 return (nIndex
>= 1000) ?
52 lclGetStyleElement( maBgFillStyleList
, nIndex
- 1000 ) :
53 lclGetStyleElement( maFillStyleList
, nIndex
);
56 const LineProperties
* Theme::getLineStyle( sal_Int32 nIndex
) const
58 return lclGetStyleElement( maLineStyleList
, nIndex
);
61 const EffectProperties
* Theme::getEffectStyle( sal_Int32 nIndex
) const
63 return lclGetStyleElement( maEffectStyleList
, nIndex
);
66 const TextCharacterProperties
* Theme::getFontStyle( sal_Int32 nSchemeType
) const
68 return maFontScheme
.get( nSchemeType
).get();
71 const TextFont
* Theme::resolveFont( std::u16string_view rName
) const
73 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
78 if( (rName
.size() == 6) && (rName
[ 0 ] == '+') && (rName
[ 3 ] == '-') )
80 if( (rName
[ 1 ] == 'm') && (rName
[ 2 ] == 'j') )
81 pCharProps
= maFontScheme
.get( XML_major
).get();
82 else if( (rName
[ 1 ] == 'm') && (rName
[ 2 ] == 'n') )
83 pCharProps
= maFontScheme
.get( XML_minor
).get();
86 if( (rName
[ 4 ] == 'l') && (rName
[ 5 ] == 't') )
87 return &pCharProps
->maLatinFont
;
88 if( (rName
[ 4 ] == 'e') && (rName
[ 5 ] == 'a') )
89 return &pCharProps
->maAsianFont
;
90 if( (rName
[ 4 ] == 'c') && (rName
[ 5 ] == 's') )
91 return &pCharProps
->maComplexFont
;
95 // See writerfilter::dmapper::ThemeTable::getFontNameForTheme().
96 if (rName
== u
"majorHAnsi" || rName
== u
"majorAscii" || rName
== u
"majorBidi" || rName
== u
"majorEastAsia")
97 pCharProps
= maFontScheme
.get(XML_major
).get();
98 else if (rName
== u
"minorHAnsi" || rName
== u
"minorAscii" || rName
== u
"minorBidi" || rName
== u
"minorEastAsia")
99 pCharProps
= maFontScheme
.get(XML_minor
).get();
102 if (rName
== u
"majorAscii" || rName
== u
"majorHAnsi" || rName
== u
"minorAscii" || rName
== u
"minorHAnsi")
103 return &pCharProps
->maLatinFont
;
104 else if (rName
== u
"minorBidi" || rName
== u
"majorBidi")
105 return &pCharProps
->maComplexFont
;
106 else if (rName
== u
"minorEastAsia" || rName
== u
"majorEastAsia")
107 return &pCharProps
->maAsianFont
;
112 void Theme::addTheme(const css::uno::Reference
<css::drawing::XDrawPage
>& xDrawPage
) const
114 SAL_WARN_IF(!xDrawPage
.is(), "oox", "DrawPage is not set");
116 SdrPage
* pPage
= GetSdrPageFromXDrawPage(xDrawPage
);
118 SAL_WARN_IF(!pPage
, "oox", "Can't get SdrPage from XDrawPage");
123 pPage
->getSdrPageProperties().setTheme(getTheme());
126 } // namespace oox::drawingml
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */