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


Python Context.translate方法代码示例

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


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

示例1: __missing__

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import translate [as 别名]
 def __missing__(self, zoom):
     zoomfac    = (1 + 2*self._r)*zoom
     self[zoom] = SVGC = ImageSurface(FORMAT_ARGB32, ceil(zoomfac*self._h), ceil(zoomfac*self._k))
     sccr = Context(SVGC)
     sccr.scale(zoom, zoom)
     sccr.translate(self._uh, self._uk)
     self._paint_function(sccr)
     return SVGC
开发者ID:kelvin13,项目名称:Knockout,代码行数:10,代码来源:vectorcache.py

示例2: illustrate

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import translate [as 别名]
 def illustrate(self, surface):
     if self.art != None:
         illustration = Context(surface)
         illustration.scale(0.6, 0.6)
         illustration.translate(self.w / 6, self.h / 6)
         self.art.render_cairo(illustration)
         illustration.translate(self.w * 4 / 3, self.h * 4 / 3)
         illustration.rotate(pi)
         self.art.render_cairo(illustration)
开发者ID:,项目名称:,代码行数:11,代码来源:

示例3: on_draw

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

示例4: on_draw

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

示例5: renderText

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import translate [as 别名]
 def renderText(self, surface,
                text, y_offset, size,
                shade, w=(2,3), wrap=True):
     if len(text) < 1:
         return
     def setdesc(l, size):
         l.set_font_description(
                 FontDescription(
                     self.font + " " + str(size)))
     origin = Context(surface)
     origin.translate(self.w * (w[1] - w[0]) /
                      (w[1] * 2), y_offset)
     box = CairoContext(origin)
 #  Start laying out text 
     layout = box.create_layout()
     setdesc(layout, size)
     width = self.w * w[0] / w[1]
     if wrap:
         layout.set_width(width * pango.SCALE)
     else:
         layout.set_width(-1)
     layout.set_alignment(pango.ALIGN_CENTER)
     layout.set_text(text)
 #   Resize text to make sure it doesn't exceed width.
     wi, n = layout.get_pixel_size()
     if wi > width:
         s = size * width / wi
         setdesc(layout, s)
     layout.set_width(width * pango.SCALE)
 #   Draw a transparent pane behind the text
     origin.set_source_rgba(1, 1, 1, 0.7)
     origin.rectangle(*layout.get_pixel_extents()[1])
     origin.fill()
 #   Draw text
     origin.set_source_rgb(shade, shade, shade)
     box.update_layout(layout)
     box.show_layout(layout)
开发者ID:,项目名称:,代码行数:39,代码来源:

示例6: Face

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import translate [as 别名]
    face = Face('./Vera.ttf')
    face.set_char_size( 48*64 )
    face.load_char('S')
    slot = face.glyph

    outline = slot.outline
    points = numpy.array(outline.points, dtype=[('x',float), ('y',float)])
    x, y = points['x'], points['y']

    cbox = outline.get_cbox()
    surface = ImageSurface(FORMAT_ARGB32,
                           (cbox.xMax - cbox.xMin)//4 + 20,
                           (cbox.yMax - cbox.yMin)//4 + 20)
    ctx = Context(surface)
    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):
开发者ID:moyogo,项目名称:freetype-py,代码行数:33,代码来源:glyph-vector-cairo.py

示例7: main

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

示例8: Ceil64

# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import translate [as 别名]
    def Ceil64(x):
        return ((x+63)//64) * 64

    width_s = (width * 64)//scale + 2 * MARGIN
    height_s = (rows * 64)//scale + 2 * MARGIN

    surface = SVGSurface('glyph-vector-2-cairo.svg',
                         width_s,
                         height_s)
    ctx = Context(surface)
    ctx.set_source_rgb(1,1,1)
    ctx.paint()
    ctx.save()
    ctx.scale(1.0/scale,1.0/scale)
    ctx.translate(-Floor64(bbox.xMin) + MARGIN * scale,-Floor64(bbox.yMin) + MARGIN * scale)
    ctx.transform(Matrix(1,0,0,-1))
    ctx.translate(0, -(Ceil64(bbox.yMax) + Floor64(bbox.yMin))) # difference!

    start, end = 0, 0

    VERTS, CODES = [], []
    # Iterate over each contour
    for i in range(len(outline.contours)):
        end    = outline.contours[i]
        points = outline.points[start:end+1]
        points.append(points[0])
        tags   = outline.tags[start:end+1]
        tags.append(tags[0])

        segments = [ [points[0],], ]
开发者ID:moyogo,项目名称:freetype-py,代码行数:32,代码来源:glyph-vector-2-cairo.py


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