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#include <sal/log.hxx>
28#include <svx/unopage.hxx>
29#include <svx/svdpage.hxx>
32#include <svx/unoapi.hxx>
33
34using namespace com::sun::star;
35
36namespace oox::drawingml {
37
38namespace {
39
40template< typename Type >
41const Type* lclGetStyleElement( const RefVector< Type >& rVector, sal_Int32 nIndex )
42{
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();
45}
46
47} // namespace
48
49const FillProperties* Theme::getFillStyle( sal_Int32 nIndex ) const
50{
51 return (nIndex >= 1000) ?
52 lclGetStyleElement( maBgFillStyleList, nIndex - 1000 ) :
53 lclGetStyleElement( maFillStyleList, nIndex );
54}
55
56const LineProperties* Theme::getLineStyle( sal_Int32 nIndex ) const
57{
58 return lclGetStyleElement( maLineStyleList, nIndex );
59}
60
61const EffectProperties* Theme::getEffectStyle( sal_Int32 nIndex ) const
62{
63 return lclGetStyleElement( maEffectStyleList, nIndex );
64}
65
66const TextCharacterProperties* Theme::getFontStyle( sal_Int32 nSchemeType ) const
67{
68 return maFontScheme.get( nSchemeType ).get();
69}
70
71const TextFont* Theme::resolveFont( std::u16string_view rName ) const
72{
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
77 */
78 if( (rName.size() == 6) && (rName[ 0 ] == '+') && (rName[ 3 ] == '-') )
79 {
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();
84 if( pCharProps )
85 {
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;
92 }
93 }
94
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();
100 if (pCharProps)
101 {
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;
108 }
109 return nullptr;
110}
111
112std::unique_ptr<model::Theme> Theme::createSvxTheme() const
113{
114 auto pTheme = std::make_unique<model::Theme>(maThemeName);
115 auto pColorSet = std::make_unique<model::ColorSet>(maClrScheme.GetName());
116 maClrScheme.fill(*pColorSet);
117 pTheme->SetColorSet(std::move(pColorSet));
118
120
121 if (auto* pCharProps = getFontStyle(XML_minor))
122 {
123 model::ThemeFont aMinorLatin;
124 pCharProps->maLatinFont.fillThemeFont(aMinorLatin);
125 aFontScheme.setMinorLatin(aMinorLatin);
126
127 model::ThemeFont aMinorAsian;
128 pCharProps->maAsianFont.fillThemeFont(aMinorAsian);
129 aFontScheme.setMinorAsian(aMinorAsian);
130
131 model::ThemeFont aMinorComplex;
132 pCharProps->maComplexFont.fillThemeFont(aMinorComplex);
133 aFontScheme.setMinorComplex(aMinorComplex);
134 }
135
136 if (auto* pCharProps = getFontStyle(XML_major))
137 {
138 model::ThemeFont aMajorLatin;
139 pCharProps->maLatinFont.fillThemeFont(aMajorLatin);
140 aFontScheme.setMajorLatin(aMajorLatin);
141
142 model::ThemeFont aMajorAsian;
143 pCharProps->maAsianFont.fillThemeFont(aMajorAsian);
144 aFontScheme.setMajorAsian(aMajorAsian);
145
146 model::ThemeFont aMajorComplex;
147 pCharProps->maComplexFont.fillThemeFont(aMajorComplex);
148 aFontScheme.setMajorComplex(aMajorComplex);
149 }
150
151 if (maSupplementalFontMap.find(XML_minor) != maSupplementalFontMap.cend())
152 {
153 std::vector<model::ThemeSupplementalFont> aList;
154 for (auto const& [rScript, rTypeface] : maSupplementalFontMap.at(XML_minor))
155 {
156 aList.push_back(model::ThemeSupplementalFont{rScript, rTypeface});
157 }
158 aFontScheme.setMinorSupplementalFontList(aList);
159 }
160
161 if (maSupplementalFontMap.find(XML_major) != maSupplementalFontMap.cend())
162 {
163 std::vector<model::ThemeSupplementalFont> aList;
164 for (auto const& [rScript, rTypeface] : maSupplementalFontMap.at(XML_major))
165 {
166 aList.push_back(model::ThemeSupplementalFont{rScript, rTypeface});
167 }
168 aFontScheme.setMajorSupplementalFontList(aList);
169 }
170
171 pTheme->setFontScheme(aFontScheme);
172
173 return pTheme;
174}
175
176void Theme::addTheme(const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage) const
177{
178 SAL_WARN_IF(!xDrawPage.is(), "oox", "DrawPage is not set");
179
180 SdrPage* pPage = GetSdrPageFromXDrawPage(xDrawPage);
181
182 SAL_WARN_IF(!pPage, "oox", "Can't get SdrPage from XDrawPage");
183
184 if (!pPage)
185 return;
186
187 std::unique_ptr<model::Theme> pTheme = createSvxTheme();
188
189 pPage->getSdrPageProperties().SetTheme(std::move(pTheme));
190}
191
192} // namespace oox::drawingml
193
194/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetTheme(std::unique_ptr< model::Theme > pTheme)
SdrPageProperties & getSdrPageProperties()
void setMajorAsian(ThemeFont const &aMajor)
void setMinorComplex(ThemeFont const &aMinor)
void setMajorLatin(ThemeFont const &aMajor)
void setMinorSupplementalFontList(std::vector< ThemeSupplementalFont > const &rSupplementalFont)
void setMinorAsian(ThemeFont const &aMinor)
void setMinorLatin(ThemeFont const &aMinor)
void setMajorSupplementalFontList(std::vector< ThemeSupplementalFont > const &rSupplementalFont)
void setMajorComplex(ThemeFont const &aMajor)
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
const OUString & GetName() const
Definition: clrscheme.hxx:95
void fill(model::ColorSet &rColorSet) const
Definition: clrscheme.cxx:133
carries a CT_TextFont
Definition: textfont.hxx:34
const EffectProperties * getEffectStyle(sal_Int32 nIndex) const
Definition: theme.cxx:61
EffectStyleList maEffectStyleList
Definition: theme.hxx:121
const FillProperties * getFillStyle(sal_Int32 nIndex) const
Returns the fill properties of the passed one-based themed style index.
Definition: theme.cxx:49
FontScheme maFontScheme
Definition: theme.hxx:122
FillStyleList maBgFillStyleList
Definition: theme.hxx:119
std::unique_ptr< model::Theme > createSvxTheme() const
Definition: theme.cxx:112
const LineProperties * getLineStyle(sal_Int32 nIndex) const
Returns the line properties of the passed one-based themed style index.
Definition: theme.cxx:56
std::map< sal_Int32, std::vector< std::pair< OUString, OUString > > > maSupplementalFontMap
Definition: theme.hxx:123
void addTheme(const css::uno::Reference< css::drawing::XDrawPage > &xDrawPage) const
Definition: theme.cxx:176
const TextCharacterProperties * getFontStyle(sal_Int32 nSchemeType) const
Returns theme font properties by scheme type (major/minor).
Definition: theme.cxx:66
OUString maThemeName
Definition: theme.hxx:114
LineStyleList maLineStyleList
Definition: theme.hxx:120
FillStyleList maFillStyleList
Definition: theme.hxx:118
OUString maFontSchemeName
Definition: theme.hxx:115
const TextFont * resolveFont(std::u16string_view rName) const
Returns theme font by placeholder name, e.g.
Definition: theme.cxx:71
ClrScheme maClrScheme
Definition: theme.hxx:117
float u
sal_Int32 nIndex
#define SAL_WARN_IF(condition, area, stream)
Type
SVXCORE_DLLPUBLIC SdrPage * GetSdrPageFromXDrawPage(const css::uno::Reference< css::drawing::XDrawPage > &xDrawPage) noexcept