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 from __future__
import absolute_import
10 f
= open(sys
.argv
[1] if len(sys
.argv
) > 1 else "StandardizedVariants.txt")
13 m
= re
.compile("^# (StandardizedVariants(-\d+(\.\d+)*)?\.txt)").search(line
)
14 fileversion
= m
.group(1)
17 "^([0-9A-F]{4,6}) (FE0[0-9A-F]); CJK COMPATIBILITY IDEOGRAPH-([0-9A-F]{4,6});"
23 if "CJK COMPATIBILITY IDEOGRAPH-" not in line
:
27 unified
= int(m
.group(1), 16)
28 vs
= int(m
.group(2), 16)
29 compat
= int(m
.group(3), 16)
33 vsdict
[vs
][unified
] = compat
38 length
= 10 + 11 * len(vsdict
)
39 for (k
, mappings
) in sorted(vsdict
.items()):
40 offsets
.append(length
)
41 length
+= 4 + 5 * len(mappings
)
43 f
= open(sys
.argv
[2] if len(sys
.argv
) > 2 else "CJKCompatSVS.cpp", "wb")
45 """// Generated by %s. Do not edit.
49 #define U16(v) (((v) >> 8) & 0xFF), ((v) & 0xFF)
50 #define U24(v) (((v) >> 16) & 0xFF), (((v) >> 8) & 0xFF), ((v) & 0xFF)
51 #define U32(v) (((v) >> 24) & 0xFF), (((v) >> 16) & 0xFF), (((v) >> 8) & 0xFF), ((v) & 0xFF)
52 #define GLYPH(v) U16(v >= 0x2F800 ? (v) - (0x2F800 - 0xFB00) : (v))
54 // Fallback mappings for CJK Compatibility Ideographs Standardized Variants
56 // Using OpenType format 14 cmap subtable structure to reuse the lookup code
57 // for fonts. The glyphID field is used to store the corresponding codepoints
58 // CJK Compatibility Ideographs. To fit codepoints into the 16-bit glyphID
59 // field, CJK Compatibility Ideographs Supplement (U+2F800..U+2FA1F) will be
60 // mapped to 0xFB00..0xFD1F.
61 extern const uint8_t sCJKCompatSVSTable[] = {
63 % (os
.path
.basename(sys
.argv
[0]), fileversion
)
65 f
.write(" U16(14), // format\n")
66 f
.write(" U32(%d), // length\n" % length
)
67 f
.write(" U32(%d), // numVarSelectorRecords\n" % len(vsdict
))
68 for i
, k
in enumerate(sorted(vsdict
.keys())):
70 " U24(0x%04X), U32(0), U32(%d), // varSelectorRecord[%d]\n"
73 for (k
, mappings
) in sorted(vsdict
.items()):
74 f
.write(" // 0x%04X\n" % k
)
75 f
.write(" U32(%d), // numUVSMappings\n" % len(mappings
))
76 for (unified
, compat
) in sorted(mappings
.items()):
77 f
.write(" U24(0x%04X), GLYPH(0x%04X),\n" % (unified
, compat
))
86 static_assert(sizeof sCJKCompatSVSTable == %d, "Table generator has a bug.");