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 
36 #include <cppuhelper/implbase3.hxx>
38 
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;
43 
44 namespace vcl
45 {
46 
47 class FontIdentificator : public ::cppu::WeakAggImplHelper3< XMaterialHolder, XInitialization, XServiceInfo >
48 {
50 public:
52 
53  // XServiceInfo
54  virtual OUString SAL_CALL getImplementationName( ) override;
55  virtual sal_Bool SAL_CALL supportsService( const OUString& ) override;
56  virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
57 
58  // XInitialization
59  virtual void SAL_CALL initialize( const Sequence< Any >& ) override;
60 
61  // XMaterialHolder
62  virtual Any SAL_CALL getMaterial() override;
63 
64 };
65 
66 void SAL_CALL FontIdentificator::initialize( const Sequence<Any>& i_rArgs )
67 {
68  if( !ImplGetSVData() )
69  return; // VCL not initialized
70 
71  Sequence< sal_Int8 > aFontBuf;
72  for( const auto& rArg : i_rArgs )
73  {
74  if( rArg >>= aFontBuf )
75  {
76  m_aFont = Font::identifyFont( aFontBuf.getConstArray(), aFontBuf.getLength() );
77  break;
78  }
79  }
80 }
81 
83 {
84  if( !ImplGetSVData() )
85  return Any(); // VCL not initialized
86 
87  FontDescriptor aFD;
88  aFD.Name = m_aFont.GetFamilyName();
89  aFD.Height = 0;
90  aFD.Width = 0;
91  aFD.StyleName = m_aFont.GetStyleName();
92  aFD.CharSet = 0;
93  aFD.CharacterWidth = 0;
94  aFD.Underline = 0;
95  aFD.Strikeout = 0;
96  aFD.Orientation = 0;
97  aFD.Kerning = false;
98  aFD.WordLineMode = false;
99  aFD.Type = 0;
100  switch( m_aFont.GetFamilyType() )
101  {
102  case FAMILY_DECORATIVE: aFD.Family = css::awt::FontFamily::DECORATIVE;break;
103  case FAMILY_MODERN: aFD.Family = css::awt::FontFamily::MODERN;break;
104  case FAMILY_ROMAN: aFD.Family = css::awt::FontFamily::ROMAN;break;
105  case FAMILY_SCRIPT: aFD.Family = css::awt::FontFamily::SCRIPT;break;
106  case FAMILY_SWISS: aFD.Family = css::awt::FontFamily::SWISS;break;
107  case FAMILY_SYSTEM: aFD.Family = css::awt::FontFamily::SYSTEM;break;
108  default:
109  aFD.Family = css::awt::FontFamily::DONTKNOW;
110  break;
111  }
112  switch( m_aFont.GetPitch() )
113  {
114  case PITCH_VARIABLE: aFD.Pitch = css::awt::FontPitch::VARIABLE;break;
115  case PITCH_FIXED: aFD.Pitch = css::awt::FontPitch::FIXED;break;
116  default:
117  aFD.Pitch = css::awt::FontPitch::DONTKNOW;
118  break;
119  }
120  switch( m_aFont.GetWeight() )
121  {
122  case WEIGHT_THIN: aFD.Weight = css::awt::FontWeight::THIN;break;
123  case WEIGHT_ULTRALIGHT: aFD.Weight = css::awt::FontWeight::ULTRALIGHT;break;
124  case WEIGHT_LIGHT: aFD.Weight = css::awt::FontWeight::LIGHT;break;
125  case WEIGHT_SEMILIGHT: aFD.Weight = css::awt::FontWeight::SEMILIGHT;break;
126  case WEIGHT_MEDIUM:
127  case WEIGHT_NORMAL: aFD.Weight = css::awt::FontWeight::NORMAL;break;
128  case WEIGHT_SEMIBOLD: aFD.Weight = css::awt::FontWeight::SEMIBOLD;break;
129  case WEIGHT_BOLD: aFD.Weight = css::awt::FontWeight::BOLD;break;
130  case WEIGHT_ULTRABOLD: aFD.Weight = css::awt::FontWeight::ULTRABOLD;break;
131  case WEIGHT_BLACK: aFD.Weight = css::awt::FontWeight::BLACK;break;
132  default:
133  aFD.Weight = css::awt::FontWeight::DONTKNOW;
134  break;
135  }
136  switch( m_aFont.GetItalic() )
137  {
138  case ITALIC_OBLIQUE: aFD.Slant = css::awt::FontSlant_OBLIQUE;break;
139  case ITALIC_NORMAL: aFD.Slant = css::awt::FontSlant_ITALIC;break;
140  default:
141  aFD.Slant = css::awt::FontSlant_DONTKNOW;
142  break;
143  }
144  return makeAny( aFD );
145 }
146 
148 {
149  return Sequence< OUString >{ "com.sun.star.awt.FontIdentificator" };
150 }
151 
153 {
154  return "vcl::FontIdentificator";
155 }
156 
158 {
159  return static_cast< ::cppu::OWeakObject * >( new FontIdentificator );
160 }
161 
162 // XServiceInfo
164 {
166 }
167 
168 sal_Bool SAL_CALL FontIdentificator::supportsService( const OUString& i_rServiceName )
169 {
170  return cppu::supportsService(this, i_rServiceName);
171 }
172 
174 {
176 }
177 
178 } // namespace vcl
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: fontident.cxx:173
OUString FontIdentificator_getImplementationName()
Definition: fontident.cxx:152
static Font identifyFont(const void *pBuffer, sal_uInt32 nLen)
Definition: font/font.cxx:647
const OUString & GetFamilyName() const
Definition: font/font.cxx:670
FAMILY_SCRIPT
FAMILY_MODERN
const OUString & GetStyleName() const
Definition: font/font.cxx:671
WEIGHT_THIN
WEIGHT_BLACK
WEIGHT_SEMIBOLD
virtual void SAL_CALL initialize(const Sequence< Any > &) override
Definition: fontident.cxx:66
FAMILY_ROMAN
WEIGHT_LIGHT
FontFamily GetFamilyType()
Definition: font/font.cxx:694
WEIGHT_BOLD
FontItalic GetItalic()
Definition: font/font.cxx:693
virtual sal_Bool SAL_CALL supportsService(const OUString &) override
Definition: fontident.cxx:168
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
PITCH_VARIABLE
FAMILY_DECORATIVE
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:67
WEIGHT_SEMILIGHT
FontPitch GetPitch()
Definition: font/font.cxx:690
PITCH_FIXED
ITALIC_OBLIQUE
WEIGHT_MEDIUM
WEIGHT_NORMAL
WEIGHT_ULTRALIGHT
unsigned char sal_Bool
Reference< XInterface > FontIdentificator_createInstance(const Reference< XMultiServiceFactory > &)
Definition: fontident.cxx:157
virtual OUString SAL_CALL getImplementationName() override
Definition: fontident.cxx:163
WEIGHT_ULTRABOLD
FAMILY_SYSTEM
virtual Any SAL_CALL getMaterial() override
Definition: fontident.cxx:82
FontWeight GetWeight()
Definition: font/font.cxx:691
ITALIC_NORMAL
FAMILY_SWISS
Sequence< OUString > FontIdentificator_getSupportedServiceNames()
Definition: fontident.cxx:147
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)