本文整理汇总了Python中cairo.Context.scale方法的典型用法代码示例。如果您正苦于以下问题:Python Context.scale方法的具体用法?Python Context.scale怎么用?Python Context.scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo.Context
的用法示例。
在下文中一共展示了Context.scale方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_svg2png
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import scale [as 别名]
def convert_svg2png(infile, outfile, w, h):
"""
Converts svg files to png using Cairosvg or Inkscape
@file_path : String; the svg file absolute path
@dest_path : String; the png file absolute path
"""
if use_inkscape:
p = Popen(["inkscape", "-z", "-f", infile, "-e", outfile,
"-w", str(w), "-h", str(h)],
stdout=PIPE, stderr=PIPE)
output, err = p.communicate()
else:
handle = Rsvg.Handle()
svg = handle.new_from_file(infile)
dim = svg.get_dimensions()
img = ImageSurface(FORMAT_ARGB32, w, h)
ctx = Context(img)
ctx.scale(w / dim.width, h / dim.height)
svg.render_cairo(ctx)
png_io = BytesIO()
img.write_to_png(png_io)
with open(outfile, 'wb') as fout:
fout.write(png_io.getvalue())
svg.close()
png_io.close()
img.finish()
示例2: convert_to_png
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import scale [as 别名]
def convert_to_png(input_file, output_file, width=None, height=None):
"""Convert svg to png."""
if width and height:
handle = Rsvg.Handle()
svg = handle.new_from_file(input_file)
dim = svg.get_dimensions()
img = ImageSurface(FORMAT_ARGB32, width, height)
ctx = Context(img)
ctx.scale(width / dim.width, height / dim.height)
svg.render_cairo(ctx)
png_io = BytesIO()
img.write_to_png(png_io)
with open(output_file, 'wb') as fout:
fout.write(png_io.getvalue())
fout.close()
svg.close()
png_io.close()
img.finish()
else:
with open(input_file, "r") as content_file:
svg = content_file.read()
content_file.close()
fout = open(output_file, "wb")
svg2png(bytestring=bytes(svg, "UTF-8"), write_to=fout)
fout.close()
示例3: __missing__
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import scale [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
示例4: illustrate
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import scale [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)
示例5: setup_doc
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import scale [as 别名]
def setup_doc(name):
'''
'''
doc = PDFSurface(name, sheet_width*ptpin, sheet_height*ptpin)
ctx = Context(doc)
ctx.scale(ptpin, ptpin)
set_font_face_from_file(ctx, 'DejaVuSerifCondensed.ttf')
return doc, ctx
示例6: _scale_down
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import scale [as 别名]
def _scale_down(self, handle, ratio):
xsize, ysize = self.size
if ratio >= 1.0:
# Convert
surface = ImageSurface(FORMAT_ARGB32, xsize, ysize)
ctx = Context(surface)
else:
# Scale
xsize, ysize = int(xsize * ratio), int(ysize * ratio)
surface = ImageSurface(FORMAT_ARGB32, xsize, ysize)
ctx = Context(surface)
ctx.scale(ratio, ratio)
# Render
handle.render_cairo(ctx)
# Transform to a PIL image for further manipulation
size = (xsize, ysize)
im = frombuffer('RGBA', size, surface.get_data(), 'raw', 'BGRA', 0, 1)
surface.finish()
return im, xsize, ysize
示例7: Face
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import scale [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])
示例8: main
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import scale [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
示例9: return
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import scale [as 别名]
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])