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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_vcl.hxx" 30 31 #include <tools/debug.hxx> 32 33 #include "vcl/svapp.hxx" 34 #include "vcl/font.hxx" 35 36 #include "svdata.hxx" 37 38 #include <com/sun/star/lang/XServiceInfo.hpp> 39 #include <com/sun/star/beans/XMaterialHolder.hpp> 40 #include <com/sun/star/awt/FontDescriptor.hpp> 41 #include <com/sun/star/awt/FontFamily.hpp> 42 #include <com/sun/star/awt/FontPitch.hpp> 43 #include <com/sun/star/awt/FontWeight.hpp> 44 #include <com/sun/star/awt/FontSlant.hpp> 45 #include <com/sun/star/lang/XInitialization.hpp> 46 #include <com/sun/star/lang/DisposedException.hpp> 47 48 #include <cppuhelper/implbase3.hxx> 49 50 using ::rtl::OUString; 51 using namespace ::com::sun::star::uno; 52 using namespace ::com::sun::star::lang; 53 using namespace ::com::sun::star::beans; 54 using namespace ::com::sun::star::awt; 55 56 // ----------------------------------------------------------------------- 57 58 namespace vcl 59 { 60 61 class FontIdentificator : public ::cppu::WeakAggImplHelper3< XMaterialHolder, XInitialization, XServiceInfo > 62 { 63 Font m_aFont; 64 public: 65 FontIdentificator() {} 66 virtual ~FontIdentificator(); 67 68 69 // XServiceInfo 70 virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException); 71 virtual ::sal_Bool SAL_CALL supportsService( const OUString& ) throw (RuntimeException); 72 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); 73 74 // XInitialization 75 virtual void SAL_CALL initialize( const Sequence< Any >& ) throw (Exception, RuntimeException); 76 77 // XMaterialHolder 78 virtual Any SAL_CALL getMaterial() throw(RuntimeException); 79 80 }; 81 82 // -------------------------------------------------------------------- 83 84 FontIdentificator::~FontIdentificator() 85 { 86 } 87 88 void SAL_CALL FontIdentificator::initialize( const Sequence<Any>& i_rArgs ) throw(Exception,RuntimeException) 89 { 90 if( !ImplGetSVData() ) 91 return; // VCL not initialized 92 93 sal_uInt32 nArgs = i_rArgs.getLength(); 94 const Any* pArgs = i_rArgs.getConstArray(); 95 Sequence< sal_Int8 > aFontBuf; 96 for( sal_uInt32 i = 0; i < nArgs; i++ ) 97 { 98 if( pArgs[i] >>= aFontBuf ) 99 { 100 m_aFont = Font::identifyFont( aFontBuf.getConstArray(), aFontBuf.getLength() ); 101 break; 102 } 103 } 104 } 105 106 Any SAL_CALL FontIdentificator::getMaterial() throw(RuntimeException) 107 { 108 if( !ImplGetSVData() ) 109 return Any(); // VCL not initialized 110 111 FontDescriptor aFD; 112 aFD.Name = m_aFont.GetName(); 113 aFD.Height = 0; 114 aFD.Width = 0; 115 aFD.StyleName = m_aFont.GetStyleName(); 116 aFD.CharSet = 0; 117 aFD.CharacterWidth = 0; 118 aFD.Underline = 0; 119 aFD.Strikeout = 0; 120 aFD.Orientation = 0; 121 aFD.Kerning = sal_False; 122 aFD.WordLineMode = sal_False; 123 aFD.Type = 0; 124 switch( m_aFont.GetFamily() ) 125 { 126 case FAMILY_DECORATIVE: aFD.Family = com::sun::star::awt::FontFamily::DECORATIVE;break; 127 case FAMILY_MODERN: aFD.Family = com::sun::star::awt::FontFamily::MODERN;break; 128 case FAMILY_ROMAN: aFD.Family = com::sun::star::awt::FontFamily::ROMAN;break; 129 case FAMILY_SCRIPT: aFD.Family = com::sun::star::awt::FontFamily::SCRIPT;break; 130 case FAMILY_SWISS: aFD.Family = com::sun::star::awt::FontFamily::SWISS;break; 131 case FAMILY_SYSTEM: aFD.Family = com::sun::star::awt::FontFamily::SYSTEM;break; 132 default: 133 aFD.Family = com::sun::star::awt::FontFamily::DONTKNOW; 134 break; 135 } 136 switch( m_aFont.GetPitch() ) 137 { 138 case PITCH_VARIABLE: aFD.Pitch = com::sun::star::awt::FontPitch::VARIABLE;break; 139 case PITCH_FIXED: aFD.Pitch = com::sun::star::awt::FontPitch::FIXED;break; 140 default: 141 aFD.Pitch = com::sun::star::awt::FontPitch::DONTKNOW; 142 break; 143 } 144 switch( m_aFont.GetWeight() ) 145 { 146 case WEIGHT_THIN: aFD.Weight = com::sun::star::awt::FontWeight::THIN;break; 147 case WEIGHT_ULTRALIGHT: aFD.Weight = com::sun::star::awt::FontWeight::ULTRALIGHT;break; 148 case WEIGHT_LIGHT: aFD.Weight = com::sun::star::awt::FontWeight::LIGHT;break; 149 case WEIGHT_SEMILIGHT: aFD.Weight = com::sun::star::awt::FontWeight::SEMILIGHT;break; 150 case WEIGHT_MEDIUM: 151 case WEIGHT_NORMAL: aFD.Weight = com::sun::star::awt::FontWeight::NORMAL;break; 152 case WEIGHT_SEMIBOLD: aFD.Weight = com::sun::star::awt::FontWeight::SEMIBOLD;break; 153 case WEIGHT_BOLD: aFD.Weight = com::sun::star::awt::FontWeight::BOLD;break; 154 case WEIGHT_ULTRABOLD: aFD.Weight = com::sun::star::awt::FontWeight::ULTRABOLD;break; 155 case WEIGHT_BLACK: aFD.Weight = com::sun::star::awt::FontWeight::BLACK;break; 156 default: 157 aFD.Weight = com::sun::star::awt::FontWeight::DONTKNOW; 158 break; 159 } 160 switch( m_aFont.GetItalic() ) 161 { 162 case ITALIC_OBLIQUE: aFD.Slant = com::sun::star::awt::FontSlant_OBLIQUE;break; 163 case ITALIC_NORMAL: aFD.Slant = com::sun::star::awt::FontSlant_ITALIC;break; 164 default: 165 aFD.Slant = com::sun::star::awt::FontSlant_DONTKNOW; 166 break; 167 } 168 return makeAny( aFD ); 169 } 170 171 Sequence< OUString > FontIdentificator_getSupportedServiceNames() 172 { 173 static OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.FontIdentificator" ) ); 174 static Sequence< OUString > aServiceNames( &aServiceName, 1 ); 175 return aServiceNames; 176 } 177 178 OUString FontIdentificator_getImplementationName() 179 { 180 return OUString( RTL_CONSTASCII_USTRINGPARAM( "vcl::FontIdentificator" ) ); 181 } 182 183 Reference< XInterface > SAL_CALL FontIdentificator_createInstance( const Reference< XMultiServiceFactory >& ) 184 { 185 return static_cast< ::cppu::OWeakObject * >( new FontIdentificator ); 186 } 187 188 189 // XServiceInfo 190 OUString SAL_CALL FontIdentificator::getImplementationName() throw (RuntimeException) 191 { 192 return FontIdentificator_getImplementationName(); 193 } 194 195 sal_Bool SAL_CALL FontIdentificator::supportsService( const OUString& i_rServiceName ) throw (RuntimeException) 196 { 197 Sequence< OUString > aSN( FontIdentificator_getSupportedServiceNames() ); 198 for( sal_Int32 nService = 0; nService < aSN.getLength(); nService++ ) 199 { 200 if( aSN[nService] == i_rServiceName ) 201 return sal_True; 202 } 203 return sal_False; 204 } 205 206 Sequence< OUString > SAL_CALL FontIdentificator::getSupportedServiceNames() throw (RuntimeException) 207 { 208 return FontIdentificator_getSupportedServiceNames(); 209 } 210 211 } // namespace vcl 212