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


Python Context.move_to方法代码示例

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


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

示例1: _draw_cell

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

示例2: on_draw

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

示例3: renegerate_overlay_buffer

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [as 别名]
    def renegerate_overlay_buffer(self):
        image = ImageSurface(cairo.FORMAT_ARGB32, self.video_width, self.video_height)
        context = Context(image)
        text = "Foo bar 123"
        font = pango.FontDescription('sans normal 22')
        text_offset = [6, 6]

        textOverflowed = False
        if text:
            pcContext = pangocairo.CairoContext(context)
            pangoLayout = pcContext.create_layout()
            font = pango.FontDescription('sans normal 22')
            pangoLayout.set_font_description(font)
    
            context.move_to(text_offset[0]+2, text_offset[1]+2)
            pangoLayout.set_markup('<span foreground="black" >%s</span>' % text)
            pcContext.show_layout(pangoLayout)
            context.move_to(text_offset[0], text_offset[1])
            pangoLayout.set_markup('<span foreground="white" >%s</span>' % text)
            pcContext.show_layout(pangoLayout)
    
            textWidth, textHeight = pangoLayout.get_pixel_size()
        
        self.overlay_buffer = image.get_data()
        print "overlay_buffer size: %d" % len(self.overlay_buffer)
开发者ID:HelsinkiHacklab,项目名称:cambot,代码行数:27,代码来源:cairo_overlay_pango_text.py

