Ejemplo n.º 1
0
    def OnPrintPage(self, page):
        page_objs = self.pages[page - 1]
        dc = self.GetDC()
        w, h = dc.GetSizeTuple()
        pw, ph = self.GetPageSizeMM()
        print 'PPI', self.GetPPIPrinter()
        print 'DC', w, h
        print 'Page', pw, ph
        pw *= uc2const.mm_to_pt
        ph *= uc2const.mm_to_pt
        trafo = (w / pw, 0, 0, -h / ph, w / 2.0, h / 2.0)

        canvas_matrix = cairo.Matrix(*trafo)
        surface = cairo.ImageSurface(cairo.FORMAT_RGB24, int(w), int(h))
        ctx = cairo.Context(surface)
        ctx.set_matrix(canvas_matrix)
        ctx.set_source_rgb(1, 1, 1)
        ctx.paint()

        rend = crenderer.CairoRenderer(self.doc.cms)
        rend.render(ctx, page_objs)

        bmp = wal.copy_surface_to_bitmap(surface)
        #		dc.DrawBitmap(bmp, 0, 0, False)
        return True
Ejemplo n.º 2
0
	def OnPrintPage(self, page):
		page_objs = self.pages[page - 1]
		dc = self.GetDC()
		w, h = dc.GetSizeTuple()
		pw, ph = self.GetPageSizeMM()
		print 'PPI', self.GetPPIPrinter()
		print 'DC', w, h
		print 'Page', pw, ph
		pw *= uc2const.mm_to_pt
		ph *= uc2const.mm_to_pt
		trafo = (w / pw, 0, 0, -h / ph, w / 2.0, h / 2.0)

		canvas_matrix = cairo.Matrix(*trafo)
		surface = cairo.ImageSurface(cairo.FORMAT_RGB24, int(w), int(h))
		ctx = cairo.Context(surface)
		ctx.set_matrix(canvas_matrix)
		ctx.set_source_rgb(1, 1, 1)
		ctx.paint()

		rend = crenderer.CairoRenderer(self.doc.cms)
		rend.render(ctx, page_objs)

		bmp = wal.copy_surface_to_bitmap(surface)
#		dc.DrawBitmap(bmp, 0, 0, False)
		return True
Ejemplo n.º 3
0
	def _on_paint(self, event):
		w, h = self.panel.GetSize()
		pdc = wx.BufferedPaintDC(self.panel)
		pdc.BeginDrawing()
		if self.presenter is None: return
		shift = 0
		if is_msw():shift = 1
		if self.surface is None:
			self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w - shift, h - shift)
			self.width = w
			self.height = h
		elif self.width <> w or self.height <> h:
			self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w - shift, h - shift)
			self.width = w
			self.height = h
		self.ctx = cairo.Context(self.surface)
		self.ctx.set_matrix(cairo.Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0))
		self.ctx.set_source_rgb(*config.ruler_bg)
		self.ctx.paint()
		self.ctx.set_antialias(cairo.ANTIALIAS_NONE)
		self.ctx.set_line_width(1.0)
		self.ctx.set_dash([])
		self.ctx.set_source_rgb(*config.ruler_fg)
		if self.init_flag:
			if self.style == HORIZONTAL: self.hrender(w, h)
			else: self.vrender(w, h)
		pdc.DrawBitmap(copy_surface_to_bitmap(self.surface), 0, 0, True)
Ejemplo n.º 4
0
 def paint(self):
     w, h = self.get_size()
     shift = 0
     if wal.is_msw(): shift = 1
     if self.surface is None:
         self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w - shift,
                                           h - shift)
         self.width = w
         self.height = h
     elif self.width <> w or self.height <> h:
         self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w - shift,
                                           h - shift)
         self.width = w
         self.height = h
     self.ctx = cairo.Context(self.surface)
     self.ctx.set_matrix(cairo.Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0))
     self.ctx.set_source_rgb(*config.ruler_bg)
     self.ctx.paint()
     self.ctx.set_antialias(cairo.ANTIALIAS_NONE)
     self.ctx.set_line_width(1.0)
     self.ctx.set_dash([])
     self.ctx.set_source_rgb(*config.ruler_fg)
     if self.horizontal: self.hrender(w, h)
     else: self.vrender(w, h)
     self.draw_bitmap(wal.copy_surface_to_bitmap(self.surface))
