From 493564b491d4104c8313d08d448863b7bd06af4c Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Fri, 22 Mar 2024 17:25:33 +0000 Subject: [PATCH] V0.42 Default mapping is now horizontal. --- FONT_TO_PY.md | 5 ++++- font_to_py.py | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/FONT_TO_PY.md b/FONT_TO_PY.md index 578960d..66dcbe7 100644 --- a/FONT_TO_PY.md +++ b/FONT_TO_PY.md @@ -13,6 +13,7 @@ built into firmware is known as frozen bytecode. ## 1.1 Revision history +22 Mar 2024 V0.42 Default mapping is now horizontal. 30 Jan 2023 V0.41 With thanks to @ferrolive (Igor Oliveira) who supplied the charset file. 1. Charset file enables Chinese, Japanese and Korean glyphs to be specified. @@ -92,7 +93,9 @@ $ font_to_py.py -k extended FreeSans.ttf 23 my_extended_font.py * -f or --fixed If specified, all characters will have the same width. By default fonts are assumed to be variable pitch. - * -x or --xmap Specifies horizontal mapping (default is vertical). + * -x or --xmap Specifies horizontal mapping (this is the default). + * -y or --ymap Vertical mapping for specialist display hardware. Not compatible + with `Writer` classes. * -r or --reverse Specifies bit reversal in each font byte. * -s or --smallest Ordinal value of smallest character to be stored. Default 32 (ASCII space). diff --git a/font_to_py.py b/font_to_py.py index 7a57185..3f07450 100755 --- a/font_to_py.py +++ b/font_to_py.py @@ -11,7 +11,7 @@ # The MIT License (MIT) # -# Copyright (c) 2016-2023 Peter Hinch +# Copyright (c) 2016-2024 Peter Hinch # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -450,7 +450,7 @@ class Font(dict): STR01 = """# Code generated by font_to_py.py. # Font: {}{} # Cmd: {} -version = '0.33' +version = '0.42' """ @@ -492,14 +492,14 @@ def get_ch(ch): STR02H = """ next_offs = doff + 2 + ((width - 1)//8 + 1) * {0} return _mvfont[doff + 2:next_offs], {0}, width - + """ # Code emitted for vertically mapped fonts. STR02V = """ next_offs = doff + 2 + (({0} - 1)//8 + 1) * width return _mvfont[doff + 2:next_offs], {0}, width - + """ # Extra code emitted where -i is specified. @@ -570,13 +570,13 @@ def write_data(stream, fnt, font_path, hmap, reverse, iterate, charset): bw_sparse.odata(sparse) bw_sparse.eot() stream.write(STRSP) - print("Sparse") + print("Sparse font file.") else: bw_index = ByteWriter(stream, "_index") bw_index.odata(index) bw_index.eot() stream.write(STR02.format(minchar, maxchar)) - print("Normal") + print("Normal (non-sparse) font file.") if hmap: stream.write(STR02H.format(height)) else: @@ -643,6 +643,7 @@ if __name__ == "__main__": parser.add_argument("outfile", type=str, help="Path and name of output file") parser.add_argument("-x", "--xmap", action="store_true", help="Horizontal (x) mapping") + parser.add_argument("-y", "--ymap", action="store_true", help="Vertical (y) mapping") parser.add_argument("-r", "--reverse", action="store_true", help="Bit reversal") parser.add_argument("-f", "--fixed", action="store_true", help="Fixed width (monospaced) font") parser.add_argument( @@ -705,6 +706,11 @@ if __name__ == "__main__": if not os.path.splitext(args.infile)[1].upper() in (".TTF", ".OTF", ".BDF", ".PCF"): quit("Font file should be a ttf or otf file.") + if args.xmap and args.ymap: + quit("Cannot be both horizontally and vertically mapped.") + + xmap = args.xmap or not args.ymap # Default is now horizontal + if args.binary: if os.path.splitext(args.outfile)[1].upper() == ".PY": quit("Binary file must not have a .py extension.") @@ -713,7 +719,7 @@ if __name__ == "__main__": quit(BINARY) print("Writing binary font file.") - if not write_binary_font(args.outfile, args.infile, args.height, args.xmap, args.reverse): + if not write_binary_font(args.outfile, args.infile, args.height, xmap, args.reverse): sys.exit(1) else: if not os.path.splitext(args.outfile)[1].upper() == ".PY": @@ -760,7 +766,7 @@ if __name__ == "__main__": args.infile, args.height, args.fixed, - args.xmap, + xmap, args.reverse, args.smallest, args.largest,