示例4: export_svg

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [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

示例5: __init__

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [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

示例6: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [as 别名]
    def on_draw(self, widget: Widget, context: cairo.Context):


        for b in self._buttons:
            b.set_shape_from_context(context)

        shapes = [b.shape for b in self._buttons]

        context.save()
        context.select_font_face("", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
        xb, yb, w, h, xa, ya = context.text_extents(self.title)

        width = max(shape.width for shape in shapes)
        width = max(width, xa)
        container_width = self.container_size[0]
        translation = Point(0, self.distance)
        if container_width > width:
            translation += Point((container_width)/2, 0)
        else:
            translation += Point(width/2, 0)

        context.move_to(translation.x - xa/2, h + 2 * self.distance)
        context.show_text(self.title)
        context.restore()

        height = h + self.distance * 3
        for b in self._buttons:
            height += b.shape.height + self.distance

        self.min_size = width + 2 * self.distance, height + self.distance

        start_point = context.get_current_point()
        translation += Point(0, h + self.distance * 3)
        context.translate(translation.x, translation.y)

        distance_offset = Point(0, self.distance)


        for b in self._buttons:
            context.move_to(*start_point)
            b.set_translate(translation.x, translation.y)
            context.save()
            b.on_draw(widget, context)
            context.restore()

            to_translate = Point(distance_offset.x,
                                 distance_offset.y + b.shape.height)
            context.translate(to_translate.x, to_translate.y)
            translation += to_translate
开发者ID:gcali,项目名称:crucipixel,代码行数:51,代码来源:main_menu.py

示例7: export_svg

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [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

示例8: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [as 别名]
    def on_draw(self, widget: Widget, context: cairo.Context):

        max_height = 0
        max_width = 0
        for line in self._lines:
            line.set_shape_from_context(context)
            max_height = max(max_height, line.shape.height)
            max_width = max(max_width, line.shape.width)


        offset = 0
        if self._orientation == Orientation.HORIZONTAL:
            def handle_line(line: _GuideLine):
                nonlocal offset
                line.line_extension = max_height - line.shape.height
                line.set_translate(offset, 0)
                offset += line.shape.width
        else:
            def handle_line(line: _GuideLine):
                nonlocal offset
                line.line_extension = max_width - line.shape.width
                line.set_translate(0, offset)
                offset += line.shape.height

        for line in self._lines:
            handle_line(line)

        super().on_draw(self, context)

        context.set_line_width(self.THICK_LINE)
        if self._orientation == Orientation.HORIZONTAL:
            context.move_to(offset, 0)
            context.line_to(offset, -max_height)
        else:
            context.move_to(0, offset)
            context.line_to(-max_width, offset)
        context.stroke()
开发者ID:gcali,项目名称:crucipixel,代码行数:39,代码来源:guides.py

示例9: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [as 别名]
    def on_draw(self, widget: Widget, context: cairo.Context):

        start_x, start_y = context.get_current_point()
        context.set_font_size(self.font_size)

        context.move_to(0, 0)

        if not self.is_shape_set:
            self.set_shape_from_context(context)
        shape = self.shape
        start = shape.start
        padding = self.padding
        h = shape.height - 2 * padding
        label = self.label

        context.set_source_rgb(*self.background_color)
        shape.draw_on_context(context)
        context.fill_preserve()

        context.set_line_width(1)
        context.set_source_rgb(*self.label_color)
        context.stroke()

        if self.disabled:
            context.set_source_rgba(1, 1, 1, .7)
            context.move_to(start.x + padding-1,
                            start.y + padding + h+1)
            context.show_text(label)
            context.set_source_rgba(*self.label_color, .9)
        else:
            context.set_source_rgb(*self.label_color)
        context.move_to(start.x + padding,
                        start.y + padding + h)
        context.show_text(label)

        if self.disabled:
            context.set_source_rgba(1, 1, 1, .7)
            context.move_to(0, 0)
            shape.draw_on_context(context)
            context.fill()
开发者ID:gcali,项目名称:crucipixel,代码行数:42,代码来源:buttons.py

示例10: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [as 别名]
    def on_draw(self, widget: Widget, context: cairo.Context):
        self.min_size = 200, 150
        super().on_draw(widget, context)

        context.save()
        context.set_font_size(self.font_size)

        if self._table_extents is None:
            self._update_table_extents(context)

        skip = max(self.skip, 0)
        how_many = self.how_many

        table_extents = self._table_extents
        title_extents = self._table_extents.title_extents

        expected_height = title_extents.total_height + self.margin

        entries = self.entries

        base = skip
        up_to = skip
        over = False
        while up_to < len(entries) and not over:
            expected_height += table_extents[up_to].total_height
            over = expected_height >= self._max_height
            if not over:
                up_to += 1

        while base > 0 and not over:
            expected_height += table_extents[base-1].total_height
            over = expected_height >= self._max_height
            if not over:
                base -= 1

        how_many = up_to - base
        skip = base
        self.base = base

        entries = self.entries[skip:skip + how_many]

        def table_extents_iterator():
            return table_extents.iter_over(
                skip, how_many
            )

        start_x, start_y = context.get_current_point()

        start_y += title_extents.total_height
        h = title_extents.total_height
        self.title_height = h
        for (index, cell), data in zip(enumerate(title_extents), self.title):
            context.save()
            offset = title_extents.get_cell_data_left(index)
            context.rectangle(start_x + offset, start_y - h, cell.width, 2*h)
            context.clip()
            context.move_to(
                start_x + offset,
                start_y
            )
            context.show_text(data)
            context.restore()
        # start_y += self.margin

        curr_x, curr_y = start_x, start_y# + title_extents.total_height

        for line_index, (line_extent, entry) in enumerate(zip(table_extents_iterator(), entries)):
            h = line_extent.total_height
            curr_y += h
            if curr_y + self.margin >= self._max_height:
                break
            for (cell_index, cell), data in zip(enumerate(line_extent), entry):
                context.save()
                offset = line_extent.get_cell_data_left(cell_index)
                context.rectangle(curr_x + offset, curr_y - h, cell.width, 2*h)
                context.clip()
                context.move_to(
                    curr_x + offset,
                    curr_y
                )
                context.show_text(data)
                context.restore()

        curr_x = start_x
        end_x = table_extents.entries_width
        curr_y = start_y + self.margin
        end_y = table_extents.get_height_up_to(skip, how_many) + start_y + self.margin + 1

        self.table_height = end_y
        self.table_width = end_x

        for line in table_extents_iterator():
            context.move_to(curr_x, curr_y)
            context.line_to(end_x, curr_y)
            context.stroke()
            curr_y += line.total_height
        context.move_to(curr_x, curr_y)
        context.line_to(end_x, curr_y)
        context.stroke()

#.........这里部分代码省略.........
开发者ID:gcali,项目名称:crucipixel,代码行数:103,代码来源:chooser_table.py

示例11: on_draw

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [as 别名]
 def on_draw(self, widget: "Widget", context: cairo.Context):
     self._set_font(context)
     for tl in self.__text_lines:
         context.move_to(tl.start.x, tl.start.y)
         context.show_text(tl.text)
开发者ID:gcali,项目名称:crucipixel,代码行数:7,代码来源:text.py

示例12: range

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [as 别名]
                    codes.extend([ CURVE3, CURVE3])
                verts.append(segment[-1])
                codes.append(CURVE3)
            [tags.pop() for x in range(len(segment) - 1)]
        VERTS.extend(verts)
        CODES.extend(codes)
        start = end+1


    # Draw glyph
    ctx.new_path()
    ctx.set_source_rgba(0.8,0.5,0.8, 1)
    i = 0
    while (i < len(CODES)):
        if (CODES[i] == MOVETO):
            ctx.move_to(VERTS[i][0],VERTS[i][1])
            i += 1
        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()
开发者ID:moyogo,项目名称:freetype-py,代码行数:33,代码来源:glyph-vector-2-cairo.py

示例13: range

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [as 别名]
    ctx.scale(0.25,0.25)
    ctx.translate(-cbox.xMin + 40,-cbox.yMin + 40)
    ctx.transform(Matrix(1,0,0,-1))
    ctx.translate(0, -(cbox.yMax + cbox.yMin)) # difference!

    Curve_Tag = [FT_Curve_Tag(tag) for tag in outline.tags]

    start, end = 0, 0

    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()
开发者ID:moyogo,项目名称:freetype-py,代码行数:33,代码来源:glyph-vector-cairo.py

示例14: main

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [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

示例15: generateOverlay

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import move_to [as 别名]
def generateOverlay(text,
                    font,
                    showFlumotion,
                    showCC,
                    showXiph,
                    width, height):
    """Generate an transparent image with text + logotypes rendered on top
    of it suitable for mixing into a video stream
    @param text: text to put in the top left corner
    @type text: str
    @param font: font description used to render the text
    @type: str
    @param showFlumotion: if we should show the flumotion logo
    @type showFlumotion: bool
    @param showCC: if we should show the Creative Common logo
    @type showCC: bool
    @param showXiph: if we should show the xiph logo
    @type showXiph: bool
    @param width: width of the image to generate
    @type width: int
    @param height: height of the image to generate
    @type height: int
    @returns: raw image and if images or if text overflowed
    @rtype: 3 sized tuple of string and 2 booleans
    """
    from cairo import ImageSurface
    from cairo import Context

    image = ImageSurface(cairo.FORMAT_ARGB32, width, height)
    context = Context(image)

    subImages = []
    if showXiph:
        subImages.append(os.path.join(configure.imagedir, '36x36', 'xiph.png'))
    if showCC:
        subImages.append(os.path.join(configure.imagedir, '36x36', 'cc.png'))
    if showFlumotion:
        subImages.append(os.path.join(configure.imagedir, '36x36',
                                      'fluendo.png'))

    imagesOverflowed = False

    offsetX = BORDER
    for subPath in subImages:
        sub = ImageSurface.create_from_png(subPath)
        subX = sub.get_width()
        subY = sub.get_height()
        offsetY = height - subY - BORDER
        context.set_source_surface(sub, offsetX, offsetY)
        context.paint()
        if (offsetX + subX) > width:
            imagesOverflowed = True
        offsetX += subX + BORDER

    textOverflowed = False
    if text:
        pcContext = pangocairo.CairoContext(context)
        pangoLayout = pcContext.create_layout()
        if font is not None:
            font = pango.FontDescription(font)
            if not font.get_family() or \
               not font.get_family().lower() in [family.get_name().lower()
                    for family in pangoLayout.get_context().list_families()]:
                font.set_family(FONT)
            if font.get_size() == 0:
                font.set_size(FONT_SIZE)
        else:
            font = pango.FontDescription('%s %s' % (FONT, FONT_PROPS))
        pangoLayout.set_font_description(font)

        context.move_to(TEXT_XOFFSET+2, TEXT_YOFFSET+2)
        pangoLayout.set_markup('<span foreground="black" >%s</span>' % text)
        pcContext.show_layout(pangoLayout)
        context.move_to(TEXT_XOFFSET, TEXT_YOFFSET)
        pangoLayout.set_markup('<span foreground="white" >%s</span>' % text)
        pcContext.show_layout(pangoLayout)

        textWidth, textHeight = pangoLayout.get_pixel_size()
        if textWidth > width:
            textOverflowed = True

    if cairo.version < '1.2.6':
        buf = image.get_data_as_rgba()
    else:
        buf = image.get_data()

    return buf, imagesOverflowed, textOverflowed
开发者ID:offlinehacker,项目名称:flumotion,代码行数:89,代码来源:genimg.py


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