#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+
#include "types.h"
#include "proto.h"
+#include "ttftool.h"
struct TableDirectoryEntry *
-readDirectory (int fd, struct OffsetTable *ot)
+readDirectory (FILE *fd, struct OffsetTable *ot)
{
unsigned n;
int i;
struct TableDirectoryEntry *td;
+
surely_read (fd, ot, sizeof (struct OffsetTable));
FIX_OffsetTable (*ot);
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
fprintf (stderr, "%d tables\n", ot->numTables);
+
n = sizeof (struct TableDirectoryEntry) * ot->numTables;
td = mymalloc (n);
surely_read (fd, td, n);
}
char **
-readNamingTable (int fd)
+readNamingTable (FILE *fd)
{
USHORT format;
USHORT nrecords;
char *data;
char **strings;
- position = surely_lseek (fd, 0, SEEK_CUR);
+ position = ftell (fd);
surely_read (fd, &format, sizeof (USHORT));
FIX_UH (format);
strings[records[i].nameID] = mymalloc (records[i].length / 2 + 1);
unistrncpy (strings[records[i].nameID],
data + records[i].offset, records[i].length);
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
fprintf (stderr, "%d: %s\n", records[i].nameID,
strings[records[i].nameID]);
}
strncpy (strings[id],
data + records[i].offset, records[i].length);
strings[id][records[i].length] = 0;
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
fprintf (stderr, "%d: %s\n", records[i].nameID,
strings[records[i].nameID]);
}
}
int
-readMaxpTable (int fd)
+readMaxpTable (FILE *fd)
{
struct
{
surely_read (fd, &data, sizeof (data));
FIX_Fixed (data.version);
FIX_UH (data.nglyphs);
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
fprintf (stderr, " version %d.%u\n",
data.version.mantissa, data.version.fraction);
return data.nglyphs;
}
void
-readHeadTable (int fd, struct HeadTable *ht)
+readHeadTable (FILE *fd, struct HeadTable *ht)
{
surely_read (fd, ht, sizeof (struct HeadTable));
FIX_HeadTable (*ht);
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
{
fprintf (stderr, " version %d.%d\n",
ht->version.mantissa, ht->version.fraction);
}
if (ht->magicNumber != 0x5F0F3CF5)
ttf_error ("Bad magic number");
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
fprintf (stderr, " %d units per Em\n", ht->unitsPerEm);
}
int
-readPostTable (int fd, int nglyphs, struct PostTable *pt,
+readPostTable (FILE *fd, int root_nglyphs, struct PostTable *pt,
struct GlyphName **gt)
{
- USHORT nglyphspost;
+ USHORT nglyphs;
USHORT *glyphNameIndex;
struct GlyphName *glyphNames;
char **glyphNamesTemp;
surely_read (fd, pt, sizeof (struct PostTable));
FIX_PostTable (*pt);
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
fprintf (stderr, " format type %d.%u\n",
pt->formatType.mantissa, pt->formatType.fraction);
case 2:
if (pt->formatType.fraction != 0)
ttf_error ("Unsupported `post' table format");
- surely_read (fd, &nglyphspost, sizeof (USHORT));
- FIX_UH (nglyphspost);
- if (nglyphspost != nglyphs)
- ttf_error ("Inconsistency between `maxp' and `nglyphs' tables!");
- if (verbosity >= 2)
+ surely_read (fd, &nglyphs, sizeof (USHORT));
+
+ /*from freetype2:
+ */
+ /*
+ UNDOCUMENTED! The number of glyphs in this table can be smaller
+ than the value in the maxp table (cf. cyberbit.ttf).
+ */
+ FIX_UH (nglyphs);
+ if (nglyphs > root_nglyphs)
+ {
+ fprintf (stderr, "More glyphs in 'post' table than in 'maxp' table");
+ }
+
+ if (ttf_verbosity >= 2)
fprintf (stderr, " %d glyphs\n", nglyphs);
glyphNameIndex = mymalloc (sizeof (USHORT) * nglyphs);
surely_read (fd, glyphNameIndex, sizeof (USHORT) * nglyphs);
glyphNamesTemp[i] = mymalloc (c + 1);
surely_read (fd, glyphNamesTemp[i], c);
glyphNamesTemp[i][c] = '\0';
- if (verbosity >= 3)
+ if (ttf_verbosity >= 3)
fprintf (stderr, " %d: %s\n", i, glyphNamesTemp[i]);
i++;
}
/*NOTREACHED*/}
void *
-readLocaTable (int fd, int nglyphs, int format)
+readLocaTable (FILE *fd, int nglyphs, int format)
{
int i;
switch (format)
/*NOTREACHED*/}
struct Box *
-readGlyfTable (int fd, int nglyphs, int format, void *loca)
+readGlyfTable (FILE *fd, int nglyphs, int format, void *loca)
{
int i;
struct Box *bbox;
off_t base, offset;
- base = surely_lseek (fd, 0, SEEK_CUR);
+ base = ftell (fd);
bbox = mymalloc (nglyphs * sizeof (struct Box));
for (i = 0; i < nglyphs; i++)
}
longHorMetric *
-readHmtxTable (int fd, int nummetrics)
+readHmtxTable (FILE *fd, int nummetrics)
{
longHorMetric *metrics;
int i;
}
struct HheaTable *
-readHheaTable (int fd)
+readHheaTable (FILE *fd)
{
struct HheaTable *hhea;
hhea = mymalloc (sizeof (struct HheaTable));
surely_read (fd, hhea, sizeof (struct HheaTable));
FIX_HheaTable (*hhea);
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
fprintf (stderr, " version %d.%u\n",
hhea->version.mantissa, hhea->version.fraction);
if (hhea->metricDataFormat != 0)
}
int
-readKernTable (int fd, int **nkep, struct KernEntry0 ***kep)
+readKernTable (FILE *fd, int **nkep, struct KernEntry0 ***kep)
{
struct KernTable kt;
struct KernSubTableHeader ksth;
surely_read (fd, &kt, sizeof (struct KernTable));
FIX_KernTable (kt);
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
{
fprintf (stderr, " version %d\n", kt.version);
fprintf (stderr, " %d subtables\n", kt.nTables);
{
surely_read (fd, &ksth, sizeof (struct KernSubTableHeader));
FIX_KernSubTableHeader (ksth);
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
fprintf (stderr, " analyzing subtable %d, version %d... ",
i, ksth.version);
if ((ksth.coverage & kernHorizontal) &&
{
surely_read (fd, &kst, sizeof (struct KernSubTable0));
FIX_KernSubTable0 (kst);
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
fprintf (stderr, "reading %d entries.\n", kst.nPairs);
nke[i] = kst.nPairs;
ke[i] = mymalloc (kst.nPairs * sizeof (struct KernEntry0));
}
else
{
- if (verbosity >= 2)
+ if (ttf_verbosity >= 2)
fprintf (stderr, "skipping.\n");
surely_lseek (fd, ksth.length - sizeof (struct KernSubTableHeader),
SEEK_CUR);