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 : :
30 : : #include <canvas/debug.hxx>
31 : :
32 : : #include <rtl/math.hxx>
33 : : #include <basegfx/numeric/ftools.hxx>
34 : : #include <i18npool/mslangid.hxx>
35 : : #include <vcl/metric.hxx>
36 : :
37 : : #include <com/sun/star/rendering/PanoseProportion.hpp>
38 : :
39 : : #include "canvasfont.hxx"
40 : : #include "textlayout.hxx"
41 : :
42 : : using namespace ::com::sun::star;
43 : :
44 : :
45 : : namespace vclcanvas
46 : : {
47 : 0 : CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest,
48 : : const uno::Sequence< beans::PropertyValue >& ,
49 : : const geometry::Matrix2D& rFontMatrix,
50 : : rendering::XGraphicDevice& rDevice,
51 : : const OutDevProviderSharedPtr& rOutDevProvider ) :
52 : : CanvasFont_Base( m_aMutex ),
53 : : maFont( Font( rFontRequest.FontDescription.FamilyName,
54 : : rFontRequest.FontDescription.StyleName,
55 : : Size( 0, ::basegfx::fround(rFontRequest.CellSize) ) ) ),
56 : : maFontRequest( rFontRequest ),
57 : : mpRefDevice( &rDevice ),
58 : 0 : mpOutDevProvider( rOutDevProvider )
59 : : {
60 : 0 : maFont->SetAlign( ALIGN_BASELINE );
61 : 0 : maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==com::sun::star::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
62 : 0 : maFont->SetVertical( (rFontRequest.FontDescription.IsVertical==com::sun::star::util::TriState_YES) ? sal_True : sal_False );
63 : :
64 : : // TODO(F2): improve panose->vclenum conversion
65 : 0 : maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
66 : 0 : maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL );
67 : : maFont->SetPitch(
68 : : rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED
69 : 0 : ? PITCH_FIXED : PITCH_VARIABLE);
70 : :
71 : 0 : maFont->SetLanguage(MsLangId::convertLocaleToLanguage(rFontRequest.Locale));
72 : :
73 : : // adjust to stretched/shrinked font
74 : 0 : if( !::rtl::math::approxEqual( rFontMatrix.m00, rFontMatrix.m11) )
75 : : {
76 : 0 : OutputDevice& rOutDev( rOutDevProvider->getOutDev() );
77 : :
78 : 0 : const bool bOldMapState( rOutDev.IsMapModeEnabled() );
79 : 0 : rOutDev.EnableMapMode(sal_False);
80 : :
81 : 0 : const Size aSize = rOutDev.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 : rOutDev.EnableMapMode(bOldMapState);
94 : : }
95 : 0 : }
96 : :
97 : 0 : void SAL_CALL CanvasFont::disposing()
98 : : {
99 : 0 : SolarMutexGuard aGuard;
100 : :
101 : 0 : mpOutDevProvider.reset();
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 : : mpRefDevice,
117 : 0 : mpOutDevProvider);
118 : : }
119 : :
120 : 0 : rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException)
121 : : {
122 : 0 : SolarMutexGuard aGuard;
123 : :
124 : 0 : return maFontRequest;
125 : : }
126 : :
127 : 0 : rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException)
128 : : {
129 : 0 : SolarMutexGuard aGuard;
130 : :
131 : 0 : OutputDevice& rOutDev = mpOutDevProvider->getOutDev();
132 : 0 : VirtualDevice aVDev( rOutDev );
133 : 0 : aVDev.SetFont(getVCLFont());
134 : 0 : const ::FontMetric& aMetric( aVDev.GetFontMetric() );
135 : :
136 : : return rendering::FontMetrics(
137 : 0 : aMetric.GetAscent(),
138 : 0 : aMetric.GetDescent(),
139 : 0 : aMetric.GetIntLeading(),
140 : 0 : aMetric.GetExtLeading(),
141 : : 0,
142 : 0 : aMetric.GetDescent() / 2.0,
143 : 0 : aMetric.GetAscent() / 2.0);
144 : : }
145 : :
146 : 0 : uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException)
147 : : {
148 : 0 : SolarMutexGuard aGuard;
149 : :
150 : : // TODO(F1)
151 : 0 : return uno::Sequence< double >();
152 : : }
153 : :
154 : 0 : uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException)
155 : : {
156 : 0 : SolarMutexGuard aGuard;
157 : :
158 : : // TODO(F1)
159 : 0 : return uno::Sequence< beans::PropertyValue >();
160 : : }
161 : :
162 : : #define IMPLEMENTATION_NAME "VCLCanvas::CanvasFont"
163 : : #define SERVICE_NAME "com.sun.star.rendering.CanvasFont"
164 : :
165 : 0 : ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException )
166 : : {
167 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
168 : : }
169 : :
170 : 0 : sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
171 : : {
172 : 0 : return ServiceName == SERVICE_NAME;
173 : : }
174 : :
175 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException )
176 : : {
177 : 0 : uno::Sequence< ::rtl::OUString > aRet(1);
178 : 0 : aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
179 : :
180 : 0 : return aRet;
181 : : }
182 : :
183 : 0 : ::Font CanvasFont::getVCLFont() const
184 : : {
185 : 0 : return *maFont;
186 : : }
187 : 0 : }
188 : :
189 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|