xref: /AOO41X/main/vcl/source/fontsubset/gsub.cxx (revision 9f62ea84a806e17e6f2bbff75724a7257a0eb5d9)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "sft.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "gsub.h"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <osl/diagnose.h>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <vector>
34cdf0e10cSrcweir #include <map>
35cdf0e10cSrcweir #include <algorithm>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace vcl
38cdf0e10cSrcweir {
39cdf0e10cSrcweir 
40cdf0e10cSrcweir typedef sal_uIntPtr sal_uLong;
41cdf0e10cSrcweir typedef sal_uInt8 FT_Byte;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir typedef std::map<sal_uInt16,sal_uInt16> GlyphSubstitution;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
NEXT_Long(const unsigned char * & p)46cdf0e10cSrcweir inline long NEXT_Long( const unsigned char* &p )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     long nVal = (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3];
49cdf0e10cSrcweir     p += 4;
50cdf0e10cSrcweir     return nVal;
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
NEXT_UShort(const unsigned char * & p)53cdf0e10cSrcweir inline sal_uInt16 NEXT_UShort( const unsigned char* &p )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     sal_uInt16 nVal = (p[0]<<8) + p[1];
56cdf0e10cSrcweir     p += 2;
57cdf0e10cSrcweir     return nVal;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir #define MKTAG(s) ((((((s[0]<<8)+s[1])<<8)+s[2])<<8)+s[3])
61cdf0e10cSrcweir 
ReadGSUB(struct _TrueTypeFont * pTTFile,int nRequestedScript,int nRequestedLangsys)62cdf0e10cSrcweir int ReadGSUB( struct _TrueTypeFont* pTTFile,
63cdf0e10cSrcweir     int nRequestedScript, int nRequestedLangsys )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     const FT_Byte* pGsubBase = (FT_Byte*)pTTFile->tables[ O_gsub ];
66cdf0e10cSrcweir     if( !pGsubBase )
67cdf0e10cSrcweir         return -1;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     // #129682# check offsets inside GSUB table
70cdf0e10cSrcweir     const FT_Byte* pGsubLimit = pGsubBase + pTTFile->tlens[ O_gsub ];
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     // parse GSUB header
73cdf0e10cSrcweir     const FT_Byte* pGsubHeader = pGsubBase;
74cdf0e10cSrcweir     const sal_uLong nVersion            = NEXT_Long( pGsubHeader );
75cdf0e10cSrcweir     const sal_uInt16 nOfsScriptList     = NEXT_UShort( pGsubHeader );
76cdf0e10cSrcweir     const sal_uInt16 nOfsFeatureTable   = NEXT_UShort( pGsubHeader );
77cdf0e10cSrcweir     const sal_uInt16 nOfsLookupList     = NEXT_UShort( pGsubHeader );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     // sanity check the GSUB header
80cdf0e10cSrcweir     if( nVersion != 0x00010000 )
81cdf0e10cSrcweir         if( nVersion != 0x00001000 )    // workaround for SunBatang etc.
82cdf0e10cSrcweir             return -1;                  // unknown format or broken
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     typedef std::vector<sal_uLong> ReqFeatureTagList;
85cdf0e10cSrcweir     ReqFeatureTagList aReqFeatureTagList;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     aReqFeatureTagList.push_back( MKTAG("vert") );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     typedef std::vector<sal_uInt16> UshortList;
90cdf0e10cSrcweir     UshortList aFeatureIndexList;
91cdf0e10cSrcweir     UshortList aFeatureOffsetList;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     // parse Script Table
94cdf0e10cSrcweir     const FT_Byte* pScriptHeader = pGsubBase + nOfsScriptList;
95cdf0e10cSrcweir     const sal_uInt16 nCntScript = NEXT_UShort( pScriptHeader );
96cdf0e10cSrcweir     if( pGsubLimit < pScriptHeader + 6 * nCntScript )
97cdf0e10cSrcweir         return false;
98cdf0e10cSrcweir     for( sal_uInt16 nScriptIndex = 0; nScriptIndex < nCntScript; ++nScriptIndex )
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         const sal_uLong nTag            = NEXT_Long( pScriptHeader ); // e.g. hani/arab/kana/hang
101cdf0e10cSrcweir         const sal_uInt16 nOfsScriptTable= NEXT_UShort( pScriptHeader );
102cdf0e10cSrcweir         if( (nTag != (sal_uInt16)nRequestedScript) && (nRequestedScript != 0) )
103cdf0e10cSrcweir             continue;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         const FT_Byte* pScriptTable     = pGsubBase + nOfsScriptList + nOfsScriptTable;
106cdf0e10cSrcweir         if( pGsubLimit < pScriptTable + 4 )
107cdf0e10cSrcweir             return false;
108cdf0e10cSrcweir         const sal_uInt16 nDefaultLangsysOfs = NEXT_UShort( pScriptTable );
109cdf0e10cSrcweir         const sal_uInt16 nCntLangSystem     = NEXT_UShort( pScriptTable );
110cdf0e10cSrcweir         sal_uInt16 nLangsysOffset = 0;
111cdf0e10cSrcweir         if( pGsubLimit < pScriptTable + 6 * nCntLangSystem )
112cdf0e10cSrcweir             return false;
113cdf0e10cSrcweir         for( sal_uInt16 nLangsysIndex = 0; nLangsysIndex < nCntLangSystem; ++nLangsysIndex )
114cdf0e10cSrcweir         {
115cdf0e10cSrcweir             const sal_uLong nInnerTag = NEXT_Long( pScriptTable );    // e.g. KOR/ZHS/ZHT/JAN
116cdf0e10cSrcweir             const sal_uInt16 nOffset= NEXT_UShort( pScriptTable );
117cdf0e10cSrcweir             if( (nInnerTag != (sal_uInt16)nRequestedLangsys) && (nRequestedLangsys != 0) )
118cdf0e10cSrcweir                 continue;
119cdf0e10cSrcweir             nLangsysOffset = nOffset;
120cdf0e10cSrcweir             break;
121cdf0e10cSrcweir         }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         if( (nDefaultLangsysOfs != 0) && (nDefaultLangsysOfs != nLangsysOffset) )
124cdf0e10cSrcweir         {
125cdf0e10cSrcweir             const FT_Byte* pLangSys = pGsubBase + nOfsScriptList + nOfsScriptTable + nDefaultLangsysOfs;
126cdf0e10cSrcweir             if( pGsubLimit < pLangSys + 6 )
127cdf0e10cSrcweir                 return false;
128cdf0e10cSrcweir             /*const sal_uInt16 nLookupOrder   =*/ NEXT_UShort( pLangSys );
129cdf0e10cSrcweir             const sal_uInt16 nReqFeatureIdx = NEXT_UShort( pLangSys );
130cdf0e10cSrcweir             const sal_uInt16 nCntFeature    = NEXT_UShort( pLangSys );
131cdf0e10cSrcweir             if( pGsubLimit < pLangSys + 2 * nCntFeature )
132cdf0e10cSrcweir                 return false;
133cdf0e10cSrcweir             aFeatureIndexList.push_back( nReqFeatureIdx );
134cdf0e10cSrcweir             for( sal_uInt16 i = 0; i < nCntFeature; ++i )
135cdf0e10cSrcweir             {
136cdf0e10cSrcweir                 const sal_uInt16 nFeatureIndex = NEXT_UShort( pLangSys );
137cdf0e10cSrcweir                 aFeatureIndexList.push_back( nFeatureIndex );
138cdf0e10cSrcweir             }
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         if( nLangsysOffset != 0 )
142cdf0e10cSrcweir         {
143cdf0e10cSrcweir             const FT_Byte* pLangSys = pGsubBase + nOfsScriptList + nOfsScriptTable + nLangsysOffset;
144cdf0e10cSrcweir             if( pGsubLimit < pLangSys + 6 )
145cdf0e10cSrcweir                 return false;
146cdf0e10cSrcweir             /*const sal_uInt16 nLookupOrder   =*/ NEXT_UShort( pLangSys );
147cdf0e10cSrcweir             const sal_uInt16 nReqFeatureIdx = NEXT_UShort( pLangSys );
148cdf0e10cSrcweir             const sal_uInt16 nCntFeature    = NEXT_UShort( pLangSys );
149cdf0e10cSrcweir             if( pGsubLimit < pLangSys + 2 * nCntFeature )
150cdf0e10cSrcweir                 return false;
151cdf0e10cSrcweir             aFeatureIndexList.push_back( nReqFeatureIdx );
152cdf0e10cSrcweir             for( sal_uInt16 i = 0; i < nCntFeature; ++i )
153cdf0e10cSrcweir             {
154cdf0e10cSrcweir                 const sal_uInt16 nFeatureIndex = NEXT_UShort( pLangSys );
155cdf0e10cSrcweir                 aFeatureIndexList.push_back( nFeatureIndex );
156cdf0e10cSrcweir             }
157cdf0e10cSrcweir         }
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     if( !aFeatureIndexList.size() )
161cdf0e10cSrcweir         return true;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     UshortList aLookupIndexList;
164cdf0e10cSrcweir     UshortList aLookupOffsetList;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     // parse Feature Table
167cdf0e10cSrcweir     const FT_Byte* pFeatureHeader = pGsubBase + nOfsFeatureTable;
168cdf0e10cSrcweir     if( pGsubLimit < pFeatureHeader + 2 )
169cdf0e10cSrcweir           return false;
170cdf0e10cSrcweir     const sal_uInt16 nCntFeature = NEXT_UShort( pFeatureHeader );
171cdf0e10cSrcweir     if( pGsubLimit < pFeatureHeader + 6 * nCntFeature )
172cdf0e10cSrcweir           return false;
173cdf0e10cSrcweir     for( sal_uInt16 nFeatureIndex = 0; nFeatureIndex < nCntFeature; ++nFeatureIndex )
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         const sal_uLong nTag    = NEXT_Long( pFeatureHeader ); // e.g. locl/vert/trad/smpl/liga/fina/...
176cdf0e10cSrcweir         const sal_uInt16 nOffset= NEXT_UShort( pFeatureHeader );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         // ignore unneeded feature lookups
179cdf0e10cSrcweir         if( aFeatureIndexList[0] != nFeatureIndex ) // do not ignore the required feature
180cdf0e10cSrcweir         {
181cdf0e10cSrcweir             const int nRequested = std::count( aFeatureIndexList.begin(), aFeatureIndexList.end(), nFeatureIndex);
182cdf0e10cSrcweir             if( !nRequested )	// ignore features that are not requested
183cdf0e10cSrcweir                 continue;
184cdf0e10cSrcweir             const int nAvailable = std::count( aReqFeatureTagList.begin(), aReqFeatureTagList.end(), nTag);
185cdf0e10cSrcweir             if( !nAvailable )	// some fonts don't provide features they request!
186cdf0e10cSrcweir                 continue;
187cdf0e10cSrcweir         }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         const FT_Byte* pFeatureTable = pGsubBase + nOfsFeatureTable + nOffset;
190cdf0e10cSrcweir         if( pGsubLimit < pFeatureTable + 2 )
191cdf0e10cSrcweir             return false;
192cdf0e10cSrcweir         const sal_uInt16 nCntLookups = NEXT_UShort( pFeatureTable );
193cdf0e10cSrcweir         if( pGsubLimit < pFeatureTable + 2 * nCntLookups )
194cdf0e10cSrcweir             return false;
195cdf0e10cSrcweir         for( sal_uInt16 i = 0; i < nCntLookups; ++i )
196cdf0e10cSrcweir         {
197cdf0e10cSrcweir             const sal_uInt16 nLookupIndex = NEXT_UShort( pFeatureTable );
198cdf0e10cSrcweir             aLookupIndexList.push_back( nLookupIndex );
199cdf0e10cSrcweir         }
200cdf0e10cSrcweir         if( nCntLookups == 0 ) //### hack needed by Mincho/Gothic/Mingliu/Simsun/...
201cdf0e10cSrcweir             aLookupIndexList.push_back( 0 );
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     // parse Lookup List
205cdf0e10cSrcweir     const FT_Byte* pLookupHeader = pGsubBase + nOfsLookupList;
206cdf0e10cSrcweir     if( pGsubLimit < pLookupHeader + 2 )
207cdf0e10cSrcweir         return false;
208cdf0e10cSrcweir     const sal_uInt16 nCntLookupTable = NEXT_UShort( pLookupHeader );
209cdf0e10cSrcweir     if( pGsubLimit < pLookupHeader + 2 * nCntLookupTable )
210cdf0e10cSrcweir         return false;
211cdf0e10cSrcweir     for( sal_uInt16 nLookupIdx = 0; nLookupIdx < nCntLookupTable; ++nLookupIdx )
212cdf0e10cSrcweir     {
213cdf0e10cSrcweir         const sal_uInt16 nOffset = NEXT_UShort( pLookupHeader );
214cdf0e10cSrcweir         if( std::count( aLookupIndexList.begin(), aLookupIndexList.end(), nLookupIdx ) )
215cdf0e10cSrcweir             aLookupOffsetList.push_back( nOffset );
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     UshortList::const_iterator it = aLookupOffsetList.begin();
219cdf0e10cSrcweir     for(; it != aLookupOffsetList.end(); ++it )
220cdf0e10cSrcweir     {
221cdf0e10cSrcweir         const sal_uInt16 nOfsLookupTable = *it;
222cdf0e10cSrcweir         const FT_Byte* pLookupTable = pGsubBase + nOfsLookupList + nOfsLookupTable;
223cdf0e10cSrcweir         if( pGsubLimit < pLookupTable + 6 )
224cdf0e10cSrcweir             return false;
225cdf0e10cSrcweir         const sal_uInt16 eLookupType        = NEXT_UShort( pLookupTable );
226cdf0e10cSrcweir         /*const sal_uInt16 eLookupFlag        =*/ NEXT_UShort( pLookupTable );
227cdf0e10cSrcweir         const sal_uInt16 nCntLookupSubtable = NEXT_UShort( pLookupTable );
228cdf0e10cSrcweir 
229cdf0e10cSrcweir         // TODO: switch( eLookupType )
230cdf0e10cSrcweir         if( eLookupType != 1 )  // TODO: once we go beyond SingleSubst
231cdf0e10cSrcweir             continue;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         if( pGsubLimit < pLookupTable + 2 * nCntLookupSubtable )
234cdf0e10cSrcweir             return false;
235cdf0e10cSrcweir         for( sal_uInt16 nSubTableIdx = 0; nSubTableIdx < nCntLookupSubtable; ++nSubTableIdx )
236cdf0e10cSrcweir         {
237cdf0e10cSrcweir             const sal_uInt16 nOfsSubLookupTable = NEXT_UShort( pLookupTable );
238cdf0e10cSrcweir             const FT_Byte* pSubLookup = pGsubBase + nOfsLookupList + nOfsLookupTable + nOfsSubLookupTable;
239cdf0e10cSrcweir             if( pGsubLimit < pSubLookup + 6 )
240cdf0e10cSrcweir                 return false;
241cdf0e10cSrcweir             const sal_uInt16 nFmtSubstitution   = NEXT_UShort( pSubLookup );
242cdf0e10cSrcweir             const sal_uInt16 nOfsCoverage       = NEXT_UShort( pSubLookup );
243cdf0e10cSrcweir 
244cdf0e10cSrcweir             typedef std::pair<sal_uInt16,sal_uInt16> GlyphSubst;
245cdf0e10cSrcweir             typedef std::vector<GlyphSubst> SubstVector;
246cdf0e10cSrcweir             SubstVector aSubstVector;
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             const FT_Byte* pCoverage    = pGsubBase
249cdf0e10cSrcweir                 + nOfsLookupList + nOfsLookupTable + nOfsSubLookupTable + nOfsCoverage;
250cdf0e10cSrcweir             if( pGsubLimit < pCoverage + 4 )
251cdf0e10cSrcweir                 return false;
252cdf0e10cSrcweir             const sal_uInt16 nFmtCoverage   = NEXT_UShort( pCoverage );
253cdf0e10cSrcweir             switch( nFmtCoverage )
254cdf0e10cSrcweir             {
255cdf0e10cSrcweir                 case 1:         // Coverage Format 1
256cdf0e10cSrcweir                 {
257cdf0e10cSrcweir                     const sal_uInt16 nCntGlyph = NEXT_UShort( pCoverage );
258cdf0e10cSrcweir                     if( pGsubLimit < pCoverage + 2 * nCntGlyph )
259cdf0e10cSrcweir                         // TODO? nCntGlyph = (pGsubLimit - pCoverage) / 2;
260cdf0e10cSrcweir                         return false;
261cdf0e10cSrcweir                     aSubstVector.reserve( nCntGlyph );
262cdf0e10cSrcweir                     for( sal_uInt16 i = 0; i < nCntGlyph; ++i )
263cdf0e10cSrcweir                     {
264cdf0e10cSrcweir                         const sal_uInt16 nGlyphId = NEXT_UShort( pCoverage );
265cdf0e10cSrcweir                         aSubstVector.push_back( GlyphSubst( nGlyphId, 0 ) );
266cdf0e10cSrcweir                     }
267cdf0e10cSrcweir                 }
268cdf0e10cSrcweir                 break;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir                 case 2:         // Coverage Format 2
271cdf0e10cSrcweir                 {
272cdf0e10cSrcweir                     const sal_uInt16 nCntRange = NEXT_UShort( pCoverage );
273cdf0e10cSrcweir                     if( pGsubLimit < pCoverage + 6 * nCntRange )
274cdf0e10cSrcweir                         // TODO? nCntGlyph = (pGsubLimit - pCoverage) / 6;
275cdf0e10cSrcweir                         return false;
276cdf0e10cSrcweir                     for( int i = nCntRange; --i >= 0; )
277cdf0e10cSrcweir                     {
278cdf0e10cSrcweir                         const sal_uInt32 nGlyph0 = NEXT_UShort( pCoverage );
279cdf0e10cSrcweir                         const sal_uInt32 nGlyph1 = NEXT_UShort( pCoverage );
280cdf0e10cSrcweir                         const sal_uInt16 nCovIdx = NEXT_UShort( pCoverage );
281cdf0e10cSrcweir                         for( sal_uInt32 j = nGlyph0; j <= nGlyph1; ++j )
282cdf0e10cSrcweir                             aSubstVector.push_back( GlyphSubst( static_cast<sal_uInt16>(j + nCovIdx), 0 ) );
283cdf0e10cSrcweir                     }
284cdf0e10cSrcweir                 }
285cdf0e10cSrcweir                 break;
286cdf0e10cSrcweir             }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir             SubstVector::iterator subst_it( aSubstVector.begin() );
289cdf0e10cSrcweir 
290cdf0e10cSrcweir             switch( nFmtSubstitution )
291cdf0e10cSrcweir             {
292cdf0e10cSrcweir                 case 1:     // Single Substitution Format 1
293cdf0e10cSrcweir                 {
294cdf0e10cSrcweir                     const sal_uInt16 nDeltaGlyphId = NEXT_UShort( pSubLookup );
295cdf0e10cSrcweir 
296cdf0e10cSrcweir                     for(; subst_it != aSubstVector.end(); ++subst_it )
297cdf0e10cSrcweir                         (*subst_it).second = (*subst_it).first + nDeltaGlyphId;
298cdf0e10cSrcweir                 }
299cdf0e10cSrcweir                 break;
300cdf0e10cSrcweir 
301cdf0e10cSrcweir                 case 2:     // Single Substitution Format 2
302cdf0e10cSrcweir                 {
303cdf0e10cSrcweir                     const sal_uInt16 nCntGlyph = NEXT_UShort( pSubLookup );
304cdf0e10cSrcweir                     for( int i = nCntGlyph; (subst_it != aSubstVector.end()) && (--i>=0); ++subst_it )
305cdf0e10cSrcweir                     {
306cdf0e10cSrcweir                         if( pGsubLimit < pSubLookup + 2 )
307cdf0e10cSrcweir                             return false;
308cdf0e10cSrcweir                         const sal_uInt16 nGlyphId = NEXT_UShort( pSubLookup );
309cdf0e10cSrcweir                         (*subst_it).second = nGlyphId;
310cdf0e10cSrcweir                     }
311cdf0e10cSrcweir                 }
312cdf0e10cSrcweir                 break;
313cdf0e10cSrcweir             }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir             // now apply the glyph substitutions that have been collected in this subtable
316cdf0e10cSrcweir             if( aSubstVector.size() > 0 )
317cdf0e10cSrcweir             {
318cdf0e10cSrcweir                 GlyphSubstitution* pGSubstitution = new GlyphSubstitution;
319cdf0e10cSrcweir                 pTTFile->pGSubstitution = (void*)pGSubstitution;
320cdf0e10cSrcweir                 for( subst_it = aSubstVector.begin(); subst_it != aSubstVector.end(); ++subst_it )
321cdf0e10cSrcweir                     (*pGSubstitution)[ (*subst_it).first ] =  (*subst_it).second;
322cdf0e10cSrcweir             }
323cdf0e10cSrcweir         }
324cdf0e10cSrcweir     }
325cdf0e10cSrcweir     return true;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
ReleaseGSUB(struct _TrueTypeFont * pTTFile)328cdf0e10cSrcweir void ReleaseGSUB(struct _TrueTypeFont* pTTFile)
329cdf0e10cSrcweir {
330cdf0e10cSrcweir     GlyphSubstitution* pGlyphSubstitution = (GlyphSubstitution*)pTTFile->pGSubstitution;
331cdf0e10cSrcweir     if( pGlyphSubstitution )
332cdf0e10cSrcweir         delete pGlyphSubstitution;
333cdf0e10cSrcweir }
334cdf0e10cSrcweir 
UseGSUB(struct _TrueTypeFont * pTTFile,int nGlyph,int)335cdf0e10cSrcweir int UseGSUB( struct _TrueTypeFont* pTTFile, int nGlyph, int /*wmode*/ )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir     GlyphSubstitution* pGlyphSubstitution = (GlyphSubstitution*)pTTFile->pGSubstitution;
338cdf0e10cSrcweir     if( pGlyphSubstitution != 0 )
339cdf0e10cSrcweir     {
340cdf0e10cSrcweir         GlyphSubstitution::const_iterator it( pGlyphSubstitution->find( sal::static_int_cast<sal_uInt16>(nGlyph) ) );
341cdf0e10cSrcweir         if( it != pGlyphSubstitution->end() )
342cdf0e10cSrcweir             nGlyph = (*it).second;
343cdf0e10cSrcweir     }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     return nGlyph;
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
HasVerticalGSUB(struct _TrueTypeFont * pTTFile)348cdf0e10cSrcweir int HasVerticalGSUB( struct _TrueTypeFont* pTTFile )
349cdf0e10cSrcweir {
350cdf0e10cSrcweir     GlyphSubstitution* pGlyphSubstitution = (GlyphSubstitution*)pTTFile->pGSubstitution;
351cdf0e10cSrcweir     return pGlyphSubstitution ? +1 : 0;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir }
355