当前位置: 首页>>代码示例>>Python>>正文


Python Context.set_line_width方法代码示例

本文整理汇总了Python中cairo.Context.set_line_width方法的典型用法代码示例。如果您正苦于以下问题:Python Context.set_line_width方法的具体用法?Python Context.set_line_width怎么用?Python Context.set_line_width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cairo.Context的用法示例。


在下文中一共展示了Context.set_line_width方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: export_svg

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [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()
开发者ID:inconvergent,项目名称:ddd-utils,代码行数:29,代码来源:svg.py

示例2: outline

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [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()
开发者ID:,项目名称:,代码行数:9,代码来源:

示例3: __init__

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [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)
开发者ID:Katiesun,项目名称:Skeletron,代码行数:57,代码来源:draw.py

示例4: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [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)
开发者ID:gcali,项目名称:crucipixel,代码行数:15,代码来源:buttons.py

示例5: glyphs

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [as 别名]
def glyphs(*args, **kwargs):

    options = Options(infname='data/vorttest.txt', saveas='output/part1/',
            outfname='vorttest.png', scale=100., seed_num=20, stepsize=.01,
            steps=5, directions=1, norm=False, line_width=.5)
    options.update(kwargs)

    print >> log, options.infname

    if not path.exists(options.saveas): os.makedirs(options.saveas)

    (xmin, ymin), (xmax, ymax), uv = read2vecs(options.infname)

    width, height = xmax - xmin, ymax - ymin

    def index2world(points, xmin=xmin, ymin=ymin, scale=options.scale,
            debug=False):
        if debug: 
            print "index2world:",
            print xscale, yscale, points.dtype
        if debug: print points,
        points[:,0] -= xmin
        if debug: print points,
        points[:,1] -= ymin
        if debug: print points,
        points *= scale
        if debug: print points

    if 'seed' in options:
        seed = options.seed
    else: 
        seed = product(np.linspace(xmin, xmax, num=options.seed_num), 
                np.linspace(ymin, ymax, num=options.seed_num))


    ctx = Context(ImageSurface(cairo.FORMAT_ARGB32, int(options.scale * width),
        int(options.scale * height)))

    ctx.set_source_rgba(0,0,0)
    ctx.set_line_width(options.line_width)
    for s in seed:
        points = sline(uv, (xmin, ymin), (xmax, ymax), np.array(s),
            options.stepsize, options.steps, options.norm, options.directions)
        print >> log, points
        index2world(points)
        print >> log, points
        draw_arrow(ctx, points, arrowhead_size=2)

    with open(path.join(options.saveas, options.outfname), 'w') as outf:
        ctx.get_target().write_to_png(outf)
开发者ID:damonwang,项目名称:scivis-proj4,代码行数:52,代码来源:proj4.py

示例6: export_svg

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [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()
开发者ID:r1cc4rd0,项目名称:svg-sorter,代码行数:20,代码来源:svg-sorter.py

示例7: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [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)
开发者ID:gcali,项目名称:crucipixel,代码行数:20,代码来源:guides.py

示例8: main

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [as 别名]
def main(args, **argv):

  from dddUtils.ioOBJ import load_2d as load
  from cairo import SVGSurface, Context
  from numpy import array
  from glob import glob

  prefix = args.prefix
  size = args.size
  scale = args.scale
  one = 1.0/size
  steps = args.steps
  stride = args.stride
  skip = args.skip

  out = prefix + '.svg'
  print('making file: {:s}'.format(out))

  s = SVGSurface(out, size, size)
  c = Context(s)

  c.set_line_width(0.1)
  c.set_source_rgba(*BLACK)


  for fn in sorted(glob(prefix + '*.2obj'))[skip:steps:stride]:

    print(fn)

    data = load(fn)

    vertices = data['vertices']
    vertices *= scale*size
    edges = data['edges']
    # make_random_line(c, vertices, edges)
    make_line(c, vertices, edges)

  c.save()

  return
开发者ID:inconvergent,项目名称:ddd-utils,代码行数:42,代码来源:render_line_svg.py

示例9: main

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [as 别名]
def main(args, **argv):

  # from render.render import Render
  from dddUtils.ioOBJ import load_2d as load
  from cairo import SVGSurface, Context
  from numpy import array

  size = args.size
  scale = args.scale
  one = 1.0/size

  data = load(args.fn)
  print(data)

  vertices = data['vertices']
  faces = data['faces']
  edges = data['edges']

  out = '.'.join(args.fn.split('.')[:-1])+'.svg'
  print('making file: {:s}'.format(out))

  s = SVGSurface(out, size, size)
  c = Context(s)

  c.set_line_width(0.1)
  c.set_source_rgba(*BLACK)

  vertices -= get_mid(vertices)
  vertices *= scale
  vertices += array([[0.5,0.5]])
  vertices *= size

  make_triangles(c, vertices, faces, edges)
  # make_random_length_strips(c, vertices, faces, edges)

  c.save()

  return
开发者ID:inconvergent,项目名称:ddd-utils,代码行数:40,代码来源:render_tris_svg.py

示例10: Mono

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [as 别名]
    else:
        # Mono(1-bit) Rendering
        face.load_char('S', FT_LOAD_RENDER |
                       FT_LOAD_TARGET_MONO )

    bitmap = face.glyph.bitmap
    width  = face.glyph.bitmap.width
    rows   = face.glyph.bitmap.rows
    pitch  = face.glyph.bitmap.pitch

    glyph_surface = make_image_surface(face.glyph.bitmap)

    surface = ImageSurface(FORMAT_ARGB32, 800, 600)
    ctx = Context(surface)
    ctx.rectangle(0,0,800,600)
    ctx.set_line_width(0)
    ctx.set_source_rgb (0.5 , 0.5, 0.5)
    ctx.fill()
    #
    scale = 480.0 / rows
    ctx.set_source_surface(glyph_surface, 0, 0)
    pattern = ctx.get_source()
    SurfacePattern.set_filter(pattern, FILTER_BEST)
    scalematrix = Matrix()
    scalematrix.scale(1.0/scale,1.0/scale)
    scalematrix.translate(-(400.0 - width *scale /2.0 ), -60)
    pattern.set_matrix(scalematrix)
    ctx.set_source_rgb (0 , 0, 1)
    ctx.mask(pattern)
    ctx.fill()
    surface.flush()
开发者ID:moyogo,项目名称:freetype-py,代码行数:33,代码来源:glyph-mono+alpha-cairo.py

示例11: main

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [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
开发者ID:DEKOR01,项目名称:safetymaps,代码行数:84,代码来源:compose.py

示例12: do_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [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
开发者ID:GNOME,项目名称:meld,代码行数:66,代码来源:chunkmap.py

示例13: elif

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [as 别名]
        elif (CODES[i] == LINETO):
            ctx.line_to(VERTS[i][0],VERTS[i][1])
            i += 1
        elif (CODES[i] == CURVE3):
            ctx.curve_to(VERTS[i][0],VERTS[i][1],
                         VERTS[i+1][0],VERTS[i+1][1], # undocumented
                         VERTS[i+1][0],VERTS[i+1][1])
            i += 2
        elif (CODES[i] == CURVE4):
            ctx.curve_to(VERTS[i][0],VERTS[i][1],
                         VERTS[i+1][0],VERTS[i+1][1],
                         VERTS[i+2][0],VERTS[i+2][1])
            i += 3
    ctx.fill_preserve()
    ctx.set_source_rgb(0,0,0)
    ctx.set_line_width(6)
    ctx.stroke()
    ctx.restore()

    scale2 = (height_s - 2.0 * MARGIN)/rows

    ctx.set_source_surface(Z, 0, 0)
    pattern = ctx.get_source()
    SurfacePattern.set_filter(pattern, FILTER_BEST)
    scalematrix = Matrix()
    scalematrix.scale(1.0/scale2, 1.0/scale2)
    scalematrix.translate(-( width_s/2.0  - width *scale2 /2.0 ), -MARGIN)
    pattern.set_matrix(scalematrix)
    ctx.set_source_rgba (0, 0, 0, 0.7)
    ctx.mask(pattern)
    ctx.fill()
开发者ID:moyogo,项目名称:freetype-py,代码行数:33,代码来源:glyph-vector-2-cairo.py

示例14: _paint_panel

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_width [as 别名]

#.........这里部分代码省略.........

        if min_y is None or max_y is None or min_y == 9999 or max_y == -9999 or min_y == max_y:
            max_y = 1
            min_y = 0

        min_y = math.floor(min_y)
        max_y = math.ceil(max_y)

        if typ == 2:
            if min_y < 0 and max_y < 0:
                max_y = 0
            elif min_y > 0 and max_y > 0:
                min_y = 0

        # Определяем цвета
        colors = [[1, 0, 0], [0, 0.65, 0.31], [0, 0, 1], [1, 0, 1]]

        off_y = (max_y - min_y) / 10
        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
开发者ID:SolitonNew,项目名称:pyhome,代码行数:70,代码来源:page5_1.py


注:本文中的cairo.Context.set_line_width方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。