Contexts: Pango Reference Manual

## Contexts Contexts — Global context object |

## Functions

PangoContext * | pango_context_new ()
void | pango_context_changed ()
guint | pango_context_get_serial ()
void | pango_context_set_font_map ()
PangoFontMap * | pango_context_get_font_map ()
PangoFontDescription * | pango_context_get_font_description ()
void | pango_context_set_font_description ()
PangoLanguage * | pango_context_get_language ()
void | pango_context_set_language ()
PangoDirection | pango_context_get_base_dir ()
void | pango_context_set_base_dir ()
PangoGravity | pango_context_get_base_gravity ()
void | pango_context_set_base_gravity ()
PangoGravity | pango_context_get_gravity ()
PangoGravityHint | pango_context_get_gravity_hint ()
void | pango_context_set_gravity_hint ()
const PangoMatrix * | pango_context_get_matrix ()
void | pango_context_set_matrix ()
gboolean | pango_context_get_round_glyph_positions ()
void | pango_context_set_round_glyph_positions ()
PangoFont * | pango_context_load_font ()
PangoFontset * | pango_context_load_fontset ()
PangoFontMetrics * | pango_context_get_metrics ()
void | pango_context_list_families ()

## Types and Values

| PangoContext

## Object Hierarchy

        GObject
        ╰── PangoContext

## Description

The PangoContext structure stores global information influencing Pango's operation, such as the fontmap used to look up fonts, and default values such as the default language, default gravity, or default font.

## Functions

### pango_context_new ()

    PangoContext *
    pango_context_new (void);

Creates a new PangoContext initialized to default values.

This function is not particularly useful as it should always be followed by a `pango_context_set_font_map()` call, and the function `pango_font_map_create_context()` does these two steps together and hence users are recommended to use that.

If you are using Pango as part of a higher-level system, that system may have it's own way of create a PangoContext. For instance, the GTK+ toolkit has, among others, `gdk_pango_context_get_for_screen()`, and `gtk_widget_get_pango_context()`. Use those instead.

#### Returns

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

### pango_context_changed ()

    void
    pango_context_changed (PangoContext *context);

Forces a change in the context, which will cause any PangoLayout using this context to re-layout.

This function is only useful when implementing a new backend for Pango, something applications won't do. Backends should call this function if they have attached extra data to the context and such data is changed.

#### Parameters

context | a PangoContext |

Since: 1.32.4

### pango_context_get_serial ()

    guint
    pango_context_get_serial (PangoContext *context);

Returns the current serial number of `context` . The serial number is initialized to an small number larger than zero when a new context is created and is increased whenever the context is changed using any of the setter functions, or the PangoFontMap it uses to find fonts has changed. The serial may wrap, but will never have the value 0. Since it can wrap, never compare it with "less than", always use "not equals".

This can be used to automatically detect changes to a PangoContext, and is only useful when implementing objects that need update when their PangoContext changes, like PangoLayout.

#### Parameters

context | a PangoContext |

#### Returns

The current serial number of `context` .

Since: 1.32.4

### pango_context_set_font_map ()

    void
    pango_context_set_font_map (PangoContext *context,
                                PangoFontMap *font_map);

Sets the font map to be searched when fonts are looked-up in this context. This is only for internal use by Pango backends, a PangoContext obtained via one of the recommended methods should already have a suitable font map.

#### Parameters

context | a PangoContext |
font_map | the PangoFontMap to set. |

### pango_context_get_font_map ()

    PangoFontMap *
    pango_context_get_font_map (PangoContext *context);

Gets the PangoFontMap used to look up fonts for this context.

#### Parameters

context | a PangoContext |

#### Returns

the font map for the PangoContext. This value is owned by Pango and should not be unreferenced.

[transfer none]

Since: 1.6

### pango_context_get_font_description ()

    PangoFontDescription *
    pango_context_get_font_description (PangoContext *context);

Retrieve the default font description for the context.

#### Parameters

context | a PangoContext |

#### Returns