Ejemplo n.º 5
0
	def _on_paint(self, event):
		w, h = self.panel.GetSize()
		pdc = wx.BufferedPaintDC(self.panel)
		pdc.BeginDrawing()
		if self.presenter is None: return
		shift = 0
		if is_msw():shift = 1
		if self.surface is None:
			self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w - shift, h - shift)
			self.width = w
			self.height = h
		elif self.width <> w or self.height <> h:
			self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w - shift, h - shift)
			self.width = w
			self.height = h
		self.ctx = cairo.Context(self.surface)
		self.ctx.set_matrix(cairo.Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0))
		self.ctx.set_source_rgb(*config.ruler_bg)
		self.ctx.paint()
		self.ctx.set_antialias(cairo.ANTIALIAS_NONE)
		self.ctx.set_line_width(1.0)
		self.ctx.set_dash([])
		self.ctx.set_source_rgb(*config.ruler_fg)
		if self.init_flag:
			if self.style == HORIZONTAL: self.hrender(w, h)
			else: self.vrender(w, h)
		pdc.DrawBitmap(copy_surface_to_bitmap(self.surface), 0, 0, True)
Ejemplo n.º 6
0
	def draw_pattern(self):
		w, h = self.get_size()
		pattern = self.fill[2]
		surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
		ctx = cairo.Context(surface)
		self.draw_cairo_background(ctx)
		bmpstr = b64decode(pattern[1])
		if self.cms.app.current_doc:
			config = self.cms.app.current_doc.model.config
		else:
			config = sk2_config.SK2_Config()
			config_file = os.path.join(self.cms.app.appdata.app_config_dir,
									'sk2_config.xml')
			config.load(config_file)
		image_obj = sk2_model.Pixmap(config)
		libimg.set_image_data(self.cms, image_obj, bmpstr)
		libimg.flip_left_to_right(image_obj)
		if pattern[0] == sk2_const.PATTERN_IMG and len(pattern) > 2:
			image_obj.style[3] = deepcopy(pattern[2])
		libimg.update_image(self.cms, image_obj)
		sp = cairo.SurfacePattern(image_obj.cache_cdata)
		sp.set_extend(cairo.EXTEND_REPEAT)
		trafo = [-1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
		if len(pattern) > 3:
			trafo = libgeom.multiply_trafo(pattern[3], trafo)
		pattern_matrix = cairo.Matrix(*trafo)
		pattern_matrix.invert()
		sp.set_matrix(pattern_matrix)
		ctx.set_source(sp)
		ctx.rectangle(0, 0, w, h)
		ctx.fill()
		image_obj.cache_cdata = None
		self.gc_draw_bitmap(wal.copy_surface_to_bitmap(surface), 0, 0)
Ejemplo n.º 7
0
 def _on_paint(self, event):
     w, h = self.panel.GetSize()
     pdc = wal.get_buffered_dc(self.panel)
     if self.presenter is None:
         return
     shift = 0
     if wal.IS_MSW:
         shift = 1
     fmt = cairo.FORMAT_RGB24
     if self.surface is None:
         self.surface = cairo.ImageSurface(fmt, w - shift, h - shift)
         self.width = w
         self.height = h
     elif self.width != w or self.height != h:
         self.surface = cairo.ImageSurface(fmt, w - shift, h - shift)
         self.width = w
         self.height = h
     self.ctx = cairo.Context(self.surface)
     self.ctx.set_matrix(cairo.Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0))
     self.ctx.set_source_rgb(*config.ruler_bg)
     self.ctx.paint()
     self.ctx.set_antialias(cairo.ANTIALIAS_NONE)
     self.ctx.set_line_width(1.0)
     self.ctx.set_dash([])
     self.ctx.set_source_rgb(*config.ruler_fg)
     if self.init_flag:
         if self.style == wal.HORIZONTAL:
             self.hrender(w, h)
         else:
             self.vrender(w, h)
     pdc.DrawBitmap(wal.copy_surface_to_bitmap(self.surface), 0, 0, True)
