import os
import gs_frontend
import theme

class T(gs_frontend.T):
    def close(self, out_fname):
	if self.__output_lines == []:
	    return

        if theme.use_color:
            gs_args = "-sDEVICE=png256 -dTextAlphaBits=4 -q -dNOPAUSE" #PDS
        else:
            gs_args = "-sDEVICE=pnggray -dTextAlphaBits=4 -q -dNOPAUSE" #PDS
        
        if out_fname:
            gs_args += " -sOutputFile=%s" % out_fname
        else:
            raise Exception, "PNG file cannot be sent to stdout. (due to some arcane problem regarding ghostscript interaction."
            #dev = dev + " -sOutputFile=-"
            
        self.start_gs(gs_args)
        self.close_gs()

