LibreOffice Module canvas (master)  1
dx_canvasfont.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 <sal/config.h>
22 
23 #include <com/sun/star/rendering/PanoseWeight.hpp>
24 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
26 
27 #include "dx_canvasfont.hxx"
28 #include "dx_spritecanvas.hxx"
29 #include "dx_textlayout.hxx"
30 #include "dx_winstuff.hxx"
31 
32 using namespace ::com::sun::star;
33 
34 namespace dxcanvas
35 {
36  namespace
37  {
38  INT calcFontStyle( const rendering::FontRequest& rFontRequest )
39  {
40  INT nFontStyle( Gdiplus::FontStyleRegular );
41 
42  if( rFontRequest.FontDescription.FontDescription.Weight > rendering::PanoseWeight::BOOK )
43  nFontStyle = Gdiplus::FontStyleBold;
44 
45  return nFontStyle;
46  }
47  }
48 
49  CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest,
50  const uno::Sequence< beans::PropertyValue >& extraFontProperties,
51  const geometry::Matrix2D& fontMatrix ) :
53  mpGdiPlusUser( GDIPlusUser::createInstance() ),
54  mpFontFamily(),
55  mpFont(),
56  maFontRequest( rFontRequest ),
57  mnEmphasisMark(0),
58  maFontMatrix( fontMatrix )
59  {
60  mpFontFamily.reset( new Gdiplus::FontFamily(o3tl::toW(rFontRequest.FontDescription.FamilyName.getStr()),nullptr) );
61  if( !mpFontFamily->IsAvailable() )
62  mpFontFamily.reset( new Gdiplus::FontFamily(L"Arial",nullptr) );
63 
64  mpFont.reset( new Gdiplus::Font( mpFontFamily.get(),
65  static_cast<Gdiplus::REAL>(rFontRequest.CellSize),
66  calcFontStyle( rFontRequest ),
67  Gdiplus::UnitWorld ));
68 
69  ::canvas::tools::extractExtraFontProperties(extraFontProperties, mnEmphasisMark);
70  }
71 
72  void SAL_CALL CanvasFont::disposing()
73  {
74  ::osl::MutexGuard aGuard( m_aMutex );
75 
76  mpFont.reset();
77  mpFontFamily.reset();
78  mpGdiPlusUser.reset();
79  }
80 
81  uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText,
82  sal_Int8 nDirection,
83  sal_Int64 nRandomSeed )
84  {
85  ::osl::MutexGuard aGuard( m_aMutex );
86 
87  return new TextLayout( aText, nDirection, nRandomSeed, ImplRef( this ) );
88  }
89 
90  uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( )
91  {
92  // TODO
93  return uno::Sequence< double >();
94  }
95 
96  uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( )
97  {
98  // TODO
99  return uno::Sequence< beans::PropertyValue >();
100  }
101 
102  rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( )
103  {
104  ::osl::MutexGuard aGuard( m_aMutex );
105 
106  return maFontRequest;
107  }
108 
109  rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( )
110  {
111  // TODO
112  return rendering::FontMetrics();
113  }
114 
116  {
117  return "DXCanvas::CanvasFont";
118  }
119 
120  sal_Bool SAL_CALL CanvasFont::supportsService( const OUString& ServiceName )
121  {
122  return cppu::supportsService( this, ServiceName );
123  }
124 
125  uno::Sequence< OUString > SAL_CALL CanvasFont::getSupportedServiceNames()
126  {
127  return { "com.sun.star.rendering.CanvasFont" };
128  }
129 
131  {
132  ::osl::MutexGuard aGuard( m_aMutex );
133 
134  return mpFontFamily->GetCellAscent(0); // TODO(F1): rFontRequest.styleName
135  }
136 
137  double CanvasFont::getEmHeight() const
138  {
139  ::osl::MutexGuard aGuard( m_aMutex );
140 
141  return mpFontFamily->GetEmHeight(0); // TODO(F1): rFontRequest.styleName
142  }
143 
145  {
146  ::osl::MutexGuard aGuard( m_aMutex );
147 
148  return mpFont;
149  }
150 
151  const css::geometry::Matrix2D& CanvasFont::getFontMatrix() const
152  {
153  ::osl::MutexGuard aGuard( m_aMutex );
154 
155  return maFontMatrix;
156  }
157 }
158 
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::geometry::Matrix2D & getFontMatrix() const
osl::Mutex m_aMutex
signed char sal_Int8
FontSharedPtr mpFont
virtual css::rendering::FontMetrics SAL_CALL getFontMetrics() override
mutable::osl::Mutex m_aMutex
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
CanvasFont(const CanvasFont &)=delete
make noncopyable
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual void SAL_CALL disposing() override
Dispose all internal references.
FontSharedPtr getFont() const
std::shared_ptr< Gdiplus::Font > FontSharedPtr
GDIPlusUserSharedPtr mpGdiPlusUser
virtual css::uno::Sequence< double > SAL_CALL getAvailableSizes() override
virtual css::rendering::FontRequest SAL_CALL getFontRequest() override
void extractExtraFontProperties(const uno::Sequence< beans::PropertyValue > &rExtraFontProperties, sal_uInt32 &rEmphasisMark)
double getEmHeight() const
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
unsigned char sal_Bool
css::geometry::Matrix2D maFontMatrix
FontFamilySharedPtr mpFontFamily
std::unique_ptr< vcl::Font > mpFont
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getExtraFontProperties() override
rtl::Reference< CanvasFont > ImplRef
::cppu::WeakComponentImplHelper< css::rendering::XCanvasFont, css::lang::XServiceInfo > CanvasFont_Base
double getCellAscent() const
css::rendering::FontRequest maFontRequest
virtual css::uno::Reference< css::rendering::XTextLayout > SAL_CALL createTextLayout(const css::rendering::StringContext &aText, sal_Int8 nDirection, sal_Int64 nRandomSeed) override