Ejemplo n.º 8
0
 def cdc_draw_frame(self, start, end, temp_surfase=False):
     if start and end:
         if self.frame:
             if start == self.frame[0] and end == self.frame[1]:
                 return
         cpath = libcairo.convert_bbox_to_cpath(start + end)
         bbox = self.cdc_to_int(*libcairo.get_cpath_bbox(cpath))
         frame = self.cdc_bbox_to_frame(bbox)
         if not self.frame:
             self.frame = frame
         bbox2 = self.cdc_frame_to_bbox(self.frame)
         frame_sum = self.cdc_bbox_to_frame(libgeom.sum_bbox(bbox, bbox2))
         x, y, w, h = self.cdc_normalize_rect(*frame_sum)
         self.frame = frame
         surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w + 2, h + 2)
         ctx = cairo.Context(surface)
         if temp_surfase:
             ctx.set_source_surface(self.temp_surface, -x + 1, -y + 1)
         else:
             ctx.set_source_surface(self.surface, -x + 1, -y + 1)
         ctx.paint()
         ctx.set_matrix(cairo.Matrix(1.0, 0.0, 0.0, 1.0, -x + 1, -y + 1))
         self._cdc_draw_cpath(ctx, cpath)
         dc = wx.ClientDC(self.canvas)
         dc.DrawBitmap(copy_surface_to_bitmap(surface), x - 1, y - 1)
         self.cdc_reflect_snapping()
Ejemplo n.º 9
0
 def cdc_draw_move_frame(self, trafo):
     bbox = self.presenter.selection.bbox
     if bbox:
         cpath = libcairo.convert_bbox_to_cpath(bbox)
         libcairo.apply_trafo(cpath, trafo)
         libcairo.apply_trafo(cpath, self.canvas.trafo)
         bbox = self.cdc_to_int(*libcairo.get_cpath_bbox(cpath))
         frame = self.cdc_bbox_to_frame(bbox)
         if self.frame and frame == self.frame:
             return
         if not self.frame:
             self.frame = frame
         bbox2 = self.cdc_frame_to_bbox(self.frame)
         frame_sum = self.cdc_bbox_to_frame(libgeom.sum_bbox(bbox, bbox2))
         x, y, w, h = self.cdc_normalize_rect(*frame_sum)
         self.frame = frame
         surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w + 2, h + 2)
         ctx = cairo.Context(surface)
         ctx.set_source_surface(self.surface, -x + 1, -y + 1)
         ctx.paint()
         ctx.set_matrix(cairo.Matrix(1.0, 0.0, 0.0, 1.0, -x + 1, -y + 1))
         self._cdc_draw_cpath(ctx, cpath)
         dc = wx.ClientDC(self.canvas)
         dc.DrawBitmap(copy_surface_to_bitmap(surface), x - 1, y - 1)
         self.cdc_reflect_snapping()
Ejemplo n.º 10
0
 def draw_pattern(self):
     w, h = self.get_size()
     pattern = self.fill[2]
     surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
     ctx = cairo.Context(surface)
     self.draw_cairo_background(ctx)
     if self.cms.app.current_doc:
         cfg = self.cms.app.current_doc.model.config
     else:
         cfg = sk2_config.SK2_Config()
         config_file = os.path.join(self.cms.app.appdata.app_config_dir,
                                    'sk2_config.xml')
         cfg.load(config_file)
     image_obj = sk2_model.Pixmap(cfg)
     hndl = image_obj.handler
     hndl.load_from_b64str(self.cms, pattern[1])
     hndl.flip_left_to_right()
     if pattern[0] == sk2const.PATTERN_IMG and len(pattern) > 2:
         image_obj.style[3] = deepcopy(pattern[2])
     sp = cairo.SurfacePattern(hndl.get_surface(self.cms))
     sp.set_extend(cairo.EXTEND_REPEAT)
     trafo = [-1.0, 0.0, 0.0, 1.0, 0.0, 0.0]
     if len(pattern) > 3:
         trafo = libgeom.multiply_trafo(pattern[3], trafo)
     pattern_matrix = cairo.Matrix(*trafo)
     pattern_matrix.invert()
     sp.set_matrix(pattern_matrix)
     ctx.set_source(sp)
     ctx.rectangle(0, 0, w, h)
     ctx.fill()
     self.gc_draw_bitmap(wal.copy_surface_to_bitmap(surface), 0, 0)
Ejemplo n.º 11
0
	def cdc_clear_rect(self, start, end):
		if start and end:
			x, y, w, h = self.cdc_to_int(*self.cdc_normalize_rect(start, end))
			dc = wx.ClientDC(self.canvas)
			x -= 2;y -= 2
			w += 4;h += 4
			if not w: w = 1
			if not h: h = 1
			surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
			ctx = cairo.Context(surface)
			ctx.set_source_surface(self.surface, -x, -y)
			ctx.paint()
			dc.DrawBitmap(copy_surface_to_bitmap(surface), x, y)
