本文整理汇总了Python中cairo.ImageSurface方法的典型用法代码示例。如果您正苦于以下问题:Python cairo.ImageSurface方法的具体用法?Python cairo.ImageSurface怎么用?Python cairo.ImageSurface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo
的用法示例。
在下文中一共展示了cairo.ImageSurface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
def paint(self):
w, h = self.get_size()
if self.surface is None or self.width != w or self.height != h:
self.surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
self.width, self.height = w, 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))
示例2: paint
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
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))
示例3: load_font
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
def load_font(self, font_size, color):
fntdir = 'ruler-font%dpx' % font_size
fntdir = os.path.join(config.resource_dir, 'fonts', fntdir)
def get_colored_surface(filename, clr):
filename = fsutils.get_sys_path(filename)
surface = cairo.ImageSurface.create_from_png(filename)
w, h = surface.get_width(), surface.get_height()
res = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
cr = cairo.Context(res)
cr.set_source_rgb(*clr)
cr.mask_surface(surface, 0, 0)
cr.fill()
return w, res
for char in '.,-0123456789':
file_name = 'hdot.png' if char in '.,' else 'h%s.png' % char
file_name = os.path.join(fntdir, file_name)
self.font[char] = get_colored_surface(file_name, color)
示例4: draw_gradient
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
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)
示例5: generate_dash_bitmap
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
def generate_dash_bitmap(dash=None):
if not dash:
dash = []
w, h = DASH_BITMAP_SIZE
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
ctx = cairo.Context(surface)
y = round(h / 2.0)
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)
示例6: generate_arrow_bitmap
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
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)
示例7: generate_fontsample_cache
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
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_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))
示例8: cdc_draw_move_frame
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
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)
self.canvas.dc.put_surface(surface, x - 1, y - 1, False)
self.cdc_reflect_snapping()
示例9: load_font
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
def load_font(color=(0, 0, 0)):
fntdir = 'ruler-font%dpx' % config.ruler_font_size
fntdir = os.path.join(config.resource_dir, 'fonts', fntdir)
def get_colored_surface(file_name, color, vertical=False):
file_name = fsutils.get_sys_path(file_name)
surface = cairo.ImageSurface.create_from_png(file_name)
w, h = surface.get_width(), surface.get_height()
res = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
cr = cairo.Context(res)
cr.set_source_rgb(*color)
cr.mask_surface(surface, 0, 0)
cr.fill()
return h if vertical else w, res
for char in '.,-0123456789':
file_name = 'hdot.png' if char in '.,' else 'h%s.png' % char
file_name = os.path.join(fntdir, file_name)
HFONT[char] = get_colored_surface(file_name, color)
file_name = 'vdot.png' if char in '.,' else 'v%s.png' % char
file_name = os.path.join(fntdir, file_name)
VFONT[char] = get_colored_surface(file_name, color, True)
示例10: paint
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
def paint(self):
if self.presenter is None:
return
w, h = self.dc.get_size()
fmt = cairo.FORMAT_RGB24
if self.surface is None or self.width != w or self.height != h:
self.surface = cairo.ImageSurface(fmt, w, h)
self.width, self.height = w, 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.vertical:
self.vrender(w, h)
else:
self.hrender(w, h)
self.dc.draw_surface(self.surface, 0, 0)
示例11: render
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
def render(self, scale=96/25.4, margin=10, line_width=0.5):
import cairo
x1, y1, x2, y2 = self.bounds
width = int(scale * self.width + margin * 2)
height = int(scale * self.height + margin * 2)
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
dc = cairo.Context(surface)
dc.set_line_cap(cairo.LINE_CAP_ROUND)
dc.translate(margin, height - margin)
dc.scale(scale, -scale)
dc.translate(-x1, -y1)
dc.set_line_width(line_width)
dc.set_source_rgb(1, 1, 1)
dc.paint()
# dc.arc(0, 0, 3.0 / scale, 0, 2 * math.pi)
# dc.set_source_rgb(1, 0, 0)
# dc.fill()
dc.set_source_rgb(0, 0, 0)
for path in self.paths:
dc.move_to(*path[0])
for x, y in path:
dc.line_to(x, y)
dc.stroke()
return surface
示例12: layout
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
def layout(self, width):
self.__width = width
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1)
ctx = cairo.Context(surface)
line_height = 0
total_height = self.__padding
line_used = self.__padding
for legend in self.__legends:
(t_width, t_height) = ctx.text_extents(legend)[2:4]
item_width = self.__padding + self.__padding + t_width + self.__padding
item_height = t_height + self.__padding
if item_height > line_height:
line_height = item_height
if line_used + item_width > self.__width:
line_used = self.__padding + item_width
total_height += line_height
else:
line_used += item_width
x = line_used - item_width
total_height += line_height
self.__height = total_height
示例13: draw_image
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
def draw_image(self, gc, x, y, im):
# bbox - not currently used
if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name()))
im.flipud_out()
rows, cols, buf = im.color_conv (BYTE_FORMAT)
surface = cairo.ImageSurface.create_for_data (
buf, cairo.FORMAT_ARGB32, cols, rows, cols*4)
ctx = gc.ctx
y = self.height - y - rows
ctx.save()
ctx.set_source_surface (surface, x, y)
ctx.paint()
ctx.restore()
im.flipud_out()
示例14: thumbshot
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
def thumbshot(width, height):
"""Return a thumbshot of the current screen as bytes."""
root = Gdk.get_default_root_window()
if root is None:
raise RuntimeError('Cannot find the root window, is xorg running?')
geometry = root.get_geometry()
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
ctx = cairo.Context(surface)
# TODO: check if this actually does client-size resizing
ctx.scale(float(width) / geometry.width, float(height) / geometry.height)
Gdk.cairo_set_source_window(ctx, root, 0, 0)
ctx.paint()
# TODO: is a pixbuf necessary, or can we get the bytes from the surface?
pixbuf = Gdk.pixbuf_get_from_surface(surface, 0, 0, width, height)
rowst = pixbuf.get_rowstride()
pixels = pixbuf.get_pixels()
return (b"%i\n%ix%i\n" % (rowst, width, height)
+ pixels
# TODO: the last padding isn't included, so do it manually
+ b"\0"*(rowst*height - len(pixels)))
示例15: size_image
# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import ImageSurface [as 别名]
def size_image(image_path):
"""
Gets the size of the image
Need to use a dummy CTX (dctx) as using the final ctx to get this
information seems to ruin the final image.
"""
dctx.save()
iw = 0
ih = 0
image = cairo.ImageSurface.create_from_png(image_path)
if image:
iw = cairo.ImageSurface.get_width(image)
ih = cairo.ImageSurface.get_height(image)
log.debug('Image Size (unscaled): height=%d width=%d', ih, iw)
dctx.restore()
return (iw, ih)