2002-02-27 22:25:47 +01:00
|
|
|
#include "t1cmap.h"
|
2002-03-21 16:02:54 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include FT_INTERNAL_DEBUG_H
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** TYPE1 STANDARD (AND EXPERT) ENCODING CMAPS *****/
|
|
|
|
/***** *****/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2002-03-21 16:02:54 +01:00
|
|
|
static void
|
2002-03-28 09:07:16 +01:00
|
|
|
t1_cmap_std_init( T1_CMapStd cmap,
|
|
|
|
FT_Int is_expert )
|
2002-02-27 22:25:47 +01:00
|
|
|
{
|
2002-03-28 09:07:16 +01:00
|
|
|
T1_Face face = (T1_Face)FT_CMAP_FACE( cmap );
|
|
|
|
PSNames_Service psnames = (PSNames_Service)face->psnames;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-21 16:02:54 +01:00
|
|
|
cmap->num_glyphs = face->type1.num_glyphs;
|
2002-03-25 18:02:26 +01:00
|
|
|
cmap->glyph_names = (const char* const*)face->type1.glyph_names;
|
2002-03-21 16:02:54 +01:00
|
|
|
cmap->sid_to_string = psnames->adobe_std_strings;
|
|
|
|
cmap->code_to_sid = is_expert ? psnames->adobe_expert_encoding
|
|
|
|
: psnames->adobe_std_encoding;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
FT_ASSERT( cmap->code_to_sid != NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( void )
|
|
|
|
t1_cmap_std_done( T1_CMapStd cmap )
|
|
|
|
{
|
2002-03-21 16:02:54 +01:00
|
|
|
cmap->num_glyphs = 0;
|
|
|
|
cmap->glyph_names = NULL;
|
|
|
|
cmap->sid_to_string = NULL;
|
|
|
|
cmap->code_to_sid = NULL;
|
2002-02-27 22:25:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
|
|
|
t1_cmap_std_char_index( T1_CMapStd cmap,
|
|
|
|
FT_UInt32 char_code )
|
|
|
|
{
|
|
|
|
FT_UInt result = 0;
|
|
|
|
|
|
|
|
if ( char_code < 256 )
|
|
|
|
{
|
2002-03-21 16:02:54 +01:00
|
|
|
FT_UInt code, n;
|
2002-02-27 22:25:47 +01:00
|
|
|
const char* glyph_name;
|
|
|
|
|
|
|
|
/* conver character code to Adobe SID string */
|
|
|
|
code = cmap->code_to_sid[ char_code ];
|
2002-03-21 16:02:54 +01:00
|
|
|
glyph_name = cmap->sid_to_string( code );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
/* look for the corresponding glyph name */
|
|
|
|
for ( n = 0; n < cmap->num_glyphs; n++ )
|
|
|
|
{
|
|
|
|
const char* gname = cmap->glyph_names[n];
|
|
|
|
|
|
|
|
if ( gname && gname[0] == glyph_name[0] &&
|
|
|
|
strcmp( gname, glyph_name ) == 0 )
|
|
|
|
{
|
|
|
|
result = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
|
|
|
t1_cmap_std_char_next( T1_CMapStd cmap,
|
|
|
|
FT_UInt32 *pchar_code )
|
|
|
|
{
|
|
|
|
FT_UInt result = 0;
|
2002-03-21 11:39:23 +01:00
|
|
|
FT_UInt32 char_code = *pchar_code + 1;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
while ( char_code < 256 )
|
|
|
|
{
|
2002-03-21 16:02:54 +01:00
|
|
|
result = t1_cmap_std_char_index( cmap, char_code );
|
2002-02-27 22:25:47 +01:00
|
|
|
if ( result != 0 )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
char_code++;
|
|
|
|
}
|
|
|
|
char_code = 0;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
*pchar_code = char_code;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
|
|
|
t1_cmap_standard_init( T1_CMapStd cmap )
|
|
|
|
{
|
|
|
|
t1_cmap_std_init( cmap, 0 );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-28 09:07:16 +01:00
|
|
|
FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
|
2002-02-27 22:25:47 +01:00
|
|
|
t1_cmap_standard_class_rec =
|
|
|
|
{
|
|
|
|
sizeof( T1_CMapStdRec ),
|
|
|
|
|
2002-03-21 16:02:54 +01:00
|
|
|
(FT_CMap_InitFunc) t1_cmap_standard_init,
|
|
|
|
(FT_CMap_DoneFunc) t1_cmap_std_done,
|
|
|
|
(FT_CMap_CharIndexFunc) t1_cmap_std_char_index,
|
|
|
|
(FT_CMap_CharNextFunc) t1_cmap_std_char_next
|
2002-02-27 22:25:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 16:02:54 +01:00
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
2002-02-27 22:25:47 +01:00
|
|
|
t1_cmap_expert_init( T1_CMapStd cmap )
|
|
|
|
{
|
|
|
|
t1_cmap_std_init( cmap, 1 );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-03-28 09:07:16 +01:00
|
|
|
FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
|
2002-02-27 22:25:47 +01:00
|
|
|
t1_cmap_expert_class_rec =
|
|
|
|
{
|
|
|
|
sizeof( T1_CMapStdRec ),
|
|
|
|
|
2002-03-21 16:02:54 +01:00
|
|
|
(FT_CMap_InitFunc) t1_cmap_expert_init,
|
|
|
|
(FT_CMap_DoneFunc) t1_cmap_std_done,
|
|
|
|
(FT_CMap_CharIndexFunc) t1_cmap_std_char_index,
|
|
|
|
(FT_CMap_CharNextFunc) t1_cmap_std_char_next
|
2002-02-27 22:25:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** TYPE1 CUSTOM ENCODING CMAP *****/
|
|
|
|
/***** *****/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
|
|
|
t1_cmap_custom_init( T1_CMapCustom cmap )
|
|
|
|
{
|
2002-03-21 16:02:54 +01:00
|
|
|
T1_Face face = (T1_Face) FT_CMAP_FACE(cmap);
|
|
|
|
T1_Encoding encoding = &face->type1.encoding;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
cmap->first = encoding->code_first;
|
|
|
|
cmap->count = (FT_UInt)(encoding->code_last - cmap->first + 1);
|
|
|
|
cmap->indices = encoding->char_index;
|
|
|
|
|
|
|
|
FT_ASSERT( cmap->indices != NULL );
|
|
|
|
FT_ASSERT( encoding->code_first <= encoding->code_last );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( void )
|
|
|
|
t1_cmap_custom_done( T1_CMapCustom cmap )
|
|
|
|
{
|
|
|
|
cmap->indices = NULL;
|
|
|
|
cmap->first = 0;
|
|
|
|
cmap->count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
|
|
|
t1_cmap_custom_char_index( T1_CMapCustom cmap,
|
|
|
|
FT_UInt32 char_code )
|
|
|
|
{
|
|
|
|
FT_UInt result = 0;
|
|
|
|
FT_UInt32 index;
|
|
|
|
|
|
|
|
index = (FT_UInt32)( char_code - cmap->first );
|
|
|
|
if ( index < cmap->count )
|
|
|
|
result = cmap->indices[ index ];
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-21 16:02:54 +01:00
|
|
|
t1_cmap_custom_char_next( T1_CMapCustom cmap,
|
|
|
|
FT_UInt32 *pchar_code )
|
2002-02-27 22:25:47 +01:00
|
|
|
{
|
|
|
|
FT_UInt result = 0;
|
|
|
|
FT_UInt32 char_code = *pchar_code;
|
|
|
|
FT_UInt32 index;
|
|
|
|
|
|
|
|
++char_code;
|
|
|
|
|
|
|
|
if ( char_code < cmap->first )
|
|
|
|
char_code = cmap->first;
|
|
|
|
|
|
|
|
index = (FT_UInt32)( char_code - cmap->first );
|
2002-03-21 16:02:54 +01:00
|
|
|
for ( ; index < cmap->count; index++, char_code++ )
|
2002-02-27 22:25:47 +01:00
|
|
|
{
|
|
|
|
result = cmap->indices[index];
|
|
|
|
if ( result != 0 )
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
char_code = 0;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
*pchar_code = char_code;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-28 09:07:16 +01:00
|
|
|
FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
|
2002-02-27 22:25:47 +01:00
|
|
|
t1_cmap_custom_class_rec =
|
|
|
|
{
|
|
|
|
sizeof( T1_CMapCustomRec ),
|
2002-03-21 16:02:54 +01:00
|
|
|
(FT_CMap_InitFunc) t1_cmap_custom_init,
|
|
|
|
(FT_CMap_DoneFunc) t1_cmap_custom_done,
|
|
|
|
(FT_CMap_CharIndexFunc) t1_cmap_custom_char_index,
|
|
|
|
(FT_CMap_CharNextFunc) t1_cmap_custom_char_next
|
2002-02-27 22:25:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** TYPE1 SYNTHETIC UNICODE ENCODING CMAP *****/
|
|
|
|
/***** *****/
|
|
|
|
/***************************************************************************/
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2002-03-21 16:02:54 +01:00
|
|
|
FT_CALLBACK_DEF( FT_Int )
|
|
|
|
t1_cmap_uni_pair_compare( const void* pair1,
|
|
|
|
const void* pair2 )
|
|
|
|
{
|
|
|
|
FT_UInt32 u1 = ((T1_CMapUniPair)pair1)->unicode;
|
|
|
|
FT_UInt32 u2 = ((T1_CMapUniPair)pair2)->unicode;
|
|
|
|
|
|
|
|
if ( u1 < u2 )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if ( u1 > u2 )
|
|
|
|
return +1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
|
|
|
t1_cmap_unicode_init( T1_CMapUnicode cmap )
|
|
|
|
{
|
2002-03-21 16:02:54 +01:00
|
|
|
FT_Error error;
|
|
|
|
FT_UInt count;
|
2002-03-28 09:07:16 +01:00
|
|
|
T1_Face face = (T1_Face)FT_CMAP_FACE( cmap );
|
|
|
|
FT_Memory memory = FT_FACE_MEMORY( face );
|
|
|
|
PSNames_Service psnames = (PSNames_Service)face->psnames;
|
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
cmap->num_pairs = 0;
|
|
|
|
cmap->pairs = NULL;
|
|
|
|
|
|
|
|
count = face->type1.num_glyphs;
|
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( !FT_NEW_ARRAY( cmap->pairs, count ) )
|
2002-02-27 22:25:47 +01:00
|
|
|
{
|
|
|
|
FT_UInt n, new_count;
|
|
|
|
T1_CMapUniPair pair;
|
|
|
|
FT_UInt32 uni_code;
|
|
|
|
|
|
|
|
|
|
|
|
pair = cmap->pairs;
|
|
|
|
for ( n = 0; n < count; n++ )
|
|
|
|
{
|
|
|
|
const char* gname = face->type1.glyph_names[n];
|
|
|
|
|
|
|
|
/* build unsorted pair table by matching glyph names */
|
|
|
|
if ( gname )
|
|
|
|
{
|
2002-03-21 16:02:54 +01:00
|
|
|
uni_code = psnames->unicode_value( gname );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
if ( uni_code != 0 )
|
|
|
|
{
|
|
|
|
pair->unicode = uni_code;
|
|
|
|
pair->gindex = n;
|
|
|
|
pair++;
|
|
|
|
}
|
|
|
|
}
|
2002-03-21 16:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
new_count = (FT_UInt)( pair - cmap->pairs );
|
|
|
|
if ( new_count == 0 )
|
|
|
|
{
|
|
|
|
/* there are no unicode characters in here !! */
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( cmap->pairs );
|
2002-03-21 16:02:54 +01:00
|
|
|
error = FT_Err_Invalid_Argument;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* re-allocate if the new array is much smaller than the original */
|
|
|
|
/* one.. */
|
|
|
|
if ( new_count != count && new_count < count/2 )
|
2002-02-27 22:25:47 +01:00
|
|
|
{
|
2002-03-22 14:52:37 +01:00
|
|
|
(void)FT_RENEW_ARRAY( cmap->pairs, count, new_count );
|
2002-03-21 16:02:54 +01:00
|
|
|
error = 0;
|
2002-02-27 22:25:47 +01:00
|
|
|
}
|
2002-03-21 16:02:54 +01:00
|
|
|
|
|
|
|
/* sort the pairs table to allow efficient binary searches */
|
|
|
|
qsort( cmap->pairs,
|
|
|
|
new_count,
|
|
|
|
sizeof(T1_CMapUniPairRec),
|
|
|
|
t1_cmap_uni_pair_compare );
|
|
|
|
|
|
|
|
cmap->num_pairs = new_count;
|
2002-02-27 22:25:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( void )
|
|
|
|
t1_cmap_unicode_done( T1_CMapUnicode cmap )
|
|
|
|
{
|
2002-03-21 16:02:54 +01:00
|
|
|
FT_Face face = FT_CMAP_FACE(cmap);
|
2002-02-27 22:25:47 +01:00
|
|
|
FT_Memory memory = FT_FACE_MEMORY(face);
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( cmap->pairs );
|
2002-02-27 22:25:47 +01:00
|
|
|
cmap->num_pairs = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-21 16:02:54 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
|
|
|
t1_cmap_unicode_char_index( T1_CMapUnicode cmap,
|
|
|
|
FT_UInt32 char_code )
|
|
|
|
{
|
|
|
|
FT_UInt min = 0;
|
|
|
|
FT_UInt max = cmap->num_pairs;
|
|
|
|
FT_UInt mid;
|
|
|
|
T1_CMapUniPair pair;
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
while ( min < max )
|
|
|
|
{
|
|
|
|
mid = min + (max - min)/2;
|
|
|
|
pair = cmap->pairs + mid;
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
if ( pair->unicode == char_code )
|
|
|
|
return pair->gindex;
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
if ( pair->unicode < char_code )
|
|
|
|
min = mid+1;
|
|
|
|
else
|
|
|
|
max = mid;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
|
|
|
t1_cmap_unicode_char_next( T1_CMapUnicode cmap,
|
|
|
|
FT_UInt32 *pchar_code )
|
|
|
|
{
|
2002-03-21 16:02:54 +01:00
|
|
|
FT_UInt result = 0;
|
|
|
|
FT_UInt32 char_code = *pchar_code + 1;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
Restart:
|
|
|
|
{
|
|
|
|
FT_UInt min = 0;
|
|
|
|
FT_UInt max = cmap->num_pairs;
|
|
|
|
FT_UInt mid;
|
|
|
|
T1_CMapUniPair pair;
|
|
|
|
|
|
|
|
while ( min < max )
|
|
|
|
{
|
2002-03-21 16:02:54 +01:00
|
|
|
mid = min + ((max - min) >> 1);
|
2002-02-27 22:25:47 +01:00
|
|
|
pair = cmap->pairs + mid;
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
if ( pair->unicode == char_code )
|
|
|
|
{
|
|
|
|
result = pair->gindex;
|
|
|
|
if ( result != 0 )
|
|
|
|
goto Exit;
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
char_code++;
|
|
|
|
goto Restart;
|
|
|
|
}
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
if ( pair->unicode < char_code )
|
|
|
|
min = mid+1;
|
|
|
|
else
|
|
|
|
max = mid;
|
|
|
|
}
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
/* we didn't find it, but we have a pair just above it */
|
|
|
|
char_code = 0;
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
if ( min < cmap->num_pairs )
|
|
|
|
{
|
2002-03-21 16:02:54 +01:00
|
|
|
pair = cmap->pairs + min;
|
2002-02-27 22:25:47 +01:00
|
|
|
result = pair->gindex;
|
|
|
|
if ( result != 0 )
|
|
|
|
char_code = pair->unicode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
*pchar_code = char_code;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-28 09:07:16 +01:00
|
|
|
FT_CALLBACK_TABLE_DEF const FT_CMap_ClassRec
|
2002-02-27 22:25:47 +01:00
|
|
|
t1_cmap_unicode_class_rec =
|
|
|
|
{
|
|
|
|
sizeof( T1_CMapUnicodeRec ),
|
2002-03-21 16:02:54 +01:00
|
|
|
(FT_CMap_InitFunc) t1_cmap_unicode_init,
|
|
|
|
(FT_CMap_DoneFunc) t1_cmap_unicode_done,
|
|
|
|
(FT_CMap_CharIndexFunc) t1_cmap_unicode_char_index,
|
|
|
|
(FT_CMap_CharNextFunc) t1_cmap_unicode_char_next
|
2002-02-27 22:25:47 +01:00
|
|
|
};
|
2002-03-21 16:02:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
|