update dev300-m58
[ooovba.git] / canvas / source / cairo / cairo_canvasfont.cxx
blob1762357403bd50ccffed0a758eda2ad591097896
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cairo_canvasfont.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <canvas/debug.hxx>
36 #include <rtl/math.hxx>
37 #include <basegfx/numeric/ftools.hxx>
39 #include <vcl/metric.hxx>
40 #include <i18npool/mslangid.hxx>
42 #include "cairo_canvasfont.hxx"
43 #include "cairo_textlayout.hxx"
45 using namespace ::com::sun::star;
47 namespace cairocanvas
49 namespace
51 // Little helper to encapsulate locking into policy class
52 class LocalGuard
54 public:
55 LocalGuard() :
56 aGuard( Application::GetSolarMutex() )
60 /// To be compatible with CanvasBase mutex concept
61 LocalGuard( const ::osl::Mutex& ) :
62 aGuard( Application::GetSolarMutex() )
66 private:
67 ::vos::OGuard aGuard;
68 };
71 CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest,
72 const uno::Sequence< beans::PropertyValue >& /*rExtraFontProperties*/,
73 const geometry::Matrix2D& rFontMatrix,
74 const SurfaceProviderRef& rDevice ) :
75 CanvasFont_Base( m_aMutex ),
76 maFont( Font( rFontRequest.FontDescription.FamilyName,
77 rFontRequest.FontDescription.StyleName,
78 Size( 0, ::basegfx::fround(rFontRequest.CellSize) ) ) ),
79 maFontRequest( rFontRequest ),
80 mpRefDevice( rDevice )
82 maFont->SetAlign( ALIGN_BASELINE );
83 maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==com::sun::star::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
84 maFont->SetVertical( (rFontRequest.FontDescription.IsVertical==com::sun::star::util::TriState_YES) ? TRUE : FALSE );
86 // TODO(F2): improve panose->vclenum conversion
87 maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
88 maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL );
90 maFont->SetLanguage(MsLangId::convertLocaleToLanguage(rFontRequest.Locale));
92 // adjust to stretched/shrinked font
93 if( !::rtl::math::approxEqual( rFontMatrix.m00, rFontMatrix.m11) )
95 OutputDevice* pOutDev( mpRefDevice->getOutputDevice() );
97 if( pOutDev )
99 const bool bOldMapState( pOutDev->IsMapModeEnabled() );
100 pOutDev->EnableMapMode(FALSE);
102 const Size aSize = pOutDev->GetFontMetric( *maFont ).GetSize();
104 const double fDividend( rFontMatrix.m10 + rFontMatrix.m11 );
105 double fStretch = (rFontMatrix.m00 + rFontMatrix.m01);
107 if( !::basegfx::fTools::equalZero( fDividend) )
108 fStretch /= fDividend;
110 const long nNewWidth = ::basegfx::fround( aSize.Width() * fStretch );
112 maFont->SetWidth( nNewWidth );
114 pOutDev->EnableMapMode(bOldMapState);
119 void SAL_CALL CanvasFont::disposing()
121 LocalGuard aGuard;
123 mpRefDevice.clear();
126 uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 nRandomSeed ) throw (uno::RuntimeException)
128 LocalGuard aGuard;
130 if( !mpRefDevice.is() )
131 return uno::Reference< rendering::XTextLayout >(); // we're disposed
133 return new TextLayout( aText,
134 nDirection,
135 nRandomSeed,
136 Reference( this ),
137 mpRefDevice );
140 rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException)
142 LocalGuard aGuard;
144 return maFontRequest;
147 rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException)
149 LocalGuard aGuard;
151 // TODO(F1)
152 return rendering::FontMetrics();
155 uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException)
157 LocalGuard aGuard;
159 // TODO(F1)
160 return uno::Sequence< double >();
163 uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException)
165 LocalGuard aGuard;
167 // TODO(F1)
168 return uno::Sequence< beans::PropertyValue >();
171 #define IMPLEMENTATION_NAME "CairoCanvas::CanvasFont"
172 #define SERVICE_NAME "com.sun.star.rendering.CanvasFont"
174 ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException )
176 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) );
179 sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException )
181 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
184 uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException )
186 uno::Sequence< ::rtl::OUString > aRet(1);
187 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
189 return aRet;
192 ::Font CanvasFont::getVCLFont() const
194 return *maFont;