<s> import os . path <EOL> import aggdraw as agg <EOL> from ginga import colors <EOL> import ginga . fonts <EOL> fontdir , xx = os . path . split ( ginga . fonts . __file__ ) <EOL> known_font = os . path . join ( fontdir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class AggContext ( object ) : <EOL> def __init__ ( self , canvas ) : <EOL> self . canvas = canvas <EOL> def set_canvas ( self , canvas ) : <EOL> self . canvas = canvas <EOL> def get_color ( self , color ) : <EOL> if isinstance ( color , str ) : <EOL> r , g , b = colors . lookup_color ( color ) <EOL> elif isinstance ( color , tuple ) : <EOL> r , g , b = color <EOL> else : <EOL> r , g , b = <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> <EOL> return ( int ( r * <NUM_LIT:255> ) , int ( g * <NUM_LIT:255> ) , int ( b * <NUM_LIT:255> ) ) <EOL> def get_pen ( self , color , linewidth = <NUM_LIT:1> , alpha = <NUM_LIT:1.0> ) : <EOL> op = int ( alpha * <NUM_LIT:255> ) <EOL> p = agg . Pen ( self . get_color ( color ) , width = linewidth , <EOL> opacity = op ) <EOL> return p <EOL> def get_brush ( self , color , alpha = <NUM_LIT:1.0> ) : <EOL> op = int ( alpha * <NUM_LIT:255> ) <EOL> b = agg . Brush ( self . get_color ( color ) , opacity = op ) <EOL> return b <EOL> def get_font ( self , name , size , color , alpha = <NUM_LIT:1.0> ) : <EOL> color = self . get_color ( color ) <EOL> op = int ( alpha * <NUM_LIT:255> ) <EOL> filepath = known_font <EOL> f = agg . Font ( color , filepath , size = size , opacity = op ) <EOL> return f <EOL> def text_extents ( self , text , font ) : <EOL> wd , ht = self . canvas . textsize ( text , font ) <EOL> return wd , ht </s>
