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 #include <com/sun/star/beans/PropertyValues.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/drawing/XDrawPage.hpp>
27 
28 using namespace com::sun::star;
29 
30 namespace oox::drawingml {
31 
32 namespace {
33 
34 template< typename Type >
35 const Type* lclGetStyleElement( const RefVector< Type >& rVector, sal_Int32 nIndex )
36 {
37  return (rVector.empty() || (nIndex < 1)) ? nullptr :
38  rVector.get( ::std::min( static_cast< sal_Int32 >( nIndex - 1 ), static_cast< sal_Int32 >( rVector.size() - 1 ) ) ).get();
39 }
40 
41 } // namespace
42 
43 const FillProperties* Theme::getFillStyle( sal_Int32 nIndex ) const
44 {
45  return (nIndex >= 1000) ?
46  lclGetStyleElement( maBgFillStyleList, nIndex - 1000 ) :
47  lclGetStyleElement( maFillStyleList, nIndex );
48 }
49 
50 const LineProperties* Theme::getLineStyle( sal_Int32 nIndex ) const
51 {
52  return lclGetStyleElement( maLineStyleList, nIndex );
53 }
54 
55 const EffectProperties* Theme::getEffectStyle( sal_Int32 nIndex ) const
56 {
57  return lclGetStyleElement( maEffectStyleList, nIndex );
58 }
59 
60 const TextCharacterProperties* Theme::getFontStyle( sal_Int32 nSchemeType ) const
61 {
62  return maFontScheme.get( nSchemeType ).get();
63 }
64 
65 const TextFont* Theme::resolveFont( const OUString& rName ) const
66 {
67  const TextCharacterProperties* pCharProps = nullptr;
68  /* Resolves the following names:
69  +mj-lt, +mj-ea, +mj-cs -- major Latin, Asian, Complex font
70  +mn-lt, +mn-ea, +mn-cs -- minor Latin, Asian, Complex font
71  */
72  if( (rName.getLength() == 6) && (rName[ 0 ] == '+') && (rName[ 3 ] == '-') )
73  {
74  if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'j') )
75  pCharProps = maFontScheme.get( XML_major ).get();
76  else if( (rName[ 1 ] == 'm') && (rName[ 2 ] == 'n') )
77  pCharProps = maFontScheme.get( XML_minor ).get();
78  if( pCharProps )
79  {
80  if( (rName[ 4 ] == 'l') && (rName[ 5 ] == 't') )
81  return &pCharProps->maLatinFont;
82  if( (rName[ 4 ] == 'e') && (rName[ 5 ] == 'a') )
83  return &pCharProps->maAsianFont;
84  if( (rName[ 4 ] == 'c') && (rName[ 5 ] == 's') )
85  return &pCharProps->maComplexFont;
86  }
87  }
88 
89  // See writerfilter::dmapper::ThemeTable::getFontNameForTheme().
90  if (rName == "majorHAnsi" || rName == "majorAscii" || rName == "majorBidi" || rName == "majorEastAsia")
91  pCharProps = maFontScheme.get(XML_major).get();
92  else if (rName == "minorHAnsi" || rName == "minorAscii" || rName == "minorBidi" || rName == "minorEastAsia")
93  pCharProps = maFontScheme.get(XML_minor).get();
94  if (pCharProps)
95  {
96  if (rName == "majorAscii" || rName == "majorHAnsi" || rName == "minorAscii" || rName == "minorHAnsi")
97  return &pCharProps->maLatinFont;
98  else if (rName == "minorBidi" || rName == "majorBidi")
99  return &pCharProps->maComplexFont;
100  else if (rName == "minorEastAsia" || rName == "majorEastAsia")
101  return &pCharProps->maAsianFont;
102  }
103  return nullptr;
104 }
105 
106 void Theme::addTheme(const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage) const
107 {
108  beans::PropertyValue aColorScheme;
109  aColorScheme.Name = "ColorScheme";
110  maClrScheme.ToAny(aColorScheme.Value);
111  beans::PropertyValues aValues = {
112  comphelper::makePropertyValue("Name", maThemeName),
113  comphelper::makePropertyValue("ColorSchemeName", maClrScheme.GetName()),
114  aColorScheme,
115  };
116  uno::Reference<beans::XPropertySet> xPropertySet(xDrawPage, uno::UNO_QUERY);
117  xPropertySet->setPropertyValue("Theme", uno::makeAny(aValues));
118 }
119 
120 } // namespace oox::drawingml
121 
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
Any makeAny(Color const &value)
carries a CT_TextFont
Definition: textfont.hxx:32