Pango.Matrix

Fields

Name

Type

Access

Description

x0

float

r/w

x translation

xx

float

r/w

1st component of the transformation matrix

xy

float

r/w

2nd component of the transformation matrix

y0

float

r/w

y translation

yx

float

r/w

3rd component of the transformation matrix

yy

float

r/w

4th component of the transformation matrix

Methods

concat (new_matrix)

copy ()

free ()

get_font_scale_factor ()

get_font_scale_factors ()

get_slant_ratio ()

rotate (degrees)

scale (scale_x, scale_y)

transform_distance (dx, dy)

transform_pixel_rectangle (rect)

transform_point (x, y)

transform_rectangle (rect)

translate (tx, ty)

Details

class Pango.Matrix

A PangoMatrix specifies a transformation between user-space and device coordinates.

The transformation is given by

`` x_device = x_user * matrix->xx + y_user * matrix->xy + matrix->x0; y_device = x_user * matrix->yx + y_user * matrix->yy + matrix->y0; ``

New in version 1.6.

concat(new_matrix)[source]
Parameters:

new_matrix (Pango.Matrix) – a PangoMatrix

Changes the transformation represented by self to be the transformation given by first applying transformation given by new_matrix then applying the original transformation.

New in version 1.6.

copy()[source]
Returns:

the newly allocated PangoMatrix

Return type:

Pango.Matrix or None

Copies a PangoMatrix.

New in version 1.6.

free()[source]

Free a PangoMatrix.

New in version 1.6.

get_font_scale_factor()[source]
Returns:

the scale factor of self on the height of the font, or 1.0 if self is None.

Return type:

float

Returns the scale factor of a matrix on the height of the font.

That is, the scale factor in the direction perpendicular to the vector that the X coordinate is mapped to. If the scale in the X coordinate is needed as well, use [method`Pango`.Matrix.get_font_scale_factors].

New in version 1.12.

get_font_scale_factors()[source]
Returns:

xscale:

output scale factor in the x direction

yscale:

output scale factor perpendicular to the x direction

Return type:

(xscale: float, yscale: float)

Calculates the scale factor of a matrix on the width and height of the font.

That is, xscale is the scale factor in the direction of the X coordinate, and yscale is the scale factor in the direction perpendicular to the vector that the X coordinate is mapped to.

Note that output numbers will always be non-negative.

New in version 1.38.

get_slant_ratio()[source]
Returns:

the slant ratio of self

Return type:

float

Gets the slant ratio of a matrix.

For a simple shear matrix in the form:

1 λ 0 1

this is simply λ.

New in version 1.50.

rotate(degrees)[source]
Parameters:

degrees (float) – degrees to rotate counter-clockwise

Changes the transformation represented by self to be the transformation given by first rotating by degrees degrees counter-clockwise then applying the original transformation.

New in version 1.6.

scale(scale_x, scale_y)[source]
Parameters:
  • scale_x (float) – amount to scale by in X direction

  • scale_y (float) – amount to scale by in Y direction

Changes the transformation represented by self to be the transformation given by first scaling by sx in the X direction and sy in the Y direction then applying the original transformation.

New in version 1.6.

transform_distance(dx, dy)[source]
Parameters:
  • dx (float) – in/out X component of a distance vector

  • dy (float) – in/out Y component of a distance vector

Returns:

dx:

in/out X component of a distance vector

dy:

in/out Y component of a distance vector

Return type:

(dx: float, dy: float)

Transforms the distance vector (dx,`dy`) by self.

This is similar to [method`Pango`.Matrix.transform_point], except that the translation components of the transformation are ignored. The calculation of the returned vector is as follows:

`` dx2 = dx1 * xx + dy1 * xy; dy2 = dx1 * yx + dy1 * yy; ``

Affine transformations are position invariant, so the same vector always transforms to the same vector. If (x1,`y1`) transforms to (x2,`y2`) then (x1+`dx1`,`y1`+`dy1`) will transform to (x1+`dx2`,`y1`+`dy2`) for all values of x1 and x2.

New in version 1.16.

transform_pixel_rectangle(rect)[source]
Parameters:

rect (Pango.Rectangle) – in/out bounding box in device units

Returns:

in/out bounding box in device units

Return type:

rect: Pango.Rectangle

First transforms the rect using self, then calculates the bounding box of the transformed rectangle.

This function is useful for example when you want to draw a rotated PangoLayout to an image buffer, and want to know how large the image should be and how much you should shift the layout when rendering.

For better accuracy, you should use [method`Pango`.Matrix.transform_rectangle] on original rectangle in Pango units and convert to pixels afterward using [func`extents_to_pixels`]’s first argument.

New in version 1.16.

transform_point(x, y)[source]
Parameters:
  • x (float) – in/out X position

  • y (float) – in/out Y position

Returns:

x:

in/out X position

y:

in/out Y position

Return type:

(x: float, y: float)

Transforms the point (x, y) by self.

New in version 1.16.

transform_rectangle(rect)[source]
Parameters:

rect (Pango.Rectangle) – in/out bounding box in Pango units

Returns:

in/out bounding box in Pango units

Return type:

rect: Pango.Rectangle

First transforms rect using self, then calculates the bounding box of the transformed rectangle.

This function is useful for example when you want to draw a rotated PangoLayout to an image buffer, and want to know how large the image should be and how much you should shift the layout when rendering.

If you have a rectangle in device units (pixels), use [method`Pango`.Matrix.transform_pixel_rectangle].

If you have the rectangle in Pango units and want to convert to transformed pixel bounding box, it is more accurate to transform it first (using this function) and pass the result to Pango.extents_to_pixels(), first argument, for an inclusive rounded rectangle. However, there are valid reasons that you may want to convert to pixels first and then transform, for example when the transformed coordinates may overflow in Pango units (large matrix translation for example).

New in version 1.16.

translate(tx, ty)[source]
Parameters:
  • tx (float) – amount to translate in the X direction

  • ty (float) – amount to translate in the Y direction

Changes the transformation represented by self to be the transformation given by first translating by (tx, ty) then applying the original transformation.

New in version 1.6.