Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / drawingml / textfont.cxx
blob9cc83c632de41507b17ac1b910d48080f3564b85
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 "drawingml/textfont.hxx"
21 #include <com/sun/star/awt/FontFamily.hpp>
22 #include <com/sun/star/awt/FontPitch.hpp>
23 #include "oox/drawingml/theme.hxx"
24 #include "oox/core/xmlfilterbase.hxx"
25 #include "oox/helper/attributelist.hxx"
26 #include <oox/token/tokens.hxx>
28 using ::oox::core::XmlFilterBase;
30 namespace oox {
31 namespace drawingml {
33 namespace {
35 sal_Int16 lclGetFontPitch( sal_Int32 nOoxValue )
37 using namespace ::com::sun::star::awt::FontPitch;
38 static const sal_Int16 spnFontPitch[] = { DONTKNOW, FIXED, VARIABLE };
39 return STATIC_ARRAY_SELECT( spnFontPitch, nOoxValue, DONTKNOW );
42 sal_Int16 lclGetFontFamily( sal_Int32 nOoxValue )
44 using namespace ::com::sun::star::awt::FontFamily;
45 static const sal_Int16 spnFontFamily[] = { DONTKNOW, ROMAN, SWISS, MODERN, SCRIPT, DECORATIVE };
46 return STATIC_ARRAY_SELECT( spnFontFamily, nOoxValue, DONTKNOW );
49 } // namespace
51 TextFont::TextFont() :
52 mnPitch( 0 ),
53 mnCharset( WINDOWS_CHARSET_ANSI )
57 void TextFont::setAttributes( const AttributeList& rAttribs )
59 maTypeface = rAttribs.getString( XML_typeface, OUString() );
60 maPanose = rAttribs.getString( XML_panose, OUString() );
61 mnPitch = rAttribs.getInteger( XML_pitchFamily, 0 );
62 mnCharset = rAttribs.getInteger( XML_charset, WINDOWS_CHARSET_DEFAULT );
65 void TextFont::setAttributes( const OUString& sFontName )
67 maTypeface = sFontName;
68 maPanose.clear();
69 mnPitch = 0;
70 mnCharset = WINDOWS_CHARSET_DEFAULT;
73 void TextFont::assignIfUsed( const TextFont& rTextFont )
75 if( !rTextFont.maTypeface.isEmpty() )
76 *this = rTextFont;
79 bool TextFont::getFontData( OUString& rFontName, sal_Int16& rnFontPitch, sal_Int16& rnFontFamily, const XmlFilterBase& rFilter ) const
81 if( const Theme* pTheme = rFilter.getCurrentTheme() )
82 if( const TextFont* pFont = pTheme->resolveFont( maTypeface ) )
83 return pFont->implGetFontData( rFontName, rnFontPitch, rnFontFamily );
84 return implGetFontData( rFontName, rnFontPitch, rnFontFamily );
87 bool TextFont::implGetFontData( OUString& rFontName, sal_Int16& rnFontPitch, sal_Int16& rnFontFamily ) const
89 rFontName = maTypeface;
90 rnFontPitch = lclGetFontPitch( extractValue< sal_Int16 >( mnPitch, 0, 4 ) );
91 rnFontFamily = lclGetFontFamily( extractValue< sal_Int16 >( mnPitch, 4, 4 ) );
92 return !rFontName.isEmpty();
95 } // namespace drawingml
96 } // namespace oox
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */