Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <canvas/debug.hxx>
30 : :
31 : : #include <com/sun/star/rendering/PanoseProportion.hpp>
32 : :
33 : : #include <rtl/math.hxx>
34 : : #include <basegfx/numeric/ftools.hxx>
35 : :
36 : : #include <vcl/metric.hxx>
37 : : #include <i18npool/mslangid.hxx>
38 : :
39 : : #include "cairo_canvasfont.hxx"
40 : : #include "cairo_textlayout.hxx"
41 : :
42 : : using namespace ::com::sun::star;
43 : :
44 : : namespace cairocanvas
45 : : {
46 : :
47 : 0 : CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest,
48 : : const uno::Sequence< beans::PropertyValue >& /*rExtraFontProperties*/,
49 : : const geometry::Matrix2D& rFontMatrix,
50 : : const SurfaceProviderRef& rDevice ) :
51 : : CanvasFont_Base( m_aMutex ),
52 : : maFont( Font( rFontRequest.FontDescription.FamilyName,
53 : : rFontRequest.FontDescription.StyleName,
54 : : Size( 0, ::basegfx::fround(rFontRequest.CellSize) ) ) ),
55 : : maFontRequest( rFontRequest ),
56 : 0 : mpRefDevice( rDevice )
57 : : {
58 : 0 : maFont->SetAlign( ALIGN_BASELINE );
59 : 0 : maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==com::sun::star::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
60 : 0 : maFont->SetVertical( (rFontRequest.FontDescription.IsVertical==com::sun::star::util::TriState_YES) ? sal_True : sal_False );
61 : :
62 : : // TODO(F2): improve panose->vclenum conversion
63 : 0 : maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
64 : 0 : maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL );
65 : : maFont->SetPitch(
66 : : rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED
67 : 0 : ? PITCH_FIXED : PITCH_VARIABLE);
68 : :
69 : 0 : maFont->SetLanguage(MsLangId::convertLocaleToLanguage(rFontRequest.Locale));
70 : :
71 : : // adjust to stretched/shrinked font
72 : 0 : if( !::rtl::math::approxEqual( rFontMatrix.m00, rFontMatrix.m11) )
73 : : {
74 : 0 : OutputDevice* pOutDev( mpRefDevice->getOutputDevice() );
75 : :
76 : 0 : if( pOutDev )
77 : : {
78 : 0 : const bool bOldMapState( pOutDev->IsMapModeEnabled() );
79 : 0 : pOutDev->EnableMapMode(sal_False);
80 : :
81 : 0 : const Size aSize = pOutDev->GetFontMetric( *maFont ).GetSize();
82 : :
83 : 0 : const double fDividend( rFontMatrix.m10 + rFontMatrix.m11 );
84 : 0 : double fStretch = (rFontMatrix.m00 + rFontMatrix.m01);
85 : :
86 : 0 : if( !::basegfx::fTools::equalZero( fDividend) )
87 : 0 : fStretch /= fDividend;
88 : :
89 : 0 : const long nNewWidth = ::basegfx::fround( aSize.Width() * fStretch );
90 : :
91 : 0 : maFont->SetWidth( nNewWidth );
92 : :
93 : 0 : pOutDev->EnableMapMode(bOldMapState);
94 : : }
95 : : }
96 : 0 : }
97 : :
98 : 0 : void SAL_CALL CanvasFont::disposing()
99 : : {
100 : 0 : SolarMutexGuard aGuard;
101 : :
102 : 0 : mpRefDevice.clear();
103 : 0 : }
104 : :
105 : 0 : uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 nRandomSeed ) throw (uno::RuntimeException)
106 : : {
107 : 0 : SolarMutexGuard aGuard;
108 : :
109 : 0 : if( !mpRefDevice.is() )
110 : 0 : return uno::Reference< rendering::XTextLayout >(); // we're disposed
111 : :
112 : : return new TextLayout( aText,
113 : : nDirection,
114 : : nRandomSeed,
115 : : Reference( this ),
116 : 0 : mpRefDevice );
117 : : }
118 : :
119 : 0 : rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException)
120 : : {
121 : 0 : SolarMutexGuard aGuard;
122 : :
123 : 0 : return maFontRequest;
124 : : }
125 : :
126 : 0 : rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException)
127 : : {
128 : 0 : SolarMutexGuard aGuard;
129 : :
130 : : // TODO(F1)
131 : 0 : return rendering::FontMetrics();
132 : : }
133 : :
134 : 0 : uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException)
135 : : {
136 : 0 : SolarMutexGuard aGuard;
137 : :
138 : : // TODO(F1)
139 : 0 : return uno::Sequence< double >();
140 : : }
141 : :
142 : 0 : uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException)
143 : : {
144 : 0 : SolarMutexGuard aGuard;
145 : :
146 : : // TODO(F1)
147 : 0 : return uno::Sequence< beans::PropertyValue >();
148 : : }
149 : :
150 : : #define IMPLEMENTATION_NAME "CairoCanvas::CanvasFont"
151 : : #define SERVICE_NAME "com.sun.star.rendering.CanvasFont"
152 : :
153 : 0 : ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException )
154 : : {
155 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
156 : : }
157 : :
158 : 0 : sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
159 : : {
160 : 0 : return ServiceName == SERVICE_NAME;
161 : : }
162 : :
163 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException )
164 : : {
165 : 0 : uno::Sequence< ::rtl::OUString > aRet(1);
166 : 0 : aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
167 : :
168 : 0 : return aRet;
169 : : }
170 : :
171 : 0 : ::Font CanvasFont::getVCLFont() const
172 : : {
173 : 0 : return *maFont;
174 : : }
175 : 0 : }
176 : :
177 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|