Pango¶
API reference for the Pango namespace (version 1.0), generated from GObject-Introspection.
Classes¶
- Analysis — The
PangoAnalysisstructure stores information about the properties of a segment of text. - AttrClass — The
PangoAttrClassstructure stores the type and operations for a particular type of attribute. The functions in this structure should… - AttrColor — The
PangoAttrColorstructure is used to represent attributes that are colors. - AttrFloat — The
PangoAttrFloatstructure is used to represent attributes with a float or double value. - AttrFontDesc — The
PangoAttrFontDescstructure is used to store an attribute that sets all aspects of the font description at once. - AttrFontFeatures — The
PangoAttrFontFeaturesstructure is used to represent OpenType font features as an attribute. - AttrInt — The
PangoAttrIntstructure is used to represent attributes with an integer or enumeration value. - AttrIterator — A
PangoAttrIteratoris used to iterate through aPangoAttrList. A new iterator is created with AttrList.get_iterator. Once the iterator… - AttrLanguage — The
PangoAttrLanguagestructure is used to represent attributes that are languages. - AttrList — A
PangoAttrListrepresents a list of attributes that apply to a section of text. The attributes in aPangoAttrListare, in general,… - AttrShape — The
PangoAttrShapestructure is used to represent attributes which impose shape restrictions. - AttrSize — The
PangoAttrSizestructure is used to represent attributes which set font size. - AttrString — The
PangoAttrStringstructure is used to represent attributes with a string value. - Attribute — The
PangoAttributestructure represents the common portions of all attributes. Particular types of attributes include this structure as… - Color — The
PangoColorstructure is used to represent a color in an uncalibrated RGB color-space. - Context — A
PangoContextstores global information used to control the itemization process. The information stored byPangoContextincludes the… - ContextClass
- Coverage — A
PangoCoveragestructure is a map from Unicode characters to CoverageLevel values. It is often necessary in Pango to determine if a… - Font — A
PangoFontis used to represent a font in a rendering-system-independent manner. - FontClass
- FontDescription — A
PangoFontDescriptiondescribes a font in an implementation-independent manner.PangoFontDescriptionstructures are used both to list… - FontFace — A
PangoFontFaceis used to represent a group of fonts with the same family, slant, weight, and width, but varying sizes. - FontFaceClass
- FontFamily — A
PangoFontFamilyis used to represent a family of related font faces. The font faces in a family share a common design, but differ in… - FontFamilyClass
- FontMap — A
PangoFontMaprepresents the set of fonts available for a particular rendering system. This is a virtual object with implementations… - FontMapClass — The
PangoFontMapClassstructure holds the virtual functions for a particularPangoFontMapimplementation. - FontMetrics — A
PangoFontMetricsstructure holds the overall metric information for a font. The information in aPangoFontMetricsstructure may be… - Fontset — A
PangoFontsetrepresents a set ofPangoFontto use when rendering text. APangoFontsetis the result of resolving a… - FontsetClass — The
PangoFontsetClassstructure holds the virtual functions for a particularPangoFontsetimplementation. - FontsetSimple —
PangoFontsetSimpleis a implementation of the abstractPangoFontsetbase class as an array of fonts. When creating a… - FontsetSimpleClass
- GlyphGeometry — The
PangoGlyphGeometrystructure contains width and positioning information for a single glyph. Note thatwidthis not guaranteed to be… - GlyphInfo — A
PangoGlyphInfostructure represents a single glyph with positioning information and visual attributes. - GlyphItem — A
PangoGlyphItemis a pair of aPangoItemand the glyphs resulting from shaping the items text. As an example of the usage of… - GlyphItemIter — A
PangoGlyphItemIteris an iterator over the clusters in aPangoGlyphItem. The forward direction of the iterator is the logical… - GlyphString — A
PangoGlyphStringis used to store strings of glyphs with geometry and visual attribute information. The storage for the glyph… - GlyphVisAttr — A
PangoGlyphVisAttrstructure communicates information between the shaping and rendering phases. Currently, it contains cluster start and… - Item — The
PangoItemstructure stores information about a segment of text. You typically obtainPangoItemsby itemizing a piece of text with… - Language — The
PangoLanguagestructure is used to represent a language.PangoLanguagepointers can be efficiently copied and compared with each… - Layout — A
PangoLayoutstructure represents an entire paragraph of text. While complete access to the layout capabilities of Pango is provided… - LayoutClass
- LayoutIter — A
PangoLayoutItercan be used to iterate over the visual extents of aPangoLayout. To obtain aPangoLayoutIter, use Layout.get_iter.… - LayoutLine — A
PangoLayoutLinerepresents one of the lines resulting from laying out a paragraph viaPangoLayout.PangoLayoutLinestructures are… - LogAttr — The
PangoLogAttrstructure stores information about the attributes of a single character. - Matrix — A
PangoMatrixspecifies a transformation between user-space and device coordinates. The transformation is given by ``` x_device = x_user… - Rectangle — The
PangoRectanglestructure represents a rectangle.PangoRectangleis frequently used to represent the logical or ink extents of a… - Renderer —
PangoRendereris a base class for objects that can render text provided asPangoGlyphStringorPangoLayout. By subclassing… - RendererClass — Class structure for
PangoRenderer. The following vfuncs take user space coordinates in Pango units and have default implementations: -… - RendererPrivate
- ScriptIter — A
PangoScriptIteris used to iterate through a string and identify ranges in different scripts. - TabArray — A
PangoTabArraycontains an array of tab stops.PangoTabArraycan be used to set tab stops in aPangoLayout. Each tab stop has an…
Functions¶
attr_allow_breaks_new¶
Create a new allow-breaks attribute.
If breaks are disabled, the range will be kept in a single run, as far as possible.
Parameters:
allow_breaks—Trueif we line breaks are allowed
attr_background_alpha_new¶
Create a new background alpha attribute.
Parameters:
alpha— the alpha value, between 1 and 65536
attr_background_new¶
Create a new background color attribute.
Parameters:
red— the red value (ranging from 0 to 65535)green— the green valueblue— the blue value
attr_baseline_shift_new¶
Create a new baseline displacement attribute.
The effect of this attribute is to shift the baseline of a run, relative to the run of preceding run.
<picture> <source srcset="baseline-shift-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Baseline Shift" src="baseline-shift-light.png"> </picture>
Parameters:
shift— either aPangoBaselineShiftenumeration value or an absolute value (> 1024) in Pango units, relative to the baseline of the previous run. Positive values displace the text upwards.
attr_break¶
Apply customization from attributes to the breaks in attrs.
The line breaks are assumed to have been produced
by default_break and tailor_break.
Parameters:
text— text to break. Must be valid UTF-8length— length of text in bytes (may be -1 iftextis nul-terminated)attr_list—PangoAttrListto applyoffset— Byte offset oftextfrom the beginning of the paragraph
attr_fallback_new¶
Create a new font fallback attribute.
If fallback is disabled, characters will only be used from the closest matching font on the system. No fallback will be done to other fonts on the system that might contain the characters in the text.
Parameters:
enable_fallback—Trueif we should fall back on other fonts for characters the active font is missing
attr_family_new¶
Create a new font family attribute.
Parameters:
family— the family or comma-separated list of families
attr_font_scale_new¶
Create a new font scale attribute.
The effect of this attribute is to change the font size of a run, relative to the size of preceding run.
Parameters:
scale— aPangoFontScalevalue, which indicates font size change relative to the size of the previous run.
attr_foreground_alpha_new¶
Create a new foreground alpha attribute.
Parameters:
alpha— the alpha value, between 1 and 65536
attr_foreground_new¶
Create a new foreground color attribute.
Parameters:
red— the red value (ranging from 0 to 65535)green— the green valueblue— the blue value
attr_gravity_hint_new¶
Create a new gravity hint attribute.
Parameters:
hint— the gravity hint value
attr_gravity_new¶
Create a new gravity attribute.
Parameters:
gravity— the gravity value; should not beGravity.AUTO
attr_insert_hyphens_new¶
Create a new insert-hyphens attribute.
Pango will insert hyphens when breaking lines in the middle of a word. This attribute can be used to suppress the hyphen.
Parameters:
insert_hyphens—Trueif hyphens should be inserted
attr_letter_spacing_new¶
Create a new letter-spacing attribute.
Parameters:
letter_spacing— amount of extra space to add between graphemes of the text, in Pango units
attr_line_height_new¶
Modify the height of logical line extents by a factor.
This affects the values returned by
LayoutLine.get_extents,
LayoutLine.get_pixel_extents and
LayoutIter.get_line_extents.
Parameters:
factor— the scaling factor to apply to the logical height
attr_line_height_new_absolute¶
Override the height of logical line extents to be height.
This affects the values returned by
LayoutLine.get_extents,
LayoutLine.get_pixel_extents and
LayoutIter.get_line_extents.
Parameters:
height— the line height, inSCALE-ths of a point
attr_overline_color_new¶
Create a new overline color attribute.
This attribute modifies the color of overlines. If not set, overlines will use the foreground color.
Parameters:
red— the red value (ranging from 0 to 65535)green— the green valueblue— the blue value
attr_overline_new¶
Create a new overline-style attribute.
Parameters:
overline— the overline style
attr_rise_new¶
Create a new baseline displacement attribute.
Parameters:
rise— the amount that the text should be displaced vertically, in Pango units. Positive values displace the text upwards.
attr_scale_new¶
Create a new font size scale attribute.
The base font for the affected text will have
its size multiplied by scale_factor.
Parameters:
scale_factor— factor to scale the font
attr_sentence_new¶
Marks the range of the attribute as a single sentence.
Note that this may require adjustments to word and sentence classification around the range.
attr_show_new¶
Create a new attribute that influences how invisible characters are rendered.
Parameters:
flags—PangoShowFlagsto apply
attr_stretch_new¶
Create a new font stretch attribute.
Parameters:
stretch— the stretch
attr_strikethrough_color_new¶
Create a new strikethrough color attribute.
This attribute modifies the color of strikethrough lines. If not set, strikethrough lines will use the foreground color.
Parameters:
red— the red value (ranging from 0 to 65535)green— the green valueblue— the blue value
attr_strikethrough_new¶
Create a new strike-through attribute.
Parameters:
strikethrough—Trueif the text should be struck-through
attr_style_new¶
Create a new font slant style attribute.
Parameters:
style— the slant style
attr_text_transform_new¶
Create a new attribute that influences how characters are transformed during shaping.
Parameters:
transform—PangoTextTransformto apply
attr_underline_color_new¶
Create a new underline color attribute.
This attribute modifies the color of underlines. If not set, underlines will use the foreground color.
Parameters:
red— the red value (ranging from 0 to 65535)green— the green valueblue— the blue value
attr_underline_new¶
Create a new underline-style attribute.
Parameters:
underline— the underline style
attr_variant_new¶
Create a new font variant attribute (normal or small caps).
Parameters:
variant— the variant
attr_weight_new¶
Create a new font weight attribute.
Parameters:
weight— the weight
attr_word_new¶
Marks the range of the attribute as a single word.
Note that this may require adjustments to word and sentence classification around the range.
break_¶
:::warning Deprecated since 1.44 This API is deprecated. :::
Determines possible line, word, and character breaks for a string of Unicode text with a single analysis.
For most purposes you may want to use get_log_attrs.
Parameters:
text— the text to process. Must be valid UTF-8length— length oftextin bytes (may be -1 iftextis nul-terminated)analysis—PangoAnalysisstructure fortext
default_break¶
This is the default break algorithm.
It applies rules from the Unicode Line Breaking Algorithm
without language-specific tailoring, therefore the analyis argument is unused
and can be None.
See tailor_break for language-specific breaks.
See attr_break for attribute-based customization.
Parameters:
text— text to break. Must be valid UTF-8length— length of text in bytes (may be -1 iftextis nul-terminated)analysis— aPangoAnalysisstructure for thetext
extents_to_pixels¶
Converts extents from Pango units to device units.
The conversion is done by dividing by the SCALE factor and
performing rounding.
The inclusive rectangle is converted by flooring the x/y coordinates
and extending width/height, such that the final rectangle completely
includes the original rectangle.
The nearest rectangle is converted by rounding the coordinates
of the rectangle to the nearest device unit (pixel).
The rule to which argument to use is: if you want the resulting device-space
rectangle to completely contain the original rectangle, pass it in as
inclusive. If you want two touching-but-not-overlapping rectangles stay
touching-but-not-overlapping after rounding to device units, pass them in
as nearest.
Parameters:
inclusive— rectangle to round to pixels inclusivelynearest— rectangle to round to nearest pixels
find_base_dir¶
Searches a string the first character that has a strong direction, according to the Unicode bidirectional algorithm.
Parameters:
text— the text to process. Must be valid UTF-8length— length oftextin bytes (may be -1 iftextis nul-terminated)
find_paragraph_boundary¶
Locates a paragraph boundary in text.
A boundary is caused by delimiter characters, such as a newline, carriage return, carriage return-newline pair, or Unicode paragraph separator character.
The index of the run of delimiters is returned in
paragraph_delimiter_index. The index of the start of the
next paragraph (index after all delimiters) is stored n
next_paragraph_start.
If no delimiters are found, both paragraph_delimiter_index
and next_paragraph_start are filled with the length of text
(an index one off the end).
Parameters:
text— UTF-8 textlength— length oftextin bytes, or -1 if nul-terminated
get_log_attrs¶
Computes a PangoLogAttr for each character in text.
The attrs array must have one PangoLogAttr for
each position in text; if text contains N characters,
it has N+1 positions, including the last position at the
end of the text. text should be an entire paragraph;
logical attributes can't be computed without context
(for example you need to see spaces on either side of
a word to know the word is a word).
Parameters:
text— text to process. Must be valid UTF-8length— length in bytes oftextlevel— embedding level, or -1 if unknownlanguage— language tag
get_mirror_char¶
:::warning Deprecated since 1.30 This API is deprecated. :::
Returns the mirrored character of a Unicode character.
Mirror characters are determined by the Unicode mirrored property.
Parameters:
ch— a Unicode character
is_zero_width¶
Checks if a character that should not be normally rendered.
This includes all Unicode characters with "ZERO WIDTH" in their name, as well as bidi formatting characters, and a few other ones.
This is totally different from GLib.unichar_iszerowidth and is at best misnamed.
Parameters:
ch— a Unicode character
itemize¶
def itemize(context: Context, text: str, start_index: int, length: int, attrs: AttrList, cached_iter: AttrIterator | None = ...) -> list[Item]
Breaks a piece of text into segments with consistent directional level and font.
Each byte of text will be contained in exactly one of the items in the
returned list; the generated list of items will be in logical order (the
start offsets of the items are ascending).
cached_iter should be an iterator over attrs currently positioned
at a range before or containing start_index; cached_iter will be
advanced to the range covering the position just after
start_index + length. (i.e. if itemizing in a loop, just keep passing
in the same cached_iter).
Parameters:
context— a structure holding information that affects the itemization process.text— the text to itemize. Must be valid UTF-8start_index— first byte intextto processlength— the number of bytes (not characters) to process afterstart_index. This must be >= 0.attrs— the set of attributes that apply totext.cached_iter— Cached attribute iterator
itemize_with_base_dir¶
def itemize_with_base_dir(context: Context, base_dir: Direction | int, text: str, start_index: int, length: int, attrs: AttrList, cached_iter: AttrIterator | None = ...) -> list[Item]
Like pango_itemize(), but with an explicitly specified base direction.
The base direction is used when computing bidirectional levels.
itemize gets the base direction from the PangoContext
(see Context.set_base_dir).
Parameters:
context— a structure holding information that affects the itemization process.base_dir— base direction to use for bidirectional processingtext— the text to itemize.start_index— first byte intextto processlength— the number of bytes (not characters) to process afterstart_index. This must be >= 0.attrs— the set of attributes that apply totext.cached_iter— Cached attribute iterator
log2vis_get_embedding_levels¶
def log2vis_get_embedding_levels(text: str, length: int, pbase_dir: Direction | int) -> tuple[list[int], Direction | int]
Return the bidirectional embedding levels of the input paragraph.
The bidirectional embedding levels are defined by the Unicode Bidirectional Algorithm.
If the input base direction is a weak direction, the direction of the characters in the text will determine the final resolved direction.
Parameters:
text— the text to itemize.length— the number of bytes (not characters) to process, or -1 iftextis nul-terminated and the length should be calculated.pbase_dir— input base direction, and output resolved direction.
markup_parser_finish¶
Finishes parsing markup.
After feeding a Pango markup parser some data with GLib.MarkupParseContext.parse,
use this function to get the list of attributes and text out of the
markup. This function will not free context, use GLib.MarkupParseContext.free
to do so.
Parameters:
context— A valid parse context that was returned frommarkup_parser_new
markup_parser_new¶
Incrementally parses marked-up text to create a plain-text string and an attribute list.
See the Pango Markup docs for details about the supported markup.
If accel_marker is nonzero, the given character will mark the
character following it as an accelerator. For example, accel_marker
might be an ampersand or underscore. All characters marked
as an accelerator will receive a Underline.LOW attribute,
and the first character so marked will be returned in accel_char,
when calling markup_parser_finish. Two accel_marker characters
following each other produce a single literal accel_marker character.
To feed markup to the parser, use GLib.MarkupParseContext.parse
on the returned GLib.MarkupParseContext. When done with feeding markup
to the parser, use markup_parser_finish to get the data out
of it, and then use GLib.MarkupParseContext.free to free it.
This function is designed for applications that read Pango markup
from streams. To simply parse a string containing Pango markup,
the parse_markup API is recommended instead.
Parameters:
accel_marker— character that precedes an accelerator, or 0 for none
parse_enum¶
:::warning Deprecated since 1.38 This API is deprecated. :::
Parses an enum type and stores the result in value.
If str does not match the nick name of any of the possible values
for the enum and is not an integer, False is returned, a warning
is issued if warn is True, and a string representing the list of
possible values is stored in possible_values. The list is
slash-separated, eg. "none/start/middle/end".
If failed and possible_values is not None, returned string should
be freed using GLib.free.
Parameters:
type— enum type to parse, eg.PANGO_TYPE_ELLIPSIZE_MODEstr— string to parsewarn— ifTrue, issue a g_warning() on bad input
parse_markup¶
def parse_markup(markup_text: str, length: int, accel_marker: str) -> tuple[bool, AttrList, str, str]
Parses marked-up text to create a plain-text string and an attribute list.
See the Pango Markup docs for details about the supported markup.
If accel_marker is nonzero, the given character will mark the
character following it as an accelerator. For example, accel_marker
might be an ampersand or underscore. All characters marked
as an accelerator will receive a Underline.LOW attribute,
and the first character so marked will be returned in accel_char.
Two accel_marker characters following each other produce a single
literal accel_marker character.
To parse a stream of pango markup incrementally, use markup_parser_new.
If any error happens, none of the output arguments are touched except
for error.
Parameters:
markup_text— markup to parse (see the Pango Markup docs)length— length ofmarkup_text, or -1 if nul-terminatedaccel_marker— character that precedes an accelerator, or 0 for none
parse_stretch¶
Parses a font stretch.
The allowed values are "ultra_condensed", "extra_condensed", "condensed", "semi_condensed", "normal", "semi_expanded", "expanded", "extra_expanded" and "ultra_expanded". Case variations are ignored and the '_' characters may be omitted.
Parameters:
str— a string to parse.warn— ifTrue, issue a g_warning() on bad input.
parse_style¶
Parses a font style.
The allowed values are "normal", "italic" and "oblique", case variations being ignored.
Parameters:
str— a string to parse.warn— ifTrue, issue a g_warning() on bad input.
parse_variant¶
Parses a font variant.
The allowed values are "normal", "small-caps", "all-small-caps", "petite-caps", "all-petite-caps", "unicase" and "title-caps", case variations being ignored.
Parameters:
str— a string to parse.warn— ifTrue, issue a g_warning() on bad input.
parse_weight¶
Parses a font weight.
The allowed values are "heavy", "ultrabold", "bold", "normal", "light", "ultraleight" and integers. Case variations are ignored.
Parameters:
str— a string to parse.warn— ifTrue, issue a g_warning() on bad input.
quantize_line_geometry¶
Quantizes the thickness and position of a line to whole device pixels.
This is typically used for underline or strikethrough. The purpose of this function is to avoid such lines looking blurry.
Care is taken to make sure thickness is at least one pixel when this
function returns, but returned position may become zero as a result
of rounding.
Parameters:
thickness— pointer to the thickness of a line, in Pango unitsposition— corresponding position
read_line¶
:::warning Deprecated since 1.38 This API is deprecated. :::
Reads an entire line from a file into a buffer.
Lines may be delimited with '\n', '\r', '\n\r', or '\r\n'. The delimiter is not written into the buffer. Text after a '#' character is treated as a comment and skipped. '\' can be used to escape a # character. '\' proceeding a line delimiter combines adjacent lines. A '\' proceeding any other character is ignored and written into the output buffer unmodified.
Parameters:
stream— a stdio streamstr—GStringbuffer into which to write the result
reorder_items¶
Reorder items from logical order to visual order.
The visual order is determined from the associated directional levels of the items. The original list is unmodified.
(Please open a bug if you use this function. It is not a particularly convenient interface, and the code is duplicated elsewhere in Pango for that reason.)
Parameters:
items— aGListofPangoItemin logical order.
scan_int¶
:::warning Deprecated since 1.38 This API is deprecated. :::
Scans an integer.
Leading white space is skipped.
Parameters:
pos— in/out string position
scan_string¶
:::warning Deprecated since 1.38 This API is deprecated. :::
Scans a string into a GString buffer.
The string may either be a sequence of non-white-space characters, or a quoted string with '"'. Instead a quoted string, '\"' represents a literal quote. Leading white space outside of quotes is skipped.
Parameters:
pos— in/out string positionout— aGStringinto which to write the result
scan_word¶
:::warning Deprecated since 1.38 This API is deprecated. :::
Scans a word into a GString buffer.
A word consists of [A-Za-z_] followed by zero or more [A-Za-z_0-9]. Leading white space is skipped.
Parameters:
pos— in/out string positionout— aGStringinto which to write the result
shape¶
Convert the characters in text into glyphs.
Given a segment of text and the corresponding PangoAnalysis structure
returned from itemize, convert the characters into glyphs. You
may also pass in only a substring of the item from itemize.
It is recommended that you use shape_full instead, since
that API allows for shaping interaction happening across text item
boundaries.
Some aspects of hyphen insertion and text transformation (in particular,
capitalization) require log attrs, and thus can only be handled by
shape_item.
Note that the extra attributes in the analyis that is returned from
itemize have indices that are relative to the entire paragraph,
so you need to subtract the item offset from their indices before
calling shape.
Parameters:
text— the text to processlength— the length (in bytes) oftextanalysis—PangoAnalysisstructure fromitemize
shape_full¶
def shape_full(item_text: str, item_length: int, paragraph_text: str | None, paragraph_length: int, analysis: Analysis) -> GlyphString
Convert the characters in text into glyphs.
Given a segment of text and the corresponding PangoAnalysis structure
returned from itemize, convert the characters into glyphs.
You may also pass in only a substring of the item from itemize.
This is similar to shape, except it also can optionally take
the full paragraph text as input, which will then be used to perform
certain cross-item shaping interactions. If you have access to the broader
text of which item_text is part of, provide the broader text as
paragraph_text. If paragraph_text is None, item text is used instead.
Some aspects of hyphen insertion and text transformation (in particular,
capitalization) require log attrs, and thus can only be handled by
shape_item.
Note that the extra attributes in the analyis that is returned from
itemize have indices that are relative to the entire paragraph,
so you do not pass the full paragraph text as paragraph_text, you need
to subtract the item offset from their indices before calling
shape_full.
Parameters:
item_text— valid UTF-8 text to shape.item_length— the length (in bytes) ofitem_text. -1 means nul-terminated text.paragraph_text— text of the paragraph (see details).paragraph_length— the length (in bytes) ofparagraph_text. -1 means nul-terminated text.analysis—PangoAnalysisstructure fromitemize.
shape_item¶
def shape_item(item: Item, paragraph_text: str | None, paragraph_length: int, log_attrs: LogAttr | None, flags: ShapeFlags | int) -> GlyphString
Convert the characters in item into glyphs.
This is similar to shape_with_flags, except it takes a
PangoItem instead of separate item_text and analysis arguments.
It also takes log_attrs, which are needed for implementing some aspects
of hyphen insertion and text transforms (in particular, capitalization).
Note that the extra attributes in the analyis that is returned from
itemize have indices that are relative to the entire paragraph,
so you do not pass the full paragraph text as paragraph_text, you need
to subtract the item offset from their indices before calling
shape_with_flags.
Parameters:
item—PangoItemto shapeparagraph_text— text of the paragraph (see details).paragraph_length— the length (in bytes) ofparagraph_text. -1 means nul-terminated text.log_attrs— array ofPangoLogAttrforitemflags— flags influencing the shaping process
shape_with_flags¶
def shape_with_flags(item_text: str, item_length: int, paragraph_text: str | None, paragraph_length: int, analysis: Analysis, flags: ShapeFlags | int) -> GlyphString
Convert the characters in text into glyphs.
Given a segment of text and the corresponding PangoAnalysis structure
returned from itemize, convert the characters into glyphs.
You may also pass in only a substring of the item from itemize.
This is similar to shape_full, except it also takes flags
that can influence the shaping process.
Some aspects of hyphen insertion and text transformation (in particular,
capitalization) require log attrs, and thus can only be handled by
shape_item.
Note that the extra attributes in the analyis that is returned from
itemize have indices that are relative to the entire paragraph,
so you do not pass the full paragraph text as paragraph_text, you need
to subtract the item offset from their indices before calling
shape_with_flags.
Parameters:
item_text— valid UTF-8 text to shapeitem_length— the length (in bytes) ofitem_text. -1 means nul-terminated text.paragraph_text— text of the paragraph (see details).paragraph_length— the length (in bytes) ofparagraph_text. -1 means nul-terminated text.analysis—PangoAnalysisstructure fromitemizeflags— flags influencing the shaping process
skip_space¶
:::warning Deprecated since 1.38 This API is deprecated. :::
Skips 0 or more characters of white space.
Parameters:
pos— in/out string position
split_file_list¶
:::warning Deprecated since 1.38 This API is deprecated. :::
Splits a GLib.SEARCHPATH_SEPARATOR-separated list of files, stripping
white space and substituting ~/ with $HOME/.
Parameters:
str— aGLib.SEARCHPATH_SEPARATORseparated list of filenames
tailor_break¶
Apply language-specific tailoring to the breaks in attrs.
The line breaks are assumed to have been produced by default_break.
If offset is not -1, it is used to apply attributes from analysis that are
relevant to line breaking.
Note that it is better to pass -1 for offset and use attr_break
to apply attributes to the whole paragraph.
Parameters:
text— text to process. Must be valid UTF-8length— length in bytes oftextanalysis—PangoAnalysisfortextoffset— Byte offset oftextfrom the beginning of the paragraph, or -1 to ignore attributes fromanalysis
trim_string¶
:::warning Deprecated since 1.38 This API is deprecated. :::
Trims leading and trailing whitespace from a string.
Parameters:
str— a string
unichar_direction¶
Determines the inherent direction of a character.
The inherent direction is either PANGO_DIRECTION_LTR, PANGO_DIRECTION_RTL,
or PANGO_DIRECTION_NEUTRAL.
This function is useful to categorize characters into left-to-right
letters, right-to-left letters, and everything else. If full Unicode
bidirectional type of a character is needed, BidiType.for_unichar
can be used instead.
Parameters:
ch— a Unicode character
units_from_double¶
Converts a floating-point number to Pango units.
The conversion is done by multiplying d by SCALE and
rounding the result to nearest integer.
Parameters:
d— double floating-point value
units_to_double¶
Converts a number in Pango units to floating-point.
The conversion is done by dividing i by SCALE.
Parameters:
i— value in Pango units
version¶
Returns the encoded version of Pango available at run-time.
This is similar to the macro PANGO_VERSION except that the macro
returns the encoded version available at compile-time. A version
number can be encoded into an integer using PANGO_VERSION_ENCODE().
version_check¶
Checks that the Pango library in use is compatible with the given version.
Generally you would pass in the constants VERSION_MAJOR,
VERSION_MINOR, VERSION_MICRO as the three arguments
to this function; that produces a check that the library in use at
run-time is compatible with the version of Pango the application or
module was compiled against.
Compatibility is defined by two things: first the version
of the running library is newer than the version
required_major.required_minor.required_micro. Second
the running library must be binary compatible with the
version required_major.required_minor.required_micro
(same major version.)
For compile-time version checking use PANGO_VERSION_CHECK().
Parameters:
required_major— the required major versionrequired_minor— the required minor versionrequired_micro— the required major version
version_string¶
Returns the version of Pango available at run-time.
This is similar to the macro VERSION_STRING except that the
macro returns the version available at compile-time.
Enumerations¶
Alignment¶
Enumeration.
LEFT=0— Put all available space on the rightCENTER=1— Center the line within the available spaceRIGHT=2— Put all available space on the left
AttrType¶
Enumeration.
INVALID=0— does not happenLANGUAGE=1— language (AttrLanguage)FAMILY=2— font family name list (AttrString)STYLE=3— font slant style (AttrInt)WEIGHT=4— font weight (AttrInt)VARIANT=5— font variant (normal or small caps) (AttrInt)STRETCH=6— font stretch (AttrInt)SIZE=7— font size in points scaled bySCALE(AttrInt)FONT_DESC=8— font description (AttrFontDesc)FOREGROUND=9— foreground color (AttrColor)BACKGROUND=10— background color (AttrColor)UNDERLINE=11— whether the text has an underline (AttrInt)STRIKETHROUGH=12— whether the text is struck-through (AttrInt)RISE=13— baseline displacement (AttrInt)SHAPE=14— shape (AttrShape)SCALE=15— font size scale factor (AttrFloat)FALLBACK=16— whether fallback is enabled (AttrInt)LETTER_SPACING=17— letter spacing (PangoAttrInt)UNDERLINE_COLOR=18— underline color (AttrColor)STRIKETHROUGH_COLOR=19— strikethrough color (AttrColor)ABSOLUTE_SIZE=20— font size in pixels scaled bySCALE(AttrInt)GRAVITY=21— base text gravity (AttrInt)GRAVITY_HINT=22— gravity hint (AttrInt)FONT_FEATURES=23— OpenType font features (AttrFontFeatures). Since 1.38FOREGROUND_ALPHA=24— foreground alpha (AttrInt). Since 1.38BACKGROUND_ALPHA=25— background alpha (AttrInt). Since 1.38ALLOW_BREAKS=26— whether breaks are allowed (AttrInt). Since 1.44SHOW=27— how to render invisible characters (AttrInt). Since 1.44INSERT_HYPHENS=28— whether to insert hyphens at intra-word line breaks (AttrInt). Since 1.44OVERLINE=29— whether the text has an overline (AttrInt). Since 1.46OVERLINE_COLOR=30— overline color (AttrColor). Since 1.46LINE_HEIGHT=31— line height factor (AttrFloat). Since: 1.50ABSOLUTE_LINE_HEIGHT=32— line height (AttrInt). Since: 1.50TEXT_TRANSFORM=33WORD=34— override segmentation to classify the range of the attribute as a single word (AttrInt). Since 1.50SENTENCE=35— override segmentation to classify the range of the attribute as a single sentence (AttrInt). Since 1.50BASELINE_SHIFT=36— baseline displacement (AttrInt). Since 1.50FONT_SCALE=37— font-relative size change (AttrInt). Since 1.50
BaselineShift¶
Enumeration.
NONE=0— Leave the baseline unchangedSUPERSCRIPT=1— Shift the baseline to the superscript position, relative to the previous runSUBSCRIPT=2— Shift the baseline to the subscript position, relative to the previous run
BidiType¶
Enumeration.
L=0— Left-to-RightLRE=1— Left-to-Right EmbeddingLRO=2— Left-to-Right OverrideR=3— Right-to-LeftAL=4— Right-to-Left ArabicRLE=5— Right-to-Left EmbeddingRLO=6— Right-to-Left OverridePDF=7— Pop Directional FormatEN=8— European NumberES=9— European Number SeparatorET=10— European Number TerminatorAN=11— Arabic NumberCS=12— Common Number SeparatorNSM=13— Nonspacing MarkBN=14— Boundary NeutralB=15— Paragraph SeparatorS=16— Segment SeparatorWS=17— WhitespaceON=18— Other NeutralsLRI=19— Left-to-Right isolate. Since 1.48.6RLI=20— Right-to-Left isolate. Since 1.48.6FSI=21— First strong isolate. Since 1.48.6PDI=22— Pop directional isolate. Since 1.48.6
CoverageLevel¶
Enumeration.
NONE=0— The character is not representable with the font.FALLBACK=1— The character is represented in a way that may be comprehensible but is not the correct graphical form. For instance, a Hangul character represented as a a sequence of Jamos, or a Latin transliteration of a Cyrillic word.APPROXIMATE=2— The character is represented as basically the correct graphical form, but with a stylistic variant inappropriate for the current script.EXACT=3— The character is represented as the correct graphical form.
Direction¶
Enumeration.
LTR=0— A strong left-to-right directionRTL=1— A strong right-to-left directionTTB_LTR=2— Deprecated value; treated the same asPANGO_DIRECTION_RTL.TTB_RTL=3— Deprecated value; treated the same asPANGO_DIRECTION_LTRWEAK_LTR=4— A weak left-to-right directionWEAK_RTL=5— A weak right-to-left directionNEUTRAL=6— No direction specified
EllipsizeMode¶
Enumeration.
NONE=0— No ellipsizationSTART=1— Omit characters at the start of the textMIDDLE=2— Omit characters in the middle of the textEND=3— Omit characters at the end of the text
FontColor¶
Enumeration.
FORBIDDEN=0— The font should not have color glyphsREQUIRED=1— The font should have color glyphsDONT_CARE=2— The font may or may not use color
FontMask¶
Bit flags.
FAMILY=1— the font family is specified.STYLE=2— the font style is specified.VARIANT=4— the font variant is specified.WEIGHT=8— the font weight is specified.STRETCH=16— the font stretch is specified.SIZE=32— the font size is specified.GRAVITY=64— The font gravity is specified.VARIATIONS=128— OpenType font variations are specified.FEATURES=256— OpenType font features are specified.COLOR=512— Font color is specified.
FontScale¶
Enumeration.
NONE=0— Leave the font size unchangedSUPERSCRIPT=1— Change the font to a size suitable for superscriptsSUBSCRIPT=2— Change the font to a size suitable for subscriptsSMALL_CAPS=3— Change the font to a size suitable for Small Caps
Gravity¶
Enumeration.
SOUTH=0— Glyphs stand upright (default) <img align="right" valign="center" src="m-south.png">EAST=1— Glyphs are rotated 90 degrees counter-clockwise. <img align="right" valign="center" src="m-east.png">NORTH=2— Glyphs are upside-down. <img align="right" valign="cener" src="m-north.png">WEST=3— Glyphs are rotated 90 degrees clockwise. <img align="right" valign="center" src="m-west.png">AUTO=4— Gravity is resolved from the context matrix
GravityHint¶
Enumeration.
NATURAL=0— scripts will take their natural gravity based on the base gravity and the script. This is the default.STRONG=1— always use the base gravity set, regardless of the script.LINE=2— for scripts not in their natural direction (eg. Latin in East gravity), choose per-script gravity such that every script respects the line progression. This means, Latin and Arabic will take opposite gravities and both flow top-to-bottom for example.
LayoutDeserializeError¶
Enumeration.
INVALID=0— Unspecified errorINVALID_VALUE=1— A JSon value could not be interpretedMISSING_VALUE=2— A required JSon member was not found
LayoutDeserializeFlags¶
Bit flags.
DEFAULT=0— Default behaviorCONTEXT=1— Apply context information from the serialization to thePangoContext
LayoutSerializeFlags¶
Bit flags.
DEFAULT=0— Default behaviorCONTEXT=1— Include context informationOUTPUT=2— Include information about the formatted output
Overline¶
Enumeration.
NONE=0— no overline should be drawnSINGLE=1— Draw a single line above the ink extents of the text being underlined.
RenderPart¶
Enumeration.
FOREGROUND=0— the text itselfBACKGROUND=1— the area behind the textUNDERLINE=2— underlinesSTRIKETHROUGH=3— strikethrough linesOVERLINE=4— overlines
Script¶
Enumeration.
INVALID_CODE=-1— a value never returned fromScript.for_unicharCOMMON=0— a character used by multiple different scriptsINHERITED=1— a mark glyph that takes its script from the base glyph to which it is attachedARABIC=2— ArabicARMENIAN=3— ArmenianBENGALI=4— BengaliBOPOMOFO=5— BopomofoCHEROKEE=6— CherokeeCOPTIC=7— CopticCYRILLIC=8— CyrillicDESERET=9— DeseretDEVANAGARI=10— DevanagariETHIOPIC=11— EthiopicGEORGIAN=12— GeorgianGOTHIC=13— GothicGREEK=14— GreekGUJARATI=15— GujaratiGURMUKHI=16— GurmukhiHAN=17— HanHANGUL=18— HangulHEBREW=19— HebrewHIRAGANA=20— HiraganaKANNADA=21— KannadaKATAKANA=22— KatakanaKHMER=23— KhmerLAO=24— LaoLATIN=25— LatinMALAYALAM=26— MalayalamMONGOLIAN=27— MongolianMYANMAR=28— MyanmarOGHAM=29— OghamOLD_ITALIC=30— Old ItalicORIYA=31— OriyaRUNIC=32— RunicSINHALA=33— SinhalaSYRIAC=34— SyriacTAMIL=35— TamilTELUGU=36— TeluguTHAANA=37— ThaanaTHAI=38— ThaiTIBETAN=39— TibetanCANADIAN_ABORIGINAL=40— Canadian AboriginalYI=41— YiTAGALOG=42— TagalogHANUNOO=43— HanunooBUHID=44— BuhidTAGBANWA=45— TagbanwaBRAILLE=46— BrailleCYPRIOT=47— CypriotLIMBU=48— LimbuOSMANYA=49— OsmanyaSHAVIAN=50— ShavianLINEAR_B=51— Linear BTAI_LE=52— Tai LeUGARITIC=53— UgariticNEW_TAI_LUE=54— New Tai Lue. Since 1.10BUGINESE=55— Buginese. Since 1.10GLAGOLITIC=56— Glagolitic. Since 1.10TIFINAGH=57— Tifinagh. Since 1.10SYLOTI_NAGRI=58— Syloti Nagri. Since 1.10OLD_PERSIAN=59— Old Persian. Since 1.10KHAROSHTHI=60— Kharoshthi. Since 1.10UNKNOWN=61— an unassigned code point. Since 1.14BALINESE=62— Balinese. Since 1.14CUNEIFORM=63— Cuneiform. Since 1.14PHOENICIAN=64— Phoenician. Since 1.14PHAGS_PA=65— Phags-pa. Since 1.14NKO=66— N'Ko. Since 1.14KAYAH_LI=67— Kayah Li. Since 1.20.1LEPCHA=68— Lepcha. Since 1.20.1REJANG=69— Rejang. Since 1.20.1SUNDANESE=70— Sundanese. Since 1.20.1SAURASHTRA=71— Saurashtra. Since 1.20.1CHAM=72— Cham. Since 1.20.1OL_CHIKI=73— Ol Chiki. Since 1.20.1VAI=74— Vai. Since 1.20.1CARIAN=75— Carian. Since 1.20.1LYCIAN=76— Lycian. Since 1.20.1LYDIAN=77— Lydian. Since 1.20.1BATAK=78— Batak. Since 1.32BRAHMI=79— Brahmi. Since 1.32MANDAIC=80— Mandaic. Since 1.32CHAKMA=81— Chakma. Since: 1.32MEROITIC_CURSIVE=82— Meroitic Cursive. Since: 1.32MEROITIC_HIEROGLYPHS=83— Meroitic Hieroglyphs. Since: 1.32MIAO=84— Miao. Since: 1.32SHARADA=85— Sharada. Since: 1.32SORA_SOMPENG=86— Sora Sompeng. Since: 1.32TAKRI=87— Takri. Since: 1.32BASSA_VAH=88— Bassa. Since: 1.40CAUCASIAN_ALBANIAN=89— Caucasian Albanian. Since: 1.40DUPLOYAN=90— Duployan. Since: 1.40ELBASAN=91— Elbasan. Since: 1.40GRANTHA=92— Grantha. Since: 1.40KHOJKI=93— Kjohki. Since: 1.40KHUDAWADI=94— Khudawadi, Sindhi. Since: 1.40LINEAR_A=95— Linear A. Since: 1.40MAHAJANI=96— Mahajani. Since: 1.40MANICHAEAN=97— Manichaean. Since: 1.40MENDE_KIKAKUI=98— Mende Kikakui. Since: 1.40MODI=99— Modi. Since: 1.40MRO=100— Mro. Since: 1.40NABATAEAN=101— Nabataean. Since: 1.40OLD_NORTH_ARABIAN=102— Old North Arabian. Since: 1.40OLD_PERMIC=103— Old Permic. Since: 1.40PAHAWH_HMONG=104— Pahawh Hmong. Since: 1.40PALMYRENE=105— Palmyrene. Since: 1.40PAU_CIN_HAU=106— Pau Cin Hau. Since: 1.40PSALTER_PAHLAVI=107— Psalter Pahlavi. Since: 1.40SIDDHAM=108— Siddham. Since: 1.40TIRHUTA=109— Tirhuta. Since: 1.40WARANG_CITI=110— Warang Citi. Since: 1.40AHOM=111— Ahom. Since: 1.40ANATOLIAN_HIEROGLYPHS=112— Anatolian Hieroglyphs. Since: 1.40HATRAN=113— Hatran. Since: 1.40MULTANI=114— Multani. Since: 1.40OLD_HUNGARIAN=115— Old Hungarian. Since: 1.40SIGNWRITING=116— Signwriting. Since: 1.40
ShapeFlags¶
Bit flags.
NONE=0— Default valueROUND_POSITIONS=1— Round glyph positions and widths to whole device units This option should be set if the target renderer can't do subpixel positioning of glyphs
ShowFlags¶
Bit flags.
NONE=0— No special treatment for invisible charactersSPACES=1— Render spaces, tabs and newlines visiblyLINE_BREAKS=2— Render line breaks visiblyIGNORABLES=4— Render default-ignorable Unicode characters visibly
Stretch¶
Enumeration.
ULTRA_CONDENSED=0— ultra condensed widthEXTRA_CONDENSED=1— extra condensed widthCONDENSED=2— condensed widthSEMI_CONDENSED=3— semi condensed widthNORMAL=4— the normal widthSEMI_EXPANDED=5— semi expanded widthEXPANDED=6— expanded widthEXTRA_EXPANDED=7— extra expanded widthULTRA_EXPANDED=8— ultra expanded width
Style¶
Enumeration.
NORMAL=0— the font is upright.OBLIQUE=1— the font is slanted, but in a roman style.ITALIC=2— the font is slanted in an italic style.
TabAlign¶
Enumeration.
LEFT=0— the text appears to the right of the tab stop positionRIGHT=1— the text appears to the left of the tab stop position until the available space is filled. Since: 1.50CENTER=2— the text is centered at the tab stop position until the available space is filled. Since: 1.50DECIMAL=3— text before the first occurrence of the decimal point character appears to the left of the tab stop position (until the available space is filled), the rest to the right. Since: 1.50
TextTransform¶
Enumeration.
NONE=0— Leave text unchangedLOWERCASE=1— Display letters and numbers as lowercaseUPPERCASE=2— Display letters and numbers as uppercaseCAPITALIZE=3— Display the first character of a word in titlecase
Underline¶
Enumeration.
NONE=0— no underline should be drawnSINGLE=1— a single underline should be drawnDOUBLE=2— a double underline should be drawnLOW=3— a single underline should be drawn at a position beneath the ink extents of the text being underlined. This should be used only for underlining single characters, such as for keyboard accelerators.Underline.SINGLEshould be used for extended portions of text.ERROR=4— an underline indicating an error should be drawn below. The exact style of rendering is up to thePangoRendererin use, but typical styles include wavy or dotted lines. This underline is typically used to indicate an error such as a possible mispelling; in some cases a contrasting color may automatically be used. This type of underlining is available since Pango 1.4.SINGLE_LINE=5— LikePANGO_UNDERLINE_SINGLE, but drawn continuously across multiple runs. This type of underlining is available since Pango 1.46.DOUBLE_LINE=6— LikePANGO_UNDERLINE_DOUBLE, but drawn continuously across multiple runs. This type of underlining is available since Pango 1.46.ERROR_LINE=7— LikePANGO_UNDERLINE_ERROR, but drawn continuously across multiple runs. This type of underlining is available since Pango 1.46.
Variant¶
Enumeration.
NORMAL=0— A normal font.SMALL_CAPS=1— A font with the lower case characters replaced by smaller variants of the capital characters.ALL_SMALL_CAPS=2— A font with all characters replaced by smaller variants of the capital characters. Since: 1.50PETITE_CAPS=3— A font with the lower case characters replaced by smaller variants of the capital characters. Petite Caps can be even smaller than Small Caps. Since: 1.50ALL_PETITE_CAPS=4— A font with all characters replaced by smaller variants of the capital characters. Petite Caps can be even smaller than Small Caps. Since: 1.50UNICASE=5— A font with the upper case characters replaced by smaller variants of the capital letters. Since: 1.50TITLE_CAPS=6— A font with capital letters that are more suitable for all-uppercase titles. Since: 1.50
Weight¶
Enumeration.
THIN=100— the thin weight (= 100) Since: 1.24ULTRALIGHT=200— the ultralight weight (= 200)LIGHT=300— the light weight (= 300)SEMILIGHT=350— the semilight weight (= 350) Since: 1.36.7BOOK=380— the book weight (= 380) Since: 1.24)NORMAL=400— the default weight (= 400)MEDIUM=500— the medium weight (= 500) Since: 1.24SEMIBOLD=600— the semibold weight (= 600)BOLD=700— the bold weight (= 700)ULTRABOLD=800— the ultrabold weight (= 800)HEAVY=900— the heavy weight (= 900)ULTRAHEAVY=1000— the ultraheavy weight (= 1000) Since: 1.24
WrapMode¶
Enumeration.
WORD=0— wrap lines at word boundaries.CHAR=1— wrap lines at character boundaries.WORD_CHAR=2— wrap lines at word boundaries, but fall back to character boundaries if there is not enough space for a full word.NONE=3— do not wrap.
Constants¶
ANALYSIS_FLAG_CENTERED_BASELINE¶
Whether the segment should be shifted to center around the baseline.
This is mainly used in vertical writing directions.
ANALYSIS_FLAG_IS_ELLIPSIS¶
Whether this run holds ellipsized text.
ANALYSIS_FLAG_NEED_HYPHEN¶
Whether to add a hyphen at the end of the run during shaping.
ATTR_INDEX_FROM_TEXT_BEGINNING¶
Value for start_index in PangoAttribute that indicates
the beginning of the text.
ATTR_INDEX_TO_TEXT_END¶
Value for end_index in PangoAttribute that indicates
the end of the text.
GLYPH_EMPTY¶
A PangoGlyph value that indicates a zero-width empty glpyh.
This is useful for example in shaper modules, to use as the glyph for
various zero-width Unicode characters (those passing is_zero_width).
GLYPH_INVALID_INPUT¶
A PangoGlyph value for invalid input.
PangoLayout produces one such glyph per invalid input UTF-8 byte and such
a glyph is rendered as a crossed box.
Note that this value is defined such that it has the GLYPH_UNKNOWN_FLAG
set.
GLYPH_UNKNOWN_FLAG¶
Flag used in PangoGlyph to turn a gunichar value of a valid Unicode
character into an unknown-character glyph for that gunichar.
Such unknown-character glyphs may be rendered as a 'hex box'.
SCALE¶
The scale between dimensions used for Pango distances and device units.
The definition of device units is dependent on the output device; it will
typically be pixels for a screen, and points for a printer. SCALE is
currently 1024, but this may be changed in the future.
When setting font sizes, device units are always considered to be points (as in "12 point font"), rather than pixels.
VERSION_MAJOR¶
The major component of the version of Pango available at compile-time.
VERSION_MICRO¶
The micro component of the version of Pango available at compile-time.
VERSION_MINOR¶
The minor component of the version of Pango available at compile-time.
VERSION_STRING¶
A string literal containing the version of Pango available at compile-time.