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 .
20 #include <vcl/svapp.hxx>
21 #include <vcl/font.hxx>
23 #include <factory.hxx>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/beans/XMaterialHolder.hpp>
29 #include <com/sun/star/awt/FontDescriptor.hpp>
30 #include <com/sun/star/awt/FontFamily.hpp>
31 #include <com/sun/star/awt/FontPitch.hpp>
32 #include <com/sun/star/awt/FontWeight.hpp>
33 #include <com/sun/star/awt/FontSlant.hpp>
34 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <cppuhelper/implbase.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
;
49 class FontIdentificator
: public ::cppu::WeakImplHelper
< XMaterialHolder
, XInitialization
, XServiceInfo
>
53 FontIdentificator() {}
56 virtual OUString SAL_CALL
getImplementationName( ) override
;
57 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ) override
;
58 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
61 virtual void SAL_CALL
initialize( const Sequence
< Any
>& ) override
;
64 virtual Any SAL_CALL
getMaterial() override
;
70 void SAL_CALL
FontIdentificator::initialize( const Sequence
<Any
>& i_rArgs
)
72 if( !ImplGetSVData() )
73 return; // VCL not initialized
75 Sequence
< sal_Int8
> aFontBuf
;
76 for( const auto& rArg
: i_rArgs
)
78 if( rArg
>>= aFontBuf
)
80 m_aFont
= Font::identifyFont( aFontBuf
.getConstArray(), aFontBuf
.getLength() );
86 Any SAL_CALL
FontIdentificator::getMaterial()
88 if( !ImplGetSVData() )
89 return Any(); // VCL not initialized
92 aFD
.Name
= m_aFont
.GetFamilyName();
95 aFD
.StyleName
= m_aFont
.GetStyleName();
97 aFD
.CharacterWidth
= 0;
102 aFD
.WordLineMode
= false;
104 switch( m_aFont
.GetFamilyType() )
106 case FAMILY_DECORATIVE
: aFD
.Family
= css::awt::FontFamily::DECORATIVE
;break;
107 case FAMILY_MODERN
: aFD
.Family
= css::awt::FontFamily::MODERN
;break;
108 case FAMILY_ROMAN
: aFD
.Family
= css::awt::FontFamily::ROMAN
;break;
109 case FAMILY_SCRIPT
: aFD
.Family
= css::awt::FontFamily::SCRIPT
;break;
110 case FAMILY_SWISS
: aFD
.Family
= css::awt::FontFamily::SWISS
;break;
111 case FAMILY_SYSTEM
: aFD
.Family
= css::awt::FontFamily::SYSTEM
;break;
113 aFD
.Family
= css::awt::FontFamily::DONTKNOW
;
116 switch( m_aFont
.GetPitch() )
118 case PITCH_VARIABLE
: aFD
.Pitch
= css::awt::FontPitch::VARIABLE
;break;
119 case PITCH_FIXED
: aFD
.Pitch
= css::awt::FontPitch::FIXED
;break;
121 aFD
.Pitch
= css::awt::FontPitch::DONTKNOW
;
124 switch( m_aFont
.GetWeight() )
126 case WEIGHT_THIN
: aFD
.Weight
= css::awt::FontWeight::THIN
;break;
127 case WEIGHT_ULTRALIGHT
: aFD
.Weight
= css::awt::FontWeight::ULTRALIGHT
;break;
128 case WEIGHT_LIGHT
: aFD
.Weight
= css::awt::FontWeight::LIGHT
;break;
129 case WEIGHT_SEMILIGHT
: aFD
.Weight
= css::awt::FontWeight::SEMILIGHT
;break;
131 case WEIGHT_NORMAL
: aFD
.Weight
= css::awt::FontWeight::NORMAL
;break;
132 case WEIGHT_SEMIBOLD
: aFD
.Weight
= css::awt::FontWeight::SEMIBOLD
;break;
133 case WEIGHT_BOLD
: aFD
.Weight
= css::awt::FontWeight::BOLD
;break;
134 case WEIGHT_ULTRABOLD
: aFD
.Weight
= css::awt::FontWeight::ULTRABOLD
;break;
135 case WEIGHT_BLACK
: aFD
.Weight
= css::awt::FontWeight::BLACK
;break;
137 aFD
.Weight
= css::awt::FontWeight::DONTKNOW
;
140 switch( m_aFont
.GetItalic() )
142 case ITALIC_OBLIQUE
: aFD
.Slant
= css::awt::FontSlant_OBLIQUE
;break;
143 case ITALIC_NORMAL
: aFD
.Slant
= css::awt::FontSlant_ITALIC
;break;
145 aFD
.Slant
= css::awt::FontSlant_DONTKNOW
;
152 OUString SAL_CALL
FontIdentificator::getImplementationName()
154 return u
"vcl::FontIdentificator"_ustr
;
157 sal_Bool SAL_CALL
FontIdentificator::supportsService( const OUString
& i_rServiceName
)
159 return cppu::supportsService(this, i_rServiceName
);
162 Sequence
< OUString
> SAL_CALL
FontIdentificator::getSupportedServiceNames()
164 return { u
"com.sun.star.awt.FontIdentificator"_ustr
};
169 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
170 vcl_FontIdentificator_get_implementation(
171 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
173 return cppu::acquire(new vcl::FontIdentificator());
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */