'Emit the PostScript sniplet \'ps\' with all the attributes from \'gc\'
applied.  \'ps\' must consist of PostScript commands to construct a path.
The fill and/or stroke kwargs can be set to False if the
\'ps\' string already includes filling and/or stroking, in
which case _draw_ps is just supplying properties and
clipping.'

def _draw_ps(self, ps, gc, rgbFace, fill=True, stroke=True, command=None):

    write = self._pswriter.write
    if (debugPS and command):
        write(((u'%    ' + command) + u'\n'))
    mightstroke = gc.shouldstroke()
    stroke = (stroke and mightstroke)
    fill = (fill and (rgbFace is not None) and ((len(rgbFace) <= 3) or (rgbFace[3] != 0.0)))
    hatch = gc.get_hatch()
    if mightstroke:
        self.set_linewidth(gc.get_linewidth())
        jint = gc.get_joinstyle()
        self.set_linejoin(jint)
        cint = gc.get_capstyle()
        self.set_linecap(cint)
        self.set_linedash(*gc.get_dashes())
        self.set_color(*gc.get_rgb()[:3])
    write(u'gsave\n')
    cliprect = gc.get_clip_rectangle()
    if cliprect:
        (x, y, w, h) = cliprect.bounds
        write((u'%1.4g    %1.4g    %1.4g    %1.4g    clipbox\n' % (w, h, x, y)))
    (clippath, clippath_trans) = gc.get_clip_path()
    if clippath:
        id = self._get_clip_path(clippath, clippath_trans)
        write((u'%s\n' % id))
    write(ps.strip())
    write(u'\n')
    if fill:
        if (stroke or hatch):
            write(u'gsave\n')
        self.set_color(store=0, *rgbFace[:3])
        write(u'fill\n')
        if (stroke or hatch):
            write(u'grestore\n')
    if hatch:
        hatch_name = self.create_hatch(hatch)
        write(u'gsave\n')
        write((u'%f    %f    %f    ' % gc.get_hatch_color()[:3]))
        write((u'%s    setpattern    fill    grestore\n' % hatch_name))
    if stroke:
        write(u'stroke\n')
    write(u'grestore\n')
