ScaledFontProtocol

public protocol ScaledFontProtocol

The ScaledFontProtocol protocol exposes the methods and properties of an underlying cairo_scaled_font_t instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see ScaledFont. Alternatively, use ScaledFontRef as a lighweight, unowned reference if you already have an instance you just want to use.

  • ptr

    Untyped pointer to the underlying cairo_scaled_font_t instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • _ptr Default implementation

    Typed pointer to the underlying cairo_scaled_font_t instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the cairo_scaled_font_t instance.

    Declaration

    Swift

    var _ptr: UnsafeMutablePointer<cairo_scaled_font_t>! { get }
  • Required Initialiser for types conforming to ScaledFontProtocol

    Declaration

    Swift

    init(raw: UnsafeMutableRawPointer)
  • ref() Extension method

    Increases the reference count on @scaled_font by one. This prevents @scaled_font from being destroyed until a matching call to unref() is made.

    The number of references to a #cairo_scaled_font_t can be get using referenceCount.

    Declaration

    Swift

    @discardableResult
    @inlinable
    func ref() -> ScaledFontRef
  • unref() Extension method

    Decreases the reference count on @font by one. If the result is zero, then @font and all associated resources are freed. See ref().

    Declaration

    Swift

    @inlinable
    func unref()
  • referenceCount Extension method

    Current reference count of @scaled_font.

    Declaration

    Swift

    @inlinable
    var referenceCount: Int { get }
  • type Extension method

    type of the backend used to create a scaled font. See #cairo_font_type_t for available types. However, this never returns %CAIRO_FONT_TYPE_TOY.

    Declaration

    Swift

    @inlinable
    var type: cairo_font_type_t { get }
  • extents Extension method

    Font extents for the receiver

    Declaration

    Swift

    @inlinable
    var extents: cairo_font_extents_t { get }
  • status Extension method

    Allows to check whether an error has previously occurred for this scaled_font.

    Return value: %CAIRO_STATUS_SUCCESS or another error such as %CAIRO_STATUS_NO_MEMORY.

    Declaration

    Swift

    @inlinable
    var status: cairo_status_t { get }
  • textExtents(_:) Extension method

    Gets the extents for a string of text. The extents describe a user-space rectangle that encloses the “inked” portion of the text drawn at the origin (0,0) (as it would be drawn by cairo.showText() if the cairo graphics state were set to the same font_face, font_matrix, ctm, and font_options as @scaled_font). Additionally, the x_advance and y_advance values indicate the amount by which the current point would be advanced by cairo.showText().

    Note that whitespace characters do not directly contribute to the size of the rectangle (extents.width and extents.height). They do contribute indirectly by changing the position of non-whitespace characters. In particular, trailing whitespace characters are likely to not affect the size of the rectangle, though they will affect the x_advance and y_advance values.

    Declaration

    Swift

    @inlinable
    func textExtents(_ text: UnsafePointer<CChar>) -> cairo_text_extents_t
  • glyphExtents(_:) Extension method

    Gets the extents for an array of glyphs. The extents describe a user-space rectangle that encloses the “inked” portion of the glyphs, (as they would be drawn by cairo.showGlyphs() if the cairo graphics state were set to the same font_face, font_matrix, ctm, and font_options as @scaled_font). Additionally, the x_advance and y_advance values indicate the amount by which the current point would be advanced by cairo.showGlyphs().

    Note that whitespace glyphs do not contribute to the size of the rectangle (extents.width and extents.height).

    Declaration

    Swift

    @inlinable
    func glyphExtents(_ glyphs: [cairo_glyph_t]) -> cairo_text_extents_t
  • textToGlyphs(_:x:y:) Extension method

    Converts UTF-8 text to an array of glyphs, optionally with cluster mapping, that can be used to render later using @scaled_font.

    If @glyphs initially points to a non-%NULL value, that array is used as a glyph buffer, and @num_glyphs should point to the number of glyph entries available there. If the provided glyph array is too short for the conversion, a new glyph array is allocated using cairo_glyph_allocate() and placed in @glyphs. Upon return, @num_glyphs always contains the number of generated glyphs. If the value @glyphs points to has changed after the call, the user is responsible for freeing the allocated glyph array using cairo_glyph_free(). This may happen even if the provided array was large enough.

    If @clusters is not %NULL, @num_clusters and @cluster_flags should not be %NULL, and cluster mapping will be computed. The semantics of how cluster array allocation works is similar to the glyph array. That is, if @clusters initially points to a non-%NULL value, that array is used as a cluster buffer, and @num_clusters should point to the number of cluster entries available there. If the provided cluster array is too short for the conversion, a new cluster array is allocated using cairo_text_cluster_allocate() and placed in @clusters. Upon return, @num_clusters always contains the number of generated clusters. If the value @clusters points at has changed after the call, the user is responsible for freeing the allocated cluster array using cairo_text_cluster_free(). This may happen even if the provided array was large enough.

    In the simplest case, @glyphs and @clusters can point to %NULL initially and a suitable array will be allocated. In code: cairo_status_t status;

    cairo_glyph_t ///glyphs = NULL; int num_glyphs; cairo_text_cluster_t ///clusters = NULL; int num_clusters; cairo_text_cluster_flags_t cluster_flags;

    status = cairo_scaled_font_text_to_glyphs (scaled_font, x, y, utf8, utf8_len, &glyphs, &num_glyphs, &clusters, &num_clusters, &cluster_flags);

    if (status == CAIRO_STATUS_SUCCESS) { cairo_show_text_glyphs (cr, utf8, utf8_len, glyphs, num_glyphs, clusters, num_clusters, cluster_flags);

    cairo_glyph_free (glyphs);
    cairo_text_cluster_free (clusters);
    

    }

    If no cluster mapping is needed: cairo_status_t status;

    cairo_glyph_t ///glyphs = NULL; int num_glyphs;

    status = cairo_scaled_font_text_to_glyphs (scaled_font, x, y, utf8, utf8_len, &glyphs, &num_glyphs, NULL, NULL, NULL);

    if (status == CAIRO_STATUS_SUCCESS) { cairo_show_glyphs (cr, glyphs, num_glyphs); cairo_glyph_free (glyphs); }

    If stack-based glyph and cluster arrays are to be used for small arrays: cairo_status_t status;

    cairo_glyph_t stack_glyphs[40]; cairo_glyph_t ///glyphs = stack_glyphs; int num_glyphs = sizeof (stack_glyphs) / sizeof (stack_glyphs[0]); cairo_text_cluster_t stack_clusters[40]; cairo_text_cluster_t ///clusters = stack_clusters; int num_clusters = sizeof (stack_clusters) / sizeof (stack_clusters[0]); cairo_text_cluster_flags_t cluster_flags;

    status = cairo_scaled_font_text_to_glyphs (scaled_font, x, y, utf8, utf8_len, &glyphs, &num_glyphs, &clusters, &num_clusters, &cluster_flags);

    if (status == CAIRO_STATUS_SUCCESS) { cairo_show_text_glyphs (cr, utf8, utf8_len, glyphs, num_glyphs, clusters, num_clusters, cluster_flags);

    if (glyphs != stack_glyphs)
        cairo_glyph_free (glyphs);
    if (clusters != stack_clusters)
        cairo_text_cluster_free (clusters);
    

    }

    For details of how @clusters, @num_clusters, and @cluster_flags map input UTF-8 text to the output glyphs see cairo_show_text_glyphs().

    The output values can be readily passed to cairo_show_text_glyphs() cairo_show_glyphs(), or related functions, assuming that the exact same @scaled_font is used for the operation.

    Return value: %CAIRO_STATUS_SUCCESS upon success, or an error status if the input values are wrong or if conversion failed. If the input values are correct but the conversion failed, the error status is also set on @scaled_font.

    Declaration

    Swift

    @inlinable
    func textToGlyphs(_ text: String, x: Double = 0, y: Double = 0) -> (glyphs: [cairo_glyph_t], clusters: [cairo_text_cluster_t], flags: cairo_text_cluster_flags_t)?
  • fontFace Extension method

    the font face that this scaled font uses. This might be the font face passed to cairo_scaled_font_create(), but this does not hold true for all possible cases.

    Declaration

    Swift

    @inlinable
    var fontFace: UnsafeMutablePointer<cairo_font_face_t> { get }