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 
20 #include <oox/drawingml/theme.hxx>
21 #include <oox/token/tokens.hxx>
22 #include <drawingml/textcharacterproperties.hxx>
23 
24 namespace oox::drawingml {
25 
26 namespace {
27 
28 template< typename Type >
lclGetStyleElement(const RefVector<Type> & rVector,sal_Int32 nIndex)29 const Type* lclGetStyleElement( const RefVector< Type >& rVector, sal_Int32 nIndex )
30 {
31     return (rVector.empty() || (nIndex < 1)) ? 0 :
32         rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get();
33 }
34 
35 } // namespace
36 
getFillStyle(sal_Int32 nIndex) const37 const FillProperties* Theme::getFillStyle( sal_Int32 nIndex ) const
38 {
39     return (nIndex >= 1000) ?
40         lclGetStyleElement( maBgFillStyleList, nIndex - 1000 ) :
41         lclGetStyleElement( maFillStyleList, nIndex );
42 }
43 
getLineStyle(sal_Int32 nIndex) const44 const LineProperties* Theme::getLineStyle( sal_Int32 nIndex ) const
45 {
46      return lclGetStyleElement( maLineStyleList, nIndex );
47 }
48 
getEffectStyle(sal_Int32 nIndex) const49 const EffectProperties* Theme::getEffectStyle( sal_Int32 nIndex ) const
50 {
51     return lclGetStyleElement( maEffectStyleList, nIndex );
52 }
53 
getFontStyle(sal_Int32 nSchemeType) const54 const TextCharacterProperties* Theme::getFontStyle( sal_Int32 nSchemeType ) const
55 {
56     return maFontScheme.get( nSchemeType ).get();
57 }
58 
resolveFont(const OUString & rName) const59 const TextFont* Theme::resolveFont( const OUString& rName ) const
60 {
61     const TextCharacterProperties* pCharProps = nullptr;
62     /*  Resolves the following names:
63         +mj-lt, +mj-ea, +mj-cs  --  major Latin, Asian, Complex font
64         +mn-lt, +mn-ea, +mn-cs  --  minor Latin, Asian, Complex font
65      */
66     if( (rName.getLength() == 6) && (rName[ 0 ] == '+') && (rName[ 3 ] == '-') )
67     {
68         if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'j') )
69             pCharProps = maFontScheme.get( XML_major ).get();
70         else if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'n') )
71             pCharProps = maFontScheme.get( XML_minor ).get();
72         if( pCharProps )
73         {
74             if( (rName[ 4 ] == 'l') && (rName[ 5 ] == 't') )
75                 return &pCharProps->maLatinFont;
76             if( (rName[ 4 ] == 'e') && (rName[ 5 ] == 'a') )
77                 return &pCharProps->maAsianFont;
78             if( (rName[ 4 ] == 'c') && (rName[ 5 ] == 's') )
79                 return &pCharProps->maComplexFont;
80         }
81     }
82 
83     // See writerfilter::dmapper::ThemeTable::getFontNameForTheme().
84     if (rName == "majorHAnsi" || rName == "majorAscii" || rName == "majorBidi" || rName == "majorEastAsia")
85         pCharProps = maFontScheme.get(XML_major).get();
86     else if (rName == "minorHAnsi" || rName == "minorAscii" || rName == "minorBidi" || rName == "minorEastAsia")
87         pCharProps = maFontScheme.get(XML_minor).get();
88     if (pCharProps)
89     {
90         if (rName == "majorAscii" || rName == "majorHAnsi" || rName == "minorAscii" || rName == "minorHAnsi")
91             return &pCharProps->maLatinFont;
92         else if (rName == "minorBidi" || rName == "majorBidi")
93             return &pCharProps->maComplexFont;
94         else if (rName == "minorEastAsia" || rName == "majorEastAsia")
95             return &pCharProps->maAsianFont;
96     }
97     return nullptr;
98 }
99 
100 } // namespace oox::drawingml
101 
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
103