11
11
12
12
# The MIT License (MIT)
13
13
#
14
- # Copyright (c) 2016-2023 Peter Hinch
14
+ # Copyright (c) 2016-2024 Peter Hinch
15
15
#
16
16
# Permission is hereby granted, free of charge, to any person obtaining a copy
17
17
# of this software and associated documentation files (the "Software"), to deal
@@ -450,7 +450,7 @@ def build_binary_array(self, hmap, reverse, sig):
450
450
STR01 = """# Code generated by font_to_py.py.
451
451
# Font: {}{}
452
452
# Cmd: {}
453
- version = '0.33 '
453
+ version = '0.42 '
454
454
455
455
"""
456
456
@@ -492,14 +492,14 @@ def get_ch(ch):
492
492
STR02H = """
493
493
next_offs = doff + 2 + ((width - 1)//8 + 1) * {0}
494
494
return _mvfont[doff + 2:next_offs], {0}, width
495
-
495
+
496
496
"""
497
497
498
498
# Code emitted for vertically mapped fonts.
499
499
STR02V = """
500
500
next_offs = doff + 2 + (({0} - 1)//8 + 1) * width
501
501
return _mvfont[doff + 2:next_offs], {0}, width
502
-
502
+
503
503
"""
504
504
505
505
# Extra code emitted where -i is specified.
@@ -570,13 +570,13 @@ def write_data(stream, fnt, font_path, hmap, reverse, iterate, charset):
570
570
bw_sparse .odata (sparse )
571
571
bw_sparse .eot ()
572
572
stream .write (STRSP )
573
- print ("Sparse" )
573
+ print ("Sparse font file. " )
574
574
else :
575
575
bw_index = ByteWriter (stream , "_index" )
576
576
bw_index .odata (index )
577
577
bw_index .eot ()
578
578
stream .write (STR02 .format (minchar , maxchar ))
579
- print ("Normal" )
579
+ print ("Normal (non-sparse) font file. " )
580
580
if hmap :
581
581
stream .write (STR02H .format (height ))
582
582
else :
@@ -643,6 +643,7 @@ def quit(msg):
643
643
parser .add_argument ("outfile" , type = str , help = "Path and name of output file" )
644
644
645
645
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" )
646
647
parser .add_argument ("-r" , "--reverse" , action = "store_true" , help = "Bit reversal" )
647
648
parser .add_argument ("-f" , "--fixed" , action = "store_true" , help = "Fixed width (monospaced) font" )
648
649
parser .add_argument (
@@ -705,6 +706,11 @@ def quit(msg):
705
706
if not os .path .splitext (args .infile )[1 ].upper () in (".TTF" , ".OTF" , ".BDF" , ".PCF" ):
706
707
quit ("Font file should be a ttf or otf file." )
707
708
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
+
708
714
if args .binary :
709
715
if os .path .splitext (args .outfile )[1 ].upper () == ".PY" :
710
716
quit ("Binary file must not have a .py extension." )
@@ -713,7 +719,7 @@ def quit(msg):
713
719
quit (BINARY )
714
720
715
721
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 ):
717
723
sys .exit (1 )
718
724
else :
719
725
if not os .path .splitext (args .outfile )[1 ].upper () == ".PY" :
@@ -760,7 +766,7 @@ def quit(msg):
760
766
args .infile ,
761
767
args .height ,
762
768
args .fixed ,
763
- args . xmap ,
769
+ xmap ,
764
770
args .reverse ,
765
771
args .smallest ,
766
772
args .largest ,
0 commit comments