LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - FontTable.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 64 135 47.4 %
Date: 2015-06-13 12:38:46 Functions: 11 30 36.7 %
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 <FontTable.hxx>
      21             : #include <ooxml/resourceids.hxx>
      22             : #include <vector>
      23             : #include <osl/file.hxx>
      24             : #include <rtl/tencinfo.h>
      25             : #include <vcl/embeddedfontshelper.hxx>
      26             : #include <unotools/fontdefs.hxx>
      27             : #include <com/sun/star/awt/FontPitch.hpp>
      28             : 
      29             : using namespace com::sun::star;
      30             : 
      31             : namespace writerfilter {
      32             : namespace dmapper
      33             : {
      34             : 
      35        1747 : struct FontTable_Impl
      36             : {
      37             :     std::vector< FontEntry::Pointer_t > aFontEntries;
      38             :     FontEntry::Pointer_t pCurrentEntry;
      39        1747 :     FontTable_Impl() {}
      40             : };
      41             : 
      42        1747 : FontTable::FontTable()
      43             : : LoggedProperties("FontTable")
      44             : , LoggedTable("FontTable")
      45             : , LoggedStream("FontTable")
      46        1747 : , m_pImpl( new FontTable_Impl )
      47             : {
      48        1747 : }
      49             : 
      50        5241 : FontTable::~FontTable()
      51             : {
      52        1747 :     delete m_pImpl;
      53        3494 : }
      54             : 
      55       37766 : void FontTable::lcl_attribute(Id Name, Value & val)
      56             : {
      57             :     OSL_ENSURE( m_pImpl->pCurrentEntry, "current entry has to be set here");
      58       37766 :     if(!m_pImpl->pCurrentEntry)
      59       37766 :         return ;
      60       37766 :     int nIntValue = val.getInt();
      61       37766 :     OUString sValue = val.getString();
      62       37766 :     switch(Name)
      63             :     {
      64             :         case NS_ooxml::LN_CT_Pitch_val:
      65       12643 :             if (static_cast<Id>(nIntValue) == NS_ooxml::LN_Value_ST_Pitch_fixed)
      66         556 :                 m_pImpl->pCurrentEntry->nPitchRequest = awt::FontPitch::FIXED;
      67       12087 :             else if (static_cast<Id>(nIntValue) == NS_ooxml::LN_Value_ST_Pitch_variable)
      68       11709 :                 m_pImpl->pCurrentEntry->nPitchRequest = awt::FontPitch::VARIABLE;
      69         378 :             else if (static_cast<Id>(nIntValue) == NS_ooxml::LN_Value_ST_Pitch_default)
      70         378 :                 m_pImpl->pCurrentEntry->nPitchRequest = awt::FontPitch::DONTKNOW;
      71             :             else
      72             :                 SAL_WARN("writerfilter", "FontTable::lcl_attribute: unhandled NS_ooxml::CT_Pitch_val: " << nIntValue);
      73       12643 :             break;
      74             :         case NS_ooxml::LN_CT_Font_name:
      75       12691 :             m_pImpl->pCurrentEntry->sFontName = sValue;
      76       12691 :             break;
      77             :         case NS_ooxml::LN_CT_Charset_val:
      78             :             // w:characterSet has higher priority, set only if that one is not set
      79        9361 :             if( m_pImpl->pCurrentEntry->nTextEncoding == RTL_TEXTENCODING_DONTKNOW )
      80             :             {
      81        9361 :                 m_pImpl->pCurrentEntry->nTextEncoding = rtl_getTextEncodingFromWindowsCharset( nIntValue );
      82        9361 :                 if( IsStarSymbol( m_pImpl->pCurrentEntry->sFontName ))
      83          12 :                     m_pImpl->pCurrentEntry->nTextEncoding = RTL_TEXTENCODING_SYMBOL;
      84             :             }
      85        9361 :             break;
      86             :         case NS_ooxml::LN_CT_Charset_characterSet:
      87             :         {
      88        3071 :             OString tmp;
      89        3071 :             sValue.convertToString( &tmp, RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS );
      90        3071 :             m_pImpl->pCurrentEntry->nTextEncoding = rtl_getTextEncodingFromMimeCharset( tmp.getStr() );
      91             :             // Older LO versions used to write incorrect character set for OpenSymbol, fix.
      92        3071 :             if( IsStarSymbol( m_pImpl->pCurrentEntry->sFontName ))
      93           1 :                 m_pImpl->pCurrentEntry->nTextEncoding = RTL_TEXTENCODING_SYMBOL;
      94        3071 :             break;
      95             :         }
      96             :         default:
      97             :         {
      98             :             //----> debug
      99           0 :             int nVal = val.getInt();
     100           0 :             ++nVal;
     101             :             //<---- debug
     102             :         }
     103       37766 :     }
     104             : }
     105             : 
     106       44453 : void FontTable::lcl_sprm(Sprm& rSprm)
     107             : {
     108             :     OSL_ENSURE( m_pImpl->pCurrentEntry, "current entry has to be set here");
     109       44453 :     if(!m_pImpl->pCurrentEntry)
     110       44453 :         return ;
     111       44453 :     sal_uInt32 nSprmId = rSprm.getId();
     112             : 
     113       44453 :     switch(nSprmId)
     114             :     {
     115             :         case NS_ooxml::LN_CT_Font_charset:
     116             :         case NS_ooxml::LN_CT_Font_pitch:
     117       22015 :             resolveSprm( rSprm );
     118       22015 :             break;
     119             :         case NS_ooxml::LN_CT_Font_embedRegular:
     120             :         case NS_ooxml::LN_CT_Font_embedBold:
     121             :         case NS_ooxml::LN_CT_Font_embedItalic:
     122             :         case NS_ooxml::LN_CT_Font_embedBoldItalic:
     123             :         {
     124           0 :             writerfilter::Reference< Properties >::Pointer_t pProperties = rSprm.getProps();
     125           0 :             if( pProperties.get( ))
     126             :             {
     127           0 :                 EmbeddedFontHandler handler( m_pImpl->pCurrentEntry->sFontName,
     128           0 :                     nSprmId == NS_ooxml::LN_CT_Font_embedRegular ? ""
     129           0 :                     : nSprmId == NS_ooxml::LN_CT_Font_embedBold ? "b"
     130           0 :                     : nSprmId == NS_ooxml::LN_CT_Font_embedItalic ? "i"
     131           0 :                     : /*NS_ooxml::LN_CT_Font_embedBoldItalic*/ "bi" );
     132           0 :                 pProperties->resolve( handler );
     133             :             }
     134           0 :             break;
     135             :         }
     136             :         case NS_ooxml::LN_CT_Font_altName:
     137        2146 :             break;
     138             :         case NS_ooxml::LN_CT_Font_panose1:
     139        5156 :             break;
     140             :         case NS_ooxml::LN_CT_Font_family:
     141        9372 :             break;
     142             :         case NS_ooxml::LN_CT_Font_sig:
     143        5207 :             break;
     144             :         default:
     145             :             SAL_WARN("writerfilter", "FontTable::lcl_sprm: unhandled token: " << nSprmId);
     146         557 :             break;
     147             :     }
     148             : }
     149             : 
     150       22015 : void FontTable::resolveSprm(Sprm & r_Sprm)
     151             : {
     152       22015 :     writerfilter::Reference<Properties>::Pointer_t pProperties = r_Sprm.getProps();
     153       22015 :     if( pProperties.get())
     154       22015 :         pProperties->resolve(*this);
     155       22015 : }
     156             : 
     157       12691 : void FontTable::lcl_entry(int /*pos*/, writerfilter::Reference<Properties>::Pointer_t ref)
     158             : {
     159             :     //create a new font entry
     160             :     OSL_ENSURE( !m_pImpl->pCurrentEntry, "current entry has to be NULL here");
     161       12691 :     m_pImpl->pCurrentEntry.reset(new FontEntry);
     162       12691 :     ref->resolve(*this);
     163             :     //append it to the table
     164       12691 :     m_pImpl->aFontEntries.push_back( m_pImpl->pCurrentEntry );
     165       12691 :     m_pImpl->pCurrentEntry.reset();
     166       12691 : }
     167             : 
     168           0 : void FontTable::lcl_startSectionGroup()
     169             : {
     170           0 : }
     171             : 
     172           0 : void FontTable::lcl_endSectionGroup()
     173             : {
     174           0 : }
     175             : 
     176           0 : void FontTable::lcl_startParagraphGroup()
     177             : {
     178           0 : }
     179             : 
     180           0 : void FontTable::lcl_endParagraphGroup()
     181             : {
     182           0 : }
     183             : 
     184           0 : void FontTable::lcl_startCharacterGroup()
     185             : {
     186           0 : }
     187             : 
     188           0 : void FontTable::lcl_endCharacterGroup()
     189             : {
     190           0 : }
     191             : 
     192           0 : void FontTable::lcl_text(const sal_uInt8*, size_t )
     193             : {
     194           0 : }
     195             : 
     196           0 : void FontTable::lcl_utext(const sal_uInt8* , size_t)
     197             : {
     198           0 : }
     199             : 
     200           0 : void FontTable::lcl_props(writerfilter::Reference<Properties>::Pointer_t)
     201             : {
     202           0 : }
     203             : 
     204           0 : void FontTable::lcl_table(Id, writerfilter::Reference<Table>::Pointer_t)
     205             : {
     206           0 : }
     207             : 
     208           0 : void FontTable::lcl_substream(Id, ::writerfilter::Reference<Stream>::Pointer_t)
     209             : {
     210           0 : }
     211             : 
     212           0 : void FontTable::lcl_info(const std::string& )
     213             : {
     214           0 : }
     215             : 
     216           0 : void FontTable::lcl_startShape(uno::Reference<drawing::XShape> const&)
     217             : {
     218           0 : }
     219             : 
     220           0 : void FontTable::lcl_endShape( )
     221             : {
     222           0 : }
     223             : 
     224         519 : const FontEntry::Pointer_t FontTable::getFontEntry(sal_uInt32 nIndex)
     225             : {
     226         519 :     return (m_pImpl->aFontEntries.size() > nIndex)
     227         519 :         ?   m_pImpl->aFontEntries[nIndex]
     228        1038 :         :   FontEntry::Pointer_t();
     229             : }
     230             : 
     231        2863 : sal_uInt32 FontTable::size()
     232             : {
     233        2863 :     return m_pImpl->aFontEntries.size();
     234             : }
     235             : 
     236           0 : EmbeddedFontHandler::EmbeddedFontHandler( const OUString& _fontName, const char* _style )
     237             : : LoggedProperties("EmbeddedFontHandler")
     238             : , fontName( _fontName )
     239           0 : , style( _style )
     240             : {
     241           0 : }
     242             : 
     243           0 : EmbeddedFontHandler::~EmbeddedFontHandler()
     244             : {
     245           0 :     if( !inputStream.is())
     246           0 :         return;
     247           0 :     std::vector< unsigned char > key( 32 );
     248           0 :     if( !fontKey.isEmpty())
     249             :     {   // key for unobfuscating
     250             :         //  1 3 5 7 10 2  5 7 20 2  5 7 9 1 3 5
     251             :         // {62E79491-959F-41E9-B76B-6B32631DEA5C}
     252             :         static const int pos[ 16 ] = { 35, 33, 31, 29, 27, 25, 22, 20, 17, 15, 12, 10, 7, 5, 3, 1 };
     253           0 :         for( int i = 0;
     254             :              i < 16;
     255             :              ++i )
     256             :         {
     257           0 :             int v1 = fontKey[ pos[ i ]];
     258           0 :             int v2 = fontKey[ pos[ i ] + 1 ];
     259             :             assert(( v1 >= '0' && v1 <= '9' ) || ( v1 >= 'A' && v1 <= 'F' ));
     260             :             assert(( v2 >= '0' && v2 <= '9' ) || ( v2 >= 'A' && v2 <= 'F' ));
     261           0 :             int val = ( v1 - ( v1 <= '9' ? '0' : 'A' - 10 )) * 16 + v2 - ( v2 <= '9' ? '0' : 'A' - 10 );
     262           0 :             key[ i ] = val;
     263           0 :             key[ i + 16 ] = val;
     264             :         }
     265             :     }
     266           0 :     EmbeddedFontsHelper::addEmbeddedFont( inputStream, fontName, style, key );
     267           0 :     inputStream->closeInput();
     268           0 : }
     269             : 
     270           0 : void EmbeddedFontHandler::lcl_attribute( Id name, Value& val )
     271             : {
     272           0 :     OUString sValue = val.getString();
     273           0 :     switch( name )
     274             :     {
     275             :         case NS_ooxml::LN_CT_FontRel_fontKey:
     276           0 :             fontKey = sValue;
     277           0 :             break;
     278             :         case NS_ooxml::LN_CT_Rel_id:
     279           0 :             id = sValue;
     280           0 :             break;
     281             :         case NS_ooxml::LN_CT_FontRel_subsetted:
     282           0 :             break; // TODO? Let's just ignore this for now and hope
     283             :                    // it doesn't break anything.
     284             :         case NS_ooxml::LN_inputstream: // the actual font data as stream
     285           0 :             val.getAny() >>= inputStream;
     286           0 :             break;
     287             :         default:
     288           0 :             break;
     289           0 :     }
     290           0 : }
     291             : 
     292           0 : void EmbeddedFontHandler::lcl_sprm( Sprm& )
     293             : {
     294           0 : }
     295             : 
     296             : 
     297             : }//namespace dmapper
     298             : }//namespace writerfilter
     299             : 
     300             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11