bump product version to 4.1.6.2
[LibreOffice.git] / oox / source / drawingml / textfont.cxx
blob553f5aef9eff0a72077c3a6ce44028fd9063f8ca
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/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"
27 using ::oox::core::XmlFilterBase;
29 namespace oox {
30 namespace drawingml {
32 // ============================================================================
34 namespace {
36 sal_Int16 lclGetFontPitch( sal_Int32 nOoxValue )
38 using namespace ::com::sun::star::awt::FontPitch;
39 static const sal_Int16 spnFontPitch[] = { DONTKNOW, FIXED, VARIABLE };
40 return STATIC_ARRAY_SELECT( spnFontPitch, nOoxValue, DONTKNOW );
43 sal_Int16 lclGetFontFamily( sal_Int32 nOoxValue )
45 using namespace ::com::sun::star::awt::FontFamily;
46 static const sal_Int16 spnFontFamily[] = { DONTKNOW, ROMAN, SWISS, MODERN, SCRIPT, DECORATIVE };
47 return STATIC_ARRAY_SELECT( spnFontFamily, nOoxValue, DONTKNOW );
50 } // namespace
52 // ============================================================================
54 TextFont::TextFont() :
55 mnPitch( 0 ),
56 mnCharset( WINDOWS_CHARSET_ANSI )
60 void TextFont::setAttributes( const AttributeList& rAttribs )
62 maTypeface = rAttribs.getString( XML_typeface, OUString() );
63 maPanose = rAttribs.getString( XML_panose, OUString() );
64 mnPitch = rAttribs.getInteger( XML_pitchFamily, 0 );
65 mnCharset = rAttribs.getInteger( XML_charset, WINDOWS_CHARSET_DEFAULT );
68 void TextFont::assignIfUsed( const TextFont& rTextFont )
70 if( !rTextFont.maTypeface.isEmpty() )
71 *this = rTextFont;
74 bool TextFont::getFontData( OUString& rFontName, sal_Int16& rnFontPitch, sal_Int16& rnFontFamily, const XmlFilterBase& rFilter ) const
76 if( const Theme* pTheme = rFilter.getCurrentTheme() )
77 if( const TextFont* pFont = pTheme->resolveFont( maTypeface ) )
78 return pFont->implGetFontData( rFontName, rnFontPitch, rnFontFamily );
79 return implGetFontData( rFontName, rnFontPitch, rnFontFamily );
82 bool TextFont::implGetFontData( OUString& rFontName, sal_Int16& rnFontPitch, sal_Int16& rnFontFamily ) const
84 rFontName = maTypeface;
85 rnFontPitch = lclGetFontPitch( extractValue< sal_Int16 >( mnPitch, 0, 4 ) );
86 rnFontFamily = lclGetFontFamily( extractValue< sal_Int16 >( mnPitch, 4, 4 ) );
87 return !rFontName.isEmpty();
90 // ============================================================================
92 } // namespace drawingml
93 } // namespace oox
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */