def on_print_page(self, page): page_obj = self.get_print_pages()[page - 1] dc = self.GetDC() w, h = dc.GetSizeTuple() pw, ph = self.GetPageSizeMM() pw *= uc2const.mm_to_pt ph *= uc2const.mm_to_pt trafo = (w / pw, 0, 0, -h / ph, w / 2.0 - self.shifts[0], h / 2.0 - self.shifts[1]) matrix = cairo.Matrix(*trafo) surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h) ctx = cairo.Context(surface) ctx.set_source_rgb(1, 1, 1) ctx.paint() ctx.set_matrix(matrix) for group in page_obj.childs: self.renderer.render(ctx, group.childs) win_surface = cairo.Win32PrintingSurface(dc.GetHDC()) win_ctx = cairo.Context(win_surface) win_ctx.set_source_surface(surface, 0, 0) win_ctx.paint()
def OnPrintPage(self, page): page_obj = self.get_print_pages()[page - 1] dc = self.GetDC() w, h = dc.GetSizeTuple() pw, ph = self.GetPageSizeMM() pw *= uc2const.mm_to_pt ph *= uc2const.mm_to_pt trafo = (w / pw, 0, 0, -h / ph, w / 2.0 - self.shifts[0], h / 2.0 - self.shifts[1]) matrix = cairo.Matrix(*trafo) surface = cairo.Win32PrintingSurface(dc.GetHDC()) ctx = cairo.Context(surface) ctx.set_matrix(matrix) for group in page_obj.childs: self.renderer.render(ctx, group.childs) return True
import cairo import pango import pangocairo import sys import win32ui import win32print printer = win32print.GetDefaultPrinter() print printer phandle = win32print.OpenPrinter(printer) dc = win32ui.CreateDC() dc.CreatePrinterDC() dc.StartDoc("foo") dc.StartPage() surf = cairo.Win32PrintingSurface(dc.GetHandleAttrib()) context = cairo.Context(surf) #draw a background rectangle: context.rectangle(0, 0, 50, 50) context.set_source_rgb(0, 0, 0) context.fill() #get font families: font_map = pangocairo.cairo_font_map_get_default() families = font_map.list_families() # to see family names: #print [f.get_name() for f in font_map.list_families()]
def __new__(cls, *args, **kwargs): import cairo return cairo.Win32PrintingSurface(*args, **kwargs)