xref: /trunk/main/oox/source/drawingml/textfont.cxx (revision ca5ec200)
1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/drawingml/textfont.hxx"
25cdf0e10cSrcweir #include <com/sun/star/awt/FontFamily.hpp>
26cdf0e10cSrcweir #include <com/sun/star/awt/FontPitch.hpp>
27cdf0e10cSrcweir #include "oox/drawingml/theme.hxx"
28cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx"
29cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using ::rtl::OUString;
32cdf0e10cSrcweir using ::oox::core::XmlFilterBase;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace oox {
35cdf0e10cSrcweir namespace drawingml {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir // ============================================================================
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace {
40cdf0e10cSrcweir 
lclGetFontPitch(sal_Int32 nOoxValue)41cdf0e10cSrcweir sal_Int16 lclGetFontPitch( sal_Int32 nOoxValue )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     using namespace ::com::sun::star::awt::FontPitch;
44cdf0e10cSrcweir     static const sal_Int16 spnFontPitch[] = { DONTKNOW, FIXED, VARIABLE };
45cdf0e10cSrcweir     return STATIC_ARRAY_SELECT( spnFontPitch, nOoxValue, DONTKNOW );
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
lclGetFontFamily(sal_Int32 nOoxValue)48cdf0e10cSrcweir sal_Int16 lclGetFontFamily( sal_Int32 nOoxValue )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     using namespace ::com::sun::star::awt::FontFamily;
51cdf0e10cSrcweir     static const sal_Int16 spnFontFamily[] = { DONTKNOW, ROMAN, SWISS, MODERN, SCRIPT, DECORATIVE };
52cdf0e10cSrcweir     return STATIC_ARRAY_SELECT( spnFontFamily, nOoxValue, DONTKNOW );
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir } // namespace
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // ============================================================================
58cdf0e10cSrcweir 
TextFont()59cdf0e10cSrcweir TextFont::TextFont() :
60cdf0e10cSrcweir     mnPitch( 0 ),
61cdf0e10cSrcweir     mnCharset( WINDOWS_CHARSET_ANSI )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
setAttributes(const AttributeList & rAttribs)65cdf0e10cSrcweir void TextFont::setAttributes( const AttributeList& rAttribs )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     maTypeface = rAttribs.getString( XML_typeface, OUString() );
68cdf0e10cSrcweir     maPanose   = rAttribs.getString( XML_panose, OUString() );
69cdf0e10cSrcweir     mnPitch    = rAttribs.getInteger( XML_pitchFamily, 0 );
70cdf0e10cSrcweir     mnCharset  = rAttribs.getInteger( XML_charset, WINDOWS_CHARSET_DEFAULT );
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
assignIfUsed(const TextFont & rTextFont)73cdf0e10cSrcweir void TextFont::assignIfUsed( const TextFont& rTextFont )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     if( rTextFont.maTypeface.getLength() > 0 )
76cdf0e10cSrcweir         *this = rTextFont;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
getFontData(OUString & rFontName,sal_Int16 rnFontPitch,sal_Int16 & rnFontFamily,const XmlFilterBase & rFilter) const79cdf0e10cSrcweir bool TextFont::getFontData( OUString& rFontName, sal_Int16 rnFontPitch, sal_Int16& rnFontFamily, const XmlFilterBase& rFilter ) const
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     if( const Theme* pTheme = rFilter.getCurrentTheme() )
82cdf0e10cSrcweir         if( const TextFont* pFont = pTheme->resolveFont( maTypeface ) )
83cdf0e10cSrcweir             return pFont->implGetFontData( rFontName, rnFontPitch, rnFontFamily );
84cdf0e10cSrcweir     return implGetFontData( rFontName, rnFontPitch, rnFontFamily );
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
implGetFontData(OUString & rFontName,sal_Int16 rnFontPitch,sal_Int16 & rnFontFamily) const87cdf0e10cSrcweir bool TextFont::implGetFontData( OUString& rFontName, sal_Int16 rnFontPitch, sal_Int16& rnFontFamily ) const
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     rFontName = maTypeface;
90cdf0e10cSrcweir     rnFontPitch = lclGetFontPitch( extractValue< sal_Int16 >( mnPitch, 0, 4 ) );
91cdf0e10cSrcweir     rnFontFamily = lclGetFontFamily( extractValue< sal_Int16 >( mnPitch, 4, 4 ) );
92cdf0e10cSrcweir     return rFontName.getLength() > 0;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir // ============================================================================
96cdf0e10cSrcweir 
97cdf0e10cSrcweir } // namespace drawingml
98cdf0e10cSrcweir } // namespace oox
99cdf0e10cSrcweir 
100