pango.layout

Module for [Layout] class

Types 3

A [pango.layout.Layout] structure represents an entire paragraph of text.

While complete access to the layout capabilities of Pango is provided using the detailed interfaces for itemization and shaping, using that functionality directly involves writing a fairly large amount of code. [pango.layout.Layout] provides a high-level driver for formatting entire paragraphs of text at once. This includes paragraph-level functionality such as line breaking, justification, alignment and ellipsization.

A [pango.layout.Layout] is initialized with a [pango.context.Context], UTF-8 string and set of attributes for that string. Once that is done, the set of formatted lines can be extracted from the object, the layout can be rendered, and conversion between logical character positions within the layout's text, and the physical position of the resulting glyphs can be made.

There are a number of parameters to adjust the formatting of a [pango.layout.Layout]. The following image shows adjustable parameters (on the left) and font metrics (on the right):

Pango Layout Parameters

The following images demonstrate the effect of alignment and justification on the layout of text:

!align=left!align=left, justify
!align=center!align=center, justify
!align=right!align=right, justify

It is possible, as well, to ignore the 2-D setup, and simply treat the results of a [pango.layout.Layout] as a list of lines.

Methods
GType _gType() @property
Layout self()Returns `this`, for use in `with` statements.
LayoutGidBuilder builder()Get builder for [pango.layout.Layout] Returns: New builder object
pango.layout.Layout deserialize(pango.context.Context context, glib.bytes.Bytes bytes, pango.types.LayoutDeserializeFlags flags)Loads data previously created via [pango.layout.Layout.serialize].
void contextChanged()Forces recomputation of any state in the [pango.layout.Layout] that might depend on the layout's context.
pango.layout.Layout copy()Creates a deep copy-by-value of the layout.
pango.types.Alignment getAlignment()Gets the alignment for the layout: how partial lines are positioned within the horizontal space available. Returns: the alignment
pango.attr_list.AttrList getAttributes()Gets the attribute list for the layout, if any. Returns: a [pango.attr_list.AttrList]
bool getAutoDir()Gets whether to calculate the base direction for the layout according to its contents.
int getBaseline()Gets the Y position of baseline of the first line in layout. Returns: baseline of first line, from top of layout
void getCaretPos(int index, out pango.types.Rectangle strongPos, out pango.types.Rectangle weakPos)Given an index within a layout, determines the positions that of the strong and weak cursors if the insertion point is at that index.
int getCharacterCount()Returns the number of Unicode characters in the the text of layout. Returns: the number of Unicode characters in the text of layout
pango.context.Context getContext()Retrieves the [pango.context.Context] used for this layout. Returns: the [pango.context.Context] for the layout
void getCursorPos(int index, out pango.types.Rectangle strongPos, out pango.types.Rectangle weakPos)Given an index within a layout, determines the positions that of the strong and weak cursors if the insertion point is at that index.
pango.types.Direction getDirection(int index)Gets the text direction at the given character position in layout.
pango.types.EllipsizeMode getEllipsize()Gets the type of ellipsization being performed for layout.
void getExtents(out pango.types.Rectangle inkRect, out pango.types.Rectangle logicalRect)Computes the logical and ink extents of layout.
pango.font_description.FontDescription getFontDescription()Gets the font description for the layout, if any. Returns: a pointer to the layout's font description, or null if the font description from the layout's context is inherited.
int getHeight()Gets the height of layout used for ellipsization.
int getIndent()Gets the paragraph indent width in Pango units.
pango.layout_iter.LayoutIter getIter()Returns an iterator to iterate over the visual extents of the layout. Returns: the new [pango.layout_iter.LayoutIter]
bool getJustify()Gets whether each complete line should be stretched to fill the entire width of the layout. Returns: the justify value
bool getJustifyLastLine()Gets whether the last line should be stretched to fill the entire width of the layout. Returns: the justify value
pango.layout_line.LayoutLine getLine(int line)Retrieves a particular line from a [pango.layout.Layout].
int getLineCount()Retrieves the count of lines for the layout. Returns: the line count
pango.layout_line.LayoutLine getLineReadonly(int line)Retrieves a particular line from a [pango.layout.Layout].
float getLineSpacing()Gets the line spacing factor of layout.
pango.layout_line.LayoutLine[] getLines()Returns the lines of the layout as a list.
pango.layout_line.LayoutLine[] getLinesReadonly()Returns the lines of the layout as a list.
void getLogAttrs(out pango.types.LogAttr[] attrs)Retrieves an array of logical attributes for each character in the layout.
pango.types.LogAttr[] getLogAttrsReadonly()Retrieves an array of logical attributes for each character in the layout.
void getPixelExtents(out pango.types.Rectangle inkRect, out pango.types.Rectangle logicalRect)Computes the logical and ink extents of layout in device units.
void getPixelSize(out int width, out int height)Determines the logical width and height of a [pango.layout.Layout] in device units.
uint getSerial()Returns the current serial number of layout.
bool getSingleParagraphMode()Obtains whether layout is in single paragraph mode.
void getSize(out int width, out int height)Determines the logical width and height of a [pango.layout.Layout] in Pango units.
int getSpacing()Gets the amount of spacing between the lines of the layout. Returns: the spacing in Pango units
pango.tab_array.TabArray getTabs()Gets the current [pango.tab_array.TabArray] used by this layout.
string getText()Gets the text in the layout.
int getUnknownGlyphsCount()Counts the number of unknown glyphs in layout.
int getWidth()Gets the width to which the lines of the [pango.layout.Layout] should wrap. Returns: the width in Pango units, or -1 if no width set.
pango.types.WrapMode getWrap()Gets the wrap mode for the layout.
void indexToLineX(int index, bool trailing, out int line, out int xPos)Converts from byte index_ within the layout to line and X position.
void indexToPos(int index, out pango.types.Rectangle pos)Converts from an index within a [pango.layout.Layout] to the onscreen position corresponding to the grapheme at that index.
bool isEllipsized()Queries whether the layout had to ellipsize any paragraphs.
bool isWrapped()Queries whether the layout had to wrap any paragraphs.
void moveCursorVisually(bool strong, int oldIndex, int oldTrailing, int direction, out int newIndex, out int newTrailing)Computes a new cursor position from an old position and a direction.
glib.bytes.Bytes serialize(pango.types.LayoutSerializeFlags flags)Serializes the layout for later deserialization via [pango.layout.Layout.deserialize].
void setAlignment(pango.types.Alignment alignment)Sets the alignment for the layout: how partial lines are positioned within the horizontal space available.
void setAttributes(pango.attr_list.AttrList attrs = null)Sets the text attributes for a layout object.
void setAutoDir(bool autoDir)Sets whether to calculate the base direction for the layout according to its contents.
void setEllipsize(pango.types.EllipsizeMode ellipsize)Sets the type of ellipsization being performed for layout.
void setFontDescription(pango.font_description.FontDescription desc = null)Sets the default font description for the layout.
void setHeight(int height)Sets the height to which the [pango.layout.Layout] should be ellipsized at.
void setIndent(int indent)Sets the width in Pango units to indent each paragraph.
void setJustify(bool justify)Sets whether each complete line should be stretched to fill the entire width of the layout.
void setJustifyLastLine(bool justify)Sets whether the last line should be stretched to fill the entire width of the layout.
void setLineSpacing(float factor)Sets a factor for line spacing.
void setMarkup(string markup)Sets the layout text and attribute list from marked-up text.
void setMarkupWithAccel(string markup, dchar accelMarker, out dchar accelChar)Sets the layout text and attribute list from marked-up text.
void setSingleParagraphMode(bool setting)Sets the single paragraph mode of layout.
void setSpacing(int spacing)Sets the amount of spacing in Pango units between the lines of the layout.
void setTabs(pango.tab_array.TabArray tabs = null)Sets the tabs to use for layout, overriding the default tabs.
void setText(string text)Sets the text of the layout.
void setWidth(int width)Sets the width to which the lines of the [pango.layout.Layout] should wrap or ellipsized.
void setWrap(pango.types.WrapMode wrap)Sets the wrap mode.
bool writeToFile(pango.types.LayoutSerializeFlags flags, string filename)A convenience method to serialize a layout to a file.
bool xyToIndex(int x, int y, out int index, out int trailing)Converts from X and Y position within a layout to the byte index to the character at that logical position.
Constructors
this(void * ptr, Flag!"Take" take)
this(pango.context.Context context)Create a new [pango.layout.Layout] object with attributes initialized to default values for a particular [pango.context.Context].

Fluent builder for [pango.layout.Layout]

Methods