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 draw_sudokus (self): #print 'getting context' self.gpc = self.job.get_context() width,height = gnomeprint.job_get_page_size_from_config(self.job.get_config()) self.margin = 50 top = height-self.margin bottom = self.margin left = self.margin right = width if not self.sudokus_per_page: self.sudokus_per_page = self.nsudokus dimensions, square_size = fit_squares_in_rectangle(width,height,self.sudokus_per_page,self.margin) while square_size < MINIMUM_SQUARE_SIZE: self.sudokus_per_page = self.sudokus_per_page - 1 dimensions, square_size = fit_squares_in_rectangle(width,height,self.sudokus_per_page,self.margin) else: dimensions,square_size = fit_squares_in_rectangle(width,height,self.sudokus_per_page,self.margin) #print 'SQUARE_SIZE=',square_size count = 0 for sudoku in self.sudokus: if type(sudoku)==tuple: label = sudoku[1] sudoku = sudoku[0] else: label = None if count % self.sudokus_per_page == 0: if count: self.gpc.showpage() self.gpc.beginpage('%s'%(count/self.sudokus_per_page+1)) pos = [1,1] left_start,top_start=self.margin,top else: # move from left to right, top to bottom if pos[0] < dimensions[0]: left_start = left_start + square_size + self.margin pos[0] += 1 else: top_start = top_start - square_size - self.margin # down ... left_start = self.margin # ...and to the left pos[0] = 1 pos[1] += 1 drawer = SudokuDrawer(sudoku, self.gpc, start_at=(left_start,top_start), grid_side_size=square_size, label=label ) drawer.draw_grid() drawer.draw_sudoku() count += 1 self.gpc.showpage() self.job.close() self.drawn = True
def my_print(job, preview): file_ = file(TEMP_FILE, "w") config = job.get_config() width, height = gnomeprint.job_get_page_size_from_config(config) output = format % (width, height) file_.write(output) # this is marked with GNOME_PRINT_UNSTABLE_API in the public headers # OK. So this example becomes useless, I know. #job.set_file(TEMP_FILE) if not preview: job.print_() else: gnomeprint.ui.JobPreview(job, "Title goes here").show()