Skip to content

Commit 9adb346

Browse files
committed
Allow having no visualization
Also allow visualizing each glyph as it's created, though there's no code for pausing long enough to see the glyphs. The focus is producing the TTF quickly, not producing pretty pictures.
1 parent 2f8fcdc commit 9adb346

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/extractpoints.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,10 @@ def create_dotted_font(fname):
538538
else:
539539
new_font.generate(args.output)
540540
print "Dotted font created as", args.output
541+
if args.visualize:
542+
print "Press any key to exit"
543+
import visualization
544+
visualization.wait_for_keypress(args.em, args.zoom)
541545

542546
def extraction_demo(fname, letter):
543547
font = silent_fontopen(fname)
@@ -551,12 +555,18 @@ def extraction_demo(fname, letter):
551555
codepoint = letter
552556
glyph = font[codepoint]
553557
glyph.unlinkRef()
554-
dots = extract_dots(glyph)
558+
dots = extract_dots(glyph, args.visualize)
555559
print "{} dots found".format(len(dots))
556-
wait_for_keypress(args.em, args.zoom)
560+
if args.visualize:
561+
import visualization
562+
visualization.wait_for_keypress(args.em, args.zoom)
557563

558564
def extract_dots(glyph, show_glyph=True):
559565
global args
566+
if args.visualize or show_glyph:
567+
from visualization import (
568+
setup_screen, draw_all, draw_midlines, red, green, blue, draw_fat_point,
569+
)
560570
layer = glyph.foreground
561571
polylines = []
562572
polylines_to_draw = []
@@ -634,13 +644,13 @@ def extract_dots(glyph, show_glyph=True):
634644
polylinecolor = (blue if args.show_glyph else None),
635645
trianglecolor = (red if args.show_triangles else None))
636646
if args.show_lines:
637-
draw_midlines(screen, allmidlines, midpoints, emsize = args.em, zoom = args.zoom, polylinecolor = green)
647+
draw_midlines(screen, allmidlines, allmidpoints, emsize = args.em, zoom = args.zoom, polylinecolor = green)
638648
return dots
639649

640650
def copy_glyph(orig_glyph, new_glyph):
641651
# (new_glyph was created with font.createChar(orig_glyph.encoding)
642652
new_glyph.glyphname = orig_glyph.glyphname
643-
dots = extract_dots(orig_glyph, False) # TODO: Refactor extract_dots to remove drawing code or make it optional
653+
dots = extract_dots(orig_glyph, args.visualize) # TODO: Refactor extract_dots to remove drawing code or make it optional
644654
for dot in dots:
645655
contour = circle_at(dot, size=args.radius)
646656
new_glyph.foreground += contour
@@ -708,11 +718,7 @@ def parse_args():
708718
parser.add_argument('-r', '--radius', action = "store", type = float, default = 15, help = "Radius of dots, in em units (default 15)")
709719
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%%)")
710720
args = parser.parse_args()
711-
if not (args.show_triangles or args.show_lines or args.show_dots):
712-
parser.print_help()
713-
print
714-
print "Error: Please use at least one of the -t, -l or -d options."
715-
sys.exit(2)
721+
args.visualize = (args.show_triangles or args.show_lines or args.show_dots or args.show_glyph)
716722
return args
717723

718724
def main():

0 commit comments

Comments
 (0)