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 namespace {
48 
49 class FontIdentificator : public ::cppu::WeakAggImplHelper3< XMaterialHolder, XInitialization, XServiceInfo >
50 {
52 public:
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 
70 void 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 
86 Any 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 makeAny( aFD );
149 }
150 
152 {
153  return Sequence< OUString >{ "com.sun.star.awt.FontIdentificator" };
154 }
155 
157 {
158  return "vcl::FontIdentificator";
159 }
160 
161 Reference< XInterface > FontIdentificator_createInstance( const Reference< XMultiServiceFactory >& )
162 {
163  return static_cast< ::cppu::OWeakObject * >( new FontIdentificator );
164 }
165 
166 // XServiceInfo
167 OUString SAL_CALL FontIdentificator::getImplementationName()
168 {
170 }
171 
172 sal_Bool SAL_CALL FontIdentificator::supportsService( const OUString& i_rServiceName )
173 {
174  return cppu::supportsService(this, i_rServiceName);
175 }
176 
177 Sequence< OUString > SAL_CALL FontIdentificator::getSupportedServiceNames()
178 {
180 }
181 
182 } // namespace vcl
183 
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString FontIdentificator_getImplementationName()
Definition: fontident.cxx:156
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
OUString getImplementationName()
WEIGHT_SEMIBOLD
FAMILY_ROMAN
WEIGHT_LIGHT
FontFamily GetFamilyType()
Definition: font/font.cxx:694
WEIGHT_BOLD
FontItalic GetItalic()
Definition: font/font.cxx:693
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
PITCH_VARIABLE
FAMILY_DECORATIVE
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:75
WEIGHT_SEMILIGHT
css::uno::Sequence< OUString > getSupportedServiceNames()
FontPitch GetPitch()
Definition: font/font.cxx:690
Font m_aFont
Definition: fontident.cxx:51
PITCH_FIXED
ITALIC_OBLIQUE
WEIGHT_MEDIUM
WEIGHT_NORMAL
WEIGHT_ULTRALIGHT
unsigned char sal_Bool
Reference< XInterface > FontIdentificator_createInstance(const Reference< XMultiServiceFactory > &)
Definition: fontident.cxx:161
WEIGHT_ULTRABOLD
FAMILY_SYSTEM
FontWeight GetWeight()
Definition: font/font.cxx:691
ITALIC_NORMAL
FAMILY_SWISS
Sequence< OUString > FontIdentificator_getSupportedServiceNames()
Definition: fontident.cxx:151
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)