Update ooo320-m1
[ooovba.git] / oox / source / drawingml / textfont.cxx
blob6c66d757339269783efb1943ec37f01f30597716
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: textfont.cxx,v $
10 * $Revision: 1.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/drawingml/textfont.hxx"
32 #include <com/sun/star/awt/FontFamily.hpp>
33 #include <com/sun/star/awt/FontPitch.hpp>
34 #include "oox/drawingml/theme.hxx"
35 #include "oox/core/xmlfilterbase.hxx"
36 #include "oox/helper/attributelist.hxx"
37 #include "tokens.hxx"
39 using ::rtl::OUString;
40 using ::oox::core::XmlFilterBase;
42 namespace oox {
43 namespace drawingml {
45 // ============================================================================
47 namespace {
49 sal_Int16 lclGetFontPitch( sal_Int32 nOoxValue )
51 using namespace ::com::sun::star::awt::FontPitch;
52 static const sal_Int16 spnFontPitch[] = { DONTKNOW, FIXED, VARIABLE };
53 return STATIC_ARRAY_SELECT( spnFontPitch, nOoxValue, DONTKNOW );
56 sal_Int16 lclGetFontFamily( sal_Int32 nOoxValue )
58 using namespace ::com::sun::star::awt::FontFamily;
59 static const sal_Int16 spnFontFamily[] = { DONTKNOW, ROMAN, SWISS, MODERN, SCRIPT, DECORATIVE };
60 return STATIC_ARRAY_SELECT( spnFontFamily, nOoxValue, DONTKNOW );
63 } // namespace
65 // ============================================================================
67 TextFont::TextFont() :
68 mnPitch( 0 ),
69 mnCharset( 0 )
73 void TextFont::setAttributes( const AttributeList& rAttribs )
75 maTypeface = rAttribs.getString( XML_typeface, OUString() );
76 maPanose = rAttribs.getString( XML_panose, OUString() );
77 mnPitch = rAttribs.getInteger( XML_pitchFamily, 0 );
78 mnCharset = rAttribs.getInteger( XML_charset, 1 );
81 void TextFont::assignIfUsed( const TextFont& rTextFont )
83 if( rTextFont.maTypeface.getLength() > 0 )
84 *this = rTextFont;
87 bool TextFont::getFontData( OUString& rFontName, sal_Int16 rnFontPitch, sal_Int16& rnFontFamily, const XmlFilterBase& rFilter ) const
89 if( const Theme* pTheme = rFilter.getCurrentTheme() )
90 if( const TextFont* pFont = pTheme->resolveFont( maTypeface ) )
91 return pFont->implGetFontData( rFontName, rnFontPitch, rnFontFamily );
92 return implGetFontData( rFontName, rnFontPitch, rnFontFamily );
95 bool TextFont::implGetFontData( OUString& rFontName, sal_Int16 rnFontPitch, sal_Int16& rnFontFamily ) const
97 rFontName = maTypeface;
98 rnFontPitch = lclGetFontPitch( extractValue< sal_Int16 >( mnPitch, 0, 4 ) );
99 rnFontFamily = lclGetFontFamily( extractValue< sal_Int16 >( mnPitch, 4, 4 ) );
100 return rFontName.getLength() > 0;
103 // ============================================================================
105 } // namespace drawingml
106 } // namespace oox