Ejemplo n.º 12
0
 def cdc_draw_horizontal_line(self, y, color, dash, clear=False):
     if y is None: return
     y = self.cdc_to_int(y)[0]
     surface = cairo.ImageSurface(cairo.FORMAT_RGB24, self.width, 1)
     ctx = cairo.Context(surface)
     ctx.set_source_surface(self.temp_surface, 0, -y + 1)
     ctx.paint()
     if not clear:
         self.cdc_set_ctx(ctx, color, dash)
         ctx.move_to(0, 1)
         ctx.line_to(self.width, 1)
         ctx.stroke()
     dc = wx.ClientDC(self.canvas)
     dc.DrawBitmap(copy_surface_to_bitmap(surface), 0, y - 1)
Ejemplo n.º 13
0
	def cdc_draw_horizontal_line(self, y, color, dash, clear=False):
		if y is None:return
		y = self.cdc_to_int(y)[0]
		surface = cairo.ImageSurface(cairo.FORMAT_RGB24, self.width, 1)
		ctx = cairo.Context(surface)
		ctx.set_source_surface(self.temp_surface, 0, -y + 1)
		ctx.paint()
		if not clear:
			self.cdc_set_ctx(ctx, color, dash)
			ctx.move_to(0, 1)
			ctx.line_to(self.width, 1)
			ctx.stroke()
		dc = wx.ClientDC(self.canvas)
		dc.DrawBitmap(copy_surface_to_bitmap(surface), 0, y - 1)
Ejemplo n.º 14
0
	def cdc_draw_vertical_line(self, x, color, dash, clear=False):
		if x is None:return
		x = self.cdc_to_int(x)[0]
		surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, self.height)
		ctx = cairo.Context(surface)
		ctx.set_source_surface(self.temp_surface, -x + 1, 0)
		ctx.paint()
		if not clear:
			self.cdc_set_ctx(ctx, color, dash)
			ctx.move_to(1, 0)
			ctx.line_to(1, self.height)
			ctx.stroke()
		dc = wx.ClientDC(self.canvas)
		dc.DrawBitmap(copy_surface_to_bitmap(surface), x - 1, 0)
Ejemplo n.º 15
0
 def cdc_draw_vertical_line(self, x, color, dash, clear=False):
     if x is None: return
     x = self.cdc_to_int(x)[0]
     surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, self.height)
     ctx = cairo.Context(surface)
     ctx.set_source_surface(self.temp_surface, -x + 1, 0)
     ctx.paint()
     if not clear:
         self.cdc_set_ctx(ctx, color, dash)
         ctx.move_to(1, 0)
         ctx.line_to(1, self.height)
         ctx.stroke()
     dc = wx.ClientDC(self.canvas)
     dc.DrawBitmap(copy_surface_to_bitmap(surface), x - 1, 0)
Ejemplo n.º 16
0
 def cdc_clear_rect(self, start, end):
     if start and end:
         x, y, w, h = self.cdc_to_int(*self.cdc_normalize_rect(start, end))
         dc = wx.ClientDC(self.canvas)
         x -= 2
         y -= 2
         w += 4
         h += 4
         if not w: w = 1
         if not h: h = 1
         surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
         ctx = cairo.Context(surface)
         ctx.set_source_surface(self.surface, -x, -y)
         ctx.paint()
         dc.DrawBitmap(copy_surface_to_bitmap(surface), x, y)
Ejemplo n.º 17
0
	def paint(self):
		if not self.matrix: self._fit_to_page()
		self.renderer.set_colorspace(self.printer.colorspace)
		self._keep_center()
		w, h = self.get_size()
		surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
		self.ctx = cairo.Context(surface)
		self.ctx.set_source_rgb(*wal.wxcolor_to_dec(wal.GRAY))
		self.ctx.paint()
		self.ctx.set_matrix(self.matrix)

		self._draw_page()
		self._render_page()
		self._draw_page_border()

		self.draw_bitmap(wal.copy_surface_to_bitmap(surface))
