1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_vcl.hxx" 26 27 #include <tools/debug.hxx> 28 29 #include "vcl/svapp.hxx" 30 #include "vcl/font.hxx" 31 32 #include "svdata.hxx" 33 34 #include <com/sun/star/lang/XServiceInfo.hpp> 35 #include <com/sun/star/beans/XMaterialHolder.hpp> 36 #include <com/sun/star/awt/FontDescriptor.hpp> 37 #include <com/sun/star/awt/FontFamily.hpp> 38 #include <com/sun/star/awt/FontPitch.hpp> 39 #include <com/sun/star/awt/FontWeight.hpp> 40 #include <com/sun/star/awt/FontSlant.hpp> 41 #include <com/sun/star/lang/XInitialization.hpp> 42 #include <com/sun/star/lang/DisposedException.hpp> 43 44 #include <cppuhelper/implbase3.hxx> 45 46 using ::rtl::OUString; 47 using namespace ::com::sun::star::uno; 48 using namespace ::com::sun::star::lang; 49 using namespace ::com::sun::star::beans; 50 using namespace ::com::sun::star::awt; 51 52 // ----------------------------------------------------------------------- 53 54 namespace vcl 55 { 56 57 class FontIdentificator : public ::cppu::WeakAggImplHelper3< XMaterialHolder, XInitialization, XServiceInfo > 58 { 59 Font m_aFont; 60 public: 61 FontIdentificator() {} 62 virtual ~FontIdentificator(); 63 64 65 // XServiceInfo 66 virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException); 67 virtual ::sal_Bool SAL_CALL supportsService( const OUString& ) throw (RuntimeException); 68 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); 69 70 // XInitialization 71 virtual void SAL_CALL initialize( const Sequence< Any >& ) throw (Exception, RuntimeException); 72 73 // XMaterialHolder 74 virtual Any SAL_CALL getMaterial() throw(RuntimeException); 75 76 }; 77 78 // -------------------------------------------------------------------- 79 80 FontIdentificator::~FontIdentificator() 81 { 82 } 83 84 void SAL_CALL FontIdentificator::initialize( const Sequence<Any>& i_rArgs ) throw(Exception,RuntimeException) 85 { 86 if( !ImplGetSVData() ) 87 return; // VCL not initialized 88 89 sal_uInt32 nArgs = i_rArgs.getLength(); 90 const Any* pArgs = i_rArgs.getConstArray(); 91 Sequence< sal_Int8 > aFontBuf; 92 for( sal_uInt32 i = 0; i < nArgs; i++ ) 93 { 94 if( pArgs[i] >>= aFontBuf ) 95 { 96 m_aFont = Font::identifyFont( aFontBuf.getConstArray(), aFontBuf.getLength() ); 97 break; 98 } 99 } 100 } 101 102 Any SAL_CALL FontIdentificator::getMaterial() throw(RuntimeException) 103 { 104 if( !ImplGetSVData() ) 105 return Any(); // VCL not initialized 106 107 FontDescriptor aFD; 108 aFD.Name = m_aFont.GetName(); 109 aFD.Height = 0; 110 aFD.Width = 0; 111 aFD.StyleName = m_aFont.GetStyleName(); 112 aFD.CharSet = 0; 113 aFD.CharacterWidth = 0; 114 aFD.Underline = 0; 115 aFD.Strikeout = 0; 116 aFD.Orientation = 0; 117 aFD.Kerning = sal_False; 118 aFD.WordLineMode = sal_False; 119 aFD.Type = 0; 120 switch( m_aFont.GetFamily() ) 121 { 122 case FAMILY_DECORATIVE: aFD.Family = com::sun::star::awt::FontFamily::DECORATIVE;break; 123 case FAMILY_MODERN: aFD.Family = com::sun::star::awt::FontFamily::MODERN;break; 124 case FAMILY_ROMAN: aFD.Family = com::sun::star::awt::FontFamily::ROMAN;break; 125 case FAMILY_SCRIPT: aFD.Family = com::sun::star::awt::FontFamily::SCRIPT;break; 126 case FAMILY_SWISS: aFD.Family = com::sun::star::awt::FontFamily::SWISS;break; 127 case FAMILY_SYSTEM: aFD.Family = com::sun::star::awt::FontFamily::SYSTEM;break; 128 default: 129 aFD.Family = com::sun::star::awt::FontFamily::DONTKNOW; 130 break; 131 } 132 switch( m_aFont.GetPitch() ) 133 { 134 case PITCH_VARIABLE: aFD.Pitch = com::sun::star::awt::FontPitch::VARIABLE;break; 135 case PITCH_FIXED: aFD.Pitch = com::sun::star::awt::FontPitch::FIXED;break; 136 default: 137 aFD.Pitch = com::sun::star::awt::FontPitch::DONTKNOW; 138 break; 139 } 140 switch( m_aFont.GetWeight() ) 141 { 142 case WEIGHT_THIN: aFD.Weight = com::sun::star::awt::FontWeight::THIN;break; 143 case WEIGHT_ULTRALIGHT: aFD.Weight = com::sun::star::awt::FontWeight::ULTRALIGHT;break; 144 case WEIGHT_LIGHT: aFD.Weight = com::sun::star::awt::FontWeight::LIGHT;break; 145 case WEIGHT_SEMILIGHT: aFD.Weight = com::sun::star::awt::FontWeight::SEMILIGHT;break; 146 case WEIGHT_MEDIUM: 147 case WEIGHT_NORMAL: aFD.Weight = com::sun::star::awt::FontWeight::NORMAL;break; 148 case WEIGHT_SEMIBOLD: aFD.Weight = com::sun::star::awt::FontWeight::SEMIBOLD;break; 149 case WEIGHT_BOLD: aFD.Weight = com::sun::star::awt::FontWeight::BOLD;break; 150 case WEIGHT_ULTRABOLD: aFD.Weight = com::sun::star::awt::FontWeight::ULTRABOLD;break; 151 case WEIGHT_BLACK: aFD.Weight = com::sun::star::awt::FontWeight::BLACK;break; 152 default: 153 aFD.Weight = com::sun::star::awt::FontWeight::DONTKNOW; 154 break; 155 } 156 switch( m_aFont.GetItalic() ) 157 { 158 case ITALIC_OBLIQUE: aFD.Slant = com::sun::star::awt::FontSlant_OBLIQUE;break; 159 case ITALIC_NORMAL: aFD.Slant = com::sun::star::awt::FontSlant_ITALIC;break; 160 default: 161 aFD.Slant = com::sun::star::awt::FontSlant_DONTKNOW; 162 break; 163 } 164 return makeAny( aFD ); 165 } 166 167 Sequence< OUString > FontIdentificator_getSupportedServiceNames() 168 { 169 static OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.FontIdentificator" ) ); 170 static Sequence< OUString > aServiceNames( &aServiceName, 1 ); 171 return aServiceNames; 172 } 173 174 OUString FontIdentificator_getImplementationName() 175 { 176 return OUString( RTL_CONSTASCII_USTRINGPARAM( "vcl::FontIdentificator" ) ); 177 } 178 179 Reference< XInterface > SAL_CALL FontIdentificator_createInstance( const Reference< XMultiServiceFactory >& ) 180 { 181 return static_cast< ::cppu::OWeakObject * >( new FontIdentificator ); 182 } 183 184 185 // XServiceInfo 186 OUString SAL_CALL FontIdentificator::getImplementationName() throw (RuntimeException) 187 { 188 return FontIdentificator_getImplementationName(); 189 } 190 191 sal_Bool SAL_CALL FontIdentificator::supportsService( const OUString& i_rServiceName ) throw (RuntimeException) 192 { 193 Sequence< OUString > aSN( FontIdentificator_getSupportedServiceNames() ); 194 for( sal_Int32 nService = 0; nService < aSN.getLength(); nService++ ) 195 { 196 if( aSN[nService] == i_rServiceName ) 197 return sal_True; 198 } 199 return sal_False; 200 } 201 202 Sequence< OUString > SAL_CALL FontIdentificator::getSupportedServiceNames() throw (RuntimeException) 203 { 204 return FontIdentificator_getSupportedServiceNames(); 205 } 206 207 } // namespace vcl 208