1*25ea7f45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*25ea7f45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*25ea7f45SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*25ea7f45SAndrew Rist * distributed with this work for additional information 6*25ea7f45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*25ea7f45SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*25ea7f45SAndrew Rist * "License"); you may not use this file except in compliance 9*25ea7f45SAndrew Rist * with the License. You may obtain a copy of the License at 10*25ea7f45SAndrew Rist * 11*25ea7f45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*25ea7f45SAndrew Rist * 13*25ea7f45SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*25ea7f45SAndrew Rist * software distributed under the License is distributed on an 15*25ea7f45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*25ea7f45SAndrew Rist * KIND, either express or implied. See the License for the 17*25ea7f45SAndrew Rist * specific language governing permissions and limitations 18*25ea7f45SAndrew Rist * under the License. 19*25ea7f45SAndrew Rist * 20*25ea7f45SAndrew Rist *************************************************************/ 21*25ea7f45SAndrew Rist 22*25ea7f45SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_canvas.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <canvas/debug.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <com/sun/star/rendering/PanoseProportion.hpp> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <rtl/math.hxx> 32cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <vcl/metric.hxx> 35cdf0e10cSrcweir #include <i18npool/mslangid.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include "cairo_canvasfont.hxx" 38cdf0e10cSrcweir #include "cairo_textlayout.hxx" 39cdf0e10cSrcweir 40cdf0e10cSrcweir using namespace ::com::sun::star; 41cdf0e10cSrcweir 42cdf0e10cSrcweir namespace cairocanvas 43cdf0e10cSrcweir { 44cdf0e10cSrcweir namespace 45cdf0e10cSrcweir { 46cdf0e10cSrcweir // Little helper to encapsulate locking into policy class 47cdf0e10cSrcweir class LocalGuard 48cdf0e10cSrcweir { 49cdf0e10cSrcweir public: LocalGuard()50cdf0e10cSrcweir LocalGuard() : 51cdf0e10cSrcweir aGuard( Application::GetSolarMutex() ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir /// To be compatible with CanvasBase mutex concept LocalGuard(const::osl::Mutex &)56cdf0e10cSrcweir LocalGuard( const ::osl::Mutex& ) : 57cdf0e10cSrcweir aGuard( Application::GetSolarMutex() ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir private: 62cdf0e10cSrcweir ::vos::OGuard aGuard; 63cdf0e10cSrcweir }; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir CanvasFont(const rendering::FontRequest & rFontRequest,const uno::Sequence<beans::PropertyValue> &,const geometry::Matrix2D & rFontMatrix,const SurfaceProviderRef & rDevice)66cdf0e10cSrcweir CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest, 67cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& /*rExtraFontProperties*/, 68cdf0e10cSrcweir const geometry::Matrix2D& rFontMatrix, 69cdf0e10cSrcweir const SurfaceProviderRef& rDevice ) : 70cdf0e10cSrcweir CanvasFont_Base( m_aMutex ), 71cdf0e10cSrcweir maFont( Font( rFontRequest.FontDescription.FamilyName, 72cdf0e10cSrcweir rFontRequest.FontDescription.StyleName, 73cdf0e10cSrcweir Size( 0, ::basegfx::fround(rFontRequest.CellSize) ) ) ), 74cdf0e10cSrcweir maFontRequest( rFontRequest ), 75cdf0e10cSrcweir mpRefDevice( rDevice ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir maFont->SetAlign( ALIGN_BASELINE ); 78cdf0e10cSrcweir maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==com::sun::star::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE ); 79cdf0e10cSrcweir maFont->SetVertical( (rFontRequest.FontDescription.IsVertical==com::sun::star::util::TriState_YES) ? sal_True : sal_False ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir // TODO(F2): improve panose->vclenum conversion 82cdf0e10cSrcweir maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) ); 83cdf0e10cSrcweir maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL ); 84cdf0e10cSrcweir maFont->SetPitch( 85cdf0e10cSrcweir rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED 86cdf0e10cSrcweir ? PITCH_FIXED : PITCH_VARIABLE); 87cdf0e10cSrcweir 88cdf0e10cSrcweir maFont->SetLanguage(MsLangId::convertLocaleToLanguage(rFontRequest.Locale)); 89cdf0e10cSrcweir 90cdf0e10cSrcweir // adjust to stretched/shrinked font 91cdf0e10cSrcweir if( !::rtl::math::approxEqual( rFontMatrix.m00, rFontMatrix.m11) ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir OutputDevice* pOutDev( mpRefDevice->getOutputDevice() ); 94cdf0e10cSrcweir 95cdf0e10cSrcweir if( pOutDev ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir const bool bOldMapState( pOutDev->IsMapModeEnabled() ); 98cdf0e10cSrcweir pOutDev->EnableMapMode(sal_False); 99cdf0e10cSrcweir 100cdf0e10cSrcweir const Size aSize = pOutDev->GetFontMetric( *maFont ).GetSize(); 101cdf0e10cSrcweir 102cdf0e10cSrcweir const double fDividend( rFontMatrix.m10 + rFontMatrix.m11 ); 103cdf0e10cSrcweir double fStretch = (rFontMatrix.m00 + rFontMatrix.m01); 104cdf0e10cSrcweir 105cdf0e10cSrcweir if( !::basegfx::fTools::equalZero( fDividend) ) 106cdf0e10cSrcweir fStretch /= fDividend; 107cdf0e10cSrcweir 108cdf0e10cSrcweir const long nNewWidth = ::basegfx::fround( aSize.Width() * fStretch ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir maFont->SetWidth( nNewWidth ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir pOutDev->EnableMapMode(bOldMapState); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir } 115cdf0e10cSrcweir } 116cdf0e10cSrcweir disposing()117cdf0e10cSrcweir void SAL_CALL CanvasFont::disposing() 118cdf0e10cSrcweir { 119cdf0e10cSrcweir LocalGuard aGuard; 120cdf0e10cSrcweir 121cdf0e10cSrcweir mpRefDevice.clear(); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir createTextLayout(const rendering::StringContext & aText,sal_Int8 nDirection,sal_Int64 nRandomSeed)124cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 nRandomSeed ) throw (uno::RuntimeException) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir LocalGuard aGuard; 127cdf0e10cSrcweir 128cdf0e10cSrcweir if( !mpRefDevice.is() ) 129cdf0e10cSrcweir return uno::Reference< rendering::XTextLayout >(); // we're disposed 130cdf0e10cSrcweir 131cdf0e10cSrcweir return new TextLayout( aText, 132cdf0e10cSrcweir nDirection, 133cdf0e10cSrcweir nRandomSeed, 134cdf0e10cSrcweir Reference( this ), 135cdf0e10cSrcweir mpRefDevice ); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir getFontRequest()138cdf0e10cSrcweir rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir LocalGuard aGuard; 141cdf0e10cSrcweir 142cdf0e10cSrcweir return maFontRequest; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir getFontMetrics()145cdf0e10cSrcweir rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir LocalGuard aGuard; 148cdf0e10cSrcweir 149cdf0e10cSrcweir // TODO(F1) 150cdf0e10cSrcweir return rendering::FontMetrics(); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir getAvailableSizes()153cdf0e10cSrcweir uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir LocalGuard aGuard; 156cdf0e10cSrcweir 157cdf0e10cSrcweir // TODO(F1) 158cdf0e10cSrcweir return uno::Sequence< double >(); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir getExtraFontProperties()161cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir LocalGuard aGuard; 164cdf0e10cSrcweir 165cdf0e10cSrcweir // TODO(F1) 166cdf0e10cSrcweir return uno::Sequence< beans::PropertyValue >(); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir #define IMPLEMENTATION_NAME "CairoCanvas::CanvasFont" 170cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.CanvasFont" 171cdf0e10cSrcweir getImplementationName()172cdf0e10cSrcweir ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir supportsService(const::rtl::OUString & ServiceName)177cdf0e10cSrcweir sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir getSupportedServiceNames()182cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(1); 185cdf0e10cSrcweir aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 186cdf0e10cSrcweir 187cdf0e10cSrcweir return aRet; 188cdf0e10cSrcweir } 189cdf0e10cSrcweir getVCLFont() const190cdf0e10cSrcweir ::Font CanvasFont::getVCLFont() const 191cdf0e10cSrcweir { 192cdf0e10cSrcweir return *maFont; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir } 195