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