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 _getGType() static nothrow
GType _gType() @property nothrow
Layout self() nothrowReturns `this`, for use in `with` statements.
LayoutGidBuilder builder() static nothrowGet 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) 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.layout.Layout copy() nothrowCreates a deep copy-by-value of the layout.
pango.types.Alignment getAlignment() nothrowGets the alignment for the layout: how partial lines are positioned within the horizontal space available. Returns: the alignment
pango.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 layout
void 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 layout
pango.context.Context getContext() nothrowRetrieves 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) 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.
int getHeight() nothrowGets the height of layout used for ellipsization.
int getIndent() nothrowGets the paragraph indent width in Pango units.
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 value
bool getJustifyLastLine() nothrowGets 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) nothrowRetrieves a particular line from a [pango.layout.Layout].
int getLineCount() nothrowRetrieves the count of lines for the layout. Returns: the line count
pango.layout_line.LayoutLine getLineReadonly(int line) nothrowRetrieves a particular line from a [pango.layout.Layout].
float getLineSpacing() nothrowGets the line spacing factor of layout.
pango.layout_line.LayoutLine[] getLines() nothrowReturns the lines of the layout as a list.
pango.layout_line.LayoutLine[] getLinesReadonly() nothrowReturns the lines of the layout as a list.
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.
uint getSerial() nothrowReturns the current serial number of layout.
bool getSingleParagraphMode() nothrowObtains whether layout is in single paragraph mode.
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 units
pango.tab_array.TabArray getTabs() nothrowGets the current [pango.tab_array.TabArray] used by this layout.
string getText() nothrowGets the text in the layout.
int getUnknownGlyphsCount() nothrowCounts the number of unknown glyphs in 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.
pango.types.WrapMode getWrap() nothrowGets the wrap mode for the layout.
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.
bool isEllipsized() nothrowQueries whether the layout had to ellipsize any paragraphs.
bool isWrapped() nothrowQueries whether the layout had to wrap any paragraphs.
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 setIndent(int indent) nothrowSets the width in Pango units to indent each paragraph.
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 setLineSpacing(float factor) nothrowSets a factor for line spacing.
void setMarkup(string markup) nothrowSets the layout text and attribute list from marked-up text.
void setMarkupWithAccel(string markup, dchar accelMarker, out dchar accelChar) nothrowSets the layout text and attribute list from marked-up text.
void setSingleParagraphMode(bool setting) nothrowSets the single paragraph mode of layout.
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 setText(string text) nothrowSets the text of the layout.
void setWidth(int width) nothrowSets the width to which the lines of the [pango.layout.Layout] should wrap or ellipsized.
void setWrap(pango.types.WrapMode wrap) nothrowSets 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) nothrowConverts 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 implementation template for pango.layout.Layout

Fluent builder for pango.layout.Layout

Methods
Layout build() nothrowCreate object from builder. Returns: New object