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