<s> import hTools2 . modules . rasterizer <EOL> reload ( hTools2 . modules . rasterizer ) <EOL> try : <EOL> from mojo . roboFont import CurrentFont <EOL> except ImportError : <EOL> from robofab . world import CurrentFont <EOL> from vanilla import * <EOL> from hTools2 import hDialog <EOL> from hTools2 . dialogs . misc import Spinner <EOL> from hTools2 . modules . fontutils import get_glyphs <EOL> from hTools2 . modules . rasterizer import * <EOL> from hTools2 . modules . messages import no_glyph_selected , no_font_open <EOL> class rasterizeGlyphDialog ( hDialog ) : <EOL> """<STR_LIT>""" <EOL> gridsize = <NUM_LIT> <EOL> element_scale = <NUM_LIT> <EOL> def __init__ ( self ) : <EOL> self . title = '<STR_LIT>' <EOL> self . column_1 = <NUM_LIT> <EOL> self . box = <NUM_LIT:20> <EOL> self . height = self . progress_bar + ( self . padding_y * <NUM_LIT:7> ) + ( self . square_button * <NUM_LIT:3> ) <EOL> self . w = FloatingWindow ( ( self . width , self . height ) , self . title ) <EOL> x = <NUM_LIT:0> <EOL> y = self . padding_y <EOL> self . w . spinner = Spinner ( <EOL> ( x , y ) , <EOL> default = '<STR_LIT>' , <EOL> integer = True , <EOL> label = '<STR_LIT>' ) <EOL> x = self . padding_x <EOL> y += self . w . spinner . getPosSize ( ) [ <NUM_LIT:3> ] <EOL> self . w . button_rasterize = SquareButton ( <EOL> ( x , y , <EOL> - self . padding_x , <EOL> self . button_height ) , <EOL> "<STR_LIT>" , <EOL> sizeStyle = self . size_style , <EOL> callback = self . _rasterize_callback ) <EOL> y += self . progress_bar + self . padding_y <EOL> self . w . bar = ProgressBar ( <EOL> ( x , y + <NUM_LIT:2> , <EOL> - self . padding_x , <EOL> self . progress_bar ) , <EOL> isIndeterminate = True , <EOL> sizeStyle = self . size_style ) <EOL> y += self . progress_bar + self . padding_y - <NUM_LIT:1> <EOL> self . w . button_print = SquareButton ( <EOL> ( x , y , <EOL> - self . padding_x , <EOL> self . button_height ) , <EOL> "<STR_LIT>" , <EOL> sizeStyle = self . size_style , <EOL> callback = self . _print_callback ) <EOL> y += self . button_height + self . padding_y <EOL> self . w . button_scan = SquareButton ( <EOL> ( x , y , <EOL> - self . padding_x , <EOL> self . button_height ) , <EOL> "<STR_LIT>" , <EOL> callback = self . _scan_callback , <EOL> sizeStyle = self . size_style ) <EOL> self . w . open ( ) <EOL> def _scan_callback ( self , sender ) : <EOL> font = CurrentFont ( ) <EOL> if font is not None : <EOL> glyph_names = get_glyphs ( font ) <EOL> if len ( glyph_names ) > <NUM_LIT:0> : <EOL> gridsize = int ( self . w . spinner . value . get ( ) ) <EOL> res = ( gridsize , gridsize ) <EOL> print "<STR_LIT>" <EOL> for glyph_name in glyph_names : <EOL> glyph = font [ glyph_name ] <EOL> R = RasterGlyph ( glyph ) <EOL> R . scan ( res = res ) <EOL> font . update ( ) <EOL> print "<STR_LIT>" <EOL> else : <EOL> print no_glyph_selected <EOL> else : <EOL> print no_font_open <EOL> def _print_callback ( self , sender ) : <EOL> font = CurrentFont ( ) <EOL> if font is not None : <EOL> glyph_names = get_glyphs ( font ) <EOL> if len ( glyph_names ) > <NUM_LIT:0> : <EOL> gridsize = int ( self . w . spinner . value . get ( ) ) <EOL> res = ( gridsize , gridsize ) <EOL> print "<STR_LIT>" <EOL> for glyph_name in glyph_names : <EOL> glyph = font [ glyph_name ] <EOL> R = RasterGlyph ( glyph ) <EOL> R . print_bits ( res = res ) <EOL> print "<STR_LIT>" <EOL> else : <EOL> print no_glyph_selected <EOL> else : <EOL> print no_font_open <EOL> def _rasterize_callback ( self , sender ) : <EOL> font = CurrentFont ( ) <EOL> if font is not None : <EOL> glyph_names = get_glyphs ( font ) <EOL> if len ( glyph_names ) > <NUM_LIT:0> : <EOL> gridsize = int ( self . w . spinner . value . get ( ) ) <EOL> res = ( gridsize , gridsize ) <EOL> self . w . bar . start ( ) <EOL> print "<STR_LIT>" <EOL> for glyph_name in glyph_names : <EOL> glyph = font [ glyph_name ] <EOL> print '<STR_LIT>' % glyph_name <EOL> glyph . prepareUndo ( '<STR_LIT>' ) <EOL> R = RasterGlyph ( glyph ) <EOL> R . rasterize ( res = res ) <EOL> glyph . update ( ) <EOL> glyph . performUndo ( ) <EOL> font . update ( ) <EOL> self . w . bar . stop ( ) <EOL> print "<STR_LIT>" <EOL> else : <EOL> print no_glyph_selected <EOL> else : <EOL> print no_font_open </s>
