1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_vcl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <tools/debug.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "vcl/svapp.hxx" 34*cdf0e10cSrcweir #include "vcl/font.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include "svdata.hxx" 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/beans/XMaterialHolder.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/awt/FontFamily.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/awt/FontPitch.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/awt/FontWeight.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/awt/FontSlant.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using ::rtl::OUString; 51*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 52*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 53*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 54*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir // ----------------------------------------------------------------------- 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir namespace vcl 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir class FontIdentificator : public ::cppu::WeakAggImplHelper3< XMaterialHolder, XInitialization, XServiceInfo > 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir Font m_aFont; 64*cdf0e10cSrcweir public: 65*cdf0e10cSrcweir FontIdentificator() {} 66*cdf0e10cSrcweir virtual ~FontIdentificator(); 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir // XServiceInfo 70*cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException); 71*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL supportsService( const OUString& ) throw (RuntimeException); 72*cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // XInitialization 75*cdf0e10cSrcweir virtual void SAL_CALL initialize( const Sequence< Any >& ) throw (Exception, RuntimeException); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir // XMaterialHolder 78*cdf0e10cSrcweir virtual Any SAL_CALL getMaterial() throw(RuntimeException); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir }; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // -------------------------------------------------------------------- 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir FontIdentificator::~FontIdentificator() 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir void SAL_CALL FontIdentificator::initialize( const Sequence<Any>& i_rArgs ) throw(Exception,RuntimeException) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir if( !ImplGetSVData() ) 91*cdf0e10cSrcweir return; // VCL not initialized 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir sal_uInt32 nArgs = i_rArgs.getLength(); 94*cdf0e10cSrcweir const Any* pArgs = i_rArgs.getConstArray(); 95*cdf0e10cSrcweir Sequence< sal_Int8 > aFontBuf; 96*cdf0e10cSrcweir for( sal_uInt32 i = 0; i < nArgs; i++ ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir if( pArgs[i] >>= aFontBuf ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir m_aFont = Font::identifyFont( aFontBuf.getConstArray(), aFontBuf.getLength() ); 101*cdf0e10cSrcweir break; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir Any SAL_CALL FontIdentificator::getMaterial() throw(RuntimeException) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir if( !ImplGetSVData() ) 109*cdf0e10cSrcweir return Any(); // VCL not initialized 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir FontDescriptor aFD; 112*cdf0e10cSrcweir aFD.Name = m_aFont.GetName(); 113*cdf0e10cSrcweir aFD.Height = 0; 114*cdf0e10cSrcweir aFD.Width = 0; 115*cdf0e10cSrcweir aFD.StyleName = m_aFont.GetStyleName(); 116*cdf0e10cSrcweir aFD.CharSet = 0; 117*cdf0e10cSrcweir aFD.CharacterWidth = 0; 118*cdf0e10cSrcweir aFD.Underline = 0; 119*cdf0e10cSrcweir aFD.Strikeout = 0; 120*cdf0e10cSrcweir aFD.Orientation = 0; 121*cdf0e10cSrcweir aFD.Kerning = sal_False; 122*cdf0e10cSrcweir aFD.WordLineMode = sal_False; 123*cdf0e10cSrcweir aFD.Type = 0; 124*cdf0e10cSrcweir switch( m_aFont.GetFamily() ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir case FAMILY_DECORATIVE: aFD.Family = com::sun::star::awt::FontFamily::DECORATIVE;break; 127*cdf0e10cSrcweir case FAMILY_MODERN: aFD.Family = com::sun::star::awt::FontFamily::MODERN;break; 128*cdf0e10cSrcweir case FAMILY_ROMAN: aFD.Family = com::sun::star::awt::FontFamily::ROMAN;break; 129*cdf0e10cSrcweir case FAMILY_SCRIPT: aFD.Family = com::sun::star::awt::FontFamily::SCRIPT;break; 130*cdf0e10cSrcweir case FAMILY_SWISS: aFD.Family = com::sun::star::awt::FontFamily::SWISS;break; 131*cdf0e10cSrcweir case FAMILY_SYSTEM: aFD.Family = com::sun::star::awt::FontFamily::SYSTEM;break; 132*cdf0e10cSrcweir default: 133*cdf0e10cSrcweir aFD.Family = com::sun::star::awt::FontFamily::DONTKNOW; 134*cdf0e10cSrcweir break; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir switch( m_aFont.GetPitch() ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir case PITCH_VARIABLE: aFD.Pitch = com::sun::star::awt::FontPitch::VARIABLE;break; 139*cdf0e10cSrcweir case PITCH_FIXED: aFD.Pitch = com::sun::star::awt::FontPitch::FIXED;break; 140*cdf0e10cSrcweir default: 141*cdf0e10cSrcweir aFD.Pitch = com::sun::star::awt::FontPitch::DONTKNOW; 142*cdf0e10cSrcweir break; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir switch( m_aFont.GetWeight() ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir case WEIGHT_THIN: aFD.Weight = com::sun::star::awt::FontWeight::THIN;break; 147*cdf0e10cSrcweir case WEIGHT_ULTRALIGHT: aFD.Weight = com::sun::star::awt::FontWeight::ULTRALIGHT;break; 148*cdf0e10cSrcweir case WEIGHT_LIGHT: aFD.Weight = com::sun::star::awt::FontWeight::LIGHT;break; 149*cdf0e10cSrcweir case WEIGHT_SEMILIGHT: aFD.Weight = com::sun::star::awt::FontWeight::SEMILIGHT;break; 150*cdf0e10cSrcweir case WEIGHT_MEDIUM: 151*cdf0e10cSrcweir case WEIGHT_NORMAL: aFD.Weight = com::sun::star::awt::FontWeight::NORMAL;break; 152*cdf0e10cSrcweir case WEIGHT_SEMIBOLD: aFD.Weight = com::sun::star::awt::FontWeight::SEMIBOLD;break; 153*cdf0e10cSrcweir case WEIGHT_BOLD: aFD.Weight = com::sun::star::awt::FontWeight::BOLD;break; 154*cdf0e10cSrcweir case WEIGHT_ULTRABOLD: aFD.Weight = com::sun::star::awt::FontWeight::ULTRABOLD;break; 155*cdf0e10cSrcweir case WEIGHT_BLACK: aFD.Weight = com::sun::star::awt::FontWeight::BLACK;break; 156*cdf0e10cSrcweir default: 157*cdf0e10cSrcweir aFD.Weight = com::sun::star::awt::FontWeight::DONTKNOW; 158*cdf0e10cSrcweir break; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir switch( m_aFont.GetItalic() ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir case ITALIC_OBLIQUE: aFD.Slant = com::sun::star::awt::FontSlant_OBLIQUE;break; 163*cdf0e10cSrcweir case ITALIC_NORMAL: aFD.Slant = com::sun::star::awt::FontSlant_ITALIC;break; 164*cdf0e10cSrcweir default: 165*cdf0e10cSrcweir aFD.Slant = com::sun::star::awt::FontSlant_DONTKNOW; 166*cdf0e10cSrcweir break; 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir return makeAny( aFD ); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir Sequence< OUString > FontIdentificator_getSupportedServiceNames() 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir static OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.FontIdentificator" ) ); 174*cdf0e10cSrcweir static Sequence< OUString > aServiceNames( &aServiceName, 1 ); 175*cdf0e10cSrcweir return aServiceNames; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir OUString FontIdentificator_getImplementationName() 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM( "vcl::FontIdentificator" ) ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir Reference< XInterface > SAL_CALL FontIdentificator_createInstance( const Reference< XMultiServiceFactory >& ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir return static_cast< ::cppu::OWeakObject * >( new FontIdentificator ); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // XServiceInfo 190*cdf0e10cSrcweir OUString SAL_CALL FontIdentificator::getImplementationName() throw (RuntimeException) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir return FontIdentificator_getImplementationName(); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir sal_Bool SAL_CALL FontIdentificator::supportsService( const OUString& i_rServiceName ) throw (RuntimeException) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir Sequence< OUString > aSN( FontIdentificator_getSupportedServiceNames() ); 198*cdf0e10cSrcweir for( sal_Int32 nService = 0; nService < aSN.getLength(); nService++ ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir if( aSN[nService] == i_rServiceName ) 201*cdf0e10cSrcweir return sal_True; 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir return sal_False; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir Sequence< OUString > SAL_CALL FontIdentificator::getSupportedServiceNames() throw (RuntimeException) 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir return FontIdentificator_getSupportedServiceNames(); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir } // namespace vcl 212