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 
20 #include <oox/drawingml/theme.hxx>
21 #include <oox/token/tokens.hxx>
23 
24 namespace oox::drawingml {
25 
27 {
28 }
29 
31 {
32 }
33 
34 namespace {
35 
36 template< typename Type >
37 const Type* lclGetStyleElement( const RefVector< Type >& rVector, sal_Int32 nIndex )
38 {
39  return (rVector.empty() || (nIndex < 1)) ? 0 :
40  rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get();
41 }
42 
43 } // namespace
44 
45 const FillProperties* Theme::getFillStyle( sal_Int32 nIndex ) const
46 {
47  return (nIndex >= 1000) ?
48  lclGetStyleElement( maBgFillStyleList, nIndex - 1000 ) :
49  lclGetStyleElement( maFillStyleList, nIndex );
50 }
51 
52 const LineProperties* Theme::getLineStyle( sal_Int32 nIndex ) const
53 {
54  return lclGetStyleElement( maLineStyleList, nIndex );
55 }
56 
57 const EffectProperties* Theme::getEffectStyle( sal_Int32 nIndex ) const
58 {
59  return lclGetStyleElement( maEffectStyleList, nIndex );
60 }
61 
62 const TextCharacterProperties* Theme::getFontStyle( sal_Int32 nSchemeType ) const
63 {
64  return maFontScheme.get( nSchemeType ).get();
65 }
66 
67 const TextFont* Theme::resolveFont( const OUString& rName ) const
68 {
69  const TextCharacterProperties* pCharProps = nullptr;
70  /* Resolves the following names:
71  +mj-lt, +mj-ea, +mj-cs -- major Latin, Asian, Complex font
72  +mn-lt, +mn-ea, +mn-cs -- minor Latin, Asian, Complex font
73  */
74  if( (rName.getLength() == 6) && (rName[ 0 ] == '+') && (rName[ 3 ] == '-') )
75  {
76  if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'j') )
77  pCharProps = maFontScheme.get( XML_major ).get();
78  else if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'n') )
79  pCharProps = maFontScheme.get( XML_minor ).get();
80  if( pCharProps )
81  {
82  if( (rName[ 4 ] == 'l') && (rName[ 5 ] == 't') )
83  return &pCharProps->maLatinFont;
84  if( (rName[ 4 ] == 'e') && (rName[ 5 ] == 'a') )
85  return &pCharProps->maAsianFont;
86  if( (rName[ 4 ] == 'c') && (rName[ 5 ] == 's') )
87  return &pCharProps->maComplexFont;
88  }
89  }
90 
91  // See writerfilter::dmapper::ThemeTable::getFontNameForTheme().
92  if (rName == "majorHAnsi" || rName == "majorAscii" || rName == "majorBidi" || rName == "majorEastAsia")
93  pCharProps = maFontScheme.get(XML_major).get();
94  else if (rName == "minorHAnsi" || rName == "minorAscii" || rName == "minorBidi" || rName == "minorEastAsia")
95  pCharProps = maFontScheme.get(XML_minor).get();
96  if (pCharProps)
97  {
98  if (rName == "majorAscii" || rName == "majorHAnsi" || rName == "minorAscii" || rName == "minorHAnsi")
99  return &pCharProps->maLatinFont;
100  else if (rName == "minorBidi" || rName == "majorBidi")
101  return &pCharProps->maComplexFont;
102  else if (rName == "minorEastAsia" || rName == "majorEastAsia")
103  return &pCharProps->maAsianFont;
104  }
105  return nullptr;
106 }
107 
108 } // namespace oox::drawingml
109 
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
const TextFont * resolveFont(const OUString &rName) const
Returns theme font by placeholder name, e.g.
Definition: theme.cxx:67
const EffectProperties * getEffectStyle(sal_Int32 nIndex) const
Definition: theme.cxx:57
FillStyleList maFillStyleList
Definition: theme.hxx:105
value_type get(sal_Int32 nIndex) const
Returns a reference to the object with the passed index, or 0 on error.
Definition: refvector.hxx:51
EffectStyleList maEffectStyleList
Definition: theme.hxx:108
FontScheme maFontScheme
Definition: theme.hxx:109
LineStyleList maLineStyleList
Definition: theme.hxx:107
FillStyleList maBgFillStyleList
Definition: theme.hxx:106
const LineProperties * getLineStyle(sal_Int32 nIndex) const
Returns the line properties of the passed one-based themed style index.
Definition: theme.cxx:52
const TextCharacterProperties * getFontStyle(sal_Int32 nSchemeType) const
Returns theme font properties by scheme type (major/minor).
Definition: theme.cxx:62
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:59
Template for a vector of ref-counted objects with additional accessor functions.
Definition: refvector.hxx:41
carries a CT_TextFont
Definition: textfont.hxx:32
const FillProperties * getFillStyle(sal_Int32 nIndex) const
Returns the fill properties of the passed one-based themed style index.
Definition: theme.cxx:45