HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/cairocffi/__pycache__/fonts.cpython-310.pyc
o

*we(L�@s�dZddlmZmZmZmZmZddlmZdd�Z	Gdd�de
�ZGdd	�d	e�Zej
eiZGd
d�de
�ZGdd
�d
e
�ZdS)z�
    cairocffi.fonts
    ~~~~~~~~~~~~~~~

    Bindings for font-related objects.

    :copyright: Copyright 2013-2019 by Simon Sapin
    :license: BSD, see LICENSE for details.

�)�
_check_status�_keepref�cairo�	constants�ffi)�MatrixcCs t|t�s
|�d�}t�d|�S)z2Return a byte string, encoding Unicode with UTF-8.�utf8zchar[])�
isinstance�bytes�encoder�new)�string�r�H/home/arjun/projects/env/lib/python3.10/site-packages/cairocffi/fonts.py�_encode_strings

rc@s,eZdZdZdd�Zdd�Zedd��ZdS)	�FontFacez�The base class for all font face types.

    Should not be instantiated directly, but see :doc:`cffi_api`.
    An instance may be returned for cairo font face types
    that are not (yet) defined in cairocffi.

    cC�"t�|tttj��|_|��dS�N)r�gcrr�cairo_font_face_destroy�_pointerr��self�pointerrrr�__init__��zFontFace.__init__cC�tt�|j��dSr)rr�cairo_font_face_statusr�rrrrr$�zFontFace._check_statuscCsH|tjkr	td��|rt�|�t�t�t�	|�t
��}t
�||�|S)uGWrap an existing ``cairo_font_face_t *`` cdata pointer.

        :type incref: bool
        :param incref:
            Whether increase the :ref:`reference count <refcounting>` now.
        :return:
            A new instance of :class:`FontFace` or one of its sub-classes,
            depending on the face’s type.

        �Null pointer)r�NULL�
ValueErrorr�cairo_font_face_reference�object�__new__�FONT_TYPE_TO_CLASS�get�cairo_font_face_get_typerr�r�increfrrrr�
_from_pointer's


�zFontFace._from_pointerN)�__name__�
__module__�__qualname__�__doc__rr�staticmethodr+rrrrrsrc@s<eZdZdZdejejfdd�Zdd�Zdd�Z	d	d
�Z
dS)�ToyFontFaceu�Creates a font face from a triplet of family, slant, and weight.
    These font faces are used in implementation of cairo’s "toy" font API.

    If family is the zero-length string ``""``,
    the platform-specific default family is assumed.
    The default family then can be queried using :meth:`get_family`.

    The :meth:`Context.select_font_face` method uses this to create font faces.
    See that method for limitations and other details of toy font faces.

    :param family: a font family name, as an Unicode or UTF-8 string.
    :param slant: The :ref:`FONT_SLANT` string for the font face.
    :param weight: The :ref:`FONT_WEIGHT` string for the font face.

    �cCst�|t�t|�||��dSr)rrr�cairo_toy_font_face_creater)r�family�slant�weightrrrrMs


�zToyFontFace.__init__cCst�t�|j���dd�S)u&Return this font face’s family name.r�replace)rr
r�cairo_toy_font_face_get_familyr�decoderrrr�
get_familyRs
��zToyFontFace.get_familycC�t�|j�S)u3Return this font face’s :ref:`FONT_SLANT` string.)r�cairo_toy_font_face_get_slantrrrrr�	get_slantW�zToyFontFace.get_slantcCr;)u4Return this font face’s :ref:`FONT_WEIGHT` string.)r�cairo_toy_font_face_get_weightrrrrr�
get_weight[r>zToyFontFace.get_weightN)r,r-r.r/r�FONT_SLANT_NORMAL�FONT_WEIGHT_NORMALrr:r=r@rrrrr1=s
�r1c@s~eZdZdZddd�Zdd�Zdd�Zed	d
��Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�
ScaledFonta�Creates a :class:`ScaledFont` object from a font face and matrices
    that describe the size of the font
    and the environment in which it will be used.

    :param font_face: A :class:`FontFace` object.
    :type font_matrix: Matrix
    :param font_matrix:
        Font space to user space transformation matrix for the font.
        In the simplest case of a N point font,
        this matrix is just a scale by N,
        but it can also be used to shear the font
        or stretch it unequally along the two axes.
        If omitted, a scale by 10 matrix is assumed (ie. a 10 point font size).
        See :class:`Context.set_font_matrix`.
    :type ctm: Matrix
    :param ctm:
        User to device transformation matrix with which the font will be used.
        If omitted, an identity matrix is assumed.
    :param options:
        The :class:`FontOptions` object to use
        when getting metrics for the font and rendering with it.
        If omitted, the default options are assumed.

    NcCsV|durt�}|�d�|durt�}|durt�}|�t�|j|j|j|j��dS)N�
)r�scale�FontOptions�
_init_pointerr�cairo_scaled_font_creater)r�	font_face�font_matrix�ctm�optionsrrrr~s

