Some formatting and improvements of comments.

This commit is contained in:
Werner Lemberg 2010-11-22 19:30:41 +01:00
parent 9f5dd61bf3
commit 9871b849dd
1 changed files with 46 additions and 21 deletions

View File

@ -149,9 +149,12 @@
static FT_Bool static FT_Bool
tt_check_trickyness_family( FT_String* name ) tt_check_trickyness_family( FT_String* name )
{ {
#define TRICK_NAMES_MAX_CHARACTERS 16 #define TRICK_NAMES_MAX_CHARACTERS 16
#define TRICK_NAMES_COUNT 8 #define TRICK_NAMES_COUNT 8
static const char trick_names[TRICK_NAMES_COUNT][TRICK_NAMES_MAX_CHARACTERS+1] =
static const char trick_names[TRICK_NAMES_COUNT]
[TRICK_NAMES_MAX_CHARACTERS + 1] =
{ {
"DFKaiSho-SB", /* dfkaisb.ttf */ "DFKaiSho-SB", /* dfkaisb.ttf */
"DFKaiShu", "DFKaiShu",
@ -162,7 +165,10 @@
"PMingLiU", /* mingliu.ttc */ "PMingLiU", /* mingliu.ttc */
"MingLi43", /* mingli.ttf */ "MingLi43", /* mingli.ttf */
}; };
int nn; int nn;
for ( nn = 0; nn < TRICK_NAMES_COUNT; nn++ ) for ( nn = 0; nn < TRICK_NAMES_COUNT; nn++ )
if ( ft_strstr( name, trick_names[nn] ) ) if ( ft_strstr( name, trick_names[nn] ) )
return TRUE; return TRUE;
@ -171,11 +177,13 @@
} }
/* XXX: this function should be in sfnt module */ /* XXX: This function should be in the `sfnt' module. */
/* some PDF generators clear the checksum in TrueType header */
/* (Quartz ContextPDF clears all, Bullzip PDF Printer clears */ /* Some PDF generators clear the checksums in the TrueType header table. */
/* for the subsetted subtables), we have to recalculate when */ /* For example, Quartz ContextPDF clears all entries, or Bullzip PDF */
/* it is cleared. */ /* Printer clears the entries for subsetted subtables. We thus have to */
/* recalculate the checksums where necessary. */
static FT_UInt32 static FT_UInt32
tt_synth_sfnt_checksum( FT_Stream stream, tt_synth_sfnt_checksum( FT_Stream stream,
FT_ULong length ) FT_ULong length )
@ -200,15 +208,18 @@
} }
/* XXX: this function should be in sfnt module */ /* XXX: This function should be in the `sfnt' module. */
static FT_ULong static FT_ULong
tt_get_sfnt_checksum( TT_Face face, tt_get_sfnt_checksum( TT_Face face,
FT_UShort i ) FT_UShort i )
{ {
if ( face->dir_tables[i].CheckSum ) if ( face->dir_tables[i].CheckSum )
return face->dir_tables[i].CheckSum; return face->dir_tables[i].CheckSum;
else if ( !face->goto_table ) else if ( !face->goto_table )
return 0; return 0;
else if ( !face->goto_table( face, else if ( !face->goto_table( face,
face->dir_tables[i].Tag, face->dir_tables[i].Tag,
face->root.stream, face->root.stream,
@ -224,6 +235,7 @@
{ {
FT_ULong CheckSum; FT_ULong CheckSum;
FT_ULong Length; FT_ULong Length;
} tt_sfnt_id_rec; } tt_sfnt_id_rec;
@ -232,11 +244,14 @@
{ {
#define TRICK_SFNT_IDS_PER_FACE 3 #define TRICK_SFNT_IDS_PER_FACE 3
#define TRICK_SFNT_IDS_NUM_FACES 5 #define TRICK_SFNT_IDS_NUM_FACES 5
static const tt_sfnt_id_rec sfnt_id[TRICK_SFNT_IDS_NUM_FACES] static const tt_sfnt_id_rec sfnt_id[TRICK_SFNT_IDS_NUM_FACES]
[TRICK_SFNT_IDS_PER_FACE] = { [TRICK_SFNT_IDS_PER_FACE] = {
#define TRICK_SFNT_ID_cvt 0 #define TRICK_SFNT_ID_cvt 0
#define TRICK_SFNT_ID_fpgm 1 #define TRICK_SFNT_ID_fpgm 1
#define TRICK_SFNT_ID_prep 2 #define TRICK_SFNT_ID_prep 2
{ /* MingLiU 1995 */ { /* MingLiU 1995 */
{ 0x05bcf058, 0x000002e4 }, /* cvt */ { 0x05bcf058, 0x000002e4 }, /* cvt */
{ 0x28233bf1, 0x000087c4 }, /* fpgm */ { 0x28233bf1, 0x000087c4 }, /* fpgm */
@ -263,36 +278,46 @@
{ 0x70020112, 0x00000008 } /* prep */ { 0x70020112, 0x00000008 } /* prep */
} }
}; };
FT_ULong checksum; FT_ULong checksum;
int num_matched_ids[TRICK_SFNT_IDS_NUM_FACES]; int num_matched_ids[TRICK_SFNT_IDS_NUM_FACES];
int i, j, k; int i, j, k;
FT_MEM_SET( num_matched_ids, 0, sizeof( int ) * TRICK_SFNT_IDS_NUM_FACES );
FT_MEM_SET( num_matched_ids, 0,
sizeof( int ) * TRICK_SFNT_IDS_NUM_FACES );
for ( i = 0; i < face->num_tables; i++ ) for ( i = 0; i < face->num_tables; i++ )
{ {
checksum = 0; checksum = 0;
switch( face->dir_tables[i].Tag ) switch( face->dir_tables[i].Tag )
{ {
case TTAG_cvt: case TTAG_cvt:
k = TRICK_SFNT_ID_cvt; k = TRICK_SFNT_ID_cvt;
break; break;
case TTAG_fpgm: case TTAG_fpgm:
k = TRICK_SFNT_ID_fpgm; k = TRICK_SFNT_ID_fpgm;
break; break;
case TTAG_prep: case TTAG_prep:
k = TRICK_SFNT_ID_prep; k = TRICK_SFNT_ID_prep;
break; break;
default: default:
continue; continue;
} }
for ( j = 0; j < TRICK_SFNT_IDS_NUM_FACES; j++ ) for ( j = 0; j < TRICK_SFNT_IDS_NUM_FACES; j++ )
if ( face->dir_tables[i].Length == sfnt_id[j][k].Length ) if ( face->dir_tables[i].Length == sfnt_id[j][k].Length )
{ {
if ( !checksum ) if ( !checksum )
checksum = tt_get_sfnt_checksum( face, i ); checksum = tt_get_sfnt_checksum( face, i );
if ( sfnt_id[j][k].CheckSum == checksum ) if ( sfnt_id[j][k].CheckSum == checksum )
num_matched_ids[j] ++; num_matched_ids[j]++;
if ( num_matched_ids[j] == TRICK_SFNT_IDS_PER_FACE ) if ( num_matched_ids[j] == TRICK_SFNT_IDS_PER_FACE )
return TRUE; return TRUE;
} }
@ -308,8 +333,7 @@
if ( !face ) if ( !face )
return FALSE; return FALSE;
/* Note that we only check the face name at the moment; it might */ /* First, check the face name. */
/* be worth to do more checks for a few special cases. */
if ( face->family_name ) if ( face->family_name )
{ {
if ( tt_check_trickyness_family( face->family_name ) ) if ( tt_check_trickyness_family( face->family_name ) )
@ -318,9 +342,10 @@
return FALSE; return FALSE;
} }
/* Type42 may lack `name' tables, try to identfiy tricky fonts by */ /* Type42 fonts may lack `name' tables, we thus try to identify */
/* the checksums of Type42-persistent sfnt tables; cvt, fpgm, prep */ /* tricky fonts by checking the checksums of Type42-persistent */
if ( tt_check_trickyness_sfnt_ids( ( TT_Face )face ) ) /* sfnt tables (`cvt', `fpgm', and `prep'). */
if ( tt_check_trickyness_sfnt_ids( (TT_Face)face ) )
return TRUE; return TRUE;
return FALSE; return FALSE;