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):
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.
LayoutGidBuilder builder() static nothrowGet builder for [pango.layout.Layout] Returns: New builder objectpango.layout.Layout deserialize(pango.context.Context context, glib.bytes.Bytes bytes, pango.types.LayoutDeserializeFlags flags) staticLoads data previously created via [pango.layout.Layout.serialize].void contextChanged() nothrowForces recomputation of any state in the [pango.layout.Layout] that might depend on the layout's context.pango.types.Alignment getAlignment() nothrowGets the alignment for the layout: how partial lines are positioned within the horizontal space available. Returns: the alignmentpango.attr_list.AttrList getAttributes() nothrowGets the attribute list for the layout, if any. Returns: a [pango.attr_list.AttrList]bool getAutoDir() nothrowGets whether to calculate the base direction for the layout according to its contents.int getBaseline() nothrowGets the Y position of baseline of the first line in layout. Returns: baseline of first line, from top of layoutvoid getCaretPos(int index, out pango.types.Rectangle strongPos, out pango.types.Rectangle weakPos) nothrowGiven 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() nothrowReturns the number of Unicode characters in the the text of layout. Returns: the number of Unicode characters in the text of layoutpango.context.Context getContext() nothrowRetrieves the [pango.context.Context] used for this layout. Returns: the [pango.context.Context] for the layoutvoid getCursorPos(int index, out pango.types.Rectangle strongPos, out pango.types.Rectangle weakPos) nothrowGiven 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) nothrowGets the text direction at the given character position in layout.pango.types.EllipsizeMode getEllipsize() nothrowGets the type of ellipsization being performed for layout.void getExtents(out pango.types.Rectangle inkRect, out pango.types.Rectangle logicalRect) nothrowComputes the logical and ink extents of layout.pango.font_description.FontDescription getFontDescription() nothrowGets 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.pango.layout_iter.LayoutIter getIter() nothrowReturns an iterator to iterate over the visual extents of the layout. Returns: the new [pango.layout_iter.LayoutIter]bool getJustify() nothrowGets whether each complete line should be stretched to fill the entire width of the layout. Returns: the justify valuebool getJustifyLastLine() nothrowGets whether the last line should be stretched to fill the entire width of the layout. Returns: the justify valuepango.layout_line.LayoutLine getLine(int line) nothrowRetrieves a particular line from a [pango.layout.Layout].pango.layout_line.LayoutLine getLineReadonly(int line) nothrowRetrieves a particular line from a [pango.layout.Layout].void getLogAttrs(out pango.types.LogAttr[] attrs) nothrowRetrieves an array of logical attributes for each character in the layout.pango.types.LogAttr[] getLogAttrsReadonly() nothrowRetrieves an array of logical attributes for each character in the layout.void getPixelExtents(out pango.types.Rectangle inkRect, out pango.types.Rectangle logicalRect) nothrowComputes the logical and ink extents of layout in device units.void getPixelSize(out int width, out int height) nothrowDetermines the logical width and height of a [pango.layout.Layout] in device units.void getSize(out int width, out int height) nothrowDetermines the logical width and height of a [pango.layout.Layout] in Pango units.int getSpacing() nothrowGets the amount of spacing between the lines of the layout. Returns: the spacing in Pango unitspango.tab_array.TabArray getTabs() nothrowGets the current [pango.tab_array.TabArray] used by this layout.int getWidth() nothrowGets 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.void indexToLineX(int index, bool trailing, out int line, out int xPos) nothrowConverts from byte index_ within the layout to line and X position.void indexToPos(int index, out pango.types.Rectangle pos) nothrowConverts from an index within a [pango.layout.Layout] to the onscreen position corresponding to the grapheme at that index.void moveCursorVisually(bool strong, int oldIndex, int oldTrailing, int direction, out int newIndex, out int newTrailing) nothrowComputes a new cursor position from an old position and a direction.glib.bytes.Bytes serialize(pango.types.LayoutSerializeFlags flags) nothrowSerializes the layout for later deserialization via [pango.layout.Layout.deserialize].void setAlignment(pango.types.Alignment alignment) nothrowSets the alignment for the layout: how partial lines are positioned within the horizontal space available.void setAttributes(pango.attr_list.AttrList attrs = null) nothrowSets the text attributes for a layout object.void setAutoDir(bool autoDir) nothrowSets whether to calculate the base direction for the layout according to its contents.void setEllipsize(pango.types.EllipsizeMode ellipsize) nothrowSets the type of ellipsization being performed for layout.void setFontDescription(pango.font_description.FontDescription desc = null) nothrowSets the default font description for the layout.void setHeight(int height) nothrowSets the height to which the [pango.layout.Layout] should be ellipsized at.void setJustify(bool justify) nothrowSets whether each complete line should be stretched to fill the entire width of the layout.void setJustifyLastLine(bool justify) nothrowSets whether the last line should be stretched to fill the entire width of the layout.void setMarkupWithAccel(string markup, dchar accelMarker, out dchar accelChar) nothrowSets the layout text and attribute list from marked-up text.void setSpacing(int spacing) nothrowSets the amount of spacing in Pango units between the lines of the layout.void setTabs(pango.tab_array.TabArray tabs = null) nothrowSets the tabs to use for layout, overriding the default tabs.void setWidth(int width) nothrowSets the width to which the lines of the [pango.layout.Layout] should wrap or ellipsized.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) nothrowConverts from X and Y position within a layout to the byte index to the character at that logical position.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 implementation template for pango.layout.Layout
Fluent builder for pango.layout.Layout