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


Python cairo.Matrix方法代码示例

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


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

示例1: paint

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

示例2: generate_fontsample_cache

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [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)) 
开发者ID:sk1project,项目名称:sk1-wx,代码行数:24,代码来源:fontctrl.py

示例3: cdc_draw_frame

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def cdc_draw_frame(self, start, end, temp_surfase=False):
        if start and end:
            if self.frame:
                if start == self.frame[0] and end == self.frame[1]:
                    return
            cpath = libcairo.convert_bbox_to_cpath(start + end)
            bbox = self.cdc_to_int(*libcairo.get_cpath_bbox(cpath))
            frame = self.cdc_bbox_to_frame(bbox)
            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)
            if temp_surfase:
                ctx.set_source_surface(self.temp_surface, -x + 1, -y + 1)
            else:
                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)
            self.cdc_reflect_snapping() 
开发者ID:sk1project,项目名称:sk1-wx,代码行数:27,代码来源:renderer.py

示例4: paint

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [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) 
开发者ID:sk1project,项目名称:sk1-wx,代码行数:23,代码来源:ruler.py

示例5: paint

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def paint(self, context, selected):
        view = self.view
        item = self.item
        cr = context.cairo
        h = item.handles()
        side_length = get_side_length_of_resize_handle(self.view, item.parent) / 1.5
        for h1, h2 in zip(h[1:-2], h[2:-1]):
            p1, p2 = h1.pos, h2.pos
            cx = (p1.x + p2.x) / 2
            cy = (p1.y + p2.y) / 2
            cr.save()
            cr.set_line_width(self.view.get_zoom_factor() / 4.)
            cr.identity_matrix()
            m = Matrix(*view.get_matrix_i2v(item))

            # cr.set_antialias(Antialias.NONE)
            cr.translate(*m.transform_point(cx, cy))
            cr.rectangle(-side_length / 2., -side_length / 2., side_length, side_length)
            cr.set_source_rgba(*get_col_rgba(self.fill_color))
            cr.fill_preserve()
            cr.set_source_rgba(*get_col_rgba(self.border_color))
            cr.set_line_width(1)
            cr.stroke()
            cr.restore() 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:26,代码来源:painter.py

示例6: matrixAround

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def matrixAround(rotated_matrix, anchor_x, anchor_y):
    """
    Description : Rotates a matrix through the hypotenuse so that the original
    matrix becomes the inverse matrix and the inverse matrix becomes matrix
    Returns a tuple representing the matrix and its inverse

    """
    corner = rotated_matrix[0]
    side = rotated_matrix[1]
    anchor_yside = anchor_y * side
    anchor_xside = anchor_x * side
    anchor_ycorner = anchor_y * (1 - corner)
    anchor_xcorner = anchor_x * (1 - corner)
    matrix = cairo.Matrix(corner, side, -side, corner,
                          anchor_xcorner + anchor_yside,
                          anchor_ycorner - anchor_xside)
    invmatrix = cairo.Matrix(corner, -side, side, corner,
                             anchor_xcorner - anchor_yside,
                             anchor_ycorner + anchor_xside)
    return matrix, invmatrix 
开发者ID:pychess,项目名称:pychess,代码行数:22,代码来源:BoardView.py

示例7: hatch

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def hatch(positive, rgba):
    hs = 64
    hatch = cairo.ImageSurface(cairo.FORMAT_ARGB32, hs, hs)
    hctx = cairo.Context(hatch)
    if positive:
        hctx.move_to(0, 0)
        hctx.line_to(hs, hs)
    else:
        hctx.move_to(0, hs)
        hctx.line_to(hs, 0)
    hctx.set_line_width(16)
    hctx.set_source_rgba(*rgba)
    hctx.stroke()
    hpat = cairo.SurfacePattern(hatch)
    hpat.set_extend(cairo.EXTEND_REPEAT)
    hpat.set_matrix(cairo.Matrix(xx=image_size, yy=image_size))
    return hpat 
开发者ID:adamgreig,项目名称:agg-kicad,代码行数:19,代码来源:draw_mod.py

