build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / components / fontident.cxx
blob9568c4c846cbe3918bcb038cc202f6b9c09b4ec4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
24 #include "svdata.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>
35 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <cppuhelper/implbase3.hxx>
38 #include <cppuhelper/supportsservice.hxx>
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::awt;
45 namespace vcl
48 class FontIdentificator : public ::cppu::WeakAggImplHelper3< XMaterialHolder, XInitialization, XServiceInfo >
50 Font m_aFont;
51 public:
52 FontIdentificator() {}
54 // XServiceInfo
55 virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException, std::exception) override;
56 virtual sal_Bool SAL_CALL supportsService( const OUString& ) throw (RuntimeException, std::exception) override;
57 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException, std::exception) override;
59 // XInitialization
60 virtual void SAL_CALL initialize( const Sequence< Any >& ) throw (Exception, RuntimeException, std::exception) override;
62 // XMaterialHolder
63 virtual Any SAL_CALL getMaterial() throw(RuntimeException, std::exception) override;
67 void SAL_CALL FontIdentificator::initialize( const Sequence<Any>& i_rArgs ) throw(Exception,RuntimeException, std::exception)
69 if( !ImplGetSVData() )
70 return; // VCL not initialized
72 sal_uInt32 nArgs = i_rArgs.getLength();
73 const Any* pArgs = i_rArgs.getConstArray();
74 Sequence< sal_Int8 > aFontBuf;
75 for( sal_uInt32 i = 0; i < nArgs; i++ )
77 if( pArgs[i] >>= aFontBuf )
79 m_aFont = Font::identifyFont( aFontBuf.getConstArray(), aFontBuf.getLength() );
80 break;
85 Any SAL_CALL FontIdentificator::getMaterial() throw(RuntimeException, std::exception)
87 if( !ImplGetSVData() )
88 return Any(); // VCL not initialized
90 FontDescriptor aFD;
91 aFD.Name = m_aFont.GetFamilyName();
92 aFD.Height = 0;
93 aFD.Width = 0;
94 aFD.StyleName = m_aFont.GetStyleName();
95 aFD.CharSet = 0;
96 aFD.CharacterWidth = 0;
97 aFD.Underline = 0;
98 aFD.Strikeout = 0;
99 aFD.Orientation = 0;
100 aFD.Kerning = false;
101 aFD.WordLineMode = false;
102 aFD.Type = 0;
103 switch( m_aFont.GetFamilyType() )
105 case FAMILY_DECORATIVE: aFD.Family = css::awt::FontFamily::DECORATIVE;break;
106 case FAMILY_MODERN: aFD.Family = css::awt::FontFamily::MODERN;break;
107 case FAMILY_ROMAN: aFD.Family = css::awt::FontFamily::ROMAN;break;
108 case FAMILY_SCRIPT: aFD.Family = css::awt::FontFamily::SCRIPT;break;
109 case FAMILY_SWISS: aFD.Family = css::awt::FontFamily::SWISS;break;
110 case FAMILY_SYSTEM: aFD.Family = css::awt::FontFamily::SYSTEM;break;
111 default:
112 aFD.Family = css::awt::FontFamily::DONTKNOW;
113 break;
115 switch( m_aFont.GetPitch() )
117 case PITCH_VARIABLE: aFD.Pitch = css::awt::FontPitch::VARIABLE;break;
118 case PITCH_FIXED: aFD.Pitch = css::awt::FontPitch::FIXED;break;
119 default:
120 aFD.Pitch = css::awt::FontPitch::DONTKNOW;
121 break;
123 switch( m_aFont.GetWeight() )
125 case WEIGHT_THIN: aFD.Weight = css::awt::FontWeight::THIN;break;
126 case WEIGHT_ULTRALIGHT: aFD.Weight = css::awt::FontWeight::ULTRALIGHT;break;
127 case WEIGHT_LIGHT: aFD.Weight = css::awt::FontWeight::LIGHT;break;
128 case WEIGHT_SEMILIGHT: aFD.Weight = css::awt::FontWeight::SEMILIGHT;break;
129 case WEIGHT_MEDIUM:
130 case WEIGHT_NORMAL: aFD.Weight = css::awt::FontWeight::NORMAL;break;
131 case WEIGHT_SEMIBOLD: aFD.Weight = css::awt::FontWeight::SEMIBOLD;break;
132 case WEIGHT_BOLD: aFD.Weight = css::awt::FontWeight::BOLD;break;
133 case WEIGHT_ULTRABOLD: aFD.Weight = css::awt::FontWeight::ULTRABOLD;break;
134 case WEIGHT_BLACK: aFD.Weight = css::awt::FontWeight::BLACK;break;
135 default:
136 aFD.Weight = css::awt::FontWeight::DONTKNOW;
137 break;
139 switch( m_aFont.GetItalic() )
141 case ITALIC_OBLIQUE: aFD.Slant = css::awt::FontSlant_OBLIQUE;break;
142 case ITALIC_NORMAL: aFD.Slant = css::awt::FontSlant_ITALIC;break;
143 default:
144 aFD.Slant = css::awt::FontSlant_DONTKNOW;
145 break;
147 return makeAny( aFD );
150 Sequence< OUString > FontIdentificator_getSupportedServiceNames()
152 return Sequence< OUString >{ "com.sun.star.awt.FontIdentificator" };
155 OUString FontIdentificator_getImplementationName()
157 return OUString( "vcl::FontIdentificator" );
160 Reference< XInterface > SAL_CALL FontIdentificator_createInstance( const Reference< XMultiServiceFactory >& )
162 return static_cast< ::cppu::OWeakObject * >( new FontIdentificator );
165 // XServiceInfo
166 OUString SAL_CALL FontIdentificator::getImplementationName() throw (RuntimeException, std::exception)
168 return FontIdentificator_getImplementationName();
171 sal_Bool SAL_CALL FontIdentificator::supportsService( const OUString& i_rServiceName ) throw (RuntimeException, std::exception)
173 return cppu::supportsService(this, i_rServiceName);
176 Sequence< OUString > SAL_CALL FontIdentificator::getSupportedServiceNames() throw (RuntimeException, std::exception)
178 return FontIdentificator_getSupportedServiceNames();
181 } // namespace vcl
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */