Module: PangoCairo

Defined in:
lib/pango/cairo-loader.rb,
lib/pango.rb

Overview

Copyright (C) 2017-2021 Ruby-GNOME Project Team

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Defined Under Namespace

Modules: Font, FontMap Classes: Loader

Instance Method Summary collapse

Instance Method Details

#context_get_font_options(context) ⇒ cairo::FontOptions

Retrieves any font rendering options previously set with
[funcPangoCairo.context_set_font_options].

This function does not report options that are derived from
the target surface by [funcupdate_context].

Parameters:

  • context (Pango::Context)

    a PangoContext, from a pangocairo font map

Returns:

  • (cairo::FontOptions)

    the font options previously set on the
    context, or nil if no options have been set. This value is
    owned by the context and must not be modified or freed.

#context_get_resolution(context) ⇒ Float

Gets the resolution for the context.

See [funcPangoCairo.context_set_resolution]

Parameters:

  • context (Pango::Context)

    a PangoContext, from a pangocairo font map

Returns:

  • (Float)

    the resolution in "dots per inch". A negative value will
    be returned if no resolution has previously been set.

#context_get_shape_renderer(context, data) ⇒ PangoCairo::ShapeRendererFunc

Sets callback function for context to use for rendering attributes
of type %PANGO_ATTR_SHAPE.

See PangoCairoShapeRendererFunc for details.

Retrieves callback function and associated user data for rendering
attributes of type %PANGO_ATTR_SHAPE as set by
[funcPangoCairo.context_set_shape_renderer], if any.

Parameters:

  • context (Pango::Context)

    a PangoContext, from a pangocairo font map

  • data (GObject)

    Pointer to gpointer to return user data

Returns:

  • (PangoCairo::ShapeRendererFunc)

    the shape rendering callback
    previously set on the context, or nil if no shape rendering callback
    have been set.

#context_set_font_options(context, options) ⇒ nil

Sets the font options used when rendering text with this context.

These options override any options that [funcupdate_context]
derives from the target surface.

Parameters:

  • context (Pango::Context)

    a PangoContext, from a pangocairo font map

  • options (cairo::FontOptions)

    a cairo_font_options_t, or nil to unset
    any previously set options. A copy is made.

Returns:

  • (nil)

#context_set_resolution(context, dpi) ⇒ nil

Sets the resolution for the context.

This is a scale factor between points specified in a PangoFontDescription
and Cairo units. The default value is 96, meaning that a 10 point font will
be 13 units high. (10 * 96. / 72. = 13.3).

Parameters:

  • context (Pango::Context)

    a PangoContext, from a pangocairo font map

  • dpi (Float)

    the resolution in "dots per inch". (Physical inches aren't actually
    involved; the terminology is conventional.) A 0 or negative value
    means to use the resolution from the font map.

Returns:

  • (nil)

#context_set_shape_renderer(context, func, data, dnotify) ⇒ nil

Sets callback function for context to use for rendering attributes
of type %PANGO_ATTR_SHAPE.

See PangoCairoShapeRendererFunc for details.

Parameters:

  • context (Pango::Context)

    a PangoContext, from a pangocairo font map

  • func (PangoCairo::ShapeRendererFunc)

    Callback function for rendering attributes of
    type %PANGO_ATTR_SHAPE, or nil to disable shape rendering.

  • data (GObject)

    User data that will be passed to func.

  • dnotify (GLib::DestroyNotify)

    Callback that will be called when the
    context is freed to release data

Returns:

  • (nil)

#create_context(cr) ⇒ Pango::Context

Creates a context object set up to match the current transformation
and target surface of the Cairo context.

This context can then be
used to create a layout using [ctorPango.Layout.new].

This function is a convenience function that creates a context using
the default font map, then updates it to cr. If you just need to
create a layout for use with cr and do not need to access PangoContext
directly, you can use [funccreate_layout] instead.

Parameters:

  • cr (cairo::Context)

    a Cairo context

Returns:

