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 maFontMatrix( rFontMatrix )
52 {
53 maFont->SetAlignment( ALIGN_BASELINE );
54 maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==css::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
55 maFont->SetVertical( rFontRequest.FontDescription.IsVertical==css::util::TriState_YES );
56
57 // TODO(F2): improve panose->vclenum conversion
58 maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
59 maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL );
60 maFont->SetPitch(
61 rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED
62 ? PITCH_FIXED : PITCH_VARIABLE);
63
64 maFont->SetLanguage( LanguageTag::convertToLanguageType( rFontRequest.Locale, false));
65
66 // adjust to stretched/shrunk font
67 tools::setupFontWidth(rFontMatrix, maFont.get(), rOutDevProvider->getOutDev());
68
69 sal_uInt32 nEmphasisMark = 0;
70
71 ::canvas::tools::extractExtraFontProperties(rExtraFontProperties, nEmphasisMark);
72
73 if (nEmphasisMark)
74 maFont->SetEmphasisMark(FontEmphasisMark(nEmphasisMark));
75 }
76
77 void SAL_CALL CanvasFont::disposing()
78 {
79 SolarMutexGuard aGuard;
80
81 mpOutDevProvider.reset();
82 mpRefDevice.clear();
83 }
84
85 uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 )
86 {
87 SolarMutexGuard aGuard;
88
89 if( !mpRefDevice.is() )
90 return uno::Reference< rendering::XTextLayout >(); // we're disposed
91
92 return new TextLayout( aText,
93 nDirection,
94 Reference( this ),
95 mpRefDevice,
96 mpOutDevProvider);
97 }
98
99 rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( )
100 {
101 SolarMutexGuard aGuard;
102
103 return maFontRequest;
104 }
105
106 rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( )
107 {
108 SolarMutexGuard aGuard;
109
110 OutputDevice& rOutDev = mpOutDevProvider->getOutDev();
112 pVDev->SetFont(getVCLFont());
113 const ::FontMetric& aMetric( pVDev->GetFontMetric() );
114
115 return rendering::FontMetrics(
116 aMetric.GetAscent(),
117 aMetric.GetDescent(),
118 aMetric.GetInternalLeading(),
119 aMetric.GetExternalLeading(),
120 0,
121 aMetric.GetDescent() / 2.0,
122 aMetric.GetAscent() / 2.0);
123 }
124
125 uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( )
126 {
127 // TODO(F1)
128 return uno::Sequence< double >();
129 }
130
131 uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( )
132 {
133 // TODO(F1)
134 return uno::Sequence< beans::PropertyValue >();
135 }
136
137 OUString SAL_CALL CanvasFont::getImplementationName()
138 {
139 return "VCLCanvas::CanvasFont";
140 }
141
142 sal_Bool SAL_CALL CanvasFont::supportsService( const OUString& ServiceName )
143 {
144 return cppu::supportsService( this, ServiceName );
145 }
146
147 uno::Sequence< OUString > SAL_CALL CanvasFont::getSupportedServiceNames()
148 {
149 return { "com.sun.star.rendering.CanvasFont" };
150 }
151
152 vcl::Font const & CanvasFont::getVCLFont() const
153 {
154 return *maFont;
155 }
156
157 const css::geometry::Matrix2D& CanvasFont::getFontMatrix() const
158 {
159 SolarMutexGuard aGuard;
160
161 return maFontMatrix;
162 }
163}
164
165/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
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
void setupFontWidth(const css::geometry::Matrix2D &rFontMatrix, vcl::Font &rFont, OutputDevice &rOutDev)
Definition: impltools.cxx:138
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