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