1
/*******************************************************************
5
* API extension for iterating over Cmaps
7
* Copyright 1996-1999 by Juliusz Chroboczek,
8
* David Turner, Robert Wilhelm, and Werner Lemberg.
10
* This file is part of the FreeType project, and may only be used
11
* modified and distributed under the terms of the FreeType project
12
* license, LICENSE.TXT. By continuing to use, modify, or distribute
13
* this file you indicate that you have read the license and
14
* understand and accept it fully.
17
******************************************************************/
25
static Long charmap_first4 ( PCMap4, UShort* );
26
static Long charmap_next4 ( PCMap4, UShort, UShort* );
27
static Long charmap_last4 ( PCMap4, UShort* );
28
static UShort charmap_find_id4( PCMap4, UShort, TCMap4Segment*, UShort );
31
/*******************************************************************
33
* Function : TT_CharMap_First
35
* Description : Returns the first valid character code in a
36
* given character map. Also returns the corresponding
39
* Input : charMap handle to the target character map
40
* id address where the glyph index will be
41
* be returned in case of success
43
* Output : First valid character code. -1 in case of failure.
47
******************************************************************/
50
TT_Long TT_CharMap_First( TT_CharMap charMap,
57
if ( !( cmap = HANDLE_CharMap( charMap ) ) )
60
switch ( cmap->format )
64
*id = cmap->c.cmap0.glyphIdArray[0];
68
return charmap_first4( &cmap->c.cmap4, id );
71
if ( cmap->c.cmap6.entryCount < 1 )
75
*id = cmap->c.cmap6.glyphIdArray[0];
76
return cmap->c.cmap6.firstCode;
79
/* Now loop from 0 to 65535. We can't use a simple "for' on */
80
/* 16-bits systems, hence the "strange" loop here.. */
84
c = TT_Char_Index( charMap, i );
92
} while ( i != 0 ); /* because i is UShort! */
99
static Long charmap_first4( PCMap4 cmap4,
105
if ( cmap4->segCountX2 / 2 < 1 )
108
firstCode = cmap4->segments[0].startCount;
111
*id = charmap_find_id4( cmap4, firstCode, &(cmap4->segments[0]), 0 );
117
/*******************************************************************
119
* Function : TT_CharMap_Next
121
* Description : Returns the next valid character code in a given
124
* Input : charMap handle to the target char. map
125
* index starting character code
126
* id address where the glyph index of the next
127
* character will be returned
129
* Output : Next valid character code after 'index'. -1 in case
134
******************************************************************/
137
TT_Long TT_CharMap_Next( TT_CharMap charMap,
145
cmap = HANDLE_CharMap( charMap );
149
switch ( cmap->format )
155
*id = cmap->c.cmap0.glyphIdArray[index + 1];
162
return charmap_next4( &cmap->c.cmap4, index, id );
166
UShort firstCode = cmap->c.cmap6.firstCode;
169
if ( index + 1 < firstCode + cmap->c.cmap6.entryCount )
172
*id = cmap->c.cmap6.glyphIdArray[index + 1 - firstCode];
180
/* Now loop from 0 to 65535. We can't use a simple "for" on */
181
/* 16-bits systems, hence the "strange" loop here.. */
185
c = TT_Char_Index( charMap, i );
193
} while ( i != 0 ); /* because i is UShort! */
200
static Long charmap_next4( PCMap4 cmap4,
204
UShort segCount, nextCode;
209
if ( charCode == 0xFFFF )
210
return -1; /* get it out of the way now */
212
segCount = cmap4->segCountX2 / 2;
214
for ( i = 0; i < segCount; i++ )
215
if ( charCode < cmap4->segments[i].endCount )
218
/* Safety check - even though the last endCount should be 0xFFFF */
222
seg4 = cmap4->segments[i];
224
if ( charCode < seg4.startCount )
225
nextCode = seg4.startCount;
227
nextCode = charCode + 1;
230
*id = charmap_find_id4( cmap4, nextCode, &seg4, i );
237
charmap_find_id4( PCMap4 cmap4,
245
if ( seg4->idRangeOffset == 0 )
246
return (charCode + seg4->idDelta) & 0xFFFF;
249
index1 = seg4->idRangeOffset / 2 + charCode-seg4->startCount -
250
( cmap4->segCountX2 / 2 - i );
252
if ( index1 >= cmap4->numGlyphId || cmap4->glyphIdArray[index1] == 0 )
255
return (cmap4->glyphIdArray[index1] + seg4->idDelta) & 0xFFFF;
260
/*******************************************************************
262
* Function : TT_CharMap_Last
264
* Description : Returns the last valid character code in a
265
* given character map. Also returns the corresponding
268
* Input : charMap handle to the target character map
269
* id address where the glyph index will be
270
* be returned in case of success
272
* Output : Last valid character code. -1 in case of failure.
276
******************************************************************/
279
TT_Long TT_CharMap_Last( TT_CharMap charMap,
286
if ( !( cmap = HANDLE_CharMap( charMap ) ) )
289
switch ( cmap->format )
293
*id = cmap->c.cmap0.glyphIdArray[255];
297
return charmap_last4( &cmap->c.cmap4, id );
300
if ( cmap->c.cmap6.entryCount < 1 )
304
*id = cmap->c.cmap6.glyphIdArray[cmap->c.cmap6.entryCount - 1];
305
return cmap->c.cmap6.firstCode + cmap->c.cmap6.entryCount - 1;
311
c = TT_Char_Index( charMap, i );
326
static Long charmap_last4( PCMap4 cmap4,
332
if ( cmap4->segCountX2 / 2 < 1 )
335
lastCode = cmap4->segments[cmap4->segCountX2 / 2 - 1].endCount;
338
*id = charmap_find_id4( cmap4,
340
&(cmap4->segments[cmap4->segCountX2 / 2 - 1]),