#create_layout(cr) ⇒ Pango::Layout

Creates a layout object set up to match the current transformation
and target surface of the Cairo context.

This layout can then be used for text measurement with functions
like [methodPango.Layout.get_size] or drawing with functions like
[funcshow_layout]. If you change the transformation or target
surface for cr, you need to call [funcupdate_layout].

This function is the most convenient way to use Cairo with Pango,
however it is slightly inefficient since it creates a separate
PangoContext object for each layout. This might matter in an
application that was laying out large amounts of text.

Parameters:

  • cr (cairo::Context)

    a Cairo context

Returns:

#error_underline_path(cr, x, y, width, height) ⇒ nil

Add a squiggly line to the current path in the specified cairo context that
approximately covers the given rectangle in the style of an underline used
to indicate a spelling error.

The width of the underline is rounded to an integer number of up/down
segments and the resulting rectangle is centered in the original rectangle.

Parameters:

  • cr (cairo::Context)

    a Cairo context

  • x (Float)

    The X coordinate of one corner of the rectangle

  • y (Float)

    The Y coordinate of one corner of the rectangle

  • width (Float)

    Non-negative width of the rectangle

  • height (Float)

    Non-negative height of the rectangle

Returns:

  • (nil)

#font_map_get_defaultPango::FontMap

Gets a default PangoCairoFontMap to use with Cairo.

Note that the type of the returned object will depend on the
particular font backend Cairo was compiled to use; you generally
should only use the PangoFontMap and PangoCairoFontMap
interfaces on the returned object.

The default Cairo fontmap can be changed by using
[methodPangoCairo.FontMap.set_default]. This can be used to
change the Cairo font backend that the default fontmap uses
for example.

Note that since Pango 1.32.6, the default fontmap is per-thread.
Each thread gets its own default fontmap. In this way, PangoCairo
can be used safely from multiple threads.

Returns:

  • (Pango::FontMap)

    the default PangoCairo fontmap
    for the current thread. This object is owned by Pango and must
    not be freed.

#font_map_newPango::FontMap

Creates a new PangoCairoFontMap object.

