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