LibreOffice Module vcl (master) 1
fontident.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <vcl/svapp.hxx>
21#include <vcl/font.hxx>
22
23#include <factory.hxx>
24#include <svdata.hxx>
25
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
38
39using namespace ::com::sun::star::uno;
40using namespace ::com::sun::star::lang;
41using namespace ::com::sun::star::beans;
42using namespace ::com::sun::star::awt;
43
44namespace vcl
45{
46
47namespace {
48
49class FontIdentificator : public ::cppu::WeakAggImplHelper3< XMaterialHolder, XInitialization, XServiceInfo >
50{
52public:
53 FontIdentificator() {}
54
55 // XServiceInfo
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;
59
60 // XInitialization
61 virtual void SAL_CALL initialize( const Sequence< Any >& ) override;
62
63 // XMaterialHolder
64 virtual Any SAL_CALL getMaterial() override;
65
66};
67
68}
69
70void SAL_CALL FontIdentificator::initialize( const Sequence<Any>& i_rArgs )
71{
72 if( !ImplGetSVData() )
73 return; // VCL not initialized
74
75 Sequence< sal_Int8 > aFontBuf;
76 for( const auto& rArg : i_rArgs )
77 {
78 if( rArg >>= aFontBuf )
79 {
80 m_aFont = Font::identifyFont( aFontBuf.getConstArray(), aFontBuf.getLength() );
81 break;
82 }
83 }
84}
85
86Any SAL_CALL FontIdentificator::getMaterial()
87{
88 if( !ImplGetSVData() )
89 return Any(); // VCL not initialized
90
91 FontDescriptor aFD;
92 aFD.Name = m_aFont.GetFamilyName();
93 aFD.Height = 0;
94 aFD.Width = 0;
95 aFD.StyleName = m_aFont.GetStyleName();
96 aFD.CharSet = 0;
97 aFD.CharacterWidth = 0;
98 aFD.Underline = 0;
99 aFD.Strikeout = 0;
100 aFD.Orientation = 0;
101 aFD.Kerning = false;
102 aFD.WordLineMode = false;
103 aFD.Type = 0;
104 switch( m_aFont.GetFamilyType() )
105 {
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;
112 default:
113 aFD.Family = css::awt::FontFamily::DONTKNOW;
114 break;
115 }
116 switch( m_aFont.GetPitch() )
117 {
118 case PITCH_VARIABLE: aFD.Pitch = css::awt::FontPitch::VARIABLE;break;
119 case PITCH_FIXED: aFD.Pitch = css::awt::FontPitch::FIXED;break;
120 default:
121 aFD.Pitch = css::awt::FontPitch::DONTKNOW;
122 break;
123 }
124 switch( m_aFont.GetWeight() )
125 {
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;
130 case WEIGHT_MEDIUM:
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;
136 default:
137 aFD.Weight = css::awt::FontWeight::DONTKNOW;
138 break;
139 }
140 switch( m_aFont.GetItalic() )
141 {
142 case ITALIC_OBLIQUE: aFD.Slant = css::awt::FontSlant_OBLIQUE;break;
143 case ITALIC_NORMAL: aFD.Slant = css::awt::FontSlant_ITALIC;break;
144 default:
145 aFD.Slant = css::awt::FontSlant_DONTKNOW;
146 break;
147 }
148 return Any( aFD );
149}
150
151// XServiceInfo
152OUString SAL_CALL FontIdentificator::getImplementationName()
153{
154 return "vcl::FontIdentificator";
155}
156
157sal_Bool SAL_CALL FontIdentificator::supportsService( const OUString& i_rServiceName )
158{
159 return cppu::supportsService(this, i_rServiceName);
160}
161
162Sequence< OUString > SAL_CALL FontIdentificator::getSupportedServiceNames()
163{
164 return { "com.sun.star.awt.FontIdentificator" };
165}
166
167} // namespace vcl
168
169extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
171 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
172{
173 return cppu::acquire(new vcl::FontIdentificator());
174}
175
176/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FontFamily GetFamilyType()
Definition: font/font.cxx:928
const OUString & GetStyleName() const
Definition: font/font.cxx:905
FontItalic GetItalic()
Definition: font/font.cxx:927
const OUString & GetFamilyName() const
Definition: font/font.cxx:904
FontPitch GetPitch()
Definition: font/font.cxx:924
FontWeight GetWeight()
Definition: font/font.cxx:925
static Font identifyFont(const void *pBuffer, sal_uInt32 nLen)
Definition: font/font.cxx:881
PITCH_VARIABLE
PITCH_FIXED
ITALIC_NORMAL
ITALIC_OBLIQUE
FAMILY_DECORATIVE
FAMILY_SYSTEM
FAMILY_SCRIPT
FAMILY_SWISS
FAMILY_MODERN
FAMILY_ROMAN
WEIGHT_ULTRALIGHT
WEIGHT_ULTRABOLD
WEIGHT_THIN
WEIGHT_BOLD
WEIGHT_NORMAL
WEIGHT_LIGHT
WEIGHT_SEMIBOLD
WEIGHT_SEMILIGHT
WEIGHT_MEDIUM
WEIGHT_BLACK
Font m_aFont
Definition: fontident.cxx:51
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * vcl_FontIdentificator_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: fontident.cxx:170
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:77
unsigned char sal_Bool