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
112void Theme::addTheme(const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage) const
113{
114 SAL_WARN_IF(!xDrawPage.is(), "oox", "DrawPage is not set");
115
116 SdrPage* pPage = GetSdrPageFromXDrawPage(xDrawPage);
117
118 SAL_WARN_IF(!pPage, "oox", "Can't get SdrPage from XDrawPage");
119
120 if (!pPage)
121 return;
122
124}
125
126} // namespace oox::drawingml
127
128/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetTheme(std::shared_ptr< model::Theme > const &pTheme)
SdrPageProperties & getSdrPageProperties()
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
carries a CT_TextFont
Definition: textfont.hxx:34
const EffectProperties * getEffectStyle(sal_Int32 nIndex) const
Definition: theme.cxx:61
EffectStyleList maEffectStyleList
Definition: theme.hxx:130
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:131
FillStyleList maBgFillStyleList
Definition: theme.hxx:128
const LineProperties * getLineStyle(sal_Int32 nIndex) const
Returns the line properties of the passed one-based themed style index.
Definition: theme.cxx:56
std::shared_ptr< model::Theme > const & getTheme() const
Definition: theme.hxx:118
void addTheme(const css::uno::Reference< css::drawing::XDrawPage > &xDrawPage) const
Definition: theme.cxx:112
const TextCharacterProperties * getFontStyle(sal_Int32 nSchemeType) const
Returns theme font properties by scheme type (major/minor).
Definition: theme.cxx:66
LineStyleList maLineStyleList
Definition: theme.hxx:129
FillStyleList maFillStyleList
Definition: theme.hxx:127
const TextFont * resolveFont(std::u16string_view rName) const
Returns theme font by placeholder name, e.g.
Definition: theme.cxx:71
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