Ejemplo n.º 18
0
    def paint(self):
        if not self.matrix: self._fit_to_page()
        self.renderer.set_colorspace(self.printer.colorspace)
        self._keep_center()
        w, h = self.get_size()
        surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
        self.ctx = cairo.Context(surface)
        self.ctx.set_source_rgb(*wal.wxcolor_to_dec(wal.GRAY))
        self.ctx.paint()
        self.ctx.set_matrix(self.matrix)

        self._draw_page()
        self._render_page()
        self._draw_page_border()

        self.draw_bitmap(wal.copy_surface_to_bitmap(surface))
Ejemplo n.º 19
0
 def draw_gradient(self):
     w, h = self.get_size()
     gradient = self.fill[2]
     surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
     ctx = cairo.Context(surface)
     self.draw_cairo_background(ctx)
     if gradient[0] == sk2const.GRADIENT_LINEAR:
         grd = cairo.LinearGradient(0.0, h / 2.0, w, h / 2.0)
     else:
         grd = cairo.RadialGradient(w / 2.0, h / 2.0, 0, w / 2.0, h / 2.0,
                                    w / 2.0)
     for stop in gradient[2]:
         grd.add_color_stop_rgba(stop[0], *self.get_cairo_color(stop[1]))
     ctx.set_source(grd)
     ctx.rectangle(0, 0, w, h)
     ctx.fill()
     self.gc_draw_bitmap(wal.copy_surface_to_bitmap(surface), 0, 0)
Ejemplo n.º 20
0
def generate_dash_bitmap(dash=[]):
    w, h = DASH_BITMAP_SIZE
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
    ctx = cairo.Context(surface)
    y = h / 2

    ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
    ctx.set_line_width(DASH_LINE_WIDTH)
    cdash = []
    for item in dash:
        cdash.append(item * DASH_LINE_WIDTH)
    ctx.set_dash(cdash)
    ctx.move_to(0, y)
    ctx.line_to(w, y)
    ctx.stroke()

    return wal.copy_surface_to_bitmap(surface)
Ejemplo n.º 21
0
	def draw_gradient(self):
		w, h = self.get_size()
		gradient = self.fill[2]
		surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
		ctx = cairo.Context(surface)
		self.draw_cairo_background(ctx)
		if gradient[0] == sk2_const.GRADIENT_LINEAR:
			grd = cairo.LinearGradient(0.0, h / 2.0, w, h / 2.0)
		else:
			grd = cairo.RadialGradient(w / 2.0, h / 2.0, 0,
									w / 2.0, h / 2.0, w / 2.0)
		for stop in gradient[2]:
			grd.add_color_stop_rgba(stop[0], *self.get_cairo_color(stop[1]))
		ctx.set_source(grd)
		ctx.rectangle(0, 0, w, h)
		ctx.fill()
		self.gc_draw_bitmap(wal.copy_surface_to_bitmap(surface), 0, 0)
Ejemplo n.º 22
0
def generate_dash_bitmap(dash=[]):
	w, h = DASH_BITMAP_SIZE
	surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
	ctx = cairo.Context(surface)
	y = h / 2

	ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
	ctx.set_line_width(DASH_LINE_WIDTH)
	cdash = []
	for item in dash:
		cdash.append(item * DASH_LINE_WIDTH)
	ctx.set_dash(cdash)
	ctx.move_to(0, y)
	ctx.line_to(w, y)
	ctx.stroke()

	return wal.copy_surface_to_bitmap(surface)
Ejemplo n.º 23
0
def generate_fontsample_cache(fonts):
    w = config.font_preview_width
    fontsize = config.font_preview_size
    color = cms.val_255(config.font_preview_color)
    text = config.font_preview_text.decode('utf-8')
    for item in fonts:
        h = libpango.get_sample_size(text, item, fontsize)[1]
        if not h:
            h = 10
            LOG.warn('Incorrect font <%s>: zero font height', item)
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
        ctx = cairo.Context(surface)
        ctx.set_source_rgb(0.0, 0.0, 0.0)
        ctx.set_matrix(cairo.Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0))
        ctx.set_antialias(cairo.ANTIALIAS_DEFAULT)
        libpango.render_sample(ctx, text, item, fontsize)
        ctx.fill()
        bmp = wal.copy_surface_to_bitmap(surface)
        FONTSAMPLE_CACHE.append(bmp)
