def __init__(self): self.header = QGFBlockHeader() self.header.type_id = QFFUnicodeGlyphTableV1.type_id self.header.length = 0 # Each glyph is key=code_point, value=QFFGlyphInfo self.glyphs = {}
class QFFFontDataDescriptorV1: type_id = 0x04 def __init__(self): self.header = QGFBlockHeader() self.header.type_id = QFFFontDataDescriptorV1.type_id self.data = [] def write(self, fp): self.header.length = len(self.data) self.header.write(fp) fp.write(bytes(self.data))
def __init__(self): self.header = QGFBlockHeader() self.header.type_id = QFFFontDescriptor.type_id self.header.length = QFFFontDescriptor.length self.version = 1 self.total_file_size = 0 self.line_height = 0 self.has_ascii_table = False self.unicode_glyph_count = 0 self.format = 0xFF self.flags = 0 self.compression = 0xFF self.transparency_index = 0xFF # TODO: Work out how to retrieve the transparent palette entry from the PIL gif loader
class QFFFontDescriptor: type_id = 0x00 length = 20 magic = 0x464651 def __init__(self): self.header = QGFBlockHeader() self.header.type_id = QFFFontDescriptor.type_id self.header.length = QFFFontDescriptor.length self.version = 1 self.total_file_size = 0 self.line_height = 0 self.has_ascii_table = False self.unicode_glyph_count = 0 self.format = 0xFF self.flags = 0 self.compression = 0xFF self.transparency_index = 0xFF # TODO: Work out how to retrieve the transparent palette entry from the PIL gif loader def write(self, fp): self.header.write(fp) fp.write(b'' # start off with empty bytes... + o24(QFFFontDescriptor.magic) # magic + o8(self.version) # version + o32(self.total_file_size) # file size + o32((~self.total_file_size) & 0xFFFFFFFF) # negated file size + o8(self.line_height) # line height + o8(1 if self.has_ascii_table is True else 0 ) # whether or not we have an ascii table present + o16(self.unicode_glyph_count & 0xFFFF) # number of unicode glyphs present + o8(self.format) # format + o8(self.flags) # flags + o8(self.compression) # compression + o8(self.transparency_index) # transparency index ) @property def is_transparent(self): return (self.flags & 0x01) == 0x01 @is_transparent.setter def is_transparent(self, val): if val: self.flags |= 0x01 else: self.flags &= ~0x01
class QFFAsciiGlyphTableV1: type_id = 0x01 length = 95 * 3 # We have 95 glyphs: [0x20...0x7E] def __init__(self): self.header = QGFBlockHeader() self.header.type_id = QFFAsciiGlyphTableV1.type_id self.header.length = QFFAsciiGlyphTableV1.length # Each glyph is key=code_point, value=QFFGlyphInfo self.glyphs = {} def add_glyph(self, glyph: QFFGlyphInfo): self.glyphs[ord(glyph.code_point)] = glyph def write(self, fp): self.header.write(fp) for n in range(0x20, 0x7F): self.glyphs[n].write(fp, False)
class QFFUnicodeGlyphTableV1: type_id = 0x02 def __init__(self): self.header = QGFBlockHeader() self.header.type_id = QFFUnicodeGlyphTableV1.type_id self.header.length = 0 # Each glyph is key=code_point, value=QFFGlyphInfo self.glyphs = {} def add_glyph(self, glyph: QFFGlyphInfo): self.glyphs[ord(glyph.code_point)] = glyph def write(self, fp): self.header.length = len(self.glyphs.keys()) * 6 self.header.write(fp) for n in sorted(self.glyphs.keys()): self.glyphs[n].write(fp, True)
def __init__(self): self.header = QGFBlockHeader() self.header.type_id = QFFFontDataDescriptorV1.type_id self.data = []