LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vcl/source/components - fontident.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 81 3.7 %
Date: 2013-07-09 Functions: 3 13 23.1 %
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 "vcl/svapp.hxx"
      22             : #include "vcl/font.hxx"
      23             : 
      24             : #include "svdata.hxx"
      25             : 
      26             : #include <com/sun/star/lang/XServiceInfo.hpp>
      27             : #include <com/sun/star/beans/XMaterialHolder.hpp>
      28             : #include <com/sun/star/awt/FontDescriptor.hpp>
      29             : #include <com/sun/star/awt/FontFamily.hpp>
      30             : #include <com/sun/star/awt/FontPitch.hpp>
      31             : #include <com/sun/star/awt/FontWeight.hpp>
      32             : #include <com/sun/star/awt/FontSlant.hpp>
      33             : #include <com/sun/star/lang/XInitialization.hpp>
      34             : #include <com/sun/star/lang/DisposedException.hpp>
      35             : 
      36             : #include <cppuhelper/implbase3.hxx>
      37             : 
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::lang;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::com::sun::star::awt;
      42             : 
      43             : // -----------------------------------------------------------------------
      44             : 
      45             : namespace vcl
      46             : {
      47             : 
      48             : class FontIdentificator : public ::cppu::WeakAggImplHelper3< XMaterialHolder, XInitialization, XServiceInfo >
      49             : {
      50             :     Font        m_aFont;
      51             : public:
      52           0 : FontIdentificator() {}
      53             :     virtual ~FontIdentificator();
      54             : 
      55             : 
      56             :     // XServiceInfo
      57             :     virtual OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
      58             :     virtual ::sal_Bool SAL_CALL supportsService( const OUString& ) throw (RuntimeException);
      59             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
      60             : 
      61             :     // XInitialization
      62             :     virtual void SAL_CALL initialize( const Sequence< Any >& ) throw (Exception, RuntimeException);
      63             : 
      64             :     // XMaterialHolder
      65             :     virtual Any SAL_CALL getMaterial() throw(RuntimeException);
      66             : 
      67             : };
      68             : 
      69             : // --------------------------------------------------------------------
      70             : 
      71           0 : FontIdentificator::~FontIdentificator()
      72             : {
      73           0 : }
      74             : 
      75           0 : void SAL_CALL FontIdentificator::initialize( const Sequence<Any>& i_rArgs ) throw(Exception,RuntimeException)
      76             : {
      77           0 :     if( !ImplGetSVData() )
      78           0 :         return; // VCL not initialized
      79             : 
      80           0 :     sal_uInt32 nArgs = i_rArgs.getLength();
      81           0 :     const Any* pArgs = i_rArgs.getConstArray();
      82           0 :     Sequence< sal_Int8 > aFontBuf;
      83           0 :     for( sal_uInt32 i = 0; i < nArgs; i++ )
      84             :     {
      85           0 :         if( pArgs[i] >>= aFontBuf )
      86             :         {
      87           0 :             m_aFont = Font::identifyFont( aFontBuf.getConstArray(), aFontBuf.getLength() );
      88           0 :             break;
      89             :         }
      90           0 :     }
      91             : }
      92             : 
      93           0 : Any SAL_CALL FontIdentificator::getMaterial() throw(RuntimeException)
      94             : {
      95           0 :     if( !ImplGetSVData() )
      96           0 :         return Any(); // VCL not initialized
      97             : 
      98           0 :     FontDescriptor aFD;
      99           0 :     aFD.Name                = m_aFont.GetName();
     100           0 :     aFD.Height              = 0;
     101           0 :     aFD.Width               = 0;
     102           0 :     aFD.StyleName           = m_aFont.GetStyleName();
     103           0 :     aFD.CharSet             = 0;
     104           0 :     aFD.CharacterWidth      = 0;
     105           0 :     aFD.Underline           = 0;
     106           0 :     aFD.Strikeout           = 0;
     107           0 :     aFD.Orientation         = 0;
     108           0 :     aFD.Kerning             = sal_False;
     109           0 :     aFD.WordLineMode        = sal_False;
     110           0 :     aFD.Type                = 0;
     111           0 :     switch( m_aFont.GetFamily() )
     112             :     {
     113           0 :     case FAMILY_DECORATIVE: aFD.Family = com::sun::star::awt::FontFamily::DECORATIVE;break;
     114           0 :     case FAMILY_MODERN: aFD.Family = com::sun::star::awt::FontFamily::MODERN;break;
     115           0 :     case FAMILY_ROMAN: aFD.Family = com::sun::star::awt::FontFamily::ROMAN;break;
     116           0 :     case FAMILY_SCRIPT: aFD.Family = com::sun::star::awt::FontFamily::SCRIPT;break;
     117           0 :     case FAMILY_SWISS: aFD.Family = com::sun::star::awt::FontFamily::SWISS;break;
     118           0 :     case FAMILY_SYSTEM: aFD.Family = com::sun::star::awt::FontFamily::SYSTEM;break;
     119             :     default:
     120           0 :         aFD.Family = com::sun::star::awt::FontFamily::DONTKNOW;
     121           0 :         break;
     122             :     }
     123           0 :     switch( m_aFont.GetPitch() )
     124             :     {
     125           0 :     case PITCH_VARIABLE: aFD.Pitch = com::sun::star::awt::FontPitch::VARIABLE;break;
     126           0 :     case PITCH_FIXED: aFD.Pitch = com::sun::star::awt::FontPitch::FIXED;break;
     127             :     default:
     128           0 :         aFD.Pitch = com::sun::star::awt::FontPitch::DONTKNOW;
     129           0 :         break;
     130             :     }
     131           0 :     switch( m_aFont.GetWeight() )
     132             :     {
     133           0 :     case WEIGHT_THIN: aFD.Weight = com::sun::star::awt::FontWeight::THIN;break;
     134           0 :     case WEIGHT_ULTRALIGHT: aFD.Weight = com::sun::star::awt::FontWeight::ULTRALIGHT;break;
     135           0 :     case WEIGHT_LIGHT: aFD.Weight = com::sun::star::awt::FontWeight::LIGHT;break;
     136           0 :     case WEIGHT_SEMILIGHT: aFD.Weight = com::sun::star::awt::FontWeight::SEMILIGHT;break;
     137             :     case WEIGHT_MEDIUM:
     138           0 :     case WEIGHT_NORMAL: aFD.Weight = com::sun::star::awt::FontWeight::NORMAL;break;
     139           0 :     case WEIGHT_SEMIBOLD: aFD.Weight = com::sun::star::awt::FontWeight::SEMIBOLD;break;
     140           0 :     case WEIGHT_BOLD: aFD.Weight = com::sun::star::awt::FontWeight::BOLD;break;
     141           0 :     case WEIGHT_ULTRABOLD: aFD.Weight = com::sun::star::awt::FontWeight::ULTRABOLD;break;
     142           0 :     case WEIGHT_BLACK: aFD.Weight = com::sun::star::awt::FontWeight::BLACK;break;
     143             :     default:
     144           0 :         aFD.Weight = com::sun::star::awt::FontWeight::DONTKNOW;
     145           0 :         break;
     146             :     }
     147           0 :     switch( m_aFont.GetItalic() )
     148             :     {
     149           0 :     case ITALIC_OBLIQUE: aFD.Slant = com::sun::star::awt::FontSlant_OBLIQUE;break;
     150           0 :     case ITALIC_NORMAL: aFD.Slant = com::sun::star::awt::FontSlant_ITALIC;break;
     151             :     default:
     152           0 :         aFD.Slant = com::sun::star::awt::FontSlant_DONTKNOW;
     153           0 :         break;
     154             :     }
     155           0 :     return makeAny( aFD );
     156             : }
     157             : 
     158           0 : Sequence< OUString > FontIdentificator_getSupportedServiceNames()
     159             : {
     160           0 :     static OUString aServiceName( "com.sun.star.awt.FontIdentificator" );
     161           0 :     static Sequence< OUString > aServiceNames( &aServiceName, 1 );
     162           0 :     return aServiceNames;
     163             : }
     164             : 
     165          98 : OUString FontIdentificator_getImplementationName()
     166             : {
     167          98 :     return OUString( "vcl::FontIdentificator" );
     168             : }
     169             : 
     170           0 : Reference< XInterface > SAL_CALL FontIdentificator_createInstance( const Reference< XMultiServiceFactory >&  )
     171             : {
     172           0 :     return static_cast< ::cppu::OWeakObject * >( new FontIdentificator );
     173             : }
     174             : 
     175             : 
     176             : // XServiceInfo
     177           0 : OUString SAL_CALL FontIdentificator::getImplementationName() throw (RuntimeException)
     178             : {
     179           0 :     return FontIdentificator_getImplementationName();
     180             : }
     181             : 
     182           0 : sal_Bool SAL_CALL FontIdentificator::supportsService( const OUString& i_rServiceName ) throw (RuntimeException)
     183             : {
     184           0 :     Sequence< OUString > aSN( FontIdentificator_getSupportedServiceNames() );
     185           0 :     for( sal_Int32 nService = 0; nService < aSN.getLength(); nService++ )
     186             :     {
     187           0 :         if( aSN[nService] == i_rServiceName )
     188           0 :             return sal_True;
     189             :     }
     190           0 :     return sal_False;
     191             : }
     192             : 
     193           0 : Sequence< OUString > SAL_CALL FontIdentificator::getSupportedServiceNames() throw (RuntimeException)
     194             : {
     195           0 :     return FontIdentificator_getSupportedServiceNames();
     196             : }
     197             : 
     198         465 : } // namespace vcl
     199             : 
     200             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10