LCOV - code coverage report
Current view: top level - libreoffice/oox/source/ole - axfontdata.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 33 55 60.0 %
Date: 2012-12-17 Functions: 7 9 77.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 "oox/ole/axfontdata.hxx"
      21             : #include "oox/ole/olehelper.hxx"
      22             : #include "oox/ole/axbinaryreader.hxx"
      23             : #include "oox/ole/axbinarywriter.hxx"
      24             : 
      25             : namespace oox {
      26             : namespace ole {
      27             : 
      28             : using ::rtl::OUString;
      29             : 
      30             : // ============================================================================
      31             : 
      32          34 : AxFontData::AxFontData() :
      33             :     mnFontEffects( 0 ),
      34             :     mnFontHeight( 160 ),
      35             :     mnFontCharSet( WINDOWS_CHARSET_DEFAULT ),
      36             :     mnHorAlign( AX_FONTDATA_LEFT ),
      37          34 :     mbDblUnderline( false )
      38             : {
      39          34 : }
      40             : 
      41          12 : sal_Int16 AxFontData::getHeightPoints() const
      42             : {
      43             :     /*  MSO uses weird font sizes:
      44             :         1pt->30, 2pt->45, 3pt->60, 4pt->75, 5pt->105, 6pt->120, 7pt->135,
      45             :         8pt->165, 9pt->180, 10pt->195, 11pt->225, ... */
      46          12 :     return getLimitedValue< sal_Int16, sal_Int32 >( (mnFontHeight + 10) / 20, 1, SAL_MAX_INT16 );
      47             : }
      48             : 
      49           4 : void AxFontData::setHeightPoints( sal_Int16 nPoints )
      50             : {
      51           4 :     mnFontHeight = getLimitedValue< sal_Int32, sal_Int32 >( ((nPoints * 4 + 1) / 3) * 15, 30, 4294967 );
      52           4 : }
      53             : 
      54          10 : bool AxFontData::importBinaryModel( BinaryInputStream& rInStrm )
      55             : {
      56          10 :     AxBinaryPropertyReader aReader( rInStrm );
      57          10 :     aReader.readStringProperty( maFontName );
      58          10 :     aReader.readIntProperty< sal_uInt32 >( mnFontEffects );
      59          10 :     aReader.readIntProperty< sal_Int32 >( mnFontHeight );
      60          10 :     aReader.skipIntProperty< sal_Int32 >(); // font offset
      61          10 :     aReader.readIntProperty< sal_uInt8 >( mnFontCharSet );
      62          10 :     aReader.skipIntProperty< sal_uInt8 >(); // font pitch/family
      63          10 :     aReader.readIntProperty< sal_uInt8 >( mnHorAlign );
      64          10 :     aReader.skipIntProperty< sal_uInt16 >(); // font weight
      65          10 :     mbDblUnderline = false;
      66          10 :     return aReader.finalizeImport();
      67             : }
      68             : 
      69           2 : void AxFontData::exportBinaryModel( BinaryOutputStream& rOutStrm )
      70             : {
      71           2 :     AxBinaryPropertyWriter aWriter( rOutStrm );
      72           2 :     aWriter.writeStringProperty( maFontName );
      73           2 :     aWriter.writeIntProperty< sal_uInt32 >( mnFontEffects );
      74           2 :     aWriter.writeIntProperty< sal_Int32 >( mnFontHeight );
      75           2 :     aWriter.skipProperty(); // font offset
      76             :     // TODO make AxFontDataModel::convertFromProperties convert the textencoding
      77           2 :     aWriter.writeIntProperty< sal_uInt8 >( mnFontCharSet );
      78           2 :     aWriter.skipProperty(); // font pitch/family
      79             : 
      80           2 :     aWriter.writeIntProperty< sal_uInt8 >( mnHorAlign );
      81           2 :     aWriter.skipProperty(); // font weight
      82           2 :     aWriter.finalizeExport();
      83           2 : }
      84             : 
      85           0 : bool AxFontData::importStdFont( BinaryInputStream& rInStrm )
      86             : {
      87           0 :     StdFontInfo aFontInfo;
      88           0 :     if( OleHelper::importStdFont( aFontInfo, rInStrm, false ) )
      89             :     {
      90           0 :         maFontName = aFontInfo.maName;
      91           0 :         mnFontEffects = 0;
      92           0 :         setFlag( mnFontEffects, AX_FONTDATA_BOLD,      aFontInfo.mnWeight >= OLE_STDFONT_BOLD );
      93           0 :         setFlag( mnFontEffects, AX_FONTDATA_ITALIC,    getFlag( aFontInfo.mnFlags, OLE_STDFONT_ITALIC ) );
      94           0 :         setFlag( mnFontEffects, AX_FONTDATA_UNDERLINE, getFlag( aFontInfo.mnFlags, OLE_STDFONT_UNDERLINE ) );
      95           0 :         setFlag( mnFontEffects, AX_FONTDATA_STRIKEOUT, getFlag( aFontInfo.mnFlags,OLE_STDFONT_STRIKE ) );
      96           0 :         mbDblUnderline = false;
      97             :         // StdFont stores font height in 1/10,000 of points
      98           0 :         setHeightPoints( getLimitedValue< sal_Int16, sal_Int32 >( aFontInfo.mnHeight / 10000, 0, SAL_MAX_INT16 ) );
      99           0 :         mnFontCharSet = aFontInfo.mnCharSet;
     100           0 :         mnHorAlign = AX_FONTDATA_LEFT;
     101           0 :         return true;
     102             :     }
     103           0 :     return false;
     104             : }
     105             : 
     106           0 : bool AxFontData::importGuidAndFont( BinaryInputStream& rInStrm )
     107             : {
     108           0 :     OUString aGuid = OleHelper::importGuid( rInStrm );
     109           0 :     if( aGuid.equalsAscii( AX_GUID_CFONT ) )
     110           0 :         return importBinaryModel( rInStrm );
     111           0 :     if ( aGuid == OLE_GUID_STDFONT )
     112           0 :         return importStdFont( rInStrm );
     113           0 :     return false;
     114             : }
     115             : 
     116             : // ============================================================================
     117             : 
     118             : } // namespace ole
     119         174 : } // namespace oox
     120             : 
     121             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10