示例8: render

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def render(objs, cms):
    bbox = reduce(lambda a, b: libgeom.sum_bbox(a, b.cache_bbox), objs, [])
    w, h = libgeom.bbox_size(bbox)
    x, y = libgeom.bbox_center(bbox)
    trafo = (1.0, 0, 0, -1.0, w / 2.0 - x, h / 2.0 + y)
    canvas_matrix = cairo.Matrix(*trafo)

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(w), int(h))
    ctx = cairo.Context(surface)
    ctx.set_matrix(canvas_matrix)
    rend = crenderer.CairoRenderer(cms)
    rend.antialias_flag = True
    rend.render(ctx, objs)

    image_stream = StringIO()
    surface.write_to_png(image_stream)
    return image_stream 
开发者ID:sk1project,项目名称:uniconvertor,代码行数:19,代码来源:crenderer.py

示例9: png_saver

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def png_saver(sk2_doc, filename=None, fileptr=None, translate=True, cnf=None,
              **kw):
    cnf = merge_cnf(cnf, kw)
    if filename and not fileptr:
        fileptr = get_fileptr(filename, True)
    page = sk2_doc.methods.get_page()
    scale = abs(float(cnf.get('scale', 1.0))) or 1.0
    w, h = [scale * item for item in page.page_format[1]]
    trafo = (scale, 0, 0, -scale, w / 2.0, h / 2.0)

    canvas_matrix = cairo.Matrix(*trafo)
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(w), int(h))
    ctx = cairo.Context(surface)
    ctx.set_matrix(canvas_matrix)
    
    antialias_flag = not cnf.get('antialiasing') in (False, 0)
    layers = sk2_doc.methods.get_visible_layers(page)
    rend = CairoRenderer(sk2_doc.cms)

    for item in layers:
        rend.antialias_flag = not any([not item.properties[3], not antialias_flag])
        rend.render(ctx, item.childs)

    surface.write_to_png(fileptr)
    fileptr.close() 
开发者ID:sk1project,项目名称:uniconvertor,代码行数:27,代码来源:__init__.py

示例10: on_print_page

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def on_print_page(self, page):
        page_obj = self.get_print_pages()[page - 1]
        dc = self.GetDC()
        w, h = dc.GetSizeTuple()
        pw, ph = self.GetPageSizeMM()
        pw *= uc2const.mm_to_pt
        ph *= uc2const.mm_to_pt

        trafo = (w / pw, 0, 0, -h / ph,
                 w / 2.0 - self.shifts[0], h / 2.0 - self.shifts[1])

        matrix = cairo.Matrix(*trafo)

        surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
        ctx = cairo.Context(surface)
        ctx.set_source_rgb(1, 1, 1)
        ctx.paint()
        ctx.set_matrix(matrix)

        for group in page_obj.childs:
            self.renderer.render(ctx, group.childs)

        win_surface = cairo.Win32PrintingSurface(dc.GetHDC())
        win_ctx = cairo.Context(win_surface)

        win_ctx.set_source_surface(surface, 0, 0)
        win_ctx.paint() 
开发者ID:sk1project,项目名称:sk1-wx,代码行数:29,代码来源:printout.py

示例11: _fit_to_page

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def _fit_to_page(self):
        width, height = self.printer.get_page_size()
        w, h = self.get_size()
        w = float(w)
        h = float(h)
        self.width = w
        self.height = h
        zoom = min(w / width, h / height) * PAGEFIT
        dx = w / 2.0
        dy = h / 2.0
        self.trafo = [zoom, 0, 0, -zoom, dx, dy]
        self.zoom_stack.append([] + self.trafo)
        self.matrix = cairo.Matrix(zoom, 0, 0, -zoom, dx, dy)
        self.zoom = zoom
        self.update_scrolls() 
开发者ID:sk1project,项目名称:sk1-wx,代码行数:17,代码来源:canvas.py

示例12: _keep_center

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def _keep_center(self):
        w, h = self.get_size()
        w = float(w)
        h = float(h)
        if not w == self.width or not h == self.height:
            _dx = (w - self.width) / 2.0
            _dy = (h - self.height) / 2.0
            m11, m12, m21, m22, dx, dy = self.trafo
            dx += _dx
            dy += _dy
            self.trafo = [m11, m12, m21, m22, dx, dy]
            self.matrix = cairo.Matrix(m11, m12, m21, m22, dx, dy)
            self.width = w
            self.height = h
            self.update_scrolls() 
开发者ID:sk1project,项目名称:sk1-wx,代码行数:17,代码来源:canvas.py

示例13: _zoom

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def _zoom(self, dzoom=1.0):
        m11, m12, m21, m22, dx, dy = self.trafo
        _dx = (self.width * dzoom - self.width) / 2.0
        _dy = (self.height * dzoom - self.height) / 2.0
        dx = dx * dzoom - _dx
        dy = dy * dzoom - _dy
        self.trafo = [m11 * dzoom, m12, m21, m22 * dzoom, dx, dy]
        self.zoom_stack.append([] + self.trafo)
        self.matrix = cairo.Matrix(*self.trafo)
        self.zoom = m11 * dzoom
        self.update_scrolls()
        self.refresh() 
开发者ID:sk1project,项目名称:sk1-wx,代码行数:14,代码来源:canvas.py

示例14: paint

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def paint(self):
        w, h = self.get_size()
        fmt = cairo.FORMAT_RGB24
        self.surface = cairo.ImageSurface(fmt, 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(*self.prefs.bg_btn.get_value())
        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(*self.prefs.fg_btn.get_value())

        self.ctx.move_to(0, h)
        self.ctx.line_to(w, h)
        self.ctx.stroke()

        small_l = self.prefs.ruler_small_tick.get_value()
        for item in SMALL_TICKS:
            self.ctx.move_to(item, h - small_l)
            self.ctx.line_to(item, h - 1)

        large_l = self.prefs.ruler_large_tick.get_value()
        for pos, txt in TEXT_TICKS:
            self.ctx.move_to(pos, h - large_l)
            self.ctx.line_to(pos, h - 1)

        self.ctx.stroke()

        vshift = self.prefs.ruler_text_vshift.get_value()
        hshift = self.prefs.ruler_text_hshift.get_value()
        for pos, txt in TEXT_TICKS:
            for character in txt:
                data = self.font[character]
                position = int(pos) + hshift
                self.ctx.set_source_surface(data[1], position, vshift)
                self.ctx.paint()
                pos += data[0]

        self.draw_surface(self.surface) 
开发者ID:sk1project,项目名称:sk1-wx,代码行数:42,代码来源:prefs_ruler.py

示例15: render

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import Matrix [as 别名]
def render(self, sel_flag=False):
        doc = self.app.current_doc
        if not doc:
            return
        if sel_flag:
            if not doc.selection.objs:
                return None
            w, h = libgeom.bbox_size(doc.selection.bbox)
            x, y = libgeom.bbox_center(doc.selection.bbox)
            trafo = (1.0, 0, 0, -1.0, w / 2.0 - x, h / 2.0 + y)
        else:
            page = doc.active_page
            w, h = page.page_format[1]
            trafo = (1.0, 0, 0, -1.0, w / 2.0, h / 2.0)

        canvas_matrix = cairo.Matrix(*trafo)
        surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(w), int(h))
        ctx = cairo.Context(surface)
        ctx.set_matrix(canvas_matrix)

        rend = crenderer.CairoRenderer(doc.cms)

        if sel_flag:
            objs = doc.selection.objs
            for obj in objs:
                layer = doc.methods.get_parent_layer(obj)
                rend.antialias_flag = layer.properties[3] == 1
                rend.render(ctx, [obj, ])
        else:
            page = doc.active_page
            layers = doc.methods.get_visible_layers(page)
            for item in layers:
                rend.antialias_flag = item.properties[3] == 1
                rend.render(ctx, item.childs)

        image_stream = StringIO()
        surface.write_to_png(image_stream)
        return image_stream 
开发者ID:sk1project,项目名称:sk1-wx,代码行数:40,代码来源:__init__.py


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