LCOV - code coverage report
Current view: top level - canvas/source/vcl - canvasfont.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 66 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <canvas/debug.hxx>
      22             : 
      23             : #include <rtl/math.hxx>
      24             : #include <basegfx/numeric/ftools.hxx>
      25             : #include <i18nlangtag/languagetag.hxx>
      26             : #include <vcl/metric.hxx>
      27             : 
      28             : #include <com/sun/star/rendering/PanoseProportion.hpp>
      29             : #include <cppuhelper/supportsservice.hxx>
      30             : 
      31             : #include "canvasfont.hxx"
      32             : #include "textlayout.hxx"
      33             : 
      34             : using namespace ::com::sun::star;
      35             : 
      36             : 
      37             : namespace vclcanvas
      38             : {
      39           0 :     CanvasFont::CanvasFont( const rendering::FontRequest&                   rFontRequest,
      40             :                             const uno::Sequence< beans::PropertyValue >&    ,
      41             :                             const geometry::Matrix2D&                       rFontMatrix,
      42             :                             rendering::XGraphicDevice&                      rDevice,
      43             :                             const OutDevProviderSharedPtr&                  rOutDevProvider ) :
      44             :         CanvasFont_Base( m_aMutex ),
      45             :         maFont( vcl::Font( rFontRequest.FontDescription.FamilyName,
      46             :                       rFontRequest.FontDescription.StyleName,
      47           0 :                       Size( 0, ::basegfx::fround(rFontRequest.CellSize) ) ) ),
      48             :         maFontRequest( rFontRequest ),
      49             :         mpRefDevice( &rDevice ),
      50           0 :         mpOutDevProvider( rOutDevProvider )
      51             :     {
      52           0 :         maFont->SetAlign( ALIGN_BASELINE );
      53           0 :         maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==com::sun::star::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
      54           0 :         maFont->SetVertical( rFontRequest.FontDescription.IsVertical==com::sun::star::util::TriState_YES );
      55             : 
      56             :         // TODO(F2): improve panose->vclenum conversion
      57           0 :         maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
      58           0 :         maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL );
      59             :         maFont->SetPitch(
      60           0 :                 rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED
      61           0 :                     ? PITCH_FIXED : PITCH_VARIABLE);
      62             : 
      63           0 :         maFont->SetLanguage( LanguageTag::convertToLanguageType( rFontRequest.Locale, false));
      64             : 
      65             :         // adjust to stretched/shrunk font
      66           0 :         if( !::rtl::math::approxEqual( rFontMatrix.m00, rFontMatrix.m11) )
      67             :         {
      68           0 :             OutputDevice& rOutDev( rOutDevProvider->getOutDev() );
      69             : 
      70           0 :             const bool bOldMapState( rOutDev.IsMapModeEnabled() );
      71           0 :             rOutDev.EnableMapMode(false);
      72             : 
      73           0 :             const Size aSize = rOutDev.GetFontMetric( *maFont ).GetSize();
      74             : 
      75           0 :             const double fDividend( rFontMatrix.m10 + rFontMatrix.m11 );
      76           0 :             double fStretch = (rFontMatrix.m00 + rFontMatrix.m01);
      77             : 
      78           0 :             if( !::basegfx::fTools::equalZero( fDividend) )
      79           0 :                 fStretch /= fDividend;
      80             : 
      81           0 :             const long nNewWidth = ::basegfx::fround( aSize.Width() * fStretch );
      82             : 
      83           0 :             maFont->SetWidth( nNewWidth );
      84             : 
      85           0 :             rOutDev.EnableMapMode(bOldMapState);
      86             :         }
      87           0 :     }
      88             : 
      89           0 :     void SAL_CALL CanvasFont::disposing()
      90             :     {
      91           0 :         SolarMutexGuard aGuard;
      92             : 
      93           0 :         mpOutDevProvider.reset();
      94           0 :         mpRefDevice.clear();
      95           0 :     }
      96             : 
      97           0 :     uno::Reference< rendering::XTextLayout > SAL_CALL  CanvasFont::createTextLayout( const rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 nRandomSeed ) throw (uno::RuntimeException, std::exception)
      98             :     {
      99           0 :         SolarMutexGuard aGuard;
     100             : 
     101           0 :         if( !mpRefDevice.is() )
     102           0 :             return uno::Reference< rendering::XTextLayout >(); // we're disposed
     103             : 
     104             :         return new TextLayout( aText,
     105             :                                nDirection,
     106             :                                nRandomSeed,
     107             :                                Reference( this ),
     108             :                                mpRefDevice,
     109           0 :                                mpOutDevProvider);
     110             :     }
     111             : 
     112           0 :     rendering::FontRequest SAL_CALL  CanvasFont::getFontRequest(  ) throw (uno::RuntimeException, std::exception)
     113             :     {
     114           0 :         SolarMutexGuard aGuard;
     115             : 
     116           0 :         return maFontRequest;
     117             :     }
     118             : 
     119           0 :     rendering::FontMetrics SAL_CALL  CanvasFont::getFontMetrics(  ) throw (uno::RuntimeException, std::exception)
     120             :     {
     121           0 :         SolarMutexGuard aGuard;
     122             : 
     123           0 :         OutputDevice& rOutDev = mpOutDevProvider->getOutDev();
     124           0 :         ScopedVclPtrInstance< VirtualDevice > pVDev( rOutDev );
     125           0 :         pVDev->SetFont(getVCLFont());
     126           0 :         const ::FontMetric& aMetric( pVDev->GetFontMetric() );
     127             : 
     128             :         return rendering::FontMetrics(
     129           0 :             aMetric.GetAscent(),
     130           0 :             aMetric.GetDescent(),
     131           0 :             aMetric.GetIntLeading(),
     132           0 :             aMetric.GetExtLeading(),
     133             :             0,
     134           0 :             aMetric.GetDescent() / 2.0,
     135           0 :             aMetric.GetAscent() / 2.0);
     136             :     }
     137             : 
     138           0 :     uno::Sequence< double > SAL_CALL  CanvasFont::getAvailableSizes(  ) throw (uno::RuntimeException, std::exception)
     139             :     {
     140           0 :         SolarMutexGuard aGuard;
     141             : 
     142             :         // TODO(F1)
     143           0 :         return uno::Sequence< double >();
     144             :     }
     145             : 
     146           0 :     uno::Sequence< beans::PropertyValue > SAL_CALL  CanvasFont::getExtraFontProperties(  ) throw (uno::RuntimeException, std::exception)
     147             :     {
     148           0 :         SolarMutexGuard aGuard;
     149             : 
     150             :         // TODO(F1)
     151           0 :         return uno::Sequence< beans::PropertyValue >();
     152             :     }
     153             : 
     154           0 :     OUString SAL_CALL CanvasFont::getImplementationName() throw( uno::RuntimeException, std::exception )
     155             :     {
     156           0 :         return OUString( "VCLCanvas::CanvasFont" );
     157             :     }
     158             : 
     159           0 :     sal_Bool SAL_CALL CanvasFont::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException, std::exception )
     160             :     {
     161           0 :         return cppu::supportsService( this, ServiceName );
     162             :     }
     163             : 
     164           0 :     uno::Sequence< OUString > SAL_CALL CanvasFont::getSupportedServiceNames()  throw( uno::RuntimeException, std::exception )
     165             :     {
     166           0 :         uno::Sequence< OUString > aRet(1);
     167           0 :         aRet[0] = "com.sun.star.rendering.CanvasFont";
     168             : 
     169           0 :         return aRet;
     170             :     }
     171             : 
     172           0 :     vcl::Font CanvasFont::getVCLFont() const
     173             :     {
     174           0 :         return *maFont;
     175             :     }
     176           0 : }
     177             : 
     178             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11