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