fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / canvas / source / vcl / canvasfont.cxx
blob549cf3e139cf9413e4b9e585d3d7d511dd13a930
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 .
21 #include <canvas/debug.hxx>
23 #include <rtl/math.hxx>
24 #include <basegfx/numeric/ftools.hxx>
25 #include <i18nlangtag/languagetag.hxx>
26 #include <vcl/metric.hxx>
28 #include <com/sun/star/rendering/PanoseProportion.hpp>
30 #include "canvasfont.hxx"
31 #include "textlayout.hxx"
33 using namespace ::com::sun::star;
36 namespace vclcanvas
38 CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest,
39 const uno::Sequence< beans::PropertyValue >& ,
40 const geometry::Matrix2D& rFontMatrix,
41 rendering::XGraphicDevice& rDevice,
42 const OutDevProviderSharedPtr& rOutDevProvider ) :
43 CanvasFont_Base( m_aMutex ),
44 maFont( Font( rFontRequest.FontDescription.FamilyName,
45 rFontRequest.FontDescription.StyleName,
46 Size( 0, ::basegfx::fround(rFontRequest.CellSize) ) ) ),
47 maFontRequest( rFontRequest ),
48 mpRefDevice( &rDevice ),
49 mpOutDevProvider( rOutDevProvider )
51 maFont->SetAlign( ALIGN_BASELINE );
52 maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==com::sun::star::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
53 maFont->SetVertical( (rFontRequest.FontDescription.IsVertical==com::sun::star::util::TriState_YES) ? sal_True : sal_False );
55 // TODO(F2): improve panose->vclenum conversion
56 maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
57 maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL );
58 maFont->SetPitch(
59 rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED
60 ? PITCH_FIXED : PITCH_VARIABLE);
62 maFont->SetLanguage( LanguageTag( rFontRequest.Locale).getLanguageType( false));
64 // adjust to stretched/shrinked font
65 if( !::rtl::math::approxEqual( rFontMatrix.m00, rFontMatrix.m11) )
67 OutputDevice& rOutDev( rOutDevProvider->getOutDev() );
69 const bool bOldMapState( rOutDev.IsMapModeEnabled() );
70 rOutDev.EnableMapMode(sal_False);
72 const Size aSize = rOutDev.GetFontMetric( *maFont ).GetSize();
74 const double fDividend( rFontMatrix.m10 + rFontMatrix.m11 );
75 double fStretch = (rFontMatrix.m00 + rFontMatrix.m01);
77 if( !::basegfx::fTools::equalZero( fDividend) )
78 fStretch /= fDividend;
80 const long nNewWidth = ::basegfx::fround( aSize.Width() * fStretch );
82 maFont->SetWidth( nNewWidth );
84 rOutDev.EnableMapMode(bOldMapState);
88 void SAL_CALL CanvasFont::disposing()
90 SolarMutexGuard aGuard;
92 mpOutDevProvider.reset();
93 mpRefDevice.clear();
96 uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 nRandomSeed ) throw (uno::RuntimeException)
98 SolarMutexGuard aGuard;
100 if( !mpRefDevice.is() )
101 return uno::Reference< rendering::XTextLayout >(); // we're disposed
103 return new TextLayout( aText,
104 nDirection,
105 nRandomSeed,
106 Reference( this ),
107 mpRefDevice,
108 mpOutDevProvider);
111 rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException)
113 SolarMutexGuard aGuard;
115 return maFontRequest;
118 rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException)
120 SolarMutexGuard aGuard;
122 OutputDevice& rOutDev = mpOutDevProvider->getOutDev();
123 VirtualDevice aVDev( rOutDev );
124 aVDev.SetFont(getVCLFont());
125 const ::FontMetric& aMetric( aVDev.GetFontMetric() );
127 return rendering::FontMetrics(
128 aMetric.GetAscent(),
129 aMetric.GetDescent(),
130 aMetric.GetIntLeading(),
131 aMetric.GetExtLeading(),
133 aMetric.GetDescent() / 2.0,
134 aMetric.GetAscent() / 2.0);
137 uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException)
139 SolarMutexGuard aGuard;
141 // TODO(F1)
142 return uno::Sequence< double >();
145 uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException)
147 SolarMutexGuard aGuard;
149 // TODO(F1)
150 return uno::Sequence< beans::PropertyValue >();
153 #define IMPLEMENTATION_NAME "VCLCanvas::CanvasFont"
154 #define SERVICE_NAME "com.sun.star.rendering.CanvasFont"
156 OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException )
158 return OUString( IMPLEMENTATION_NAME );
161 sal_Bool SAL_CALL CanvasFont::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException )
163 return ServiceName == SERVICE_NAME;
166 uno::Sequence< OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException )
168 uno::Sequence< OUString > aRet(1);
169 aRet[0] = OUString( SERVICE_NAME );
171 return aRet;
174 ::Font CanvasFont::getVCLFont() const
176 return *maFont;
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */