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

Generated by: LCOV version 1.11