#include <ft2build.h>
#include FT_FREETYPE_H
+#include <otf.h>
+
int
filter (const struct dirent *direntry)
{
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);
\f
/*** (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 *
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;