本文整理汇总了Python中cairo.Context.stroke方法的典型用法代码示例。如果您正苦于以下问题:Python Context.stroke方法的具体用法?Python Context.stroke怎么用?Python Context.stroke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo.Context
的用法示例。
在下文中一共展示了Context.stroke方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _draw_cell
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
def _draw_cell(self, context: cairo.Context,
cell_value: CrucipixelCellValue, area: Rectangle):
r, g, b = self.crucipixel_cell_value_to_color[cell_value]
context.set_source_rgb(r, g, b)
context.rectangle(area.start.x,
area.start.y,
area.width,
area.height)
context.fill()
if not self.victory_screen and cell_value == CrucipixelCellValue.EMPTY:
# draw the X
r, g, b = self.crucipixel_cell_value_to_color[
CrucipixelCellValue.SELECTED
]
context.set_source_rgb(r, g, b)
context.set_line_cap(cairo.LINE_CAP_ROUND)
delta_x = self.cell_width // 2.8
delta_y = self.cell_height // 2.8
context.move_to(area.start.x + area.width - delta_x,
area.start.y + delta_y)
context.line_to(area.start.x + delta_x,
area.start.y + area.height - delta_y)
context.move_to(area.start.x + area.width - delta_x,
area.start.y + area.width - delta_y)
context.line_to(area.start.x + delta_x,
area.start.y + delta_y)
context.stroke()
示例2: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
def on_draw(self, widget: Widget, context: cairo.Context):
self.shape.draw_on_context(context)
context.set_source_rgb(*global_constants.background)
context.fill_preserve()
context.set_source_rgb(0, 0, 0)
context.stroke()
super().on_draw(widget, context)
示例3: outline
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
def outline(self, surface):
border = Context(surface)
border.rectangle(self.w / 64, self.w / 64, self.w - self.w / 32, self.h - self.w / 32 - 2)
border.set_line_width(self.w / 32)
border.set_source_rgb(0.1, 0.1, 0.1)
border.set_line_join(rounded)
border.stroke()
示例4: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
def on_draw(self, widget: Widget, context: cairo.Context):
if not self.is_shape_set:
self.layout(context)
context.set_font_size(self.font_size)
self.shape.draw_on_context(context)
context.set_source_rgb(1, 1, 1)
context.fill_preserve()
context.set_source_rgb(0, 0, 0)
context.stroke()
shape = self.shape
label = self.label
if len(label) > 0 and label[-1] == ' ':
label += '.'
xb, yb, w, h, xa, ya = context.text_extents(label)
context.rectangle(shape.start.x + self.padding,
shape.start.y,
shape.width - self.padding,
shape.height)
context.clip()
context.move_to(shape.start.x + (shape.width - self.padding - w)/2,
shape.start.y + shape.height - self.padding)
context.show_text(self.label)
示例5: export_svg
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
def export_svg(fn, paths, size, line_with=0.1, scale_factor=None):
from cairo import SVGSurface, Context
from numpy import array
from ddd import spatial_sort_2d as sort
if not scale_factor:
scale_factor = size
one = 1.0/size
s = SVGSurface(fn, size, size)
c = Context(s)
c.set_line_width(0.1)
paths = sort(paths)
for path in paths:
path *= scale_factor
c.new_path()
c.move_to(*path[0,:])
for p in path[1:]:
c.line_to(*p)
c.stroke()
c.save()
示例6: __init__
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
class Canvas:
def __init__(self, width, height):
self.xform = lambda x, y: (x, y)
self.img = ImageSurface(FORMAT_RGB24, width, height)
self.ctx = Context(self.img)
self.ctx.move_to(0, 0)
self.ctx.line_to(width, 0)
self.ctx.line_to(width, height)
self.ctx.line_to(0, height)
self.ctx.line_to(0, 0)
self.ctx.set_source_rgb(1, 1, 1)
self.ctx.fill()
self.width = width
self.height = height
def fit(self, left, top, right, bottom):
xoff = left
yoff = top
xscale = self.width / float(right - left)
yscale = self.height / float(bottom - top)
if abs(xscale) > abs(yscale):
xscale *= abs(yscale) / abs(xscale)
elif abs(xscale) < abs(yscale):
yscale *= abs(xscale) / abs(yscale)
self.xform = lambda x, y: ((x - xoff) * xscale, (y - yoff) * yscale)
def dot(self, x, y, size=4, fill=(.5, .5, .5)):
x, y = self.xform(x, y)
self.ctx.arc(x, y, size/2., 0, 2*pi)
self.ctx.set_source_rgb(*fill)
self.ctx.fill()
def line(self, points, stroke=(.5, .5, .5), width=1):
self.ctx.move_to(*self.xform(*points[0]))
for (x, y) in points[1:]:
self.ctx.line_to(*self.xform(x, y))
self.ctx.set_source_rgb(*stroke)
self.ctx.set_line_cap(LINE_CAP_ROUND)
self.ctx.set_line_width(width)
self.ctx.stroke()
def save(self, filename):
self.img.write_to_png(filename)
示例7: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
def on_draw(self, widget: Widget, context: cairo.Context):
context.save()
context.set_source_rgb(*self.background_color)
self.shape.draw_on_context(context)
context.fill_preserve()
context.set_source_rgb(0,0,0)
context.set_line_width(1)
context.stroke()
context.restore()
super().on_draw(widget, context)
示例8: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
def on_draw(self, widget: "Widget", context: cairo.Context):
translation = 10, 10
context.translate(*translation)
self.contents.set_translate(*translation)
self.navigator.set_translate(*translation)
self.back_button.set_translate(*translation)
up_margin = 4
down_margin = 6
left_margin = 4
right_margin = self.navigator.width
navigator_margin = 4
base_x, base_y = self.fromWidgetCoords.transform_point(0, 0)
base_x += translation[0]
base_y += translation[1]
width = self.container_size[0] - 2 * base_x - right_margin - 2 * navigator_margin
height = self.container_size[1] - 2 * base_y - down_margin
self.contents.set_max_size(width, height)
self.contents.on_draw(widget, context)
offset = self.contents.table_width + navigator_margin
tot = len(self.contents.entries)
if tot != 0:
self.navigator.skip = self.contents.base / tot
else:
self.navigator.skip = 0
if tot != 0:
self.navigator.fill = self.contents._shown / tot
else:
self.navigator.fill = 1
self.navigator.translate(offset, 0)
context.translate(offset, 0)
self.navigator.down_pos = self.contents.table_height
self.navigator.on_draw(widget, context)
context.translate(-offset, 0)
rectangle_width = left_margin + offset + navigator_margin + right_margin
rectangle_height = self.contents.table_height + up_margin + down_margin
context.rectangle(
-left_margin,
-up_margin,
rectangle_width,
rectangle_height
)
context.stroke()
button_left = (rectangle_width - left_margin) / 2
button_left = 0
button_left = rectangle_width - left_margin
button_up = rectangle_height + up_margin
self.back_button.translate(button_left, button_up)
context.translate(button_left, button_up)
self.back_button.on_draw(self, context)
示例9: export_svg
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
def export_svg(fn, paths, w, h, line_width=0.1):
from cairo import SVGSurface, Context
s = SVGSurface(fn, w, h)
c = Context(s)
c.set_line_width(line_width)
for path in paths:
c.new_path()
c.move_to(*path[0,:])
for p in path[1:]:
c.line_to(*p)
c.stroke()
c.save()
示例10: on_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
def on_draw(self, widget: Widget, context: cairo.Context):
self.set_shape_from_context(context)
shape = self.shape
context.set_line_width(self.line_thickness)
if self.orientation == Orientation.HORIZONTAL:
context.move_to(shape.start.x - self.line_extension, shape.start.y)
context.line_to(shape.start.x + shape.width, shape.start.y)
else:
context.move_to(shape.start.x, shape.start.y - self.line_extension)
context.line_to(shape.start.x, shape.start.y + shape.height)
context.stroke()
for element in self._elements:
context.move_to(*element.position)
context.set_source_rgb(*element.color)
context.show_text(element.label)
示例11: range
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
VERTS, CODES = [], []
# Iterate over each contour
ctx.set_source_rgb(0.5,0.5,0.5)
for i in range(len(outline.contours)):
end = outline.contours[i]
ctx.move_to(outline.points[start][0],outline.points[start][1])
for j in range(start, end+1):
point = outline.points[j]
ctx.line_to(point[0],point[1])
#back to origin
ctx.line_to(outline.points[start][0], outline.points[start][1])
start = end+1
ctx.fill_preserve()
ctx.set_source_rgb(0,1,0)
ctx.stroke()
start, end = 0, 0
for i in range(len(outline.contours)):
end = outline.contours[i]
ctx.new_path()
ctx.set_source_rgb(0,0,1)
for j in range(start, end+1):
if ( Curve_Tag[j] == FT_Curve_Tag_On ):
point = outline.points[j]
ctx.move_to(point[0],point[1])
ctx.arc(point[0], point[1], 40, 0, 2 * math.pi)
ctx.fill()
ctx.new_path()
示例12: main
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
def main(marker, paper, format, bbox, emergency, place, recipient, sender, text, sender_is_recipient, map_href):
"""
"""
mark = Location(*marker)
handle, filename = mkstemp(prefix='safetymap-', suffix='.pdf')
close(handle)
if paper == 'a4':
surf = PDFSurface(filename, 210*ptpmm, 297*ptpmm)
elif paper == 'letter':
surf = PDFSurface(filename, 8.5*ptpin, 11*ptpin)
ctx = Context(surf)
ctx.scale(ptpmm, ptpmm)
set_font_face_from_file(ctx, 'assets/HelveticaNeue.ttc')
if paper == 'a4':
draw_a4_master(ctx, format, map_href)
ctx.translate(19, 24)
elif paper == 'letter':
draw_letter_master(ctx, format, map_href)
ctx.translate(21, 18)
ctx.set_line_width(.25 * mmppt)
ctx.set_source_rgb(*md_gray)
ctx.set_dash([3 * mmppt])
reps = {'4up': 4, '2up-fridge': 2, 'poster': 0}
if reps[format]:
card_img, mark_point = get_map_image(bbox, 84, 39, mark)
for i in range(reps[format]):
# dashed outlines
ctx.move_to(0, 61)
ctx.line_to(0, 0)
ctx.line_to(173, 0)
ctx.line_to(173, 61)
#ctx.move_to(86, 0)
#ctx.line_to(86, 61)
ctx.stroke()
# two card sides and contents
draw_card_left(ctx, recipient, sender, text, sender_is_recipient)
ctx.translate(86.5, 0)
draw_card_right(ctx, card_img, mark_point, emergency, place)
ctx.translate(-86.5, 61)
if format == '4up':
# bottom dashed outline
ctx.move_to(0, 0)
ctx.line_to(172, 0)
ctx.stroke()
elif format == '2up-fridge':
# prepare to draw sideways
ctx.translate(0, 122.5)
ctx.rotate(-pi/2)
ctx.rectangle(0, 0, 122.5, 173)
ctx.stroke()
poster_img, mark_point = get_map_image(bbox, 109, 77, mark)
draw_small_poster(ctx, poster_img, mark_point, emergency, place, recipient, sender, text, sender_is_recipient)
elif format == 'poster':
ctx.rectangle(0, 0, 173, 245)
ctx.stroke()
poster_img, mark_point = get_map_image(bbox, 153, 108, mark)
draw_large_poster(ctx, poster_img, mark_point, emergency, place, recipient, sender, text, sender_is_recipient)
surf.finish()
chmod(filename, 0644)
return filename
示例13: do_draw
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
def do_draw(self, context: cairo.Context) -> bool:
if not self.adjustment or self.adjustment.get_upper() <= 0:
return False
height = self.get_allocated_height()
width = self.get_allocated_width()
if width <= 0 or height <= 0:
return False
base_bg, base_outline, handle_overdraw, handle_outline = (
self.get_map_base_colors())
x0 = self.overdraw_padding + 0.5
x1 = width - 2 * x0
height_scale = height * self.get_height_scale()
if self._cached_map is None:
surface = cairo.Surface.create_similar(
context.get_target(), cairo.CONTENT_COLOR_ALPHA, width, height)
cache_ctx = cairo.Context(surface)
cache_ctx.set_line_width(1)
cache_ctx.rectangle(x0, -0.5, x1, height_scale + 0.5)
cache_ctx.set_source_rgba(*base_bg)
cache_ctx.fill()
# We get drawing coordinates by tag to minimise our source
# colour setting, and make this loop slightly cleaner.
tagged_diffs = self.chunk_coords_by_tag()
for tag, diffs in tagged_diffs.items():
cache_ctx.set_source_rgba(*self.fill_colors[tag])
for y0, y1 in diffs:
y0 = round(y0 * height_scale) + 0.5
y1 = round(y1 * height_scale) - 0.5
cache_ctx.rectangle(x0, y0, x1, y1 - y0)
cache_ctx.fill_preserve()
cache_ctx.set_source_rgba(*self.line_colors[tag])
cache_ctx.stroke()
cache_ctx.rectangle(x0, -0.5, x1, height_scale + 0.5)
cache_ctx.set_source_rgba(*base_outline)
cache_ctx.stroke()
self._cached_map = surface
context.set_source_surface(self._cached_map, 0, 0)
context.paint()
# Draw our scroll position indicator
context.set_line_width(1)
context.set_source_rgba(*handle_overdraw)
adj_y = self.adjustment.get_value() / self.adjustment.get_upper()
adj_h = self.adjustment.get_page_size() / self.adjustment.get_upper()
context.rectangle(
x0 - self.overdraw_padding, round(height_scale * adj_y) + 0.5,
x1 + 2 * self.overdraw_padding, round(height_scale * adj_h) - 1,
)
context.fill_preserve()
context.set_source_rgba(*handle_outline)
context.stroke()
return True
示例14: _paint_panel
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import stroke [as 别名]
#.........这里部分代码省略.........
min_y -= off_y
max_y += off_y
try:
kx = (max_x - min_x) / (width - left - right)
ky = (max_y - min_y) / (height - bottom)
if ky == 0:
ky = 1
except:
kx, ky = 1, 1
img = ImageSurface(FORMAT_ARGB32, width, height)
ctx = Context(img)
width -= right
ctx.set_line_width(1)
# Рисуем сетку
ctx.set_font_size(12)
try:
b_w, b_h = ctx.text_extents("00-00-0000")[2:4]
# Метки на оси Y
count = math.ceil(max_y) - math.ceil(min_y)
space_count = math.ceil(count / ((height - bottom) / (b_h * 1.5)))
sc = 0
for i in range(math.ceil(min_y), math.ceil(max_y)):
if sc == 0:
y = height - bottom + (min_y - i) / ky
ctx.set_source_rgb(*(color_x_line))
ctx.move_to(left, y)
ctx.line_to(width, y)
ctx.stroke()
ctx.set_source_rgb(0, 0, 0)
num = str(i)
tw, th = ctx.text_extents(num)[2:4]
ctx.move_to(left - 5 - tw, y + th // 2)
ctx.show_text(num)
sc = space_count
sc -= 1
# Метки на оси Х
x_step = 3600
if interval == "-6 hour" or interval == "-12 hour" or interval == "-1 day":
# Дополнительно метки часов
x_step = 3600
for i in range(math.ceil(min_x / x_step), math.ceil(max_x / x_step)):
x = (i * x_step - min_x) / kx + left
ctx.set_source_rgb(*(color_x_line_2))
ctx.move_to(x, 0)
ctx.line_to(x, height - bottom)
ctx.stroke()
num = datetime.datetime.fromtimestamp(i * x_step).strftime("%H")
tw, th = ctx.text_extents(num)[2:4]
ctx.move_to(x + 2, height - bottom - 3)
ctx.set_source_rgb(*(color_x_line))
ctx.show_text(num)
x_step = 3600 * 24
space_count = 1
count = math.ceil(max_x / x_step) - math.ceil(min_x / x_step)
try:
if (width / count) < b_w: