How to use the cairocffi.ffi.gc function in cairocffi

To help you get started, we’ve selected a few cairocffi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kozea / cairocffi / cairocffi / fonts.py View on Github external
"""
        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 = [
                (cluster.num_bytes, cluster.num_glyphs)
                for i in range(num_clusters[0])
                for cluster in [clusters[i]]]
            return glyphs, clusters, cluster_flags[0]
        else:
            return glyphs
github Kozea / cairocffi / cairocffi / fonts.py View on Github external
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 = [
                (cluster.num_bytes, cluster.num_glyphs)
                for i in range(num_clusters[0])
                for cluster in [clusters[i]]]
            return glyphs, clusters, cluster_flags[0]
        else:
            return glyphs
github Kozea / cairocffi / cairocffi / fonts.py View on Github external
def _init_pointer(self, pointer):
        self._pointer = ffi.gc(
            pointer, _keepref(cairo, cairo.cairo_font_options_destroy))
        self._check_status()
github Kozea / cairocffi / cairocffi / surfaces.py View on Github external
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()
github Kozea / cairocffi / cairocffi / fonts.py View on Github external
def _init_pointer(self, pointer):
        self._pointer = ffi.gc(
            pointer, _keepref(cairo, cairo.cairo_scaled_font_destroy))
        self._check_status()
github Kozea / cairocffi / cairocffi / fonts.py View on Github external
def __init__(self, pointer):
        self._pointer = ffi.gc(
            pointer, _keepref(cairo, cairo.cairo_font_face_destroy))
        self._check_status()
github Kozea / cairocffi / cairocffi / patterns.py View on Github external
def __init__(self, pointer):
        self._pointer = ffi.gc(
            pointer, _keepref(cairo, cairo.cairo_pattern_destroy))
        self._check_status()