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: fontident.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_vcl.hxx"
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/beans/XMaterialHolder.hpp>
37 #include <com/sun/star/awt/FontDescriptor.hpp>
38 #include <com/sun/star/awt/FontFamily.hpp>
39 #include <com/sun/star/awt/FontPitch.hpp>
40 #include <com/sun/star/awt/FontWeight.hpp>
41 #include <com/sun/star/awt/FontSlant.hpp>
42 #include <com/sun/star/lang/XInitialization.hpp>
43 #include <com/sun/star/lang/DisposedException.hpp>
45 #include "vcl/svapp.hxx"
46 #include "vcl/svdata.hxx"
47 #include "vcl/font.hxx"
49 #include <cppuhelper/implbase3.hxx>
51 #include <tools/debug.hxx>
54 using ::rtl::OUString
;
55 using namespace ::com::sun::star::uno
;
56 using namespace ::com::sun::star::lang
;
57 using namespace ::com::sun::star::beans
;
58 using namespace ::com::sun::star::awt
;
60 // -----------------------------------------------------------------------
65 class FontIdentificator
: public ::cppu::WeakAggImplHelper3
< XMaterialHolder
, XInitialization
, XServiceInfo
>
69 FontIdentificator() {}
70 virtual ~FontIdentificator();
74 virtual OUString SAL_CALL
getImplementationName( ) throw (RuntimeException
);
75 virtual ::sal_Bool SAL_CALL
supportsService( const OUString
& ) throw (RuntimeException
);
76 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (RuntimeException
);
79 virtual void SAL_CALL
initialize( const Sequence
< Any
>& ) throw (Exception
, RuntimeException
);
82 virtual Any SAL_CALL
getMaterial() throw(RuntimeException
);
86 // --------------------------------------------------------------------
88 FontIdentificator::~FontIdentificator()
92 void SAL_CALL
FontIdentificator::initialize( const Sequence
<Any
>& i_rArgs
) throw(Exception
,RuntimeException
)
94 if( !ImplGetSVData() )
95 return; // VCL not initialized
97 sal_uInt32 nArgs
= i_rArgs
.getLength();
98 const Any
* pArgs
= i_rArgs
.getConstArray();
99 Sequence
< sal_Int8
> aFontBuf
;
100 for( sal_uInt32 i
= 0; i
< nArgs
; i
++ )
102 if( pArgs
[i
] >>= aFontBuf
)
104 m_aFont
= Font::identifyFont( aFontBuf
.getConstArray(), aFontBuf
.getLength() );
110 Any SAL_CALL
FontIdentificator::getMaterial() throw(RuntimeException
)
112 if( !ImplGetSVData() )
113 return Any(); // VCL not initialized
116 aFD
.Name
= m_aFont
.GetName();
119 aFD
.StyleName
= m_aFont
.GetStyleName();
121 aFD
.CharacterWidth
= 0;
125 aFD
.Kerning
= sal_False
;
126 aFD
.WordLineMode
= sal_False
;
128 switch( m_aFont
.GetFamily() )
130 case FAMILY_DECORATIVE
: aFD
.Family
= com::sun::star::awt::FontFamily::DECORATIVE
;break;
131 case FAMILY_MODERN
: aFD
.Family
= com::sun::star::awt::FontFamily::MODERN
;break;
132 case FAMILY_ROMAN
: aFD
.Family
= com::sun::star::awt::FontFamily::ROMAN
;break;
133 case FAMILY_SCRIPT
: aFD
.Family
= com::sun::star::awt::FontFamily::SCRIPT
;break;
134 case FAMILY_SWISS
: aFD
.Family
= com::sun::star::awt::FontFamily::SWISS
;break;
135 case FAMILY_SYSTEM
: aFD
.Family
= com::sun::star::awt::FontFamily::SYSTEM
;break;
137 aFD
.Family
= com::sun::star::awt::FontFamily::DONTKNOW
;
140 switch( m_aFont
.GetPitch() )
142 case PITCH_VARIABLE
: aFD
.Pitch
= com::sun::star::awt::FontPitch::VARIABLE
;break;
143 case PITCH_FIXED
: aFD
.Pitch
= com::sun::star::awt::FontPitch::FIXED
;break;
145 aFD
.Pitch
= com::sun::star::awt::FontPitch::DONTKNOW
;
148 switch( m_aFont
.GetWeight() )
150 case WEIGHT_THIN
: aFD
.Weight
= com::sun::star::awt::FontWeight::THIN
;break;
151 case WEIGHT_ULTRALIGHT
: aFD
.Weight
= com::sun::star::awt::FontWeight::ULTRALIGHT
;break;
152 case WEIGHT_LIGHT
: aFD
.Weight
= com::sun::star::awt::FontWeight::LIGHT
;break;
153 case WEIGHT_SEMILIGHT
: aFD
.Weight
= com::sun::star::awt::FontWeight::SEMILIGHT
;break;
155 case WEIGHT_NORMAL
: aFD
.Weight
= com::sun::star::awt::FontWeight::NORMAL
;break;
156 case WEIGHT_SEMIBOLD
: aFD
.Weight
= com::sun::star::awt::FontWeight::SEMIBOLD
;break;
157 case WEIGHT_BOLD
: aFD
.Weight
= com::sun::star::awt::FontWeight::BOLD
;break;
158 case WEIGHT_ULTRABOLD
: aFD
.Weight
= com::sun::star::awt::FontWeight::ULTRABOLD
;break;
159 case WEIGHT_BLACK
: aFD
.Weight
= com::sun::star::awt::FontWeight::BLACK
;break;
161 aFD
.Weight
= com::sun::star::awt::FontWeight::DONTKNOW
;
164 switch( m_aFont
.GetItalic() )
166 case ITALIC_OBLIQUE
: aFD
.Slant
= com::sun::star::awt::FontSlant_OBLIQUE
;break;
167 case ITALIC_NORMAL
: aFD
.Slant
= com::sun::star::awt::FontSlant_ITALIC
;break;
169 aFD
.Slant
= com::sun::star::awt::FontSlant_DONTKNOW
;
172 return makeAny( aFD
);
175 Sequence
< OUString
> FontIdentificator_getSupportedServiceNames()
177 static OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.FontIdentificator" ) );
178 static Sequence
< OUString
> aServiceNames( &aServiceName
, 1 );
179 return aServiceNames
;
182 OUString
FontIdentificator_getImplementationName()
184 return OUString( RTL_CONSTASCII_USTRINGPARAM( "vcl::FontIdentificator" ) );
187 Reference
< XInterface
> SAL_CALL
FontIdentificator_createInstance( const Reference
< XMultiServiceFactory
>& )
189 return static_cast< ::cppu::OWeakObject
* >( new FontIdentificator
);
194 OUString SAL_CALL
FontIdentificator::getImplementationName() throw (RuntimeException
)
196 return FontIdentificator_getImplementationName();
199 sal_Bool SAL_CALL
FontIdentificator::supportsService( const OUString
& i_rServiceName
) throw (RuntimeException
)
201 Sequence
< OUString
> aSN( FontIdentificator_getSupportedServiceNames() );
202 for( sal_Int32 nService
= 0; nService
< aSN
.getLength(); nService
++ )
204 if( aSN
[nService
] == i_rServiceName
)
210 Sequence
< OUString
> SAL_CALL
FontIdentificator::getSupportedServiceNames() throw (RuntimeException
)
212 return FontIdentificator_getSupportedServiceNames();