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

Generated by: LCOV version 1.11