a pointer to the context's default font description. This value must not be modified or freed.

[transfer none]

### pango_context_set_font_description ()

    void
    pango_context_set_font_description (PangoContext *context,
                                        const PangoFontDescription *desc);

Set the default font description for the context

#### Parameters

context | a PangoContext |
desc | the new pango font description |

### pango_context_get_language ()

    PangoLanguage *
    pango_context_get_language (PangoContext *context);

Retrieves the global language tag for the context.

#### Parameters

context | a PangoContext |

#### Returns

the global language tag.

### pango_context_set_language ()

    void
    pango_context_set_language (PangoContext *context,
                                PangoLanguage *language);

Sets the global language tag for the context. The default language for the locale of the running process can be found using `pango_language_get_default()`.

#### Parameters

context | a PangoContext |
language | the new language tag. |

### pango_context_get_base_dir ()

    PangoDirection
    pango_context_get_base_dir (PangoContext *context);

Retrieves the base direction for the context. See `pango_context_set_base_dir()`.

#### Parameters

context | a PangoContext |

#### Returns

the base direction for the context.

### pango_context_set_base_dir ()

    void
    pango_context_set_base_dir (PangoContext *context,
                                PangoDirection direction);

Sets the base direction for the context.

The base direction is used in applying the Unicode bidirectional algorithm; if the `direction` is `PANGO_DIRECTION_LTR` or `PANGO_DIRECTION_RTL`, then the value will be used as the paragraph direction in the Unicode bidirectional algorithm. A value of `PANGO_DIRECTION_WEAK_LTR` or `PANGO_DIRECTION_WEAK_RTL` is used only for paragraphs that do not contain any strong characters themselves.

#### Parameters

context | a PangoContext |
direction | the new base direction |

### pango_context_get_base_gravity ()

    PangoGravity
    pango_context_get_base_gravity (PangoContext *context);

Retrieves the base gravity for the context. See `pango_context_set_base_gravity()`.

#### Parameters

context | a PangoContext |

#### Returns

the base gravity for the context.

Since: 1.16

### pango_context_set_base_gravity ()

    void
    pango_context_set_base_gravity (PangoContext *context,
                                    PangoGravity gravity);

Sets the base gravity for the context.

The base gravity is used in laying vertical text out.

#### Parameters

context | a PangoContext |
gravity | the new base gravity |

Since: 1.16

### pango_context_get_gravity ()

    PangoGravity
    pango_context_get_gravity (PangoContext *context);

Retrieves the gravity for the context. This is similar to `pango_context_get_base_gravity()`, except for when the base gravity is `PANGO_GRAVITY_AUTO` for which `pango_gravity_get_for_matrix()` is used to return the gravity from the current context matrix.

#### Parameters

context | a PangoContext |

#### Returns

the resolved gravity for the context.

Since: 1.16

### pango_context_get_gravity_hint ()

    PangoGravityHint
    pango_context_get_gravity_hint (PangoContext *context);

Retrieves the gravity hint for the context. See `pango_context_set_gravity_hint()` for details.

#### Parameters

context | a PangoContext |

#### Returns

the gravity hint for the context.

Since: 1.16

### pango_context_set_gravity_hint ()

    void
    pango_context_set_gravity_hint (PangoContext *context,
                                    PangoGravityHint hint);

Sets the gravity hint for the context.

The gravity hint is used in laying vertical text out, and is only relevant if gravity of the context as returned by `pango_context_get_gravity()` is set `PANGO_GRAVITY_EAST` or `PANGO_GRAVITY_WEST`.

#### Parameters

context | a PangoContext |
hint | the new gravity hint |

Since: 1.16

### pango_context_get_matrix ()

    const PangoMatrix *
    pango_context_get_matrix (PangoContext *context);

Gets the transformation matrix that will be applied when rendering with this context. See `pango_context_set_matrix()`.

#### Parameters

context | a PangoContext |

#### Returns

the matrix, or `NULL` if no matrix has been set (which is the same as the identity matrix). The returned matrix is owned by Pango and must not be modified or freed.

