Skip to content

Commit da1c48c

Browse files
committed
Allow specifying new font name, fix glyph width
Two bugfixes: 1. Allow user to specify new font name. Default if no new name is specified will be "(old name) Dotted". This is not compliant with the OFL as it reuses the Reserved Font Name, but it allows you to get up and running quickly. 2. Fix bug where glyph width wasn't copied to new fonts.
1 parent d9aae53 commit da1c48c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

extractpoints.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,21 @@ def create_dotted_font(fname):
520520
input_font = silent_fontopen(fname)
521521
global args
522522
args.em = input_font.em
523+
if args.font_name:
524+
new_familyname = args.font_name
525+
else:
526+
new_familyname = input_font.familyname + " Dotted"
527+
print("WARNING: New font name \"{}\" does NOT comply with the Open Font License!!".format(new_familyname))
528+
print("Please press Enter to proceed anyway, or Ctrl-C to exit.")
529+
print("By proceeding, you acknowledge that you do NOT intend to distribute this font to anyone else.")
530+
raw_input()
531+
new_fullname = input_font.fullname.replace(input_font.familyname, new_familyname)
532+
new_fontname = new_fullname.translate(None, " \t()[]{}<>/%")
523533
shutil.copy2(fname, args.output)
524534
new_font = silent_fontopen(args.output)
535+
new_font.familyname = new_familyname
536+
new_font.fullname = new_fullname
537+
new_font.fontname = new_fontname
525538
for glyphname in input_font:
526539
if glyphname in ('.notdef', '.null'): continue
527540
glyph = input_font[glyphname]
@@ -650,13 +663,18 @@ def extract_dots(glyph, show_glyph=True):
650663
return dots
651664

652665
def copy_glyph(orig_glyph, new_glyph):
666+
new_glyph.width = orig_glyph.width
667+
new_glyph.vwidth = orig_glyph.vwidth
653668
dots = extract_dots(orig_glyph, args.visualize)
654669
for dot in dots:
655670
contour = circle_at(dot, size=args.radius)
656671
contour.is_quadratic = new_glyph.foreground.is_quadratic
657672
new_glyph.foreground += contour
658673
for anchor in orig_glyph.anchorPoints:
659674
new_glyph.addAnchorPoint(*anchor)
675+
if args.copy_bearings:
676+
new_glyph.left_side_bearing = orig_glyph.left_side_bearing
677+
new_glyph.right_side_bearing = orig_glyph.right_side_bearing
660678
return new_glyph # Probably not needed as the font now contains it
661679

662680
def make_triangles_unsafe(polygon_data, holes = None):
@@ -767,6 +785,8 @@ def parse_args():
767785
parser.add_argument('-g', '--show-glyph', action = "store_true", help = "Show the glyph outline")
768786
parser.add_argument('-r', '--radius', action = "store", type = float, default = 12, help = "Radius of dots, in em units (default 12)")
769787
parser.add_argument('-s', '--spacing', action = "store", type = float, default = 6.0, help = "Spacing of dots, as a multiple of dot radius (default 6.0 for 600%%)")
788+
parser.add_argument('-b', '--copy-bearings', action = "store_true", help = "Copy left/right side bearings of glyphs to new font (default is to calculate them automatically, use this to copy them from the old font instead)")
789+
parser.add_argument('-n', '--font-name', action = "store", type = str, default = "", help = "New font name (REQUIRED if you plan to distribute this font to others, as the default is to use \"(orignal name) Dotted\", which is NOT OFL-compliant)")
770790
args = parser.parse_args()
771791
args.visualize = (args.show_triangles or args.show_lines or args.show_dots or args.show_glyph)
772792
if args.inputfilename is None:

0 commit comments

Comments
 (0)