LibreOffice Module canvas (master) 1
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
24#include <com/sun/star/rendering/PanoseProportion.hpp>
27#include <rtl/math.hxx>
28#include <vcl/metric.hxx>
29#include <vcl/virdev.hxx>
30
31#include "canvasfont.hxx"
32#include "textlayout.hxx"
33
34using namespace ::com::sun::star;
35
36
37namespace vclcanvas
38{
39 CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest,
40 const uno::Sequence< beans::PropertyValue >& rExtraFontProperties,
41 const geometry::Matrix2D& rFontMatrix,
42 rendering::XGraphicDevice& rDevice,
43 const OutDevProviderSharedPtr& rOutDevProvider ) :
45 maFont( vcl::Font( rFontRequest.FontDescription.FamilyName,
46 rFontRequest.FontDescription.StyleName,
47 Size( 0, ::basegfx::fround(rFontRequest.CellSize) ) ) ),
48 maFontRequest( rFontRequest ),
49 mpRefDevice( &rDevice ),
50 mpOutDevProvider( rOutDevProvider )
51 {
52 maFont->SetAlignment( ALIGN_BASELINE );
53 maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==css::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
54 maFont->SetVertical( rFontRequest.FontDescription.IsVertical==css::util::TriState_YES );
55
56 // TODO(F2): improve panose->vclenum conversion
57 maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
58 maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL );
59 maFont->SetPitch(
60 rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED
61 ? PITCH_FIXED : PITCH_VARIABLE);
62
63 maFont->SetLanguage( LanguageTag::convertToLanguageType( rFontRequest.Locale, false));
64
65 // adjust to stretched/shrunk font
66 if( !::rtl::math::approxEqual( rFontMatrix.m00, rFontMatrix.m11) )
67 {
68 OutputDevice& rOutDev( rOutDevProvider->getOutDev() );
69
70 const bool bOldMapState( rOutDev.IsMapModeEnabled() );
71 rOutDev.EnableMapMode(false);
72
73 const Size aSize = rOutDev.GetFontMetric( *maFont ).GetFontSize();
74
75 const double fDividend( rFontMatrix.m10 + rFontMatrix.m11 );
76 double fStretch = rFontMatrix.m00 + rFontMatrix.m01;
77
78 if( !::basegfx::fTools::equalZero( fDividend) )
79 fStretch /= fDividend;
80
81 const ::tools::Long nNewWidth = ::basegfx::fround( aSize.Width() * fStretch );
82
83 maFont->SetAverageFontWidth( nNewWidth );
84
85 rOutDev.EnableMapMode(bOldMapState);
86 }
87
88 sal_uInt32 nEmphasisMark = 0;
89
90 ::canvas::tools::extractExtraFontProperties(rExtraFontProperties, nEmphasisMark);
91
92 if (nEmphasisMark)
93 maFont->SetEmphasisMark(FontEmphasisMark(nEmphasisMark));
94 }
95
96 void SAL_CALL CanvasFont::disposing()
97 {
98 SolarMutexGuard aGuard;
99
100 mpOutDevProvider.reset();
101 mpRefDevice.clear();
102 }
103
104 uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 )
105 {
106 SolarMutexGuard aGuard;
107
108 if( !mpRefDevice.is() )
109 return uno::Reference< rendering::XTextLayout >(); // we're disposed
110
111 return new TextLayout( aText,
112 nDirection,
113 Reference( this ),
114 mpRefDevice,
115 mpOutDevProvider);
116 }
117
118 rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( )
119 {
120 SolarMutexGuard aGuard;
121
122 return maFontRequest;
123 }
124
125 rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( )
126 {
127 SolarMutexGuard aGuard;
128
129 OutputDevice& rOutDev = mpOutDevProvider->getOutDev();
131 pVDev->SetFont(getVCLFont());
132 const ::FontMetric& aMetric( pVDev->GetFontMetric() );
133
134 return rendering::FontMetrics(
135 aMetric.GetAscent(),
136 aMetric.GetDescent(),
137 aMetric.GetInternalLeading(),
138 aMetric.GetExternalLeading(),
139 0,
140 aMetric.GetDescent() / 2.0,
141 aMetric.GetAscent() / 2.0);
142 }
143
144 uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( )
145 {
146 // TODO(F1)
147 return uno::Sequence< double >();
148 }
149
150 uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( )
151 {
152 // TODO(F1)
153 return uno::Sequence< beans::PropertyValue >();
154 }
155
156 OUString SAL_CALL CanvasFont::getImplementationName()
157 {
158 return "VCLCanvas::CanvasFont";
159 }
160
161 sal_Bool SAL_CALL CanvasFont::supportsService( const OUString& ServiceName )
162 {
163 return cppu::supportsService( this, ServiceName );
164 }
165
166 uno::Sequence< OUString > SAL_CALL CanvasFont::getSupportedServiceNames()
167 {
168 return { "com.sun.star.rendering.CanvasFont" };
169 }
170
171 vcl::Font const & CanvasFont::getVCLFont() const
172 {
173 return *maFont;
174 }
175}
176
177/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
constexpr tools::Long Width() const
CanvasFont(const CanvasFont &)=delete
make noncopyable
FontEmphasisMark
std::mutex m_aMutex
B2IRange fround(const B2DRange &rRange)
void extractExtraFontProperties(const uno::Sequence< beans::PropertyValue > &rExtraFontProperties, sal_uInt32 &rEmphasisMark)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Reference
FontWeight
std::shared_ptr< OutDevProvider > OutDevProviderSharedPtr
::cppu::WeakComponentImplHelper< css::rendering::XCanvasFont, css::lang::XServiceInfo > CanvasFont_Base
Definition: canvasfont.hxx:43
unsigned char sal_Bool
signed char sal_Int8