LCOV - code coverage report
Current view: top level - toolkit/source/awt - vclxfont.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 93 0.0 %
Date: 2014-04-14 Functions: 0 19 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             : #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           0 : VCLXFont::VCLXFont()
      35             : {
      36           0 :     mpFontMetric = NULL;
      37           0 : }
      38             : 
      39           0 : VCLXFont::~VCLXFont()
      40             : {
      41           0 :     delete mpFontMetric;
      42           0 : }
      43             : 
      44           0 : void VCLXFont::Init( ::com::sun::star::awt::XDevice& rxDev, const Font& rFont )
      45             : {
      46           0 :     mxDevice = &rxDev;
      47             : 
      48           0 :     delete mpFontMetric;
      49           0 :     mpFontMetric = NULL;
      50             : 
      51           0 :     maFont = rFont;
      52           0 : }
      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           0 : ::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           0 :                                         (static_cast< ::com::sun::star::lang::XTypeProvider* >(this)) );
      79           0 :     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           0 : sal_Int16 VCLXFont::getCharWidth( sal_Unicode c ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     110             : {
     111           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     112             : 
     113           0 :     sal_Int16 nRet = -1;
     114           0 :     OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
     115           0 :     if ( pOutDev )
     116             :     {
     117           0 :         Font aOldFont = pOutDev->GetFont();
     118           0 :         pOutDev->SetFont( maFont );
     119             : 
     120             :         nRet = sal::static_int_cast< sal_Int16 >(
     121           0 :             pOutDev->GetTextWidth( OUString(c) ));
     122             : 
     123           0 :         pOutDev->SetFont( aOldFont );
     124             :     }
     125           0 :     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           0 : sal_Bool VCLXFont::hasGlyphs( const OUString& aText )
     193             :     throw(::com::sun::star::uno::RuntimeException, std::exception)
     194             : {
     195           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     196             : 
     197           0 :     OutputDevice* pOutDev = VCLUnoHelper::GetOutputDevice( mxDevice );
     198           0 :     if ( pOutDev )
     199             :     {
     200           0 :         OUString aStr( aText );
     201           0 :         if ( pOutDev->HasGlyphs( maFont, aStr ) == -1 )
     202             :         {
     203           0 :             return sal_True;
     204           0 :         }
     205             :     }
     206             : 
     207           0 :     return sal_False;
     208             : }
     209             : 
     210             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10