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 <rtl/math.hxx> 30cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 31cdf0e10cSrcweir #include <i18npool/mslangid.hxx> 32cdf0e10cSrcweir #include <vcl/metric.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <com/sun/star/rendering/PanoseProportion.hpp> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include "canvasfont.hxx" 37cdf0e10cSrcweir #include "textlayout.hxx" 38cdf0e10cSrcweir 39cdf0e10cSrcweir using namespace ::com::sun::star; 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir namespace vclcanvas 43cdf0e10cSrcweir { CanvasFont(const rendering::FontRequest & rFontRequest,const uno::Sequence<beans::PropertyValue> &,const geometry::Matrix2D & rFontMatrix,rendering::XGraphicDevice & rDevice,const OutDevProviderSharedPtr & rOutDevProvider)44cdf0e10cSrcweir CanvasFont::CanvasFont( const rendering::FontRequest& rFontRequest, 45cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& , 46cdf0e10cSrcweir const geometry::Matrix2D& rFontMatrix, 47cdf0e10cSrcweir rendering::XGraphicDevice& rDevice, 48cdf0e10cSrcweir const OutDevProviderSharedPtr& rOutDevProvider ) : 49cdf0e10cSrcweir CanvasFont_Base( m_aMutex ), 50cdf0e10cSrcweir maFont( Font( rFontRequest.FontDescription.FamilyName, 51cdf0e10cSrcweir rFontRequest.FontDescription.StyleName, 52cdf0e10cSrcweir Size( 0, ::basegfx::fround(rFontRequest.CellSize) ) ) ), 53cdf0e10cSrcweir maFontRequest( rFontRequest ), 54cdf0e10cSrcweir mpRefDevice( &rDevice ), 55cdf0e10cSrcweir mpOutDevProvider( rOutDevProvider ) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir maFont->SetAlign( ALIGN_BASELINE ); 58cdf0e10cSrcweir maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==com::sun::star::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE ); 59cdf0e10cSrcweir maFont->SetVertical( (rFontRequest.FontDescription.IsVertical==com::sun::star::util::TriState_YES) ? sal_True : sal_False ); 60cdf0e10cSrcweir 61cdf0e10cSrcweir // TODO(F2): improve panose->vclenum conversion 62cdf0e10cSrcweir maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) ); 63cdf0e10cSrcweir maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL ); 64cdf0e10cSrcweir maFont->SetPitch( 65cdf0e10cSrcweir rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED 66cdf0e10cSrcweir ? PITCH_FIXED : PITCH_VARIABLE); 67cdf0e10cSrcweir 68cdf0e10cSrcweir maFont->SetLanguage(MsLangId::convertLocaleToLanguage(rFontRequest.Locale)); 69cdf0e10cSrcweir 70cdf0e10cSrcweir // adjust to stretched/shrinked font 71cdf0e10cSrcweir if( !::rtl::math::approxEqual( rFontMatrix.m00, rFontMatrix.m11) ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir OutputDevice& rOutDev( rOutDevProvider->getOutDev() ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir const bool bOldMapState( rOutDev.IsMapModeEnabled() ); 76cdf0e10cSrcweir rOutDev.EnableMapMode(sal_False); 77cdf0e10cSrcweir 78cdf0e10cSrcweir const Size aSize = rOutDev.GetFontMetric( *maFont ).GetSize(); 79cdf0e10cSrcweir 80cdf0e10cSrcweir const double fDividend( rFontMatrix.m10 + rFontMatrix.m11 ); 81cdf0e10cSrcweir double fStretch = (rFontMatrix.m00 + rFontMatrix.m01); 82cdf0e10cSrcweir 83cdf0e10cSrcweir if( !::basegfx::fTools::equalZero( fDividend) ) 84cdf0e10cSrcweir fStretch /= fDividend; 85cdf0e10cSrcweir 86cdf0e10cSrcweir const long nNewWidth = ::basegfx::fround( aSize.Width() * fStretch ); 87cdf0e10cSrcweir 88cdf0e10cSrcweir maFont->SetWidth( nNewWidth ); 89cdf0e10cSrcweir 90cdf0e10cSrcweir rOutDev.EnableMapMode(bOldMapState); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir } 93cdf0e10cSrcweir disposing()94cdf0e10cSrcweir void SAL_CALL CanvasFont::disposing() 95cdf0e10cSrcweir { 96cdf0e10cSrcweir tools::LocalGuard aGuard; 97cdf0e10cSrcweir 98cdf0e10cSrcweir mpOutDevProvider.reset(); 99cdf0e10cSrcweir mpRefDevice.clear(); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir createTextLayout(const rendering::StringContext & aText,sal_Int8 nDirection,sal_Int64 nRandomSeed)102cdf0e10cSrcweir uno::Reference< rendering::XTextLayout > SAL_CALL CanvasFont::createTextLayout( const rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 nRandomSeed ) throw (uno::RuntimeException) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir tools::LocalGuard aGuard; 105cdf0e10cSrcweir 106cdf0e10cSrcweir if( !mpRefDevice.is() ) 107cdf0e10cSrcweir return uno::Reference< rendering::XTextLayout >(); // we're disposed 108cdf0e10cSrcweir 109cdf0e10cSrcweir return new TextLayout( aText, 110cdf0e10cSrcweir nDirection, 111cdf0e10cSrcweir nRandomSeed, 112cdf0e10cSrcweir Reference( this ), 113cdf0e10cSrcweir mpRefDevice, 114cdf0e10cSrcweir mpOutDevProvider); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir getFontRequest()117cdf0e10cSrcweir rendering::FontRequest SAL_CALL CanvasFont::getFontRequest( ) throw (uno::RuntimeException) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir tools::LocalGuard aGuard; 120cdf0e10cSrcweir 121cdf0e10cSrcweir return maFontRequest; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir getFontMetrics()124cdf0e10cSrcweir rendering::FontMetrics SAL_CALL CanvasFont::getFontMetrics( ) throw (uno::RuntimeException) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir tools::LocalGuard aGuard; 127cdf0e10cSrcweir 128cdf0e10cSrcweir OutputDevice& rOutDev = mpOutDevProvider->getOutDev(); 129cdf0e10cSrcweir VirtualDevice aVDev( rOutDev ); 130cdf0e10cSrcweir aVDev.SetFont(getVCLFont()); 131cdf0e10cSrcweir const ::FontMetric& aMetric( aVDev.GetFontMetric() ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir return rendering::FontMetrics( 134cdf0e10cSrcweir aMetric.GetAscent(), 135cdf0e10cSrcweir aMetric.GetDescent(), 136cdf0e10cSrcweir aMetric.GetIntLeading(), 137cdf0e10cSrcweir aMetric.GetExtLeading(), 138cdf0e10cSrcweir 0, 139cdf0e10cSrcweir aMetric.GetDescent() / 2.0, 140cdf0e10cSrcweir aMetric.GetAscent() / 2.0); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir getAvailableSizes()143cdf0e10cSrcweir uno::Sequence< double > SAL_CALL CanvasFont::getAvailableSizes( ) throw (uno::RuntimeException) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir tools::LocalGuard aGuard; 146cdf0e10cSrcweir 147cdf0e10cSrcweir // TODO(F1) 148cdf0e10cSrcweir return uno::Sequence< double >(); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir getExtraFontProperties()151cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > SAL_CALL CanvasFont::getExtraFontProperties( ) throw (uno::RuntimeException) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir tools::LocalGuard aGuard; 154cdf0e10cSrcweir 155cdf0e10cSrcweir // TODO(F1) 156cdf0e10cSrcweir return uno::Sequence< beans::PropertyValue >(); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir #define IMPLEMENTATION_NAME "VCLCanvas::CanvasFont" 160cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.rendering.CanvasFont" 161cdf0e10cSrcweir getImplementationName()162cdf0e10cSrcweir ::rtl::OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME ) ); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir supportsService(const::rtl::OUString & ServiceName)167cdf0e10cSrcweir sal_Bool SAL_CALL CanvasFont::supportsService( const ::rtl::OUString& ServiceName ) throw( uno::RuntimeException ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir getSupportedServiceNames()172cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL CanvasFont::getSupportedServiceNames() throw( uno::RuntimeException ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet(1); 175cdf0e10cSrcweir aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 176cdf0e10cSrcweir 177cdf0e10cSrcweir return aRet; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir getVCLFont() const180cdf0e10cSrcweir ::Font CanvasFont::getVCLFont() const 181cdf0e10cSrcweir { 182cdf0e10cSrcweir return *maFont; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir } 185