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