def render_to_job(job): pc = job.get_context() width, height = gnomeprint.job_get_page_size_from_config(job.get_config()) ## <<<begin drawing>>> pc.beginpage("1") pc.setlinewidth(3.0) x1 = width*.1 x2 = width*.9 y1 = height*.1 y2 = height*.9 pc.rect_stroked(x1, y1, x2 - x1, y2 - y1) for l in l1, l2: pc.moveto(l[0], 600 - l[1]) for i in xrange(len(l)/2): x = l[i*2] y = 600 - l[i*2 + 1] pc.lineto(x, y) pc.stroke() ## Draw a text paragraph using pango paraContext = gnomeprint.pango_create_context(gnomeprint.pango_get_default_font_map()) para = pango.Layout(paraContext) para.set_font_description(pango.FontDescription("Sans 36")) para.set_markup("♪ Hello <b>World</b> ♪") w, h = para.get_size() w /= pango.SCALE h /= pango.SCALE pc.moveto(width - w, height - h) pc.pango_layout(para) pc.showpage() ## <<<end drawing>>> job.close()
def print_pango_markup(self, context, markup): "Print some markup to the supplied context" ## need to use pango.Layout to format paragraphs ## for each block of text paraContext = gnomeprint.pango_create_context(gnomeprint.pango_get_default_font_map()) para = pango.Layout(paraContext) para.set_markup(markup) context.pango_layout(para)