Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/scripts/glyphdump.py @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 #!/usr/bin/env python3 | |
| 2 | |
| 3 import sys | |
| 4 | |
| 5 agl = [] | |
| 6 aglseen = {} | |
| 7 single_from_name = [] | |
| 8 multi_from_name = [] | |
| 9 name_from_single = {} | |
| 10 code_from_multi = {} | |
| 11 | |
| 12 print("/* This file was generated by scripts/glyphdump.py. Do not edit. */") | |
| 13 print() | |
| 14 | |
| 15 def readlist(filename): | |
| 16 f = open(filename, "r") | |
| 17 for line in f.readlines(): | |
| 18 if line[0] == '#': | |
| 19 continue | |
| 20 line = line[:-1] | |
| 21 name, alts = line.split(';') | |
| 22 for list in alts.split(','): | |
| 23 list = [int(x, 16) for x in list.split(' ')] | |
| 24 okay = True | |
| 25 for ucs in list: | |
| 26 if ucs > 0xffff: | |
| 27 okay = False | |
| 28 #if ucs >= 0xe000 and ucs <= 0xf8ff: | |
| 29 # okay = False | |
| 30 if okay and name not in aglseen: | |
| 31 agl.append((name, list)) | |
| 32 aglseen[name] = True | |
| 33 | |
| 34 readlist("scripts/glyphlist.txt") | |
| 35 readlist("scripts/texglyphlist.txt") | |
| 36 | |
| 37 for name, ucslist in agl: | |
| 38 num = len(ucslist) | |
| 39 if num == 1: | |
| 40 ucs = ucslist[0] | |
| 41 single_from_name.append((name, ucs)) | |
| 42 if ucs not in name_from_single: | |
| 43 name_from_single[ucs] = [] | |
| 44 name_from_single[ucs].append(name) | |
| 45 else: | |
| 46 multi_from_name.append((name, ucslist)) | |
| 47 | |
| 48 def dumplist(list): | |
| 49 for item in list: | |
| 50 sys.stdout.write(item) | |
| 51 | |
| 52 single_from_name.sort() | |
| 53 singlenames = [] | |
| 54 singlecodes = [] | |
| 55 for name, ucs in single_from_name: | |
| 56 singlenames.append("\"%s\",\n" % name) | |
| 57 singlecodes.append("0x%04x,\n" % ucs) | |
| 58 | |
| 59 multi_from_name.sort() | |
| 60 multinames = [] | |
| 61 multioffsets = [] | |
| 62 multicodes = [] | |
| 63 for name, ucslist in multi_from_name: | |
| 64 multinames.append("\"%s\",\n" % name) | |
| 65 multioffsets.append("%d,\n" % len(multicodes)) | |
| 66 multicodes.append("%d," % len(ucslist)) | |
| 67 for ucs in ucslist: | |
| 68 multicodes.append(" 0x%04x," % ucs) | |
| 69 multicodes.append("\n"); | |
| 70 | |
| 71 keys = list(name_from_single.keys()) | |
| 72 keys.sort() | |
| 73 dupoffsets = [] | |
| 74 dupnames = [] | |
| 75 for ucs in keys: | |
| 76 list = name_from_single[ucs] | |
| 77 if len(list) > 1: | |
| 78 ofs = len(dupnames) | |
| 79 dupoffsets.append("0x%04x, %d,\n" % (ucs, ofs)) | |
| 80 for name in list: | |
| 81 dupnames.append("\"%s\", " % name) | |
| 82 dupnames.append("0,\n") | |
| 83 | |
| 84 print("static const char *single_name_list[] = {") | |
| 85 dumplist(singlenames) | |
| 86 print("};") | |
| 87 print() | |
| 88 print("static const unsigned short single_code_list[] = {") | |
| 89 dumplist(singlecodes) | |
| 90 print("};") | |
| 91 print() | |
| 92 if False: | |
| 93 print("static const char *multi_name_list[] = {") | |
| 94 dumplist(multinames) | |
| 95 print("};") | |
| 96 print() | |
| 97 print("static const unsigned short multi_offset_list[] = {") | |
| 98 dumplist(multioffsets) | |
| 99 print("};") | |
| 100 print() | |
| 101 print("static const unsigned short multi_code_list[] = {") | |
| 102 dumplist(multicodes) | |
| 103 print("};") | |
| 104 print() | |
| 105 print("static const unsigned short agl_dup_offsets[] = {") | |
| 106 dumplist(dupoffsets) | |
| 107 print("};") | |
| 108 print() | |
| 109 print("static const char *agl_dup_names[] = {") | |
| 110 dumplist(dupnames) | |
| 111 print("};") |
