Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / drawingml / theme.cxx
blobe2cca699d1c405bfb52b1029248091c4f8705156
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 namespace oox {
25 namespace drawingml {
27 Theme::Theme()
31 Theme::~Theme()
35 namespace {
37 template< typename Type >
38 const Type* lclGetStyleElement( const RefVector< Type >& rVector, sal_Int32 nIndex )
40 return (rVector.empty() || (nIndex < 1)) ? 0 :
41 rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get();
44 } // namespace
46 const FillProperties* Theme::getFillStyle( sal_Int32 nIndex ) const
48 return (nIndex >= 1000) ?
49 lclGetStyleElement( maBgFillStyleList, nIndex - 1000 ) :
50 lclGetStyleElement( maFillStyleList, nIndex );
53 const LineProperties* Theme::getLineStyle( sal_Int32 nIndex ) const
55 return lclGetStyleElement( maLineStyleList, nIndex );
58 const EffectProperties* Theme::getEffectStyle( sal_Int32 nIndex ) const
60 return lclGetStyleElement( maEffectStyleList, nIndex );
63 const TextCharacterProperties* Theme::getFontStyle( sal_Int32 nSchemeType ) const
65 return maFontScheme.get( nSchemeType ).get();
68 const TextFont* Theme::resolveFont( const OUString& rName ) const
70 const TextCharacterProperties* pCharProps = nullptr;
71 /* Resolves the following names:
72 +mj-lt, +mj-ea, +mj-cs -- major Latin, Asian, Complex font
73 +mn-lt, +mn-ea, +mn-cs -- minor Latin, Asian, Complex font
75 if( (rName.getLength() == 6) && (rName[ 0 ] == '+') && (rName[ 3 ] == '-') )
77 if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'j') )
78 pCharProps = maFontScheme.get( XML_major ).get();
79 else if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'n') )
80 pCharProps = maFontScheme.get( XML_minor ).get();
81 if( pCharProps )
83 if( (rName[ 4 ] == 'l') && (rName[ 5 ] == 't') )
84 return &pCharProps->maLatinFont;
85 if( (rName[ 4 ] == 'e') && (rName[ 5 ] == 'a') )
86 return &pCharProps->maAsianFont;
87 if( (rName[ 4 ] == 'c') && (rName[ 5 ] == 's') )
88 return &pCharProps->maComplexFont;
92 // See writerfilter::dmapper::ThemeTable::getFontNameForTheme().
93 if (rName == "majorHAnsi" || rName == "majorAscii" || rName == "majorBidi" || rName == "majorEastAsia")
94 pCharProps = maFontScheme.get(XML_major).get();
95 else if (rName == "minorHAnsi" || rName == "minorAscii" || rName == "minorBidi" || rName == "minorEastAsia")
96 pCharProps = maFontScheme.get(XML_minor).get();
97 if (pCharProps)
99 if (rName == "majorAscii" || rName == "majorHAnsi" || rName == "minorAscii" || rName == "minorHAnsi")
100 return &pCharProps->maLatinFont;
101 else if (rName == "minorBidi" || rName == "majorBidi")
102 return &pCharProps->maComplexFont;
103 else if (rName == "minorEastAsia" || rName == "majorEastAsia")
104 return &pCharProps->maAsianFont;
106 return nullptr;
109 } // namespace drawingml
110 } // namespace oox
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */