Skip to content

Commit b3efdc2

Browse files
committed
Support for truetype collections.
1 parent c46083b commit b3efdc2

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

ttfdump.c

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
static int g_nglyphs;
2121
static int g_locafmt;
22+
static int g_indent;
2223

2324
void panic(char *fmt, ...)
2425
{
@@ -70,7 +71,7 @@ static void indent(int level, const char *fmt, ...)
7071
int i;
7172

7273
va_start(args, fmt);
73-
for (i = 0; i < level; i++)
74+
for (i = 0; i < g_indent + level; i++)
7475
putchar('\t');
7576
vprintf(fmt, args);
7677
va_end(args);
@@ -84,6 +85,8 @@ static void indentdump(int level, int offset, int max, const char *fmt, ...)
8485

8586
if (offset % max)
8687
level = 0;
88+
if (level > 0)
89+
level += g_indent;
8790
for (i = 0; i < level; i++)
8891
putchar('\t');
8992
if (fmt) {
@@ -1215,7 +1218,7 @@ void dumptable(FILE *f, ulong ofs, ulong len, char *name)
12151218
}
12161219

12171220
/*
1218-
* Main
1221+
* Main truetype
12191222
*/
12201223

12211224
void readfontdir(FILE *f)
@@ -1343,6 +1346,50 @@ void readfontdir(FILE *f)
13431346
readglyf(f, glyfofs, locaofs);
13441347
}
13451348

1349+
/*
1350+
* Main truetype collection
1351+
*/
1352+
void readcollection(FILE *f)
1353+
{
1354+
ulong tag;
1355+
ulong version;
1356+
ulong fonts;
1357+
ulong length;
1358+
ulong offset;
1359+
int i;
1360+
long save;
1361+
1362+
indent(0, "truetype collection\n");
1363+
indent(0, "{\n");
1364+
1365+
tag = readulong(f);
1366+
version = readulong(f);
1367+
fonts = readulong(f);
1368+
1369+
indent(1, "version = 0x%08x\n", version);
1370+
indent(1, "fonts = 0x%08x\n", fonts);
1371+
1372+
save = ftell(f);
1373+
1374+
for (i = 0; i < fonts; i++) {
1375+
offset = readulong(f);
1376+
indent(1, "offsetTable[% 3d]: 0x%08x\n", i, offset);
1377+
}
1378+
puts("");
1379+
1380+
fseek(f, save, 0);
1381+
for (i = 0; i < fonts; i++) {
1382+
fseek(f, 12 + i * 4, 0);
1383+
offset = readulong(f);
1384+
fseek(f, offset, 0);
1385+
g_indent = 1;
1386+
readfontdir(f);
1387+
puts("");
1388+
}
1389+
1390+
puts("}");
1391+
}
1392+
13461393
int main(int argc, char **argv)
13471394
{
13481395
if (argc < 2)
@@ -1352,7 +1399,14 @@ int main(int argc, char **argv)
13521399
if (!f)
13531400
panic("fopen failed");
13541401

1355-
readfontdir(f);
1402+
ulong tag = readulong(f);
1403+
fseek(f, 0, 0);
1404+
if (tag == 0x74746366)
1405+
readcollection(f);
1406+
else {
1407+
g_indent = 0;
1408+
readfontdir(f);
1409+
}
13561410

13571411
fclose(f);
13581412

0 commit comments

Comments
 (0)