LibreOffice Module oox (master) 1
theme.cxx
Go to the documentation of this file.
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
21#include <oox/token/tokens.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>
27
28using namespace com::sun::star;
29
30namespace oox::drawingml {
31
32namespace {
33
34template< typename Type >
35const Type* lclGetStyleElement( const RefVector< Type >& rVector, sal_Int32 nIndex )
36{
37 return (rVector.empty() || (nIndex < 1)) ? nullptr :
38 rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get();
39}
40
41} // namespace
42
43const FillProperties* Theme::getFillStyle( sal_Int32 nIndex ) const
44{
45 return (nIndex >= 1000) ?
46 lclGetStyleElement( maBgFillStyleList, nIndex - 1000 ) :
47 lclGetStyleElement( maFillStyleList, nIndex );
48}
49
50const LineProperties* Theme::getLineStyle( sal_Int32 nIndex ) const
51{
52 return lclGetStyleElement( maLineStyleList, nIndex );
53}
54
55const EffectProperties* Theme::getEffectStyle( sal_Int32 nIndex ) const
56{
57 return lclGetStyleElement( maEffectStyleList, nIndex );
58}
59
60const TextCharacterProperties* Theme::getFontStyle( sal_Int32 nSchemeType ) const
61{
62 return maFontScheme.get( nSchemeType ).get();
63}
64
65const TextFont* Theme::resolveFont( const OUString& rName ) const
66{
67 const TextCharacterProperties* pCharProps = nullptr;
68 /* Resolves the following names:
69 +mj-lt, +mj-ea, +mj-cs -- major Latin, Asian, Complex font
70 +mn-lt, +mn-ea, +mn-cs -- minor Latin, Asian, Complex font
71 */
72 if( (rName.getLength() == 6) && (rName[ 0 ] == '+') && (rName[ 3 ] == '-') )
73 {
74 if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'j') )
75 pCharProps = maFontScheme.get( XML_major ).get();
76 else if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'n') )
77 pCharProps = maFontScheme.get( XML_minor ).get();
78 if( pCharProps )
79 {
80 if( (rName[ 4 ] == 'l') && (rName[ 5 ] == 't') )
81 return &pCharProps->maLatinFont;
82 if( (rName[ 4 ] == 'e') && (rName[ 5 ] == 'a') )
83 return &pCharProps->maAsianFont;
84 if( (rName[ 4 ] == 'c') && (rName[ 5 ] == 's') )
85 return &pCharProps->maComplexFont;
86 }
87 }
88
89 // See writerfilter::dmapper::ThemeTable::getFontNameForTheme().
90 if (rName == "majorHAnsi" || rName == "majorAscii" || rName == "majorBidi" || rName == "majorEastAsia")
91 pCharProps = maFontScheme.get(XML_major).get();
92 else if (rName == "minorHAnsi" || rName == "minorAscii" || rName == "minorBidi" || rName == "minorEastAsia")
93 pCharProps = maFontScheme.get(XML_minor).get();
94 if (pCharProps)
95 {
96 if (rName == "majorAscii" || rName == "majorHAnsi" || rName == "minorAscii" || rName == "minorHAnsi")
97 return &pCharProps->maLatinFont;
98 else if (rName == "minorBidi" || rName == "majorBidi")
99 return &pCharProps->maComplexFont;
100 else if (rName == "minorEastAsia" || rName == "majorEastAsia")
101 return &pCharProps->maAsianFont;
102 }
103 return nullptr;
104}
105
106void Theme::addTheme(const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage) const
107{
108 beans::PropertyValue aColorScheme;
109 aColorScheme.Name = "ColorScheme";
110 maClrScheme.ToAny(aColorScheme.Value);
111 beans::PropertyValues aValues = {
114 aColorScheme,
115 };
116 uno::Reference<beans::XPropertySet> xPropertySet(xDrawPage, uno::UNO_QUERY);
117 xPropertySet->setPropertyValue("Theme", uno::Any(aValues));
118}
119
120} // namespace oox::drawingml
121
122/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
mapped_type get(key_type nKey) const
Returns a reference to the object associated to the passed key, or an empty reference on error.
Definition: refmap.hxx:60
void ToAny(css::uno::Any &rVal) const
Definition: clrscheme.cxx:111
const OUString & GetName() const
Definition: clrscheme.hxx:94
carries a CT_TextFont
Definition: textfont.hxx:33
const EffectProperties * getEffectStyle(sal_Int32 nIndex) const
Definition: theme.cxx:55
EffectStyleList maEffectStyleList
Definition: theme.hxx:110
const FillProperties * getFillStyle(sal_Int32 nIndex) const
Returns the fill properties of the passed one-based themed style index.
Definition: theme.cxx:43
FontScheme maFontScheme
Definition: theme.hxx:111
FillStyleList maBgFillStyleList
Definition: theme.hxx:108
const LineProperties * getLineStyle(sal_Int32 nIndex) const
Returns the line properties of the passed one-based themed style index.
Definition: theme.cxx:50
void addTheme(const css::uno::Reference< css::drawing::XDrawPage > &xDrawPage) const
Definition: theme.cxx:106
const TextCharacterProperties * getFontStyle(sal_Int32 nSchemeType) const
Returns theme font properties by scheme type (major/minor).
Definition: theme.cxx:60
OUString maThemeName
Definition: theme.hxx:105
LineStyleList maLineStyleList
Definition: theme.hxx:109
FillStyleList maFillStyleList
Definition: theme.hxx:107
ClrScheme maClrScheme
Definition: theme.hxx:106
const TextFont * resolveFont(const OUString &rName) const
Returns theme font by placeholder name, e.g.
Definition: theme.cxx:65
sal_Int32 nIndex
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
Type