Skip to content

Pango.TabArray

record (struct)

A PangoTabArray contains an array of tab stops.

PangoTabArray can be used to set tab stops in a PangoLayout. Each tab stop has an alignment, a position, and optionally a character to use as decimal point.

Constructors

new

@classmethod
def new(cls, initial_size: int, positions_in_pixels: bool) -> TabArray

Creates an array of initial_size tab stops.

Tab stops are specified in pixel units if positions_in_pixels is True, otherwise in Pango units. All stops are initially at position 0.

Parameters:

  • initial_size — Initial number of tab stops to allocate, can be 0
  • positions_in_pixels — whether positions are in pixel units

Methods

copy

def copy(self) -> TabArray

Copies a PangoTabArray.

free

def free(self) -> None

Frees a tab array and associated resources.

get_decimal_point

def get_decimal_point(self, tab_index: int) -> str

Gets the Unicode character to use as decimal point.

This is only relevant for tabs with TabAlign.DECIMAL alignment, which align content at the first occurrence of the decimal point character.

The default value of 0 means that Pango will use the decimal point according to the current locale.

Parameters:

  • tab_index — the index of a tab stop

get_positions_in_pixels

def get_positions_in_pixels(self) -> bool

Returns True if the tab positions are in pixels, False if they are in Pango units.

get_size

def get_size(self) -> int

Gets the number of tab stops in tab_array.

get_tab

def get_tab(self, tab_index: int) -> tuple[TabAlign | int, int]

Gets the alignment and position of a tab stop.

Parameters:

  • tab_index — tab stop index

get_tabs

def get_tabs(self) -> tuple[TabAlign | int, list[int]]

If non-None, alignments and locations are filled with allocated arrays.

The arrays are of length TabArray.get_size. You must free the returned array.

resize

def resize(self, new_size: int) -> None

Resizes a tab array.

You must subsequently initialize any tabs that were added as a result of growing the array.

Parameters:

  • new_size — new size of the array

set_decimal_point

def set_decimal_point(self, tab_index: int, decimal_point: str) -> None

Sets the Unicode character to use as decimal point.

This is only relevant for tabs with TabAlign.DECIMAL alignment, which align content at the first occurrence of the decimal point character.

By default, Pango uses the decimal point according to the current locale.

Parameters:

  • tab_index — the index of a tab stop
  • decimal_point — the decimal point to use

set_positions_in_pixels

def set_positions_in_pixels(self, positions_in_pixels: bool) -> None

Sets whether positions in this array are specified in pixels.

Parameters:

  • positions_in_pixels — whether positions are in pixels

set_tab

def set_tab(self, tab_index: int, alignment: TabAlign | int, location: int) -> None

Sets the alignment and location of a tab stop.

Parameters:

  • tab_index — the index of a tab stop
  • alignment — tab alignment
  • location — tab location in Pango units

sort

def sort(self) -> None

Utility function to ensure that the tab stops are in increasing order.

to_string

def to_string(self) -> str

Serializes a PangoTabArray to a string.

In the resulting string, serialized tabs are separated by newlines or commas.

Individual tabs are serialized to a string of the form

[ALIGNMENT:]POSITION[:DECIMAL_POINT]

Where ALIGNMENT is one of left, right, center or decimal, and POSITION is the position of the tab, optionally followed by the unit px. If ALIGNMENT is omitted, it defaults to left. If ALIGNMENT is decimal, the DECIMAL_POINT character may be specified as a Unicode codepoint.

Note that all tabs in the array must use the same unit.

A typical example:

100px 200px center:300px right:400px

Static functions

from_string

@staticmethod
def from_string(text: str) -> TabArray | None

Deserializes a PangoTabArray from a string.

This is the counterpart to TabArray.to_string. See that functions for details about the format.

Parameters:

  • text — a string