�zScaledFont.__init__cCrr)rrrr�cairo_scaled_font_destroyrrrrrrrG�rzScaledFont._init_pointercCrr)rr�cairo_scaled_font_statusrrrrrr�rzScaledFont._check_statuscCs:|tjkr	td��|rt�|�t�t�}t�||�|S)z�Wrap an existing ``cairo_scaled_font_t *`` cdata pointer.

        :type incref: bool
        :param incref:
            Whether increase the :ref:`reference count <refcounting>` now.
        :return: A new :class:`ScaledFont` instance.

        r )	rr!r"r�cairo_scaled_font_referencer$r%rCrGr)rrrr+�s



zScaledFont._from_pointercCstjt�|j�dd�S)a&Return the font face that this scaled font uses.

        :returns:
            A new instance of :class:`FontFace` (or one of its sub-classes).
            Might wrap be the same font face passed to :class:`ScaledFont`,
            but this does not hold true for all possible cases.

        T)r*)rr+r�cairo_scaled_font_get_font_facerrrrr�
get_font_face�s	�zScaledFont.get_font_facecCst�}t�|j|j�|S)ucCopies the scaled font’s options.

        :returns: A new :class:`FontOptions` object.

        )rFr�"cairo_scaled_font_get_font_optionsr)r�font_optionsrrr�get_font_options�s
�zScaledFont.get_font_optionscC�"t�}t�|j|j�|��|S)ubCopies the scaled font’s font matrix.

        :returns: A new :class:`Matrix` object.

        )rr�!cairo_scaled_font_get_font_matrixrr�r�matrixrrr�get_font_matrix�szScaledFont.get_font_matrixcCrU)u1Copies the scaled font’s font current transform matrix.

        Note that the translation offsets ``(x0, y0)`` of the CTM
        are ignored by :class:`ScaledFont`.
        So, the matrix this method returns always has 0 as ``x0`` and ``y0``.

        :returns: A new :class:`Matrix` object.

        )rr�cairo_scaled_font_get_ctmrrrWrrr�get_ctm�s
zScaledFont.get_ctmcCrU)uCopies the scaled font’s scaled matrix.

        The scale matrix is product of the font matrix
        and the ctm associated with the scaled font,
        and hence is the matrix mapping from font space to device space.

        :returns: A new :class:`Matrix` object.

        )rr�"cairo_scaled_font_get_scale_matrixrrrWrrr�get_scale_matrix�s
�zScaledFont.get_scale_matrixcCs8t�d�}t�|j|�|��|j|j|j|j	|j
fS)u�Return the scaled font’s extents.
        See :meth:`Context.font_extents`.

        :returns:
            A ``(ascent, descent, height, max_x_advance, max_y_advance)``
            tuple of floats.

        zcairo_font_extents_t *)rrr�cairo_scaled_font_extentsrr�ascent�descent�height�
max_x_advance�
max_y_advance)r�extentsrrrrd�s
	�zScaledFont.extentscCsBt�d�}t�|jt|�|�|��|j|j|j	|j
|j|jfS)a�Returns the extents for a string of text.

        The extents describe a user-space rectangle
        that encloses the "inked" portion of the text,
        (as it would be drawn by :meth:`Context.show_text`).
        Additionally, the ``x_advance`` and ``y_advance`` values
        indicate the amount by which the current point would be advanced
        by :meth:`Context.show_text`.

        :param text: The text to measure, as an Unicode or UTF-8 string.
        :returns:
            A ``(x_bearing, y_bearing, width, height, x_advance, y_advance)``
            tuple of floats.
            See :meth:`Context.text_extents` for details.

        �cairo_text_extents_t *)
rrr�cairo_scaled_font_text_extentsrrr�	x_bearing�	y_bearing�widthra�	x_advance�	y_advance)r�textrdrrr�text_extents�s
��zScaledFont.text_extentscCsPt�d|�}t�d�}t�|j|t|�|�|��|j|j|j	|j
|j|jfS)aReturns the extents for a list of glyphs.

        The extents describe a user-space rectangle
        that encloses the "inked" portion of the glyphs,
        (as it would be drawn by :meth:`Context.show_glyphs`).
        Additionally, the ``x_advance`` and ``y_advance`` values
        indicate the amount by which the current point would be advanced
        by :meth:`Context.show_glyphs`.

        :param glyphs:
            A list of glyphs, as returned by :meth:`text_to_glyphs`.
            Each glyph is a ``(glyph_id, x, y)`` tuple
            of an integer and two floats.
        :returns:
            A ``(x_bearing, y_bearing, width, height, x_advance, y_advance)``
            tuple of floats.
            See :meth:`Context.text_extents` for details.

        zcairo_glyph_t[]re)
rrr�cairo_scaled_font_glyph_extentsr�lenrrgrhrirarjrk)r�glyphsrdrrr�
glyph_extentss
��zScaledFont.glyph_extentsc	s�t�dtj��t�d�}|r t�dtj��t�d�}t�d�}n	tj�tj}tj}t�|j||t|�d�|�||�
}t��dtttj	���|rTt��dtttj
���t|��fdd�t|d�D��|r{�fd	d�t|d�D����|dfS�S)
aZConverts a string of text to a list of glyphs,
        optionally with cluster mapping,
        that can be used to render later using this scaled font.

        The output values can be readily passed to
        :meth:`Context.show_text_glyphs`, :meth:`Context.show_glyphs`
        or related methods,
        assuming that the exact same :class:`ScaledFont`
        is used for the operation.

        :type x: float
        :type y: float
        :type with_clusters: bool
        :param x: X position to place first glyph.
        :param y: Y position to place first glyph.
        :param text: The text to convert, as an Unicode or UTF-8 string.
        :param with_clusters: Whether to compute the cluster mapping.
        :returns:
            A ``(glyphs, clusters, clusters_flags)`` tuple
            if ``with_clusters`` is true, otherwise just ``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.

        zcairo_glyph_t **zint *zcairo_text_cluster_t **zcairo_text_cluster_flags_t *����cs$g|]}�|}|j|j|jf�qSr)�index�x�y)�.0�i�glyph)rprr�
<listcomp>cs
��z-ScaledFont.text_to_glyphs.<locals>.<listcomp>cs g|]}�|}|j|jf�qSr)�	num_bytes�
num_glyphs)rwrx�cluster)�clustersrrrzhs

��)
rrr!r� cairo_scaled_font_text_to_glyphsrrrr�cairo_glyph_free�cairo_text_cluster_freer�range)	rrurvrl�
with_clustersr|�num_clusters�
cluster_flags�statusr)r~rpr�text_to_glyphs-s8#


��

�

�zScaledFont.text_to_glyphs)NNN)r,r-r.r/rrGrr0r+rQrTrYr[r]rdrmrqr�rrrrrCes 

rCc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Ze
Ze	Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&S)'rFaTAn opaque object holding all options that are used when rendering fonts.

    Individual features of a :class:`FontOptions`
    can be set or accessed using method
    named ``set_FEATURE_NAME`` and ``get_FEATURE_NAME``,
    like :meth:`set_antialias` and :meth:`get_antialias`.

    New features may be added to :class:`FontOptions` in the future.
    For this reason, ``==``, :meth:`copy`, :meth:`merge`, and :func:`hash`
    should be used to check for equality copy,, merge,
    or compute a hash value of :class:`FontOptions` objects.

    :param values:
        Call the corresponding ``set_FEATURE_NAME`` methods
        after creating a new :class:`FontOptions`::

            options = FontOptions()
            options.set_antialias(cairocffi.ANTIALIAS_BEST)
            assert FontOptions(antialias=cairocffi.ANTIALIAS_BEST) == options

    cKs6|�t���|��D]