Ejemplo n.º 24
0
def generate_fontsamples(fonts):
	bitmaps = []
	w = config.font_preview_width
	fontsize = config.font_preview_size
	color = cms.val_255(config.font_preview_color)
	text = config.font_preview_text
	for item in fonts:
		h = libpango.get_sample_size(text, item, fontsize)[1]
		surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
		ctx = cairo.Context(surface)
		ctx.set_source_rgb(0.0, 0.0, 0.0)
		ctx.paint()
		matrix = cairo.Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
		ctx.set_matrix(matrix)
		ctx.set_source_rgb(1.0, 1.0, 1.0)
		ctx.set_antialias(cairo.ANTIALIAS_DEFAULT)
		libpango.render_sample(ctx, text, item, fontsize)
		ctx.fill()
		bmp = wal.copy_surface_to_bitmap(surface)
		bitmaps.append(wal.invert_text_bitmap(bmp, color))
	return bitmaps
Ejemplo n.º 25
0
def generate_fontsample_cache(fonts):
    w = config.font_preview_width
    fontsize = config.font_preview_size
    color = cms.val_255(config.font_preview_color)
    text = config.font_preview_text
    for item in fonts:
        h = libpango.get_sample_size(text, item, fontsize)[1]
        if not h:
            h = 10
            warn(_('incorrect font') + ' - %s' % item)
        surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
        ctx = cairo.Context(surface)
        ctx.set_source_rgb(0.0, 0.0, 0.0)
        ctx.paint()
        matrix = cairo.Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
        ctx.set_matrix(matrix)
        ctx.set_source_rgb(1.0, 1.0, 1.0)
        ctx.set_antialias(cairo.ANTIALIAS_DEFAULT)
        libpango.render_sample(ctx, text, item, fontsize)
        ctx.fill()
        bmp = wal.copy_surface_to_bitmap(surface)
        FONTSAMPLE_CACHE.append(wal.invert_text_bitmap(bmp, color))
Ejemplo n.º 26
0
def generate_arrow_bitmap(arrow=0, end=False):
    w, h = ARROW_BITMAP_SIZE
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
    ctx = cairo.Context(surface)
    y = round(h / 2.0)
    x = w / 2

    ctx.set_source_rgba(0.0, 0.0, 0.0, 1.0)
    ctx.set_line_width(ARROW_LINE_WIDTH)
    x = x - 15 if end else x - 15
    ctx.move_to(x, y)
    x2 = w if end else 0
    ctx.line_to(x2, y)
    ctx.stroke()

    if arrow:
        ctx.new_path()
        trafo = [-4, 0.0, 0.0, 4, x, y] if end else [4, 0.0, 0.0, 4, x, y]
        ctx.append_path(arrows.get_arrow_cpath(arrow - 1, trafo))
        ctx.fill()

    return wal.copy_surface_to_bitmap(surface)
Ejemplo n.º 27
0
def generate_fontsample_cache(fonts):
	w = config.font_preview_width
	fontsize = config.font_preview_size
	color = cms.val_255(config.font_preview_color)
	text = config.font_preview_text
	for item in fonts:
		h = libpango.get_sample_size(text, item, fontsize)[1]
		if not h:
			h = 10
			warn(_('incorrect font') + ' - %s' % item)
		surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
		ctx = cairo.Context(surface)
		ctx.set_source_rgb(0.0, 0.0, 0.0)
		ctx.paint()
		matrix = cairo.Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
		ctx.set_matrix(matrix)
		ctx.set_source_rgb(1.0, 1.0, 1.0)
		ctx.set_antialias(cairo.ANTIALIAS_DEFAULT)
		libpango.render_sample(ctx, text, item, fontsize)
		ctx.fill()
		bmp = wal.copy_surface_to_bitmap(surface)
		FONTSAMPLE_CACHE.append(wal.invert_text_bitmap(bmp, color))
Ejemplo n.º 28
0
	def paint(self):
		w, h = self.get_size()
		shift = 0
		if wal.is_msw():shift = 1
		if self.surface is None:
			self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w - shift, h - shift)
			self.width = w
			self.height = h
		elif self.width <> w or self.height <> h:
			self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w - shift, h - shift)
			self.width = w
			self.height = h
		self.ctx = cairo.Context(self.surface)
		self.ctx.set_matrix(cairo.Matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0))
		self.ctx.set_source_rgb(*config.ruler_bg)
		self.ctx.paint()
		self.ctx.set_antialias(cairo.ANTIALIAS_NONE)
		self.ctx.set_line_width(1.0)
		self.ctx.set_dash([])
		self.ctx.set_source_rgb(*config.ruler_fg)
		if self.horizontal: self.hrender(w, h)
		else: self.vrender(w, h)
		self.draw_bitmap(wal.copy_surface_to_bitmap(self.surface))
