LCOV - code coverage report
Current view: top level - toolkit/source/awt - vclxfont.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 34 93 36.6 %
Date: 2014-04-11 Functions: 7 19 36.8 %
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             : #include <string.h>
      21             : 
      22             : #include <toolkit/awt/vclxfont.hxx>
      23             : #include <toolkit/helper/vclunohelper.hxx>
      24             : #include <toolkit/helper/macros.hxx>
      25             : #include <cppuhelper/typeprovider.hxx>
      26             : #include <rtl/uuid.h>
      27             : #include <rtl/ustring.h>
      28             : 
      29             : #include <vcl/outdev.hxx>
      30             : 
      31             : 
      32             : //  class VCLXFont
      33             : 
      34         250 : VCLXFont::VCLXFont()
      35             : {
      36         250 :     mpFontMetric = NULL;
      37         250 : }
      38             : 
      39         750 : VCLXFont::~VCLXFont()
      40             : {
      41         250 :     delete mpFontMetric;
      42         500 : }
      43             : 
      44         250 : void VCLXFont::Init( ::com::sun::star::awt::XDevice& rxDev, const Font& rFont )
      45             : {
      46         250 :     mxDevice = &rxDev;
      47             : 
      48         250 :     delete mpFontMetric;
      49         250 :     mpFontMetric = NULL;
      50             : 
      51         250 :     maFont = rFont;
      52         250 : }
      53             : 
      54           0 : bool VCLXFont::ImplAssertValidFontMetric()
      55             : {
      56           0 :     if ( !mpFontMetric && mxDevice.is() )
      57             :     {
      58           0 :         OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
      59           0 :         if ( pOutDev )
      60             :         {
      61           0 :             Font aOldFont = pOutDev->GetFont();
      62           0 :             pOutDev->SetFont( maFont );
      63           0 :             mpFontMetric = new FontMetric( pOutDev->GetFontMetric() );
      64           0 :             pOutDev->SetFont( aOldFont );
      65             :         }
      66             :     }
      67           0 :     return mpFontMetric ? sal_True : sal_False;
      68             : }
      69             : 
      70             : 
      71             : // ::com::sun::star::uno::XInterface
      72         206 : ::com::sun::star::uno::Any VCLXFont::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception)
      73             : {
      74             :     ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
      75             :                                         (static_cast< ::com::sun::star::awt::XFont* >(this)),
      76             :                                         (static_cast< ::com::sun::star::awt::XFont2* >(this)),
      77             :                                         (static_cast< ::com::sun::star::lang::XUnoTunnel* >(this)),
      78         206 :                                         (static_cast< ::com::sun::star::lang::XTypeProvider* >(this)) );
      79         206 :     return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
      80             : }
      81             : 
      82             : // ::com::sun::star::lang::XUnoTunnel
      83           0 : IMPL_XUNOTUNNEL( VCLXFont )
      84             : 
      85             : // ::com::sun::star::lang::XTypeProvider
      86           0 : IMPL_XTYPEPROVIDER_START( VCLXFont )
      87           0 :     getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont2>* ) NULL )
      88           0 : IMPL_XTYPEPROVIDER_END
      89             : 
      90             : 
      91           0 : ::com::sun::star::awt::FontDescriptor VCLXFont::getFontDescriptor(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
      92             : {
      93           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
      94             : 
      95           0 :     return VCLUnoHelper::CreateFontDescriptor( maFont );
      96             : 
      97             : }
      98             : 
      99           0 : ::com::sun::star::awt::SimpleFontMetric VCLXFont::getFontMetric(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     100             : {
     101           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     102             : 
     103           0 :     ::com::sun::star::awt::SimpleFontMetric aFM;
     104           0 :     if ( ImplAssertValidFontMetric() )
     105           0 :         aFM = VCLUnoHelper::CreateFontMetric( *mpFontMetric );
     106           0 :     return aFM;
     107             : }
     108             : 
     109         484 : sal_Int16 VCLXFont::getCharWidth( sal_Unicode c ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     110             : {
     111         484 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     112             : 
     113         484 :     sal_Int16 nRet = -1;
     114         484 :     OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
     115         484 :     if ( pOutDev )
     116             :     {
     117         484 :         Font aOldFont = pOutDev->GetFont();
     118         484 :         pOutDev->SetFont( maFont );
     119             : 
     120             :         nRet = sal::static_int_cast< sal_Int16 >(
     121         484 :             pOutDev->GetTextWidth( OUString(c) ));
     122             : 
     123         484 :         pOutDev->SetFont( aOldFont );
     124             :     }
     125         484 :     return nRet;
     126             : }
     127             : 
     128           0 : ::com::sun::star::uno::Sequence< sal_Int16 > VCLXFont::getCharWidths( sal_Unicode nFirst, sal_Unicode nLast ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     129             : {
     130           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     131             : 
     132           0 :     ::com::sun::star::uno::Sequence<sal_Int16> aSeq;
     133           0 :     OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
     134           0 :     if ( pOutDev )
     135             :     {
     136           0 :         Font aOldFont = pOutDev->GetFont();
     137           0 :         pOutDev->SetFont( maFont );
     138             : 
     139           0 :         sal_Int16 nCount = nLast-nFirst + 1;
     140           0 :         aSeq = ::com::sun::star::uno::Sequence<sal_Int16>( nCount );
     141           0 :         for ( sal_uInt16 n = 0; n < nCount; n++ )
     142             :         {
     143           0 :             aSeq.getArray()[n] = sal::static_int_cast< sal_Int16 >(
     144             :                 pOutDev->GetTextWidth(
     145           0 :                     OUString(static_cast< sal_Unicode >(nFirst+n)) ));
     146             :         }
     147             : 
     148           0 :         pOutDev->SetFont( aOldFont );
     149             :     }
     150           0 :     return aSeq;
     151             : }
     152             : 
     153           0 : sal_Int32 VCLXFont::getStringWidth( const OUString& str ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     154             : {
     155           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     156             : 
     157           0 :     sal_Int32 nRet = -1;
     158           0 :     OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
     159           0 :     if ( pOutDev )
     160             :     {
     161           0 :         Font aOldFont = pOutDev->GetFont();
     162           0 :         pOutDev->SetFont( maFont );
     163           0 :         nRet = pOutDev->GetTextWidth( str );
     164           0 :         pOutDev->SetFont( aOldFont );
     165             :     }
     166           0 :     return nRet;
     167             : }
     168             : 
     169           0 : sal_Int32 VCLXFont::getStringWidthArray( const OUString& str, ::com::sun::star::uno::Sequence< sal_Int32 >& rDXArray ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     170             : {
     171           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     172             : 
     173           0 :     sal_Int32 nRet = -1;
     174           0 :     OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
     175           0 :     if ( pOutDev )
     176             :     {
     177           0 :         Font aOldFont = pOutDev->GetFont();
     178           0 :         pOutDev->SetFont( maFont );
     179           0 :         rDXArray = ::com::sun::star::uno::Sequence<sal_Int32>( str.getLength() );
     180           0 :         nRet = pOutDev->GetTextArray( str, rDXArray.getArray() );
     181           0 :         pOutDev->SetFont( aOldFont );
     182             :     }
     183           0 :     return nRet;
     184             : }
     185             : 
     186           0 : void VCLXFont::getKernPairs( ::com::sun::star::uno::Sequence< sal_Unicode >& /*rnChars1*/, ::com::sun::star::uno::Sequence< sal_Unicode >& /*rnChars2*/, ::com::sun::star::uno::Sequence< sal_Int16 >& /*rnKerns*/ ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     187             : {
     188             :     // NOTE: this empty method is just used for keeping the related UNO-API stable
     189           0 : }
     190             : 
     191             : // ::com::sun::star::awt::XFont2
     192        3192 : sal_Bool VCLXFont::hasGlyphs( const OUString& aText )
     193             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     194             : {
     195        3192 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     196             : 
     197        3192 :     OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
     198        3192 :     if ( pOutDev )
     199             :     {
     200        3192 :         OUString aStr( aText );
     201        3192 :         if ( pOutDev->HasGlyphs( maFont, aStr ) == -1 )
     202             :         {
     203         308 :             return sal_True;
     204        2884 :         }
     205             :     }
     206             : 
     207        2884 :     return sal_False;
     208             : }
     209             : 
     210             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10