comparison mupdf-source/thirdparty/mujs/genucd.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 # Create utfdata.h from UnicodeData.txt
2
3 import sys
4
5 tolower = []
6 toupper = []
7 isalpha = []
8
9 for line in open(sys.argv[1]).readlines():
10 line = line.split(";")
11 code = int(line[0],16)
12 # if code > 65535: continue # skip non-BMP codepoints
13 if line[2][0] == 'L':
14 isalpha.append(code)
15 if line[12]:
16 toupper.append((code,int(line[12],16)))
17 if line[13]:
18 tolower.append((code,int(line[13],16)))
19
20 def dumpalpha():
21 table = []
22 prev = 0
23 start = 0
24 for code in isalpha:
25 if code != prev+1:
26 if start:
27 table.append((start,prev))
28 start = code
29 prev = code
30 table.append((start,prev))
31
32 print("")
33 print("static const Rune ucd_alpha2[] = {")
34 for a, b in table:
35 if b - a > 0:
36 print(hex(a)+","+hex(b)+",")
37 print("};");
38
39 print("")
40 print("static const Rune ucd_alpha1[] = {")
41 for a, b in table:
42 if b - a == 0:
43 print(hex(a)+",")
44 print("};");
45
46 def dumpmap(name, input):
47 table = []
48 prev_a = 0
49 prev_b = 0
50 start_a = 0
51 start_b = 0
52 for a, b in input:
53 if a != prev_a+1 or b != prev_b+1:
54 if start_a:
55 table.append((start_a,prev_a,start_b))
56 start_a = a
57 start_b = b
58 prev_a = a
59 prev_b = b
60 table.append((start_a,prev_a,start_b))
61
62 print("")
63 print("static const Rune " + name + "2[] = {")
64 for a, b, n in table:
65 if b - a > 0:
66 print(hex(a)+","+hex(b)+","+str(n-a)+",")
67 print("};");
68
69 print("")
70 print("static const Rune " + name + "1[] = {")
71 for a, b, n in table:
72 if b - a == 0:
73 print(hex(a)+","+str(n-a)+",")
74 print("};");
75
76 print("/* This file was automatically created from " + sys.argv[1] + " */")
77 dumpalpha()
78 dumpmap("ucd_tolower", tolower)
79 dumpmap("ucd_toupper", toupper)