Skip to content

Commit 493564b

Browse files
committed
V0.42 Default mapping is now horizontal.
1 parent c37e4ac commit 493564b

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

FONT_TO_PY.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ built into firmware is known as frozen bytecode.
1313

1414
## 1.1 Revision history
1515

16+
22 Mar 2024 V0.42 Default mapping is now horizontal.
1617
30 Jan 2023 V0.41 With thanks to @ferrolive (Igor Oliveira) who supplied the
1718
charset file.
1819
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
9293

9394
* -f or --fixed If specified, all characters will have the same width. By
9495
default fonts are assumed to be variable pitch.
95-
* -x or --xmap Specifies horizontal mapping (default is vertical).
96+
* -x or --xmap Specifies horizontal mapping (this is the default).
97+
* -y or --ymap Vertical mapping for specialist display hardware. Not compatible
98+
with `Writer` classes.
9699
* -r or --reverse Specifies bit reversal in each font byte.
97100
* -s or --smallest Ordinal value of smallest character to be stored. Default
98101
32 (ASCII space).

font_to_py.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# The MIT License (MIT)
1313
#
14-
# Copyright (c) 2016-2023 Peter Hinch
14+
# Copyright (c) 2016-2024 Peter Hinch
1515
#
1616
# Permission is hereby granted, free of charge, to any person obtaining a copy
1717
# of this software and associated documentation files (the "Software"), to deal
@@ -450,7 +450,7 @@ def build_binary_array(self, hmap, reverse, sig):
450450
STR01 = """# Code generated by font_to_py.py.
451451
# Font: {}{}
452452
# Cmd: {}
453-
version = '0.33'
453+
version = '0.42'
454454
455455
"""
456456

@@ -492,14 +492,14 @@ def get_ch(ch):
492492
STR02H = """
493493
next_offs = doff + 2 + ((width - 1)//8 + 1) * {0}
494494
return _mvfont[doff + 2:next_offs], {0}, width
495-
495+
496496
"""
497497

498498
# Code emitted for vertically mapped fonts.
499499
STR02V = """
500500
next_offs = doff + 2 + (({0} - 1)//8 + 1) * width
501501
return _mvfont[doff + 2:next_offs], {0}, width
502-
502+
503503
"""
504504

505505
# Extra code emitted where -i is specified.
@@ -570,13 +570,13 @@ def write_data(stream, fnt, font_path, hmap, reverse, iterate, charset):
570570
bw_sparse.odata(sparse)
571571
bw_sparse.eot()
572572
stream.write(STRSP)
573-
print("Sparse")
573+
print("Sparse font file.")
574574
else:
575575
bw_index = ByteWriter(stream, "_index")
576576
bw_index.odata(index)
577577
bw_index.eot()
578578
stream.write(STR02.format(minchar, maxchar))
579-
print("Normal")
579+
print("Normal (non-sparse) font file.")
580580
if hmap:
581581
stream.write(STR02H.format(height))
582582
else:
@@ -643,6 +643,7 @@ def quit(msg):
643643
parser.add_argument("outfile", type=str, help="Path and name of output file")
644644

645645
parser.add_argument("-x", "--xmap", action="store_true", help="Horizontal (x) mapping")
646+
parser.add_argument("-y", "--ymap", action="store_true", help="Vertical (y) mapping")
646647
parser.add_argument("-r", "--reverse", action="store_true", help="Bit reversal")
647648
parser.add_argument("-f", "--fixed", action="store_true", help="Fixed width (monospaced) font")
648649
parser.add_argument(
@@ -705,6 +706,11 @@ def quit(msg):
705706
if not os.path.splitext(args.infile)[1].upper() in (".TTF", ".OTF", ".BDF", ".PCF"):
706707
quit("Font file should be a ttf or otf file.")
707708

709+
if args.xmap and args.ymap:
710+
quit("Cannot be both horizontally and vertically mapped.")
711+
712+
xmap = args.xmap or not args.ymap # Default is now horizontal
713+
708714
if args.binary:
709715
if os.path.splitext(args.outfile)[1].upper() == ".PY":
710716
quit("Binary file must not have a .py extension.")
@@ -713,7 +719,7 @@ def quit(msg):
713719
quit(BINARY)
714720

715721
print("Writing binary font file.")
716-
if not write_binary_font(args.outfile, args.infile, args.height, args.xmap, args.reverse):
722+
if not write_binary_font(args.outfile, args.infile, args.height, xmap, args.reverse):
717723
sys.exit(1)
718724
else:
719725
if not os.path.splitext(args.outfile)[1].upper() == ".PY":
@@ -760,7 +766,7 @@ def quit(msg):
760766
args.infile,
761767
args.height,
762768
args.fixed,
763-
args.xmap,
769+
xmap,
764770
args.reverse,
765771
args.smallest,
766772
args.largest,

0 commit comments

Comments
 (0)