Line data Source code
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 <canvas/debug.hxx>
21 :
22 : #include <com/sun/star/rendering/PanoseProportion.hpp>
23 :
24 : #include <rtl/math.hxx>
25 : #include <basegfx/numeric/ftools.hxx>
26 :
27 : #include <vcl/metric.hxx>
28 : #include <i18npool/languagetag.hxx>
29 :
30 : #include "cairo_canvasfont.hxx"
31 : #include "cairo_textlayout.hxx"
32 :
33 : using namespace ::com::sun::star;
34 :
35 : namespace cairocanvas
36 : {
37 :
38 0 : CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest,
39 : const uno::Sequence< beans::PropertyValue >& /*rExtraFontProperties*/,
40 : const geometry::Matrix2D& rFontMatrix,
41 : const SurfaceProviderRef& rDevice ) :
42 : CanvasFont_Base( m_aMutex ),
43 : maFont( Font( rFontRequest.FontDescription.FamilyName,
44 : rFontRequest.FontDescription.StyleName,
45 : Size( 0, ::basegfx::fround(rFontRequest.CellSize) ) ) ),
46 : maFontRequest( rFontRequest ),
47 0 : mpRefDevice( rDevice )
48 : {
49 0 : maFont->SetAlign( ALIGN_BASELINE );
50 0 : maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==com::sun::star::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
51 0 : maFont->SetVertical( (rFontRequest.FontDescription.IsVertical==com::sun::star::util::TriState_YES) ? sal_True : sal_False );
52 :
53 : // TODO(F2): improve panose->vclenum conversion
54 0 : maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
55 0 : maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL );
56 : maFont->SetPitch(
57 : rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED
58 0 : ? PITCH_FIXED : PITCH_VARIABLE);
59 :
60 0 : maFont->SetLanguage( LanguageTag( rFontRequest.Locale).getLanguageType( false));
61 :
62 : // adjust to stretched/shrinked font
63 0 : if( !::rtl::math::approxEqual( rFontMatrix.m00, rFontMatrix.m11) )
64 : {
65 0 : OutputDevice* pOutDev( mpRefDevice->getOutputDevice() );
66 :
67 0 : if( pOutDev )
68 : {
69 0 : const bool bOldMapState( pOutDev->IsMapModeEnabled() );
70 0 : pOutDev->EnableMapMode(sal_False);
71 :
72 0 : const Size aSize = pOutDev->GetFontMetric( *maFont ).GetSize();
73 :
74 0 : const double fDividend( rFontMatrix.m10 + rFontMatrix.m11 );
75 0 : double fStretch = (rFontMatrix.m00 + rFontMatrix.m01);
76 :
77 0 : if( !::basegfx::fTools::equalZero( fDividend) )
78 0 : fStretch /= fDividend;
79 :
80 0 : const long nNewWidth = ::basegfx::fround( aSize.Width() * fStretch );
81 :
82 0 : maFont->SetWidth( nNewWidth );
83 :
84 0 : pOutDev->EnableMapMode(bOldMapState);
85 : }
86 : }
87 0 : }
88 :
89 0 : void SAL_CALL CanvasFont::disposing()
90 : {
91 0 : SolarMutexGuard aGuard;
92 :
93 0 : mpRefDevice.clear();
94 0 : }
95 :
96 0 : uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 nRandomSeed ) throw (uno::RuntimeException)
97 : {
98 0 : SolarMutexGuard aGuard;
99 :
100 0 : if( !mpRefDevice.is() )
101 0 : return uno::Reference< rendering::XTextLayout >(); // we're disposed
102 :
103 : return new TextLayout( aText,
104 : nDirection,
105 : nRandomSeed,
106 : Reference( this ),
107 0 : mpRefDevice );
108 : }
109 :
110 0 : rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException)
111 : {
112 0 : SolarMutexGuard aGuard;
113 :
114 0 : return maFontRequest;
115 : }
116 :
117 0 : rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException)
118 : {
119 0 : SolarMutexGuard aGuard;
120 :
121 : // TODO(F1)
122 0 : return rendering::FontMetrics();
123 : }
124 :
125 0 : uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException)
126 : {
127 0 : SolarMutexGuard aGuard;
128 :
129 : // TODO(F1)
130 0 : return uno::Sequence< double >();
131 : }
132 :
133 0 : uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException)
134 : {
135 0 : SolarMutexGuard aGuard;
136 :
137 : // TODO(F1)
138 0 : return uno::Sequence< beans::PropertyValue >();
139 : }
140 :
141 : #define IMPLEMENTATION_NAME "CairoCanvas::CanvasFont"
142 : #define SERVICE_NAME "com.sun.star.rendering.CanvasFont"
143 :
144 0 : OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException )
145 : {
146 0 : return OUString( IMPLEMENTATION_NAME );
147 : }
148 :
149 0 : sal_Bool SAL_CALL CanvasFont::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException )
150 : {
151 0 : return ServiceName == SERVICE_NAME;
152 : }
153 :
154 0 : uno::Sequence< OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException )
155 : {
156 0 : uno::Sequence< OUString > aRet(1);
157 0 : aRet[0] = SERVICE_NAME;
158 :
159 0 : return aRet;
160 : }
161 :
162 0 : ::Font CanvasFont::getVCLFont() const
163 : {
164 0 : return *maFont;
165 : }
166 0 : }
167 :
168 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|