Bumping manifests a=b2g-bump
[gecko.git] / gfx / thebes / gencjkcisvs.py
blob401ebaa97a058e939de5774bd8c734a94d36b3f1
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 # You can obtain one at http://mozilla.org/MPL/2.0/.
5 import os.path
6 import re
7 import sys
9 f = open(sys.argv[1] if len(sys.argv) > 1 else 'StandardizedVariants.txt')
11 line = f.readline()
12 m = re.compile('^# (StandardizedVariants(-\d+(\.\d+)*)?\.txt)').search(line)
13 fileversion = m.group(1)
14 vsdict = {}
15 r = re.compile('^([0-9A-F]{4,6}) (FE0[0-9A-F]); CJK COMPATIBILITY IDEOGRAPH-([0-9A-F]{4,6});')
16 while True:
17 line = f.readline()
18 if not line:
19 break
20 if not 'CJK COMPATIBILITY IDEOGRAPH-' in line:
21 continue
23 m = r.search(line)
24 unified = int(m.group(1), 16)
25 vs = int(m.group(2), 16)
26 compat = int(m.group(3), 16)
28 if not vs in vsdict:
29 vsdict[vs] = {}
30 vsdict[vs][unified] = compat
32 f.close
34 offsets = []
35 length = 10 + 11 * len(vsdict)
36 for (k, mappings) in sorted(vsdict.items()):
37 offsets.append(length)
38 length += 4 + 5 * len(mappings)
40 f = open(sys.argv[2] if len(sys.argv) > 2 else 'CJKCompatSVS.cpp', 'wb')
41 f.write("""// Generated by %s. Do not edit.
43 #include <stdint.h>
45 #define U16(v) (((v) >> 8) & 0xFF), ((v) & 0xFF)
46 #define U24(v) (((v) >> 16) & 0xFF), (((v) >> 8) & 0xFF), ((v) & 0xFF)
47 #define U32(v) (((v) >> 24) & 0xFF), (((v) >> 16) & 0xFF), (((v) >> 8) & 0xFF), ((v) & 0xFF)
48 #define GLYPH(v) U16(v >= 0x2F800 ? (v) - (0x2F800 - 0xFB00) : (v))
50 // Fallback mappings for CJK Compatibility Ideographs Standardized Variants
51 // taken from %s.
52 // Using OpenType format 14 cmap subtable structure to reuse the lookup code
53 // for fonts. The glyphID field is used to store the corresponding codepoints
54 // CJK Compatibility Ideographs. To fit codepoints into the 16-bit glyphID
55 // field, CJK Compatibility Ideographs Supplement (U+2F800..U+2FA1F) will be
56 // mapped to 0xFB00..0xFD1F.
57 extern const uint8_t sCJKCompatSVSTable[] = {
58 """ % (os.path.basename(sys.argv[0]), fileversion))
59 f.write(' U16(14), // format\n')
60 f.write(' U32(%d), // length\n' % length)
61 f.write(' U32(%d), // numVarSelectorRecords\n' % len(vsdict))
62 for i, k in enumerate(sorted(vsdict.keys())):
63 f.write(' U24(0x%04X), U32(0), U32(%d), // varSelectorRecord[%d]\n' % (k, offsets[i], i))
64 for (k, mappings) in sorted(vsdict.items()):
65 f.write(' // 0x%04X\n' % k)
66 f.write(' U32(%d), // numUVSMappings\n' % len(mappings))
67 for (unified, compat) in sorted(mappings.items()):
68 f.write(' U24(0x%04X), GLYPH(0x%04X),\n' % (unified, compat))
69 f.write("""};
71 #undef U16
72 #undef U24
73 #undef U32
74 #undef GLYPH
76 static_assert(sizeof sCJKCompatSVSTable == %d, "Table generator has a bug.");
77 """ % length)