A fontmap is used to cache information about available fonts,
and holds certain global parameters such as the resolution.
In most cases, you can use `funcPangoCairo.font_map_get_default]
instead.

Note that the type of the returned object will depend
on the particular font backend Cairo was compiled to use;
You generally should only use the PangoFontMap and
PangoCairoFontMap interfaces on the returned object.

You can override the type of backend returned by using an
environment variable %PANGOCAIRO_BACKEND. Supported types,
based on your build, are fc (fontconfig), win32, and coretext.
If requested type is not available, NULL is returned. Ie.
this is only useful for testing, when at least two backends
are compiled in.

Returns:

  • (Pango::FontMap)

    the newly allocated PangoFontMap,
    which should be freed with g_object_unref().

#font_map_new_for_font_type(fonttype) ⇒ Pango::FontMap

Creates a new PangoCairoFontMap object of the type suitable
to be used with cairo font backend of type fonttype.

In most cases one should simply use [funcPangoCairo.FontMap.new], or
in fact in most of those cases, just use [funcPangoCairo.FontMap.get_default].

Parameters:

  • fonttype (cairo::FontType)

    desired #cairo_font_type_t

Returns:

  • (Pango::FontMap)

    the newly allocated
    PangoFontMap of suitable type which should be freed with
    g_object_unref(), or nil if the requested cairo font backend
    is not supported / compiled in.

#glyph_string_path(cr, font, glyphs) ⇒ nil

Adds the glyphs in glyphs to the current path in the specified
cairo context.

The origin of the glyphs (the left edge of the baseline)
will be at the current point of the cairo context.

Parameters:

  • cr (cairo::Context)

    a Cairo context

  • font (Pango::Font)

    a PangoFont from a PangoCairoFontMap

  • glyphs (Pango::GlyphString)

    a PangoGlyphString

Returns:

  • (nil)

#layout_line_path(cr, line) ⇒ nil

Adds the text in PangoLayoutLine to the current path in the
specified cairo context.

The origin of the glyphs (the left edge of the line) will be
at the current point of the cairo context.

Parameters:

  • cr (cairo::Context)

    a Cairo context

  • line (Pango::LayoutLine)

    a PangoLayoutLine

Returns:

  • (nil)

#layout_path(cr, layout) ⇒ nil

Adds the text in a PangoLayout to the current path in the
specified cairo context.

The top-left corner of the PangoLayout will be at the
current point of the cairo context.

Parameters:

  • cr (cairo::Context)

    a Cairo context

  • layout (Pango::Layout)

    a Pango layout

Returns:

  • (nil)

#show_error_underline(cr, x, y, width, height) ⇒ nil

Draw a squiggly line in the specified cairo context that approximately
covers the given rectangle in the style of an underline used to indicate a
spelling error.

The width of the underline is rounded to an integer
number of up/down segments and the resulting rectangle is centered in the
original rectangle.

Parameters:

  • cr (cairo::Context)

    a Cairo context

  • x (Float)

    The X coordinate of one corner of the rectangle

  • y (Float)

    The Y coordinate of one corner of the rectangle

  • width (Float)

    Non-negative width of the rectangle

  • height (Float)

    Non-negative height of the rectangle

Returns:

  • (nil)

#show_glyph_item(cr, text, glyph_item) ⇒ nil

Draws the glyphs in glyph_item in the specified cairo context,

embedding the text associated with the glyphs in the output if the
output format supports it (PDF for example), otherwise it acts
similar to [funcshow_glyph_string].

The origin of the glyphs (the left edge of the baseline) will
be drawn at the current point of the cairo context.

Note that text is the start of the text for layout, which is then
indexed by glyph_item->item->offset.

Parameters:

  • cr (cairo::Context)

    a Cairo context

  • text (String)

    the UTF-8 text that glyph_item refers to

  • glyph_item (Pango::GlyphItem)

    a PangoGlyphItem

Returns:

  • (nil)

#show_glyph_string(cr, font, glyphs) ⇒ nil

Draws the glyphs in glyphs in the specified cairo context.

The origin of the glyphs (the left edge of the baseline) will
be drawn at the current point of the cairo context.

Parameters:

  • cr (cairo::Context)

    a Cairo context

  • font (Pango::Font)

    a PangoFont from a PangoCairoFontMap

  • glyphs (Pango::GlyphString)

    a PangoGlyphString

Returns:

  • (nil)

#show_layout(cr, layout) ⇒ nil

Draws a PangoLayout in the specified cairo context.

The top-left corner of the PangoLayout will be drawn
at the current point of the cairo context.

Parameters:

  • cr (cairo::Context)

    a Cairo context

  • layout (Pango::Layout)

    a Pango layout

Returns:

  • (nil)

#show_layout_line(cr, line) ⇒ nil

Draws a PangoLayoutLine in the specified cairo context.

The origin of the glyphs (the left edge of the line) will
be drawn at the current point of the cairo context.

Parameters:

  • cr (cairo::Context)

    a Cairo context

  • line (Pango::LayoutLine)

    a PangoLayoutLine

Returns:

  • (nil)

#update_context(cr, context) ⇒ nil

Updates a PangoContext previously created for use with Cairo to
match the current transformation and target surface of a Cairo
context.

If any layouts have been created for the context, it's necessary
to call [methodPango.Layout.context_changed] on those layouts.

Parameters:

  • cr (cairo::Context)

    a Cairo context

  • context (Pango::Context)

    a PangoContext, from a pangocairo font map

Returns:

  • (nil)

#update_layout(cr, layout) ⇒ nil

Updates the private PangoContext of a PangoLayout created with
[funccreate_layout] to match the current transformation and target
surface of a Cairo context.

Parameters:

  • cr (cairo::Context)

    a Cairo context

  • layout (Pango::Layout)

    a PangoLayout, from [funccreate_layout]

Returns:

  • (nil)