From 219e53c45256eae3681ab245724da277887ba6b3 Mon Sep 17 00:00:00 2001 From: handa Date: Wed, 5 May 2004 00:19:45 +0000 Subject: [PATCH] *** empty log message *** --- example/otfdump.c | 1 + example/otflist.c | 29 +++++++++++++--- src/config.h.in | 4 +-- src/otf.h | 4 +++ src/otfopen.c | 95 +++++++++++++++++++++++++++++++---------------------- 5 files changed, 86 insertions(+), 47 deletions(-) diff --git a/example/otfdump.c b/example/otfdump.c index 7d1d4d9..3ec19e0 100644 --- a/example/otfdump.c +++ b/example/otfdump.c @@ -23,6 +23,7 @@ write to the Free Software Foundation, Inc., 59 Temple Place, Suite #include #include +#include #include #include #include diff --git a/example/otflist.c b/example/otflist.c index db63961..85ff998 100644 --- a/example/otflist.c +++ b/example/otflist.c @@ -29,6 +29,8 @@ write to the Free Software Foundation, Inc., 59 Temple Place, Suite #include #include FT_FREETYPE_H +#include + int filter (const struct dirent *direntry) { @@ -65,11 +67,28 @@ main (int argc, char **argv) for (i = 0; i < n; i++) if (! FT_New_Face (ft_library, namelist[i]->d_name, 0, &face)) { - char *name = alloca (strlen (namelist[i]->d_name) - + strlen (face->family_name) - + 4); - sprintf (name, "%s (%s)", namelist[i]->d_name, face->family_name); - printf ("%-40s %s", name, face->style_name); + OTF *otf = OTF_open (namelist[i]->d_name); + char *name, *family, *style; + + if (otf) + { + OTF_get_table (otf, "name"); + + if (! (family = otf->name->name[16])) + family = otf->name->name[1]; + if (! (style = otf->name->name[17])) + style = otf->name->name[2]; + } + if (! family) + family = face->family_name; + if (! style) + style = face->style_name; + + name = alloca (strlen (namelist[i]->d_name) + + strlen (family) + + 4); + sprintf (name, "%s (%s)", namelist[i]->d_name, family); + printf ("%-40s %s", name, style); for (j = 0; j < face->num_charmaps; j++) printf (" %d-%d", face->charmaps[j]->platform_id, face->charmaps[j]->encoding_id); diff --git a/src/config.h.in b/src/config.h.in index f78e200..f3d67e9 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -24,8 +24,8 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H -/* Define to 1 if your system has a working `malloc' function, and to 0 - otherwise. */ +/* Define to 1 if your system has a GNU libc compatible `malloc' function, and + to 0 otherwise. */ #undef HAVE_MALLOC /* Define to 1 if you have the header file. */ diff --git a/src/otf.h b/src/otf.h index 15b63df..6991ce7 100644 --- a/src/otf.h +++ b/src/otf.h @@ -104,6 +104,10 @@ typedef struct int nameID; int length; int offset; + + /* If nonzero, NAME is an ASCII string. */ + int ascii; + unsigned char *name; } OTF_NameRecord; #define OTF_max_nameID 23 diff --git a/src/otfopen.c b/src/otfopen.c index 6776e21..93228f0 100644 --- a/src/otfopen.c +++ b/src/otfopen.c @@ -337,52 +337,74 @@ read_head_table (OTF *otf, OTF_Stream *stream) /*** (1-3) "name" table */ -static char * -read_name (OTF *otf, OTF_Stream *stream, OTF_NameRecord *rec, int bytes) +static int +read_name (OTF *otf, OTF_Stream *stream, OTF_NameRecord *rec) { char *errfmt = "nameID (%d)"; - void *errret = NULL; + int errret = -1; OTF_StreamState state; - char *str; + int ucs = 0; + int ascii = 0; int i; - int c; + if (rec->platformID == 0) + ucs = (rec->encodingID <= 3) ? 2 : 4; + else if (rec->platformID == 1 && rec->encodingID == 0) + ascii = 1; + else if (rec->platformID == 3) + ucs = (rec->encodingID == 1 ? 2 + : rec->encodingID == 10 ? 4 + : 0); + + OTF_MALLOC (rec->name, rec->length + 1, (void *) rec->nameID); SAVE_STREAM (stream, state); SEEK_STREAM (stream, stream->pos + rec->offset); + READ_BYTES (stream, rec->name, rec->length); + RESTORE_STREAM (stream, state); + rec->name[rec->length] = 0; - if (bytes == 1) + if (ascii) { - OTF_MALLOC (str, rec->length + 1, (void *) rec->nameID); - READ_BYTES (stream, str, rec->length); - for (i = 0; i < rec->length; i++) - if (str[i] < 0) - str[i] = '?'; + rec->ascii = 1; } - else if (bytes == 2) + else if (ucs == 2) { - OTF_MALLOC (str, rec->length / 2 + 1, (void *) rec->nameID); + rec->ascii = 1; for (i = 0; i < rec->length / 2; i++) { - READ_USHORT (stream, c); - if (c >= 128) - c = '?'; - str[i] = c; + if (rec->name[i * 2] > 0 + || rec->name[i * 2 + 1] >= 128) + { + rec->ascii = 0; + break; + } } + if (rec->ascii) + for (i = 0; i < rec->length / 2; i++) + rec->name[i] = rec->name[i * 2 + 1]; + rec->name[i] = 0; } - else if (bytes == 4) + else if (ucs == 4) { - OTF_MALLOC (str, rec->length / 4 + 1, (void *) rec->nameID); + rec->ascii = 1; for (i = 0; i < rec->length / 4; i++) { - READ_ULONG (stream, c); - if (c >= 128) - c = '?'; - str[i] = c; + if (rec->name[i * 4] > 0 + || rec->name[i * 4 + 1] > 0 + || rec->name[i * 4 + 2] > 0 + || rec->name[i * 2 + 3] >= 128) + { + rec->ascii = 0; + break; + } } + if (rec->ascii) + for (i = 0; i < rec->length / 4; i++) + rec->name[i] = rec->name[i * 4 + 3]; + rec->name[i] = 0; } - str[i] = '\0'; - RESTORE_STREAM (stream, state); - return str; + + return 0; } static void * @@ -414,20 +436,13 @@ read_name_table (OTF *otf, OTF_Stream *stream) OTF_NameRecord *rec = name->nameRecord + i; int nameID = rec->nameID; - if (nameID <= OTF_max_nameID - && ! name->name[nameID]) - { - if (rec->platformID == 0) - name->name[nameID] = read_name (otf, stream, rec, - rec->encodingID <= 3 ? 2 : 4); - else if (rec->platformID == 1 - && rec->encodingID == 0) - name->name[nameID] = read_name (otf, stream, rec, 1); - else if (rec->platformID == 3 - && (rec->encodingID == 1 || rec->encodingID == 10)) - name->name[nameID] = read_name (otf, stream, - rec, rec->encodingID == 1 ? 2 : 4); - } + read_name (otf, stream, rec); + + if (nameID >= OTF_max_nameID) + continue; + if (! name->name[nameID] + && rec->ascii) + name->name[nameID] = (char *) rec->name; } return name; -- 1.7.10.4