V0.42 Default mapping is now horizontal.

pull/69/head
Peter Hinch 2024-03-22 17:25:33 +00:00
rodzic c37e4acabd
commit 493564b491
2 zmienionych plików z 18 dodań i 9 usunięć

Wyświetl plik

@ -13,6 +13,7 @@ built into firmware is known as frozen bytecode.
## 1.1 Revision history ## 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 30 Jan 2023 V0.41 With thanks to @ferrolive (Igor Oliveira) who supplied the
charset file. charset file.
1. Charset file enables Chinese, Japanese and Korean glyphs to be specified. 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 * -f or --fixed If specified, all characters will have the same width. By
default fonts are assumed to be variable pitch. 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. * -r or --reverse Specifies bit reversal in each font byte.
* -s or --smallest Ordinal value of smallest character to be stored. Default * -s or --smallest Ordinal value of smallest character to be stored. Default
32 (ASCII space). 32 (ASCII space).

Wyświetl plik

@ -11,7 +11,7 @@
# The MIT License (MIT) # 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 # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # 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. STR01 = """# Code generated by font_to_py.py.
# Font: {}{} # Font: {}{}
# Cmd: {} # Cmd: {}
version = '0.33' version = '0.42'
""" """
@ -570,13 +570,13 @@ def write_data(stream, fnt, font_path, hmap, reverse, iterate, charset):
bw_sparse.odata(sparse) bw_sparse.odata(sparse)
bw_sparse.eot() bw_sparse.eot()
stream.write(STRSP) stream.write(STRSP)
print("Sparse") print("Sparse font file.")
else: else:
bw_index = ByteWriter(stream, "_index") bw_index = ByteWriter(stream, "_index")
bw_index.odata(index) bw_index.odata(index)
bw_index.eot() bw_index.eot()
stream.write(STR02.format(minchar, maxchar)) stream.write(STR02.format(minchar, maxchar))
print("Normal") print("Normal (non-sparse) font file.")
if hmap: if hmap:
stream.write(STR02H.format(height)) stream.write(STR02H.format(height))
else: else:
@ -643,6 +643,7 @@ if __name__ == "__main__":
parser.add_argument("outfile", type=str, help="Path and name of output file") 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("-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("-r", "--reverse", action="store_true", help="Bit reversal")
parser.add_argument("-f", "--fixed", action="store_true", help="Fixed width (monospaced) font") parser.add_argument("-f", "--fixed", action="store_true", help="Fixed width (monospaced) font")
parser.add_argument( parser.add_argument(
@ -705,6 +706,11 @@ if __name__ == "__main__":
if not os.path.splitext(args.infile)[1].upper() in (".TTF", ".OTF", ".BDF", ".PCF"): if not os.path.splitext(args.infile)[1].upper() in (".TTF", ".OTF", ".BDF", ".PCF"):
quit("Font file should be a ttf or otf file.") 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 args.binary:
if os.path.splitext(args.outfile)[1].upper() == ".PY": if os.path.splitext(args.outfile)[1].upper() == ".PY":
quit("Binary file must not have a .py extension.") quit("Binary file must not have a .py extension.")
@ -713,7 +719,7 @@ if __name__ == "__main__":
quit(BINARY) quit(BINARY)
print("Writing binary font file.") 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) sys.exit(1)
else: else:
if not os.path.splitext(args.outfile)[1].upper() == ".PY": if not os.path.splitext(args.outfile)[1].upper() == ".PY":
@ -760,7 +766,7 @@ if __name__ == "__main__":
args.infile, args.infile,
args.height, args.height,
args.fixed, args.fixed,
args.xmap, xmap,
args.reverse, args.reverse,
args.smallest, args.smallest,
args.largest, args.largest,