summaryrefslogtreecommitdiff
path: root/scripts/glyphdump.py
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-04-06 14:26:21 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-04-06 14:26:21 +0200
commite516feff18c3223a597ba23cbefba01b042c70bd (patch)
tree051efda76770ca2366df6db62d3070a4c1db7725 /scripts/glyphdump.py
parent1ee5591e8a292b10fb1327bed9bea511f77f6df1 (diff)
downloadmupdf-e516feff18c3223a597ba23cbefba01b042c70bd.tar.xz
pdf: Optimize storage for the Adobe Glyph List.
Diffstat (limited to 'scripts/glyphdump.py')
-rwxr-xr-xscripts/glyphdump.py127
1 files changed, 39 insertions, 88 deletions
diff --git a/scripts/glyphdump.py b/scripts/glyphdump.py
index 25b2afcc..a63df95f 100755
--- a/scripts/glyphdump.py
+++ b/scripts/glyphdump.py
@@ -3,15 +3,15 @@
import sys
agl = []
-comments = []
agltab = []
aglmap = {}
-aglnames = []
+
+print "/*"
f = open("glyphlist.txt", "r")
for line in f.readlines():
if line[0] == '#':
- comments.append(line.strip());
+ print line.strip()
continue
line = line[:-1]
name, list = line.split(';')
@@ -26,101 +26,52 @@ for name, ucslist in agl:
aglmap[ucs] = []
aglmap[ucs].append(name)
-print "/*"
-for line in comments:
- print line
print "*/"
print
+def dumplist(list):
+ n = 0;
+ for item in list:
+ n += len(item) + 1
+ if n > 78:
+ sys.stdout.write("\n")
+ n = len(item) + 1
+ sys.stdout.write(item)
+ sys.stdout.write(",")
+ sys.stdout.write("\n")
+
agltab.sort()
-print "static const struct { char *name; int ucs; }"
-print "aglcodes[] = {"
+namelist = []
+codelist = []
for name, ucs in agltab:
- print "{\"%s\", 0x%04X}," % (name, ucs)
-print "};"
-print
+ namelist.append("\"%s\"" % name)
+ codelist.append("%d" % ucs)
keys = aglmap.keys()
keys.sort()
-print "static const struct { int ucs; int ofs; }"
-print "agldupcodes[] = {"
+dupoffsets = []
+dupnames = []
for ucs in keys:
- namelist = aglmap[ucs]
- ofs = len(aglnames)
- if len(namelist) > 1:
- print "{0x%04X, %d}," % (ucs, ofs)
- for name in namelist:
- aglnames.append(name)
- aglnames.append(0)
+ list = aglmap[ucs]
+ ofs = len(dupnames)
+ if len(list) > 1:
+ dupoffsets.append("%d,%d" % (ucs, ofs))
+ for name in list:
+ dupnames.append("\"%s\"" % name)
+ dupnames.append("0")
+
+print "static const char *agl_name_list[] = {"
+dumplist(namelist)
print "};"
print
-
-print "static char *agldupnames[] = {"
-for name in aglnames:
- if name:
- print ("\"%s\"," % name),
- else:
- print "0,"
+print "static const unsigned short agl_code_list[] = {"
+dumplist(codelist)
print "};"
print
-
-print """
-#include "fitz.h"
-#include "mupdf.h"
-
-int pdf_lookupagl(char *name)
-{
- char buf[64];
- char *p;
- int l = 0;
- int r = nelem(aglcodes) - 1;
-
- fz_strlcpy(buf, name, sizeof buf);
-
- /* kill anything after first period and underscore */
- p = strchr(buf, '.');
- if (p) p[0] = 0;
- p = strchr(buf, '_');
- if (p) p[0] = 0;
-
- while (l <= r)
- {
- int m = (l + r) >> 1;
- int c = strcmp(buf, aglcodes[m].name);
- if (c < 0)
- r = m - 1;
- else if (c > 0)
- l = m + 1;
- else
- return aglcodes[m].ucs;
- }
-
- if (strstr(buf, "uni") == buf)
- return strtol(buf + 3, nil, 16);
- else if (strstr(buf, "u") == buf)
- return strtol(buf + 1, nil, 16);
- else if (strstr(buf, "a") == buf && strlen(buf) >= 3)
- return strtol(buf + 1, nil, 10);
-
- return 0;
-}
-
-static char *aglnoname[1] = { 0 };
-
-char **pdf_lookupaglnames(int ucs)
-{
- int l = 0;
- int r = nelem(agldupcodes) - 1;
- while (l <= r)
- {
- int m = (l + r) >> 1;
- if (ucs < agldupcodes[m].ucs)
- r = m - 1;
- else if (ucs > agldupcodes[m].ucs)
- l = m + 1;
- else
- return agldupnames + agldupcodes[m].ofs;
- }
- return aglnoname;
-}
-"""
+print "static const unsigned short agl_dup_offsets[] = {"
+dumplist(dupoffsets)
+print "};"
+print
+print "static const char *agl_dup_names[] = {"
+dumplist(dupnames)
+print "};"