nss: upgrade to release 3.73
[LibreOffice.git] / canvas / source / cairo / cairo_canvasfont.cxx
blobcca052d167e0b6ab039f122786725cbc31d85c0f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <basegfx/numeric/ftools.hxx>
23 #include <com/sun/star/rendering/PanoseProportion.hpp>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <i18nlangtag/languagetag.hxx>
26 #include <rtl/math.hxx>
27 #include <vcl/metric.hxx>
29 #include "cairo_canvasfont.hxx"
30 #include "cairo_textlayout.hxx"
32 using namespace ::com::sun::star;
34 namespace cairocanvas
37 CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest,
38 const uno::Sequence< beans::PropertyValue >& /*rExtraFontProperties*/,
39 const geometry::Matrix2D& rFontMatrix,
40 const SurfaceProviderRef& rDevice ) :
41 CanvasFont_Base( m_aMutex ),
42 maFont( vcl::Font( rFontRequest.FontDescription.FamilyName,
43 rFontRequest.FontDescription.StyleName,
44 Size( 0, ::basegfx::fround(rFontRequest.CellSize) ) ) ),
45 maFontRequest( rFontRequest ),
46 mpRefDevice( rDevice )
48 maFont->SetAlignment( ALIGN_BASELINE );
49 maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==css::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
50 maFont->SetVertical( rFontRequest.FontDescription.IsVertical==css::util::TriState_YES );
52 // TODO(F2): improve panose->vclenum conversion
53 maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
54 maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL );
55 maFont->SetPitch(
56 rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED
57 ? PITCH_FIXED : PITCH_VARIABLE);
59 maFont->SetLanguage( LanguageTag::convertToLanguageType( rFontRequest.Locale, false));
61 // adjust to stretched/shrunk font
62 if( ::rtl::math::approxEqual( rFontMatrix.m00, rFontMatrix.m11) )
63 return;
65 VclPtr<OutputDevice> pOutDev( mpRefDevice->getOutputDevice() );
67 if( !pOutDev )
68 return;
70 const bool bOldMapState( pOutDev->IsMapModeEnabled() );
71 pOutDev->EnableMapMode(false);
73 const Size aSize = pOutDev->GetFontMetric( *maFont ).GetFontSize();
75 const double fDividend( rFontMatrix.m10 + rFontMatrix.m11 );
76 double fStretch = rFontMatrix.m00 + rFontMatrix.m01;
78 if( !::basegfx::fTools::equalZero( fDividend) )
79 fStretch /= fDividend;
81 const tools::Long nNewWidth = ::basegfx::fround( aSize.Width() * fStretch );
83 maFont->SetAverageFontWidth( nNewWidth );
85 pOutDev->EnableMapMode(bOldMapState);
88 void SAL_CALL CanvasFont::disposing()
90 SolarMutexGuard aGuard;
92 mpRefDevice.clear();
95 uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 nRandomSeed )
97 SolarMutexGuard aGuard;
99 if( !mpRefDevice.is() )
100 return uno::Reference< rendering::XTextLayout >(); // we're disposed
102 return new TextLayout( aText,
103 nDirection,
104 nRandomSeed,
105 Reference( this ),
106 mpRefDevice );
109 rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( )
111 SolarMutexGuard aGuard;
113 return maFontRequest;
116 rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( )
118 // TODO(F1)
119 return rendering::FontMetrics();
122 uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( )
124 // TODO(F1)
125 return uno::Sequence< double >();
128 uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( )
130 // TODO(F1)
131 return uno::Sequence< beans::PropertyValue >();
134 OUString SAL_CALL CanvasFont::getImplementationName()
136 return "CairoCanvas::CanvasFont";
139 sal_Bool SAL_CALL CanvasFont::supportsService( const OUString& ServiceName )
141 return cppu::supportsService( this, ServiceName );
144 uno::Sequence< OUString > SAL_CALL CanvasFont::getSupportedServiceNames()
146 return { "com.sun.star.rendering.CanvasFont" };
149 vcl::Font const & CanvasFont::getVCLFont() const
151 return *maFont;
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */