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

Generated by: LCOV version 1.10