[nullable]

Since: 1.6

### pango_context_set_matrix ()

    void
    pango_context_set_matrix (PangoContext *context,
                              const PangoMatrix *matrix);

Sets the transformation matrix that will be applied when rendering with this context. Note that reported metrics are in the user space coordinates before the application of the matrix, not device-space coordinates after the application of the matrix. So, they don't scale with the matrix, though they may change slightly for different matrices, depending on how the text is fit to the pixel grid.

#### Parameters

context | a PangoContext |
matrix | a PangoMatrix, or `NULL` to unset any existing matrix. (No matrix set is the same as setting the identity matrix.). | [allow-none]

Since: 1.6

### pango_context_get_round_glyph_positions ()

    gboolean
    pango_context_get_round_glyph_positions
                                   (PangoContext *context);

Returns whether font rendering with this context should round glyph positions and widths.

#### Parameters

context | a PangoContext |

Since: 1.44

### pango_context_set_round_glyph_positions ()

    void
    pango_context_set_round_glyph_positions
                                   (PangoContext *context,
                                    gboolean round_positions);

Sets whether font rendering with this context should round glyph positions and widths to integral positions, in device units.

This is useful when the renderer can't handle subpixel positioning of glyphs.

The default value is to round glyph positions, to remain compatible with previous Pango behavior.

#### Parameters

context | a PangoContext |
round_positions | whether to round glyph positions |

Since: 1.44

### pango_context_load_font ()

    PangoFont *
    pango_context_load_font (PangoContext *context,
                             const PangoFontDescription *desc);

Loads the font in one of the fontmaps in the context that is the closest match for `desc` .

#### Parameters

context | a PangoContext |
desc | a PangoFontDescription describing the font to load |

#### Returns

the newly allocated PangoFont that was loaded, or `NULL` if no font matched.

[transfer full][nullable]

### pango_context_load_fontset ()

    PangoFontset *
    pango_context_load_fontset (PangoContext *context,
                                const PangoFontDescription *desc,
                                PangoLanguage *language);

Load a set of fonts in the context that can be used to render a font matching `desc` .

#### Parameters

context | a PangoContext |
desc | a PangoFontDescription describing the fonts to load |
language | a PangoLanguage the fonts will be used for |

#### Returns

the newly allocated PangoFontset loaded, or `NULL` if no font matched.

[transfer full][nullable]

### pango_context_get_metrics ()

    PangoFontMetrics *
    pango_context_get_metrics (PangoContext *context,
                               const PangoFontDescription *desc,
                               PangoLanguage *language);

Get overall metric information for a particular font description. Since the metrics may be substantially different for different scripts, a language tag can be provided to indicate that the metrics should be retrieved that correspond to the script(s) used by that language.

The PangoFontDescription is interpreted in the same way as by `pango_itemize()`, and the family name may be a comma separated list of figures. If characters from multiple of these families would be used to render the string, then the returned fonts would be a composite of the metrics for the fonts loaded for the individual families.

#### Parameters

context | a PangoContext |
desc | a PangoFontDescription structure. `NULL` means that the font description from the context will be used. | [allow-none]
language | language tag used to determine which script to get the metrics for. `NULL` means that the language tag from the context will be used. If no language tag is set on the context, metrics for the default language (as determined by `pango_language_get_default()`) will be returned. | [allow-none]

#### Returns

a PangoFontMetrics object. The caller must call `pango_font_metrics_unref()` when finished using the object.

### pango_context_list_families ()

    void
    pango_context_list_families (PangoContext *context,
                                 PangoFontFamily ***families,
                                 int *n_families);

List all families for a context.

#### Parameters

context | a PangoContext |
families | location to store a pointer to an array of PangoFontFamily *. This array should be freed with `g_free()`. | [out][array length=n_families][transfer container]
n_families | location to store the number of elements in `descs` . | [out]

## Types and Values

### PangoContext

    typedef struct _PangoContext PangoContext;

The PangoContext structure stores global information used to control the itemization process.