gfx/thebes/gencjkcisvs.py

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial