當前位置: 首頁>>代碼示例>>Python>>正文


Python Context.save方法代碼示例

本文整理匯總了Python中cairo.Context.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Context.save方法的具體用法?Python Context.save怎麽用?Python Context.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cairo.Context的用法示例。


在下文中一共展示了Context.save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: export_svg

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [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: on_draw

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [as 別名]
 def on_draw(self, widget: Widget, context: cairo.Context):
     context.save()
     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()
     context.restore()
     super().on_draw(widget, context)
開發者ID:gcali,項目名稱:crucipixel,代碼行數:11,代碼來源:input.py

示例3: on_draw

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [as 別名]
 def on_draw(self, widget: Widget, context: cairo.Context):
     for child in self.list:
         if child.visible:
             context.save()
             context.transform(child.fromWidgetCoords)
             if child.is_clip_set():
                 rectangle = child.clip_rectangle
                 context.rectangle(rectangle.start.x,rectangle.start.y,
                                   rectangle.width,rectangle.height)
                 context.clip()
             child.on_draw(self,context)
             context.restore()
開發者ID:gcali,項目名稱:crucipixel,代碼行數:14,代碼來源:containers.py

示例4: on_draw

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [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: on_draw

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [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

示例6: on_draw

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [as 別名]
    def on_draw(self, widget: Widget, context: cairo.Context):
        self.guide_line.set_shape_from_context(context)
        shape = self.guide_line.shape
        self.guide_line.set_translate(shape.width + 10, shape.height + 10)

        context.save()
        context.set_source_rgb(1, 1, 1)
        if self.guide_line.orientation == Orientation.HORIZONTAL:
            context.rectangle(10, shape.height + 10, shape.width, 20)
        else:
            context.rectangle(shape.width + 10, 10, 20, shape.height)
        context.fill()
        context.restore()

        super().on_draw(widget, context)
開發者ID:gcali,項目名稱:crucipixel,代碼行數:17,代碼來源:guides.py

示例7: layout

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [as 別名]
    def layout(self, context: cairo.Context):
        if not self.is_shape_set:
            context.save()
            context.set_font_size(self.font_size)
            generator = (context.text_extents(chr(letter) * 10)
                         for letter in range(ord('A'), ord('Z') + 1))
            context.restore()
            sizes = [(xa, h) for xb, yb, w, h, xa, ya in generator]
            max_height = 0
            for w, h in sizes:
                max_height = max(h, max_height)

            width = self.width
            height = self.padding * 3 + max_height

            self.shape = DrawableRectangle(Point(0, 0), width, height)
開發者ID:gcali,項目名稱:crucipixel,代碼行數:18,代碼來源:input.py

示例8: _highlight_border

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [as 別名]
    def _highlight_border(self, context: cairo.Context, row: int, col: int):
        width = self._total_width
        height = self._total_height

        line_width = 3
        row_rectangles = [
            Rectangle(
                Point(1, row * self.cell_height - line_width / 2),
                width - 2,
                line_width
            ),
            Rectangle(
                Point(1, (row + 1) * self.cell_height - line_width / 2),
                width - 2,
                line_width
            )
        ]
        col_rectangles = [
            Rectangle(
                Point(col * self.cell_width - line_width / 2, 1),
                line_width,
                height - 2
            ),
            Rectangle(
                Point((col + 1) * self.cell_width - line_width / 2, 1),
                line_width,
                height - 2
            )
        ]
        context.save()
        r, g, b = self.highlight_color
        context.set_source_rgba(r, g, b, .6)
        for row_rectangle in row_rectangles:
            context.rectangle(row_rectangle.start.x,
                              row_rectangle.start.y,
                              row_rectangle.width,
                              row_rectangle.height)
            context.fill()
        for col_rectangle in col_rectangles:
            context.rectangle(col_rectangle.start.x,
                              col_rectangle.start.y,
                              col_rectangle.width,
                              col_rectangle.height)
            context.fill()
        context.restore()
開發者ID:gcali,項目名稱:crucipixel,代碼行數:47,代碼來源:grid.py

示例9: MapSurface

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [as 別名]
class MapSurface(object):
    """wrapper to render the map to svg/png"""

    def __init__(self, hexmap=None, filename=None, width=None, height=None, size=None):
        self.hexmap = hexmap
        if self.hexmap is None:
            raise ValueError("No map was passed to {}".format(self.__class__.__name__))
        self.surface_name = filename or "test.svg"
        self.size = size or 32.0
        self.surface_width = width
        if self.surface_width is None:
            self.surface_width = (self.hexmap.map.cols + .5) * self.size * SQRT3
        self.surface_height = height
        if self.surface_height is None:
            self.surface_height = (self.hexmap.map.rows * 1.5 + .25) * self.size
        self.layer = []

        # build base map
        self.surface = SVGSurface(self.surface_name + ".svg", self.surface_width, self.surface_height)
        self.context = Context(self.surface)
        # background: magenta
        self.context.save()
        self.context.set_source_rgb(1.0, 0.0, 1.0)
        self.context.paint()
        self.context.restore()

    def add_layer(self, renderer_cls, position=None):
        if not position:
            self.layer.append(renderer_cls(self))
        else:
            self.layer.insert(position, renderer_cls(self))

    def render(self):
        print "Rendering {} ({}x{})".format(self.surface_name, self.surface_width, self.surface_height)
        for renderer in self.layer:
            renderer.render()

    def finalise(self, with_png=False):
        print "finalising:"
        if with_png is True:
            print "PNG"
            self.surface.write_to_png(self.surface_name + ".png")
        print "SVG"
        self.surface.finish()
        print "DONE!"
開發者ID:,項目名稱:,代碼行數:47,代碼來源:

示例10: export_svg

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [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

示例11: main

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [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

示例12: main

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [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

示例13: layout

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [as 別名]
    def layout(self, context: cairo.Context):
        super().layout(context)
        context.save()
        self.__plus_button.layout(context)
        context.restore()
        self.__minus_button.min_height = self.__plus_button.shape.height
        context.save()
        self.__minus_button.layout(context)
        context.restore()

        plus_shape = self.__plus_button.shape
        minus_shape = self.__minus_button.shape

        self.__minus_button.set_translate(self.padding, self.padding/2)
        self.__plus_button.set_translate(
            self.padding + minus_shape.width + self.padding,
            self.padding/2
        )

        self.shape = DrawableRectangle(
            Point(0, 0),
            plus_shape.width + minus_shape.width + 3 * self.padding,
            self.padding + max(plus_shape.height, minus_shape.height)
        )
開發者ID:gcali,項目名稱:crucipixel,代碼行數:26,代碼來源:zoom.py

示例14: Floor64

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [as 別名]
    def Floor64(x):
        return (x//64) * 64

    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])
開發者ID:moyogo,項目名稱:freetype-py,代碼行數:33,代碼來源:glyph-vector-2-cairo.py

示例15: on_draw

# 需要導入模塊: from cairo import Context [as 別名]
# 或者: from cairo.Context import save [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


注:本文中的cairo.Context.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。