\}}t|d|�|�qdS)N�set_)rGr�cairo_font_options_create�items�getattr)r�values�name�valuerrrr�s�zFontOptions.__init__cCrr)rrrr�cairo_font_options_destroyrrrrrrrG�rzFontOptions._init_pointercCrr)rr�cairo_font_options_statusrrrrrr�rzFontOptions._check_statuscCs*t|�}t�|�}|�|t�|j��|S)z7Return a new :class:`FontOptions` with the same values.)�typer$r%rGr�cairo_font_options_copyr)r�cls�otherrrr�copy�s
zFontOptions.copycCs$t�|j|j�tt�|j��dS)z�Merges non-default options from ``other``,
        replacing existing values.
        This operation can be thought of as somewhat similar
        to compositing other onto options
        with the operation of :obj:`OVER <OPERATOR_OVER>`.

        N)r�cairo_font_options_mergerrr��rr�rrr�merge�szFontOptions.mergecCr;r)r�cairo_font_options_hashrrrrr�__hash__�szFontOptions.__hash__cCst�|j|j�Sr)r�cairo_font_options_equalrr�rrr�__eq__�szFontOptions.__eq__cCs
||kSrrr�rrr�__ne__�s
zFontOptions.__ne__cC�t�|j|�|��dS)z�Changes the :ref:`ANTIALIAS` for the font options object.
        This specifies the type of antialiasing to do when rendering text.

        N)r� cairo_font_options_set_antialiasrr)r�	antialiasrrr�
set_antialias�szFontOptions.set_antialiascCr;)z?Return the :ref:`ANTIALIAS` string for the font options object.)r� cairo_font_options_get_antialiasrrrrr�
get_antialias�r>zFontOptions.get_antialiascCr�)aChanges the :ref:`SUBPIXEL_ORDER` for the font options object.
         The subpixel order specifies the order of color elements
         within each pixel on the display device
         when rendering with an antialiasing mode of
         :obj:`SUBPIXEL <ANTIALIAS_SUBPIXEL>`.

        N)r�%cairo_font_options_set_subpixel_orderrr)r�subpixel_orderrrr�set_subpixel_order�s�zFontOptions.set_subpixel_ordercCr;)zVReturn the :ref:`SUBPIXEL_ORDER` string
        for the font options object.

        )r�%cairo_font_options_get_subpixel_orderrrrrr�get_subpixel_order��zFontOptions.get_subpixel_ordercCr�)z�Changes the :ref:`HINT_STYLE` for the font options object.
        This controls whether to fit font outlines to the pixel grid,
        and if so, whether to optimize for fidelity or contrast.

        N)r�!cairo_font_options_set_hint_stylerr)r�
hint_stylerrr�set_hint_style��zFontOptions.set_hint_stylecCr;)z@Return the :ref:`HINT_STYLE` string for the font options object.)r�!cairo_font_options_get_hint_stylerrrrr�get_hint_style�r>zFontOptions.get_hint_stylecCr�)z�Changes the :ref:`HINT_METRICS` for the font options object.
        This controls whether metrics are quantized
        to integer values in device units.

        N)r�#cairo_font_options_set_hint_metricsrr)r�hint_metricsrrr�set_hint_metrics�r�zFontOptions.set_hint_metricscCr;)zTReturn the :ref:`HINT_METRICS` string
        for the font options object.

        )r�#cairo_font_options_get_hint_metricsrrrrr�get_hint_metrics�r�zFontOptions.get_hint_metricscCs2|durtj}nt|�}t�|j|�|��dS)aSets the OpenType font variations for the font options object.

        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.*

        N)rr!rr�!cairo_font_options_set_variationsrr�r�
variationsrrr�set_variations�s
zFontOptions.set_variationscCs,t�|j�}|tjkrt�|��dd�SdS)aGets the OpenType font variations for the font options object.

        See :meth:`set_variations` for details about the
        string format.

        :return: the font variations for the font options object. The
          returned string belongs to the ``options`` and must not be modified.
          It is valid until either the font options object is destroyed or the
          font variations in this object is modified with
          :meth:`set_variations`.

        *New in cairo 1.16.*

        *New in cairocffi 0.9.*

        rr7N)r�!cairo_font_options_get_variationsrrr!r
r9r�rrr�get_variationss
�zFontOptions.get_variationsN)r,r-r.r/rrGrr�r�r�r�r��equal�hashr�r�r�r�r�r�r�r�r�r�rrrrrFqs,		rFN)r/r2rrrrrrXrrr$rr1�
FONT_TYPE_TOYr&rCrFrrrr�<module>s&$