Ejemplo n.º 29
0
	def cdc_draw_move_frame(self, trafo):
		bbox = self.presenter.selection.bbox
		if bbox:
			cpath = libcairo.convert_bbox_to_cpath(bbox)
			libcairo.apply_trafo(cpath, trafo)
			libcairo.apply_trafo(cpath, self.canvas.trafo)
			bbox = self.cdc_to_int(*libcairo.get_cpath_bbox(cpath))
			frame = self.cdc_bbox_to_frame(bbox)
			if self.frame and frame == self.frame:return
			if not self.frame:self.frame = frame
			bbox2 = self.cdc_frame_to_bbox(self.frame)
			frame_sum = self.cdc_bbox_to_frame(libgeom.sum_bbox(bbox, bbox2))
			x, y, w, h = self.cdc_normalize_rect(*frame_sum)
			self.frame = frame
			surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w + 2, h + 2)
			ctx = cairo.Context(surface)
			ctx.set_source_surface(self.surface, -x + 1, -y + 1)
			ctx.paint()
			ctx.set_matrix(cairo.Matrix(1.0, 0.0, 0.0, 1.0, -x + 1, -y + 1))
			self._cdc_draw_cpath(ctx, cpath)
			dc = wx.ClientDC(self.canvas)
			dc.DrawBitmap(copy_surface_to_bitmap(surface), x - 1, y - 1)
			self.cdc_reflect_snapping()
Ejemplo n.º 30
0
	def cdc_draw_frame(self, start, end, temp_surfase=False):
		if start and end:
			if self.frame:
				if start == self.frame[0] and end == self.frame[1]:return
			cpath = libcairo.convert_bbox_to_cpath(start + end)
			bbox = self.cdc_to_int(*libcairo.get_cpath_bbox(cpath))
			frame = self.cdc_bbox_to_frame(bbox)
			if not self.frame:self.frame = frame
			bbox2 = self.cdc_frame_to_bbox(self.frame)
			frame_sum = self.cdc_bbox_to_frame(libgeom.sum_bbox(bbox, bbox2))
			x, y, w, h = self.cdc_normalize_rect(*frame_sum)
			self.frame = frame
			surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w + 2, h + 2)
			ctx = cairo.Context(surface)
			if temp_surfase:
				ctx.set_source_surface(self.temp_surface, -x + 1, -y + 1)
			else:
				ctx.set_source_surface(self.surface, -x + 1, -y + 1)
			ctx.paint()
			ctx.set_matrix(cairo.Matrix(1.0, 0.0, 0.0, 1.0, -x + 1, -y + 1))
			self._cdc_draw_cpath(ctx, cpath)
			dc = wx.ClientDC(self.canvas)
			dc.DrawBitmap(copy_surface_to_bitmap(surface), x - 1, y - 1)
			self.cdc_reflect_snapping()
Ejemplo n.º 31
0
	def cdc_paint_doc(self):
		dc = wx.ClientDC(self.canvas)
		dc.DrawBitmap(copy_surface_to_bitmap(self.surface), 0, 0, False)
Ejemplo n.º 32
0
	def cdc_paint_selection(self):
		dc = wx.ClientDC(self.canvas)
		dc.DrawBitmap(copy_surface_to_bitmap(self.temp_surface), 0, 0, False)
Ejemplo n.º 33
0
 def finalize(self):
     dc = wx.PaintDC(self.canvas)
     dc.DrawBitmap(copy_surface_to_bitmap(self.temp_surface), 0, 0, False)
Ejemplo n.º 34
0
	def finalize(self):
		dc = wx.PaintDC(self.canvas)
		dc.DrawBitmap(copy_surface_to_bitmap(self.temp_surface), 0, 0, False)
Ejemplo n.º 35
0
 def cdc_paint_selection(self):
     dc = wx.ClientDC(self.canvas)
     dc.DrawBitmap(copy_surface_to_bitmap(self.temp_surface), 0, 0, False)
Ejemplo n.º 36
0
 def cdc_paint_doc(self):
     dc = wx.ClientDC(self.canvas)
     dc.DrawBitmap(copy_surface_to_bitmap(self.surface), 0, 0, False)