Layout

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):

<picture> <source srcset="layout-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Pango Layout Parameters" src="layout-light.png"> </picture>

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 |

More...
class Layout : ObjectG {}

Constructors

this
this(pango.context.Context context)

Create a new pango.layout.Layout object with attributes initialized to default values for a particular pango.context.Context.

Members

Functions

contextChanged
void contextChanged()

Forces recomputation of any state in the pango.layout.Layout that might depend on the layout's context.

copy
pango.layout.Layout copy()

Creates a deep copy-by-value of the layout.

getAlignment
pango.types.Alignment getAlignment()

Gets the alignment for the layout: how partial lines are positioned within the horizontal space available.

getAttributes
pango.attr_list.AttrList getAttributes()

Gets the attribute list for the layout, if any.

getAutoDir
bool getAutoDir()

Gets whether to calculate the base direction for the layout according to its contents.

getBaseline
int getBaseline()

Gets the Y position of baseline of the first line in layout.

getCaretPos
void getCaretPos(int index, pango.types.Rectangle strongPos, 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.

getCharacterCount
int getCharacterCount()

Returns the number of Unicode characters in the the text of layout.

getContext
pango.context.Context getContext()

Retrieves the pango.context.Context used for this layout.

getCursorPos
void getCursorPos(int index, pango.types.Rectangle strongPos, 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.

getDirection
pango.types.Direction getDirection(int index)

Gets the text direction at the given character position in layout.

getEllipsize
pango.types.EllipsizeMode getEllipsize()

Gets the type of ellipsization being performed for layout.

getExtents
void getExtents(pango.types.Rectangle inkRect, pango.types.Rectangle logicalRect)

Computes the logical and ink extents of layout.

getFontDescription
pango.font_description.FontDescription getFontDescription()

Gets the font description for the layout, if any.

getHeight
int getHeight()

Gets the height of layout used for ellipsization.

getIndent
int getIndent()

Gets the paragraph indent width in Pango units.

getIter
pango.layout_iter.LayoutIter getIter()

Returns an iterator to iterate over the visual extents of the layout.

getJustify
bool getJustify()

Gets whether each complete line should be stretched to fill the entire width of the layout.

getJustifyLastLine
bool getJustifyLastLine()

Gets whether the last line should be stretched to fill the entire width of the layout.

getLine
pango.layout_line.LayoutLine getLine(int line)

Retrieves a particular line from a pango.layout.Layout.

getLineCount
int getLineCount()

Retrieves the count of lines for the layout.

getLineReadonly
pango.layout_line.LayoutLine getLineReadonly(int line)

Retrieves a particular line from a pango.layout.Layout.

getLineSpacing
float getLineSpacing()

Gets the line spacing factor of layout.

getLines
pango.layout_line.LayoutLine[] getLines()

Returns the lines of the layout as a list.

getLinesReadonly
pango.layout_line.LayoutLine[] getLinesReadonly()

Returns the lines of the layout as a list.

getLogAttrs
void getLogAttrs(pango.types.LogAttr[] attrs)

Retrieves an array of logical attributes for each character in the layout.

getLogAttrsReadonly
pango.types.LogAttr[] getLogAttrsReadonly()

Retrieves an array of logical attributes for each character in the layout.

getPixelExtents
void getPixelExtents(pango.types.Rectangle inkRect, pango.types.Rectangle logicalRect)

Computes the logical and ink extents of layout in device units.

getPixelSize
void getPixelSize(int width, int height)

Determines the logical width and height of a pango.layout.Layout in device units.

getSerial
uint getSerial()

Returns the current serial number of layout.

getSingleParagraphMode
bool getSingleParagraphMode()

Obtains whether layout is in single paragraph mode.

getSize
void getSize(int width, int height)

Determines the logical width and height of a pango.layout.Layout in Pango units.

getSpacing
int getSpacing()

Gets the amount of spacing between the lines of the layout.

getTabs
pango.tab_array.TabArray getTabs()

Gets the current pango.tab_array.TabArray used by this layout.

getText
string getText()

Gets the text in the layout.

getUnknownGlyphsCount
int getUnknownGlyphsCount()

Counts the number of unknown glyphs in layout.

getWidth
int getWidth()

Gets the width to which the lines of the pango.layout.Layout should wrap.

getWrap
pango.types.WrapMode getWrap()

Gets the wrap mode for the layout.

indexToLineX
void indexToLineX(int index, bool trailing, int line, int xPos)

Converts from byte index_ within the layout to line and X position.

indexToPos
void indexToPos(int index, pango.types.Rectangle pos)

Converts from an index within a pango.layout.Layout to the onscreen position corresponding to the grapheme at that index.

isEllipsized
bool isEllipsized()

Queries whether the layout had to ellipsize any paragraphs.

isWrapped
bool isWrapped()

Queries whether the layout had to wrap any paragraphs.

moveCursorVisually
void moveCursorVisually(bool strong, int oldIndex, int oldTrailing, int direction, int newIndex, int newTrailing)

Computes a new cursor position from an old position and a direction.

serialize
glib.bytes.Bytes serialize(pango.types.LayoutSerializeFlags flags)

Serializes the layout for later deserialization via pango.layout.Layout.deserialize.

setAlignment
void setAlignment(pango.types.Alignment alignment)

Sets the alignment for the layout: how partial lines are positioned within the horizontal space available.

setAttributes
void setAttributes(pango.attr_list.AttrList attrs)

Sets the text attributes for a layout object.

setAutoDir
void setAutoDir(bool autoDir)

Sets whether to calculate the base direction for the layout according to its contents.

setEllipsize
void setEllipsize(pango.types.EllipsizeMode ellipsize)

Sets the type of ellipsization being performed for layout.

setFontDescription
void setFontDescription(pango.font_description.FontDescription desc)

Sets the default font description for the layout.

setHeight
void setHeight(int height)

Sets the height to which the pango.layout.Layout should be ellipsized at.

setIndent
void setIndent(int indent)

Sets the width in Pango units to indent each paragraph.

setJustify
void setJustify(bool justify)

Sets whether each complete line should be stretched to fill the entire width of the layout.

setJustifyLastLine
void setJustifyLastLine(bool justify)

Sets whether the last line should be stretched to fill the entire width of the layout.

setLineSpacing
void setLineSpacing(float factor)

Sets a factor for line spacing.

setMarkup
void setMarkup(string markup)

Sets the layout text and attribute list from marked-up text.

setMarkupWithAccel
void setMarkupWithAccel(string markup, dchar accelMarker, dchar accelChar)

Sets the layout text and attribute list from marked-up text.

setSingleParagraphMode
void setSingleParagraphMode(bool setting)

Sets the single paragraph mode of layout.

setSpacing
void setSpacing(int spacing)

Sets the amount of spacing in Pango units between the lines of the layout.

setTabs
void setTabs(pango.tab_array.TabArray tabs)

Sets the tabs to use for layout, overriding the default tabs.

setText
void setText(string text)

Sets the text of the layout.

setWidth
void setWidth(int width)

Sets the width to which the lines of the pango.layout.Layout should wrap or ellipsized.

setWrap
void setWrap(pango.types.WrapMode wrap)

Sets the wrap mode.

writeToFile
bool writeToFile(pango.types.LayoutSerializeFlags flags, string filename)

A convenience method to serialize a layout to a file.

xyToIndex
bool xyToIndex(int x, int y, int index, int trailing)

Converts from X and Y position within a layout to the byte index to the character at that logical position.

Static functions

deserialize
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.

Inherited Members

From ObjectG

setGObject
void setGObject(void* cObj, Flag!"Take" take)

Set the GObject of a D ObjectG wrapper.

cPtr
void* cPtr(Flag!"Dup" dup)

Get a pointer to the underlying C object.

ref_
void* ref_(void* gObj)

Calls g_object_ref() on a GObject.

unref
unref(void* gObj)

Calls g_object_unref() on a GObject.

getType
GType getType()

Get the GType of an object.

gType
GType gType [@property getter]

GObject GType property.

self
ObjectG self()

Convenience method to return this cast to a type. For use in D with statements.

getDObject
T getDObject(void* cptr, Flag!"Take" take)

Template to get the D object from a C GObject and cast it to the given D object type.

connectSignalClosure
ulong connectSignalClosure(string signalDetail, DClosure closure, Flag!"After" after)

Connect a D closure to an object signal.

setProperty
void setProperty(string propertyName, T val)

Template for setting a GObject property.

getProperty
T getProperty(string propertyName)

Template for getting a GObject property.

compatControl
size_t compatControl(size_t what, void* data)
bindProperty
gobject.binding.Binding bindProperty(string sourceProperty, gobject.object.ObjectG target, string targetProperty, gobject.types.BindingFlags flags)

Creates a binding between source_property on source and target_property on target.

bindPropertyFull
gobject.binding.Binding bindPropertyFull(string sourceProperty, gobject.object.ObjectG target, string targetProperty, gobject.types.BindingFlags flags, gobject.closure.Closure transformTo, gobject.closure.Closure transformFrom)

Creates a binding between source_property on source and target_property on target, allowing you to set the transformation functions to be used by the binding.

forceFloating
void forceFloating()

This function is intended for #GObject implementations to re-enforce a floating[floating-ref] object reference. Doing this is seldom required: all #GInitiallyUnowneds are created with a floating reference which usually just needs to be sunken by calling gobject.object.ObjectG.refSink.

freezeNotify
void freezeNotify()

Increases the freeze count on object. If the freeze count is non-zero, the emission of "notify" signals on object is stopped. The signals are queued until the freeze count is decreased to zero. Duplicate notifications are squashed so that at most one #GObject::notify signal is emitted for each property modified while the object is frozen.

getData
void* getData(string key)

Gets a named field from the objects table of associations (see gobject.object.ObjectG.setData).

getProperty
void getProperty(string propertyName, gobject.value.Value value)

Gets a property of an object.

getQdata
void* getQdata(glib.types.Quark quark)

This function gets back user data pointers stored via gobject.object.ObjectG.setQdata.

getv
void getv(string[] names, gobject.value.Value[] values)

Gets n_properties properties for an object. Obtained properties will be set to values. All properties must be valid. Warnings will be emitted and undefined behaviour may result if invalid properties are passed in.

isFloating
bool isFloating()

Checks whether object has a floating[floating-ref] reference.

notify
void notify(string propertyName)

Emits a "notify" signal for the property property_name on object.

notifyByPspec
void notifyByPspec(gobject.param_spec.ParamSpec pspec)

Emits a "notify" signal for the property specified by pspec on object.

refSink
gobject.object.ObjectG refSink()

Increase the reference count of object, and possibly remove the floating[floating-ref] reference, if object has a floating reference.

runDispose
void runDispose()

Releases all references to other objects. This can be used to break reference cycles.

setData
void setData(string key, void* data)

Each object carries around a table of associations from strings to pointers. This function lets you set an association.

setProperty
void setProperty(string propertyName, gobject.value.Value value)

Sets a property on an object.

stealData
void* stealData(string key)

Remove a specified datum from the object's data associations, without invoking the association's destroy handler.

stealQdata
void* stealQdata(glib.types.Quark quark)

This function gets back user data pointers stored via gobject.object.ObjectG.setQdata and removes the data from object without invoking its destroy() function (if any was set). Usually, calling this function is only required to update user data pointers with a destroy notifier, for example:

thawNotify
void thawNotify()

Reverts the effect of a previous call to gobject.object.ObjectG.freezeNotify. The freeze count is decreased on object and when it reaches zero, queued "notify" signals are emitted.

watchClosure
void watchClosure(gobject.closure.Closure closure)

This function essentially limits the life time of the closure to the life time of the object. That is, when the object is finalized, the closure is invalidated by calling gobject.closure.Closure.invalidate on it, in order to prevent invocations of the closure with a finalized (nonexisting) object. Also, gobject.object.ObjectG.ref_ and gobject.object.ObjectG.unref are added as marshal guards to the closure, to ensure that an extra reference count is held on object during invocation of the closure. Usually, this function will be called on closures that use this object as closure data.

connectNotify
ulong connectNotify(string detail, T callback, Flag!"After" after)

Connect to Notify signal.

Detailed Description

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.