Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, pointer, target_keep_alive=None):
self._pointer = ffi.gc(
pointer, _keepref(cairo, cairo.cairo_surface_destroy))
self._check_status()
if target_keep_alive not in (None, ffi.NULL):
keep_alive = KeepAlive(target_keep_alive)
_check_status(cairo.cairo_surface_set_user_data(
self._pointer, SURFACE_TARGET_KEY, *keep_alive.closure))
keep_alive.save()
if :obj:`with_clusters` is true, otherwise just :obj:`glyphs`.
See :meth:`Context.show_text_glyphs` for the data structure.
.. note::
This method is part of
what the cairo designers call the "toy" text API.
It is convenient for short demos and simple programs,
but it is not expected to be adequate
for serious text-using applications.
See :ref:`fonts` for details
and :meth:`Context.show_glyphs`
for the "real" text display API in cairo.
"""
glyphs = ffi.new('cairo_glyph_t **', ffi.NULL)
num_glyphs = ffi.new('int *')
if with_clusters:
clusters = ffi.new('cairo_text_cluster_t **', ffi.NULL)
num_clusters = ffi.new('int *')
cluster_flags = ffi.new('cairo_text_cluster_flags_t *')
else:
clusters = ffi.NULL
num_clusters = ffi.NULL
cluster_flags = ffi.NULL
# TODO: Pass len_utf8 explicitly to support NULL bytes?
status = cairo.cairo_scaled_font_text_to_glyphs(
self._pointer, x, y, _encode_string(text), -1,
glyphs, num_glyphs, clusters, num_clusters, cluster_flags)
glyphs = ffi.gc(glyphs[0], _keepref(cairo, cairo.cairo_glyph_free))
if with_clusters:
clusters = ffi.gc(
def version_to_string(version):
"""Return the string representation of the given :ref:`PDF_VERSION`.
See :meth:`get_versions` for a way to get
the list of valid version ids.
*New in cairo 1.10.*
"""
c_string = cairo.cairo_pdf_version_to_string(version)
if c_string == ffi.NULL:
raise ValueError(version)
return ffi.string(c_string).decode('ascii')
def _make_write_func(file_obj):
"""Return a CFFI callback that writes to a file-like object."""
if file_obj is None:
return ffi.NULL
@ffi.callback("cairo_write_func_t", error=constants.STATUS_WRITE_ERROR)
def write_func(_closure, data, length):
file_obj.write(ffi.buffer(data, length))
return constants.STATUS_SUCCESS
return write_func
def __init__(self, target, width_in_points, height_in_points):
if hasattr(target, 'write') or target is None:
write_func = _make_write_func(target)
pointer = cairo.cairo_ps_surface_create_for_stream(
write_func, ffi.NULL, width_in_points, height_in_points)
else:
write_func = None
pointer = cairo.cairo_ps_surface_create(
_encode_filename(target), width_in_points, height_in_points)
Surface.__init__(self, pointer, target_keep_alive=write_func)
Font variations are specified as a string with a format that is similar
to the CSS font-variation-settings. The string contains a
comma-separated list of axis assignments, which each assignment
consists of a 4-character axis name and a value, separated by
whitespace and optional equals sign.
:param variations: the new font variations, or ``None``.
*New in cairo 1.16.*
*New in cairocffi 0.9.*
"""
if variations is None:
variations = ffi.NULL
else:
variations = _encode_string(variations)
cairo.cairo_font_options_set_variations(self._pointer, variations)
self._check_status()
def __init__(self, target, width_in_points, height_in_points):
if hasattr(target, 'write') or target is None:
write_func = _make_write_func(target)
pointer = cairo.cairo_svg_surface_create_for_stream(
write_func, ffi.NULL, width_in_points, height_in_points)
else:
write_func = None
pointer = cairo.cairo_svg_surface_create(
_encode_filename(target), width_in_points, height_in_points)
Surface.__init__(self, pointer, target_keep_alive=write_func)
.. note::
This method is part of
what the cairo designers call the "toy" text API.
It is convenient for short demos and simple programs,
but it is not expected to be adequate
for serious text-using applications.
See :ref:`fonts` for details
and :meth:`Context.show_glyphs`
for the "real" text display API in cairo.
"""
glyphs = ffi.new('cairo_glyph_t **', ffi.NULL)
num_glyphs = ffi.new('int *')
if with_clusters:
clusters = ffi.new('cairo_text_cluster_t **', ffi.NULL)
num_clusters = ffi.new('int *')
cluster_flags = ffi.new('cairo_text_cluster_flags_t *')
else:
clusters = ffi.NULL
num_clusters = ffi.NULL
cluster_flags = ffi.NULL
# TODO: Pass len_utf8 explicitly to support NULL bytes?
status = cairo.cairo_scaled_font_text_to_glyphs(
self._pointer, x, y, _encode_string(text), -1,
glyphs, num_glyphs, clusters, num_clusters, cluster_flags)
glyphs = ffi.gc(glyphs[0], _keepref(cairo, cairo.cairo_glyph_free))
if with_clusters:
clusters = ffi.gc(
clusters[0], _keepref(cairo, cairo.cairo_text_cluster_free))
_check_status(status)
glyphs = [
def __init__(self, target, width_in_points, height_in_points):
if hasattr(target, 'write') or target is None:
write_func = _make_write_func(target)
pointer = cairo.cairo_pdf_surface_create_for_stream(
write_func, ffi.NULL, width_in_points, height_in_points)
else:
write_func = None
pointer = cairo.cairo_pdf_surface_create(
_encode_filename(target), width_in_points, height_in_points)
Surface.__init__(self, pointer, target_keep_alive=write_func)
but it is not expected to be adequate
for serious text-using applications.
See :ref:`fonts` for details
and :meth:`Context.show_glyphs`
for the "real" text display API in cairo.
"""
glyphs = ffi.new('cairo_glyph_t **', ffi.NULL)
num_glyphs = ffi.new('int *')
if with_clusters:
clusters = ffi.new('cairo_text_cluster_t **', ffi.NULL)
num_clusters = ffi.new('int *')
cluster_flags = ffi.new('cairo_text_cluster_flags_t *')
else:
clusters = ffi.NULL
num_clusters = ffi.NULL
cluster_flags = ffi.NULL
# TODO: Pass len_utf8 explicitly to support NULL bytes?
status = cairo.cairo_scaled_font_text_to_glyphs(
self._pointer, x, y, _encode_string(text), -1,
glyphs, num_glyphs, clusters, num_clusters, cluster_flags)
glyphs = ffi.gc(glyphs[0], _keepref(cairo, cairo.cairo_glyph_free))
if with_clusters:
clusters = ffi.gc(
clusters[0], _keepref(cairo, cairo.cairo_text_cluster_free))
_check_status(status)
glyphs = [
(glyph.index, glyph.x, glyph.y)
for i in range(num_glyphs[0])
for glyph in [glyphs[i]]]
if with_clusters:
clusters = [