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