LCOV - code coverage report
Current view: top level - vcl/source/fontsubset - fontsubset.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 51 0.0 %
Date: 2014-11-03 Functions: 0 8 0.0 %
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 <tools/debug.hxx>
      21             : 
      22             : #include <fontsubset.hxx>
      23             : #include <sft.hxx>
      24             : 
      25           0 : FontSubsetInfo::FontSubsetInfo()
      26             :     : m_nAscent( 0)
      27             :     , m_nDescent( 0)
      28             :     , m_nCapHeight( 0)
      29             :     , m_nFontType( FontSubsetInfo::NO_FONT)
      30             :     , mpInFontBytes( NULL)
      31             :     , mnInByteLength( 0)
      32             :     , meInFontType( FontSubsetInfo::NO_FONT)
      33             :     , mpSftTTFont( NULL)
      34             :     , mnReqFontTypeMask(0)
      35             :     , mpOutFile(NULL)
      36             :     , mpReqFontName(NULL)
      37             :     , mpReqGlyphIds(NULL)
      38             :     , mpReqEncodedIds(NULL)
      39           0 :     , mnReqGlyphCount(0)
      40             : {
      41           0 : }
      42             : 
      43           0 : FontSubsetInfo::~FontSubsetInfo()
      44             : {
      45           0 : }
      46             : 
      47             : // prepare subsetting for fonts where the input font file is mapped
      48           0 : bool FontSubsetInfo::LoadFont(
      49             :     FontSubsetInfo::FontType eInFontType,
      50             :     const unsigned char* pInFontBytes, int nInByteLength)
      51             : {
      52             :     DBG_ASSERT( (mpSftTTFont == NULL), "Subset from SFT and from mapped font-file requested");
      53           0 :     meInFontType = eInFontType;
      54           0 :     mpInFontBytes = pInFontBytes;
      55           0 :     mnInByteLength = nInByteLength;
      56           0 :     return (mnInByteLength > 0);
      57             : }
      58             : 
      59             : // prepare subsetting for fonts that are known to the SFT-parser
      60           0 : bool FontSubsetInfo::LoadFont( vcl::_TrueTypeFont* pSftTTFont )
      61             : {
      62             :     DBG_ASSERT( (mpInFontBytes == NULL), "Subset from SFT and from mapped font-file requested");
      63           0 :     mpSftTTFont = pSftTTFont;
      64           0 :     meInFontType = ANY_SFNT;
      65           0 :     return (mpSftTTFont == NULL);
      66             : }
      67             : 
      68           0 : bool FontSubsetInfo::CreateFontSubset(
      69             :     int nReqFontTypeMask,
      70             :     FILE* pOutFile, const char* pReqFontName,
      71             :     const sal_GlyphId* pReqGlyphIds, const sal_uInt8* pReqEncodedIds, int nReqGlyphCount,
      72             :     sal_Int32* pOutGlyphWidths)
      73             : {
      74             :     // prepare request details needed by all underlying subsetters
      75           0 :     mnReqFontTypeMask = nReqFontTypeMask;
      76           0 :     mpOutFile       = pOutFile;
      77           0 :     mpReqFontName   = pReqFontName;
      78           0 :     mpReqGlyphIds   = pReqGlyphIds;
      79           0 :     mpReqEncodedIds = pReqEncodedIds;
      80           0 :     mnReqGlyphCount = nReqGlyphCount;
      81             : 
      82             :     // TODO: move the glyphid/encid/notdef reshuffling from the callers to here
      83             : 
      84             :     // dispatch to underlying subsetters
      85           0 :     bool bOK = false;
      86             : 
      87             :     // TODO: better match available input-type to possible subset-types
      88           0 :     switch( meInFontType) {
      89             :     case SFNT_TTF:
      90             :     case SFNT_CFF:
      91             :     case ANY_SFNT:
      92           0 :         bOK = CreateFontSubsetFromSfnt( pOutGlyphWidths);
      93           0 :         break;
      94             :     case CFF_FONT:
      95           0 :         bOK = CreateFontSubsetFromCff( pOutGlyphWidths);
      96           0 :         break;
      97             :     case TYPE1_PFA:
      98             :     case TYPE1_PFB:
      99             :     case ANY_TYPE1:
     100           0 :         bOK = CreateFontSubsetFromType1( pOutGlyphWidths);
     101           0 :         break;
     102             :         // fall trough
     103             :     case NO_FONT:
     104             :         // fall trough
     105             :     default:
     106             :         OSL_FAIL( "unhandled type in CreateFontSubset()");
     107           0 :         break;
     108             :     }
     109             : 
     110           0 :     return bOK;
     111             : }
     112             : 
     113             : // TODO: move function to sft.cxx to replace dummy implementation
     114           0 : bool FontSubsetInfo::CreateFontSubsetFromSfnt( sal_Int32* pOutGlyphWidths )
     115             : {
     116             :     // handle SFNT_CFF fonts
     117           0 :     int nCffLength = 0;
     118           0 :     const sal_uInt8* pCffBytes = NULL;
     119           0 :     if( GetSfntTable( mpSftTTFont, O_CFF, &pCffBytes, &nCffLength))
     120             :     {
     121           0 :         LoadFont( CFF_FONT, pCffBytes, nCffLength);
     122           0 :         const bool bOK = CreateFontSubsetFromCff( pOutGlyphWidths);
     123           0 :         return bOK;
     124             :     }
     125             : 
     126             :     // handle SFNT_TTF fonts
     127             :     // by forwarding the subset request to AG's sft subsetter
     128             : #if 1 // TODO: remove conversion tp 16bit glyphids when sft-subsetter has been updated
     129             :     sal_uInt16 aShortGlyphIds[256];
     130           0 :     for( int i = 0; i < mnReqGlyphCount; ++i)
     131           0 :         aShortGlyphIds[i] = (sal_uInt16)mpReqGlyphIds[i];
     132             :     // remove const_cast when sft-subsetter is const-correct
     133           0 :     sal_uInt8* pEncArray = const_cast<sal_uInt8*>( mpReqEncodedIds );
     134             : #endif
     135           0 :     int nSFTErr = vcl::SF_BADARG;
     136           0 :     if( (mnReqFontTypeMask & TYPE42_FONT) != 0 )
     137             :     {
     138             :         nSFTErr = CreateT42FromTTGlyphs( mpSftTTFont, mpOutFile, mpReqFontName,
     139           0 :             aShortGlyphIds, pEncArray, mnReqGlyphCount );
     140             :     }
     141           0 :     else if( (mnReqFontTypeMask & TYPE3_FONT) != 0 )
     142             :     {
     143             :         nSFTErr = CreateT3FromTTGlyphs( mpSftTTFont, mpOutFile, mpReqFontName,
     144             :             aShortGlyphIds, pEncArray, mnReqGlyphCount,
     145           0 :                     0 /* 0 = horizontal, 1 = vertical */ );
     146             :     }
     147           0 :     else if( (mnReqFontTypeMask & SFNT_TTF) != 0 )
     148             :     {
     149             :         // TODO: use CreateTTFromTTGlyphs()
     150             :         // TODO: move functionality from callers here
     151             :     }
     152             : 
     153           0 :     return (nSFTErr != vcl::SF_OK);
     154             : }
     155             : 
     156             : // TODO: replace dummy implementation
     157           0 : bool FontSubsetInfo::CreateFontSubsetFromType1( sal_Int32* pOutGlyphWidths)
     158             : {
     159             :     (void)pOutGlyphWidths;
     160           0 :     fprintf(stderr,"CreateFontSubsetFromType1: replace dummy implementation\n");
     161           0 :     return false;
     162             : }
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10