Gravity

Added in version 1.16.

class Gravity

PangoGravity represents the orientation of glyphs in a segment of text.

This is useful when rendering vertical text layouts. In those situations, the layout is rotated using a non-identity Matrix, and then glyph orientation is controlled using PangoGravity.

Not every value in this enumeration makes sense for every usage of PangoGravity; for example, AUTO only can be passed to set_base_gravity and can only be returned by get_base_gravity.

See also: GravityHint

Methods

class Gravity
get_for_matrix(matrix: Matrix | None = None) Gravity

Finds the gravity that best matches the rotation component in a PangoMatrix.

Added in version 1.16.

Parameters:

matrix – a PangoMatrix

get_for_script(script: Script, base_gravity: Gravity, hint: GravityHint) Gravity

Returns the gravity to use in laying out a PangoItem.

The gravity is determined based on the script, base gravity, and hint.

If base_gravity is AUTO, it is first replaced with the preferred gravity of script. To get the preferred gravity of a script, pass AUTO and STRONG in.

Added in version 1.16.

Parameters:
  • scriptPangoScript to query

  • base_gravity – base gravity of the paragraph

  • hint – orientation hint

get_for_script_and_width(script: Script, wide: bool, base_gravity: Gravity, hint: GravityHint) Gravity

Returns the gravity to use in laying out a single character or PangoItem.

The gravity is determined based on the script, East Asian width, base gravity, and hint,

This function is similar to get_for_script except that this function makes a distinction between narrow/half-width and wide/full-width characters also. Wide/full-width characters always stand upright, that is, they always take the base gravity, whereas narrow/full-width characters are always rotated in vertical context.

If base_gravity is AUTO, it is first replaced with the preferred gravity of script.

Added in version 1.26.

Parameters:
  • scriptPangoScript to query

  • wideTrue for wide characters as returned by unichar_iswide()

  • base_gravity – base gravity of the paragraph

  • hint – orientation hint

to_rotation(gravity: Gravity) float

Converts a PangoGravity value to its natural rotation in radians.

Note that rotate takes angle in degrees, not radians. So, to call Matrix,rotate with the output of this function you should multiply it by (180. / G_PI).

Added in version 1.16.

Parameters:

gravity – gravity to query, should not be AUTO

Fields

class Gravity
AUTO

Gravity is resolved from the context matrix

EAST

Glyphs are rotated 90 degrees counter-clockwise. <img align=”right” valign=”center” src=”m-east.png”>

NORTH

Glyphs are upside-down. <img align=”right” valign=”cener” src=”m-north.png”>

SOUTH

Glyphs stand upright (default) <img align=”right” valign=”center” src=”m-south.png”>

WEST

Glyphs are rotated 90 degrees clockwise. <img align=”right” valign=”center” src=”m-west.png”>