xref: /aoo41x/main/oox/source/drawingml/textfont.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/drawingml/textfont.hxx"
29 #include <com/sun/star/awt/FontFamily.hpp>
30 #include <com/sun/star/awt/FontPitch.hpp>
31 #include "oox/drawingml/theme.hxx"
32 #include "oox/core/xmlfilterbase.hxx"
33 #include "oox/helper/attributelist.hxx"
34 
35 using ::rtl::OUString;
36 using ::oox::core::XmlFilterBase;
37 
38 namespace oox {
39 namespace drawingml {
40 
41 // ============================================================================
42 
43 namespace {
44 
45 sal_Int16 lclGetFontPitch( sal_Int32 nOoxValue )
46 {
47     using namespace ::com::sun::star::awt::FontPitch;
48     static const sal_Int16 spnFontPitch[] = { DONTKNOW, FIXED, VARIABLE };
49     return STATIC_ARRAY_SELECT( spnFontPitch, nOoxValue, DONTKNOW );
50 }
51 
52 sal_Int16 lclGetFontFamily( sal_Int32 nOoxValue )
53 {
54     using namespace ::com::sun::star::awt::FontFamily;
55     static const sal_Int16 spnFontFamily[] = { DONTKNOW, ROMAN, SWISS, MODERN, SCRIPT, DECORATIVE };
56     return STATIC_ARRAY_SELECT( spnFontFamily, nOoxValue, DONTKNOW );
57 }
58 
59 } // namespace
60 
61 // ============================================================================
62 
63 TextFont::TextFont() :
64     mnPitch( 0 ),
65     mnCharset( WINDOWS_CHARSET_ANSI )
66 {
67 }
68 
69 void TextFont::setAttributes( const AttributeList& rAttribs )
70 {
71     maTypeface = rAttribs.getString( XML_typeface, OUString() );
72     maPanose   = rAttribs.getString( XML_panose, OUString() );
73     mnPitch    = rAttribs.getInteger( XML_pitchFamily, 0 );
74     mnCharset  = rAttribs.getInteger( XML_charset, WINDOWS_CHARSET_DEFAULT );
75 }
76 
77 void TextFont::assignIfUsed( const TextFont& rTextFont )
78 {
79     if( rTextFont.maTypeface.getLength() > 0 )
80         *this = rTextFont;
81 }
82 
83 bool TextFont::getFontData( OUString& rFontName, sal_Int16 rnFontPitch, sal_Int16& rnFontFamily, const XmlFilterBase& rFilter ) const
84 {
85     if( const Theme* pTheme = rFilter.getCurrentTheme() )
86         if( const TextFont* pFont = pTheme->resolveFont( maTypeface ) )
87             return pFont->implGetFontData( rFontName, rnFontPitch, rnFontFamily );
88     return implGetFontData( rFontName, rnFontPitch, rnFontFamily );
89 }
90 
91 bool TextFont::implGetFontData( OUString& rFontName, sal_Int16 rnFontPitch, sal_Int16& rnFontFamily ) const
92 {
93     rFontName = maTypeface;
94     rnFontPitch = lclGetFontPitch( extractValue< sal_Int16 >( mnPitch, 0, 4 ) );
95     rnFontFamily = lclGetFontFamily( extractValue< sal_Int16 >( mnPitch, 4, 4 ) );
96     return rFontName.getLength() > 0;
97 }
98 
99 // ============================================================================
100 
101 } // namespace drawingml
102 } // namespace oox
103 
104