output.write8(code & 0xFF) else: if code <= 0x7FF: output.write8(0xC0 + (code >> 6)) else: if code <= 0xFFFF: output.write8(0xE0 + (code >> 12)) else: output.write8(0xF0 + (code >> 18)) output.write8(0x80 + ((code >> 12) & 0x3F)) output.write8(0x80 + ((code >> 6) & 0x3F)) output.write8(0x80 + (code & 0x3F)) for char in font.chars: if char.code != 0xFFFF: write_unicode(char.code) if char.code in tables: for extra in tables[char.code]: write_unicode(extra) write_unicode(0xFFFF) fnio.write_file(parsed.output_name, write_psf, encoding=None) if __name__ == '__main__': fncli.start('bdftopsf.py', Options(), Params(), main_program)
if line.startswith(b'ENDCHAR'): self.mode = MODE.META else: self.check_bitmap(line) return line def read_check(self, line, callback): match = re.search(br'^COMMENT\s*bdfcheck\s+(-.*)$', line) if match and not self.options.parse(str(match[1], 'ascii'), True, self.parsed): raise Exception('invalid bdfcheck directive') line = callback(line) return self.check_line(line) if line is not None else None def read_lines(self, callback): return fnio.InputFileStream.read_lines(self, lambda line: self.read_check(line, callback)) # -- Main -- def main_program(nonopt, parsed): for input_name in nonopt or [None]: InputFileStream(input_name, parsed).check() if __name__ == '__main__': fncli.start('bdfcheck.py', Options(), Params(), main_program)
ofs.write32(bits_offset) ofs.write8(0) # reserved # CTABLE for value in ctable: ofs.write16(value) # GLYPHS data = bytearray(font.bbx.height * font.bbx.row_size()) for char in font.chars: row_size = char.row_size() counter = 0 # MS coordinates for n in range(0, row_size): for y in range(0, font.bbx.height): data[counter] = char.data[row_size * y + n] counter += 1 ofs.write(data[:counter]) ofs.write(bytes(sentinel * font.bbx.height)) # FAMILY ofs.write_zstr(family, 1) ofs.close() except Exception as ex: raise Exception(ofs.location() + str(ex) + ofs.destroy()) fncli.start('bdftofnt.py', Options(), main_program)
num_props -= 1 continue elif name == 'ENDPROPERTIES': if new_font.default_code != -1 and new_font.props.get( 'DEFAULT_CHAR') is None: new_font.props.add('DEFAULT_CHAR', bstr(new_font.default_code)) num_props += 1 new_font.props.set('STARTPROPERTIES', bstr(num_props)) elif name == 'CHARS': value = bstr(len(new_font.chars)) new_font.props.add(name, value) # COPY FIELDS new_font.bbx = old_font.bbx new_font.finis = old_font.finis # WRITE OUTPUT ofs = fnio.OutputStream(parsed.output) try: new_font.write(ofs) ofs.close() except Exception as ex: raise Exception(ofs.location() + str(ex) + ofs.destroy()) if __name__ == '__main__': fncli.start('ucstoany.py', Options(), Params(), main_program)
def main_program(nonopt, parsed): if len(nonopt) > 1: raise Exception('invalid number of arguments, try --help') # READ INPUT def read_otb(ifs): if parsed.real_time: try: stat = ifs.fstat() if stat: parsed.created = datetime.fromtimestamp( stat.st_ctime, timezone.utc) parsed.modified = datetime.fromtimestamp( stat.st_mtime, timezone.utc) except Exception as ex: fnutil.warning(ifs.location(), str(ex)) return otb1exp.Font.read(ifs, parsed) font = fnio.read_file(nonopt[0] if nonopt else None, read_otb) # WRITE OUTPUT sfnt = otb1exp.SFNT(font) fnio.write_file(parsed.output_name, lambda ofs: ofs.write(sfnt.data), encoding=None) if __name__ == '__main__': fncli.start('otb1cli.py', Options(), Params(), main_program)