Exemplo n.º 1
0
    def __init__(self, fh, length):
        PackedFormat.__init__(self, fh)
        self.char_map = {}
        self.glyph_map = {}

        mapping = read_list_uint16(fh, self.entry_count)
        for n in range(self.entry_count):
            self.char_map[n] = mapping[n]
            self.glyph_map.setdefault(mapping[n], []).append(n)
Exemplo n.º 2
0
 def __init__(self, fh=None, length=None):
     self.subtables = []
     PackedFormat.__init__(self, fh)
     if fh is None:
         return
     for n in range(self.num_tables):
         tbl = TTF_kern_subtable(fh)
         fh.seek(tbl.length - len(tbl), 1)
         self.subtables.append(tbl)
Exemplo n.º 3
0
 def __init__(self, fh, length):
     start_pos = fh.tell()
     PackedFormat.__init__(self, fh)
     pos = fh.tell()
     fh.seek(start_pos + self.offset)
     data = fh.read(length - self.offset)
     fh.seek(pos)
     self.names = []
     for n in range(self.count):
         self.names.append(TTFNameRecord(fh, data))
Exemplo n.º 4
0
 def __init__(self, fh, data):
     self.pos = fh.tell()
     PackedFormat.__init__(self, fh)
     self.raw = data[self.offset:self.offset + self.length]
     self.value = self.raw
     if self.platform_id == 1:
         if self.encoding_id == 0:
             self.value = self.raw.decode('iso-8859-1')
     elif self.platform_id == 3:
         if self.encoding_id == 1:
             # UCS-2
             self.value = self.raw.decode('utf-16-be')
Exemplo n.º 5
0
 def __init__(self, fh):
     PackedFormat.__init__(self, fh)
     self.offsets = []
     self.is_collection = (self.tag == b'ttcf')
     if self.is_collection:
         for i in range(self.count):
             self.offsets.append(unpack('>I', fh.read(4))[0])
     else:
         self.count = 1
         self.offsets = [0]
     if self.version == 2:
         self.dsig_tag, self.dsig_length, self.dsig_offset = unpack(
             "III", fh.read(calcsize('III')))
Exemplo n.º 6
0
    def __init__(self, fh=None, num=0, data=None):
        self.glyph = num
        self.components = []
        self.required = set()
        PackedFormat.__init__(self, fh=fh, data=data)

        # If the glyph is a compound glyph, ie it's made up of parts of other glyphs,
        # then we need to ensure we have all the component glyphs listed.
        if self.contours < 0:
            while True:
                (flags, next_glyph) = read_list_uint16(fh, 2)
                self.required.add(next_glyph)
                fh.read(calcsize(glyf_skip_format(flags)))
                if not glyph_more_components(flags):
                    break
Exemplo n.º 7
0
 def as_table_string(self):
     s = PackedFormat.as_table_string(self)
     n = 0
     for t in self.tables:
         s += '\nTable: {}\n'.format(n)
         s += t.as_table_string()
         n += 1
     return s
Exemplo n.º 8
0
    def __init__(self, fh=None, length=None):
        start = fh.tell() - 4
        PackedFormat.__init__(self, fh)
        if fh is None:
            return
        self.ranges = []

        end_codes = read_list_uint16(fh, self.seg_count + 1)
        if end_codes[self.seg_count] != 0:
            print("INVALID pad byte....")
            return
        start_codes = read_list_uint16(fh, self.seg_count)
        iddelta = read_list_int16(fh, self.seg_count)
        offset_start = fh.tell()
        id_offset = read_list_uint16(fh, self.seg_count)

        ids_length = int((length - (fh.tell() - start)) / 2)
        self.glyph_ids = read_list_uint16(fh, ids_length)

        for n in range(self.seg_count):
            self.ranges.append(
                self.CMAPRange(start_codes[n], end_codes[n], iddelta[n],
                               id_offset[n], self.seg_count - n))
Exemplo n.º 9
0
    def __init__(self, fh=None, length=0):
        self.count = 0
        if fh:
            start_pos = fh.tell()
        PackedFormat.__init__(self, fh)
        self.tables = {}

        self.map_table = None

        if self.count == 0:
            return

        for n in range(self.count):
            tbl = TTFcmapTable(fh)
            self.tables[(tbl.platform_id, tbl.encoding_id)] = tbl

            pos = fh.tell()

            fh.seek(start_pos + tbl.offset)
            tbl.format, length = read_list_uint16(fh, 2)
            if tbl.format == 4:
                tbl.map_data = TTF_cmap4(fh, length)
            elif tbl.format == 6:
                tbl.map_data = TTF_cmap6(fh, length)
            fh.seek(pos)

        # Choose the mapping we are going to use, initially on preferences and
        # then just fallback to first available map.
        for p in self.PREFS:
            if p in self.tables and self.tables[p].has_map_data:
                self.map_table = self.tables[p].map_data
                break
        if self.map_table is None:
            for t in self.tables.values():
                if t.has_map_data:
                    self.map_table = t.map_data
                    break
Exemplo n.º 10
0
 def __init__(self, fh, length=None):
     self.records = []
     PackedFormat.__init__(self, fh)
     for n in range(self.count):
         self.records.append(OFT_ScriptRecord(fh))
Exemplo n.º 11
0
 def __init__(self, fh=None):
     PackedFormat.__init__(self, fh)
     self.format = 0
     self.map_data = None
     self.position = 0
Exemplo n.º 12
0
 def __init__(self, fh=None):
     if fh is not None:
         self.offset = fh.tell()
     PackedFormat.__init__(self, fh)
Exemplo n.º 13
0
 def __init__(self, fh=None):
     self.tables = []
     self.num_tables = 0
     PackedFormat.__init__(self, fh)
     for n in range(self.num_tables):
         self.tables.append(TTFOffsetTable(fh))