1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "vcl/svapp.hxx"
22 #include "vcl/font.hxx"
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/beans/XMaterialHolder.hpp>
28 #include <com/sun/star/awt/FontDescriptor.hpp>
29 #include <com/sun/star/awt/FontFamily.hpp>
30 #include <com/sun/star/awt/FontPitch.hpp>
31 #include <com/sun/star/awt/FontWeight.hpp>
32 #include <com/sun/star/awt/FontSlant.hpp>
33 #include <com/sun/star/lang/XInitialization.hpp>
34 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <cppuhelper/implbase3.hxx>
37 #include <cppuhelper/supportsservice.hxx>
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star::beans
;
42 using namespace ::com::sun::star::awt
;
44 // -----------------------------------------------------------------------
49 class FontIdentificator
: public ::cppu::WeakAggImplHelper3
< XMaterialHolder
, XInitialization
, XServiceInfo
>
53 FontIdentificator() {}
54 virtual ~FontIdentificator();
58 virtual OUString SAL_CALL
getImplementationName( ) throw (RuntimeException
);
59 virtual ::sal_Bool SAL_CALL
supportsService( const OUString
& ) throw (RuntimeException
);
60 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (RuntimeException
);
63 virtual void SAL_CALL
initialize( const Sequence
< Any
>& ) throw (Exception
, RuntimeException
);
66 virtual Any SAL_CALL
getMaterial() throw(RuntimeException
);
70 // --------------------------------------------------------------------
72 FontIdentificator::~FontIdentificator()
76 void SAL_CALL
FontIdentificator::initialize( const Sequence
<Any
>& i_rArgs
) throw(Exception
,RuntimeException
)
78 if( !ImplGetSVData() )
79 return; // VCL not initialized
81 sal_uInt32 nArgs
= i_rArgs
.getLength();
82 const Any
* pArgs
= i_rArgs
.getConstArray();
83 Sequence
< sal_Int8
> aFontBuf
;
84 for( sal_uInt32 i
= 0; i
< nArgs
; i
++ )
86 if( pArgs
[i
] >>= aFontBuf
)
88 m_aFont
= Font::identifyFont( aFontBuf
.getConstArray(), aFontBuf
.getLength() );
94 Any SAL_CALL
FontIdentificator::getMaterial() throw(RuntimeException
)
96 if( !ImplGetSVData() )
97 return Any(); // VCL not initialized
100 aFD
.Name
= m_aFont
.GetName();
103 aFD
.StyleName
= m_aFont
.GetStyleName();
105 aFD
.CharacterWidth
= 0;
109 aFD
.Kerning
= sal_False
;
110 aFD
.WordLineMode
= sal_False
;
112 switch( m_aFont
.GetFamily() )
114 case FAMILY_DECORATIVE
: aFD
.Family
= com::sun::star::awt::FontFamily::DECORATIVE
;break;
115 case FAMILY_MODERN
: aFD
.Family
= com::sun::star::awt::FontFamily::MODERN
;break;
116 case FAMILY_ROMAN
: aFD
.Family
= com::sun::star::awt::FontFamily::ROMAN
;break;
117 case FAMILY_SCRIPT
: aFD
.Family
= com::sun::star::awt::FontFamily::SCRIPT
;break;
118 case FAMILY_SWISS
: aFD
.Family
= com::sun::star::awt::FontFamily::SWISS
;break;
119 case FAMILY_SYSTEM
: aFD
.Family
= com::sun::star::awt::FontFamily::SYSTEM
;break;
121 aFD
.Family
= com::sun::star::awt::FontFamily::DONTKNOW
;
124 switch( m_aFont
.GetPitch() )
126 case PITCH_VARIABLE
: aFD
.Pitch
= com::sun::star::awt::FontPitch::VARIABLE
;break;
127 case PITCH_FIXED
: aFD
.Pitch
= com::sun::star::awt::FontPitch::FIXED
;break;
129 aFD
.Pitch
= com::sun::star::awt::FontPitch::DONTKNOW
;
132 switch( m_aFont
.GetWeight() )
134 case WEIGHT_THIN
: aFD
.Weight
= com::sun::star::awt::FontWeight::THIN
;break;
135 case WEIGHT_ULTRALIGHT
: aFD
.Weight
= com::sun::star::awt::FontWeight::ULTRALIGHT
;break;
136 case WEIGHT_LIGHT
: aFD
.Weight
= com::sun::star::awt::FontWeight::LIGHT
;break;
137 case WEIGHT_SEMILIGHT
: aFD
.Weight
= com::sun::star::awt::FontWeight::SEMILIGHT
;break;
139 case WEIGHT_NORMAL
: aFD
.Weight
= com::sun::star::awt::FontWeight::NORMAL
;break;
140 case WEIGHT_SEMIBOLD
: aFD
.Weight
= com::sun::star::awt::FontWeight::SEMIBOLD
;break;
141 case WEIGHT_BOLD
: aFD
.Weight
= com::sun::star::awt::FontWeight::BOLD
;break;
142 case WEIGHT_ULTRABOLD
: aFD
.Weight
= com::sun::star::awt::FontWeight::ULTRABOLD
;break;
143 case WEIGHT_BLACK
: aFD
.Weight
= com::sun::star::awt::FontWeight::BLACK
;break;
145 aFD
.Weight
= com::sun::star::awt::FontWeight::DONTKNOW
;
148 switch( m_aFont
.GetItalic() )
150 case ITALIC_OBLIQUE
: aFD
.Slant
= com::sun::star::awt::FontSlant_OBLIQUE
;break;
151 case ITALIC_NORMAL
: aFD
.Slant
= com::sun::star::awt::FontSlant_ITALIC
;break;
153 aFD
.Slant
= com::sun::star::awt::FontSlant_DONTKNOW
;
156 return makeAny( aFD
);
159 Sequence
< OUString
> FontIdentificator_getSupportedServiceNames()
161 static OUString
aServiceName( "com.sun.star.awt.FontIdentificator" );
162 static Sequence
< OUString
> aServiceNames( &aServiceName
, 1 );
163 return aServiceNames
;
166 OUString
FontIdentificator_getImplementationName()
168 return OUString( "vcl::FontIdentificator" );
171 Reference
< XInterface
> SAL_CALL
FontIdentificator_createInstance( const Reference
< XMultiServiceFactory
>& )
173 return static_cast< ::cppu::OWeakObject
* >( new FontIdentificator
);
177 OUString SAL_CALL
FontIdentificator::getImplementationName() throw (RuntimeException
)
179 return FontIdentificator_getImplementationName();
182 sal_Bool SAL_CALL
FontIdentificator::supportsService( const OUString
& i_rServiceName
) throw (RuntimeException
)
184 return cppu::supportsService(this, i_rServiceName
);
187 Sequence
< OUString
> SAL_CALL
FontIdentificator::getSupportedServiceNames() throw (RuntimeException
)
189 return FontIdentificator_getSupportedServiceNames();
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */