pangomm 2.52.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Pango::Layout Class Reference

A Pango::Layout represents an entire paragraph of text. More...

#include <pangomm/layout.h>

Inheritance diagram for Pango::Layout:
Inheritance graph
[legend]

Public Member Functions

 Layout (Layout && src) noexcept
 
Layoutoperator= (Layout && src) noexcept
 
 ~Layout () noexcept override
 
PangoLayout * gobj ()
 Provides access to the underlying C GObject. More...
 
const PangoLayout * gobj () const
 Provides access to the underlying C GObject. More...
 
PangoLayout * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
void update_from_cairo_context (const Cairo::RefPtr< Cairo::Context > & context)
 Updates the private Pango Context of a Pango Layout created with create(const Cairo::RefPtr<Cairo::Context>&) to match the current transformation and target surface of a Cairo Context. More...
 
Glib::RefPtr< Layoutcopy ()
 Creates a deep copy-by-value of the layout. More...
 
Glib::RefPtr< Contextget_context () const
 Retrieves the Pango::Context used for this layout. More...
 
void set_attributes (AttrList & attrs)
 Sets the text attributes for a layout object. More...
 
AttrList get_attributes () const
 Gets the attribute list for the layout, if any. More...
 
void set_text (const Glib::ustring & text)
 Set the text of the layout. More...
 
Glib::ustring get_text () const
 Gets the text in the layout. More...
 
int get_character_count () const
 Returns the number of Unicode characters in the the text of layout. More...
 
void set_markup (const Glib::ustring & markup)
 Sets the layout text and attribute list from marked-up text (see markup format). More...
 
void set_markup (const Glib::ustring & markup, gunichar accel_marker, gunichar & accel_char)
 Sets the layout text and attribute list from marked-up text (see markup format). More...
 
void set_font_description (const FontDescription & desc)
 Set the default font description for the layout. More...
 
void unset_font_description ()
 
FontDescription get_font_description () const
 Gets the font description for the layout, if any. More...
 
void set_width (int width)
 Sets the width to which the lines of the Pango::Layout should wrap or ellipsized. More...
 
int get_width () const
 Gets the width to which the lines of the Pango::Layout should wrap. More...
 
void set_height (int height)
 Sets the height to which the Pango::Layout should be ellipsized at. More...
 
int get_height () const
 Gets the height of layout used for ellipsization. More...
 
void set_wrap (WrapMode wrap)
 Sets the wrap mode. More...
 
WrapMode get_wrap () const
 Gets the wrap mode for the layout. More...
 
bool is_wrapped () const
 Queries whether the layout had to wrap any paragraphs. More...
 
void set_indent (int indent)
 Sets the width in Pango units to indent each paragraph. More...
 
int get_indent () const
 Gets the paragraph indent width in Pango units. More...
 
void set_spacing (int spacing)
 Sets the amount of spacing in Pango units between the lines of the layout. More...
 
int get_spacing () const
 Gets the amount of spacing between the lines of the layout. More...
 
void set_line_spacing (float factor)
 Sets a factor for line spacing. More...
 
float get_line_spacing () const
 Gets the line spacing factor of layout. More...
 
void set_justify (bool justify=true)
 Sets whether each complete line should be stretched to fill the entire width of the layout. More...
 
bool get_justify () const
 Gets whether each complete line should be stretched to fill the entire width of the layout. More...
 
bool get_auto_dir () const
 Gets whether to calculate the base direction for the layout according to its contents. More...
 
void set_auto_dir (bool auto_dir=true)
 Sets whether to calculate the base direction for the layout according to its contents. More...
 
void set_alignment (Alignment alignment)
 Sets the alignment for the layout: how partial lines are positioned within the horizontal space available. More...
 
Alignment get_alignment () const
 Gets the alignment for the layout: how partial lines are positioned within the horizontal space available. More...
 
void set_tabs (TabArray & tabs)
 Sets the tabs to use for layout, overriding the default tabs. More...
 
TabArray get_tabs () const
 Get the current Pango::TabArray used by this layout. More...
 
void set_single_paragraph_mode (bool setting=true)
 Sets the single paragraph mode of layout. More...
 
bool get_single_paragraph_mode () const
 Obtains whether layout is in single paragraph mode. More...
 
void set_ellipsize (EllipsizeMode ellipsize)
 Sets the type of ellipsization being performed for layout. More...
 
EllipsizeMode get_ellipsize () const
 Gets the type of ellipsization being performed for layout. More...
 
bool is_ellipsized () const
 Queries whether the layout had to ellipsize any paragraphs. More...
 
int get_unknown_glyphs_count () const
 Counts the number of unknown glyphs in layout. More...
 
void context_changed ()
 Forces recomputation of any state in the Pango::Layout that might depend on the layout's context. More...
 
guint get_serial () const
 Returns the current serial number of layout. More...
 
std::vector< LogAttrget_log_attrs () const
 Retrieve a vector of logical attributes for each character in the layout. More...
 
Rectangle index_to_pos (int index) const
 Convert from an index within the layout to the onscreen position corresponding to the grapheme at that index, which is represented as rectangle. More...
 
void index_to_line_x (int index_, bool trailing, int & line, int & x_pos) const
 Converts from byte index within the layout to line and X position. More...
 
void get_cursor_pos (int index, Rectangle & strong_pos, Rectangle & weak_pos) const
 Given an index within a layout, determines the positions that of the strong and weak cursors if the insertion point is at that index. More...
 
Rectangle get_cursor_strong_pos (int index) const
 Given an index within the layout, determine the positions that of the strong cursors if the insertion point is at that index. More...
 
Rectangle get_cursor_weak_pos (int index) const
 Given an index within the layout, determine the positions that of the weak cursors if the insertion point is at that index. More...
 
void move_cursor_visually (bool strong, int old_index, int old_trailing, int direction, int & new_index, int & new_trailing) const
 Computes a new cursor position from an old position and a direction. More...
 
bool xy_to_index (int x, int y, int & index, int & trailing) const
 Converts from X and Y position within a layout to the byte index to the character at that logical position. More...
 
void get_extents (Rectangle & ink_rect, Rectangle & logical_rect) const
 Compute the logical and ink extents of layout. More...
 
Rectangle get_ink_extents () const
 Compute the ink extents of layout. More...
 
Rectangle get_logical_extents () const
 Compute the logical extents of layout. More...
 
void get_pixel_extents (Rectangle & ink_rect, Rectangle & logical_rect) const
 Compute the logical and ink extents of layout in device units. More...
 
Rectangle get_pixel_ink_extents () const
 Compute the ink extents of the layout in device units. More...
 
Rectangle get_pixel_logical_extents () const
 Compute the logical extents of the layout in device units. More...
 
void get_size (int & width, int & height) const
 Determines the logical width and height of a Pango::Layout in Pango units. More...
 
void get_pixel_size (int & width, int & height) const
 Determines the logical width and height of a Pango::Layout in device units. More...
 
int get_baseline () const
 Gets the Y position of baseline of the first line in layout. More...
 
int get_line_count () const
 Retrieves the count of lines for the layout. More...
 
Glib::RefPtr< LayoutLineget_line (int line)
 Retrieves a particular line from a Pango::Layout. More...
 
Glib::RefPtr< const LayoutLineget_line (int line) const
 Retrieves a particular line from a Pango::Layout. More...
 
Glib::RefPtr< const LayoutLineget_const_line (int line) const
 Retrieves a particular line from a Pango::Layout. More...
 
std::vector< Glib::RefPtr< LayoutLine > > get_lines ()
 Returns the lines of the layout as a vector. More...
 
std::vector< Glib::RefPtr< const LayoutLine > > get_lines () const
 Returns the lines of the layout as a vector. More...
 
std::vector< Glib::RefPtr< const LayoutLine > > get_const_lines () const
 Returns the lines of the layout as a vector. More...
 
LayoutIter get_iter ()
 Gets an iterator to iterate over the visual extents of the layout. More...
 
void add_to_cairo_context (const Cairo::RefPtr< Cairo::Context > & context)
 Adds the text in this LayoutLine to the current path in the specified Cairo context. More...
 
void show_in_cairo_context (const Cairo::RefPtr< Cairo::Context > & context)
 Draws a Layout in the specified Cairo context. More...
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
static Glib::RefPtr< Layoutcreate (const Glib::RefPtr< Context > & context)
 
static Glib::RefPtr< Layoutcreate (const Cairo::RefPtr< Cairo::Context > & context)
 Creates a layout object set up to match the current transformation and target surface of the Cairo context. More...
 

Protected Member Functions

 Layout (const Glib::RefPtr< Context > & context)
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Pango::Layoutwrap (PangoLayout * object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Detailed Description

A Pango::Layout represents an entire paragraph of text.

It is initialized with a Pango::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.

Constructor & Destructor Documentation

◆ Layout() [1/2]

Pango::Layout::Layout ( Layout &&  src)
noexcept

◆ ~Layout()

Pango::Layout::~Layout ( )
overridenoexcept

◆ Layout() [2/2]

Pango::Layout::Layout ( const Glib::RefPtr< Context > &  context)
explicitprotected

Member Function Documentation

◆ add_to_cairo_context()

void Pango::Layout::add_to_cairo_context ( const Cairo::RefPtr< Cairo::Context > &  context)

Adds the text in this LayoutLine to the current path in the specified Cairo context.

The origin of the glyphs (the left edge of the line) will be at the current point of the cairo context.

Parameters
contextA Cairo context.

◆ context_changed()

void Pango::Layout::context_changed ( )

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

This function should be called if you make changes to the context subsequent to creating the layout.

◆ copy()

Glib::RefPtr< Layout > Pango::Layout::copy ( )

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

The attribute list, tab array, and text from the original layout are all copied by value.

Returns
The newly allocated Pango::Layout.

◆ create() [1/2]

static Glib::RefPtr< Layout > Pango::Layout::create ( const Cairo::RefPtr< Cairo::Context > &  context)
static

Creates a layout object set up to match the current transformation and target surface of the Cairo context.

This layout can then be used for text measurement with functions like get_size() or drawing with methods like show_in_cairo_contet(). If you change the transformation or target surface for context, you need to call update_from_cairo_context()

This is the most convenient way to use Cairo with Pango. However it is slightly inefficient since it creates a separate Pango Context object for each layout. This might matter in an application that is laying out large amounts of text.

Parameters
contextA Cairo context.
Returns
The newly created Pango Layout.

◆ create() [2/2]

static Glib::RefPtr< Layout > Pango::Layout::create ( const Glib::RefPtr< Context > &  context)
static

◆ get_alignment()

Alignment Pango::Layout::get_alignment ( ) const

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

Returns
The alignment.

◆ get_attributes()

AttrList Pango::Layout::get_attributes ( ) const

Gets the attribute list for the layout, if any.

Returns
A Pango::AttrList.

◆ get_auto_dir()

bool Pango::Layout::get_auto_dir ( ) const

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

See set_auto_dir().

Since pangomm 1.4:
Returns
true if the bidirectional base direction is computed from the layout's contents, false otherwise.

◆ get_baseline()

int Pango::Layout::get_baseline ( ) const

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

Since pangomm 1.22:
Returns
Baseline of first line, from top of layout.

◆ get_character_count()

int Pango::Layout::get_character_count ( ) const

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

Since pangomm 1.30:
Returns
The number of Unicode characters in the text of layout.

◆ get_const_line()

Glib::RefPtr< const LayoutLine > Pango::Layout::get_const_line ( int  line) const

Retrieves a particular line from a Pango::Layout.

This is a faster alternative to get_line(), but the user is not expected to modify the contents of the line (glyphs, glyph widths, etc.).

Since pangomm 2.50:
Parameters
lineThe index of a line, which must be between 0 and get_line_count() - 1, inclusive.
Returns
The requested Pango::LayoutLine, or an empty RefPtr if the index is out of range. This layout line will become invalid if changes are made to the Pango::Layout. No changes should be made to the line.

◆ get_const_lines()

std::vector< Glib::RefPtr< const LayoutLine > > Pango::Layout::get_const_lines ( ) const

Returns the lines of the layout as a vector.

This is a faster alternative to get_lines(), but the user is not expected to modify the contents of the lines (glyphs, glyph widths, etc.).

Since pangomm 2.50:
Returns
A std::vector containing the lines in the layout. This points to internal data of the Pango::Layout and must be used with care. It will become invalid on any change to the layout's text or properties. No changes should be made to the lines.

◆ get_context()

Glib::RefPtr< Context > Pango::Layout::get_context ( ) const

Retrieves the Pango::Context used for this layout.

Returns
The Pango::Context for the layout.

◆ get_cursor_pos()

void Pango::Layout::get_cursor_pos ( int  index,
Rectangle strong_pos,
Rectangle weak_pos 
) const

Given an index within a layout, determines the positions that of the strong and weak cursors if the insertion point is at that index.

The position of each cursor is stored as a zero-width rectangle with the height of the run extents.

<picture> <source srcset="cursor-positions-dark.png" media="(prefers-color-scheme: dark)"> Cursor positions </picture>

The strong cursor location is the location where characters of the directionality equal to the base direction of the layout are inserted. The weak cursor location is the location where characters of the directionality opposite to the base direction of the layout are inserted.

The following example shows text with both a strong and a weak cursor.

<picture> <source srcset="split-cursor-dark.png" media="(prefers-color-scheme: dark)"> Strong and weak cursors </picture>

The strong cursor has a little arrow pointing to the right, the weak cursor to the left. Typing a 'c' in this situation will insert the character after the 'b', and typing another Hebrew character, like '×’', will insert it at the end.

Parameters
indexThe byte index of the cursor.
strong_posLocation to store the strong cursor position.
weak_posLocation to store the weak cursor position.

◆ get_cursor_strong_pos()

Rectangle Pango::Layout::get_cursor_strong_pos ( int  index) const

Given an index within the layout, determine the positions that of the strong cursors if the insertion point is at that index.

Parameters
indexThe byte index of the cursor.
Returns
The strong cursor position.

◆ get_cursor_weak_pos()

Rectangle Pango::Layout::get_cursor_weak_pos ( int  index) const

Given an index within the layout, determine the positions that of the weak cursors if the insertion point is at that index.

Parameters
indexThe byte index of the cursor.
Returns
The weak cursor position.

◆ get_ellipsize()

EllipsizeMode Pango::Layout::get_ellipsize ( ) const

Gets the type of ellipsization being performed for layout.

See set_ellipsize().

Use is_ellipsized() to query whether any paragraphs were actually ellipsized.

Since pangomm 1.6:
Returns
The current ellipsization mode for layout.

◆ get_extents()

void Pango::Layout::get_extents ( Rectangle ink_rect,
Rectangle logical_rect 
) const

Compute the logical and ink extents of layout.

Logical extents are usually what you want for positioning things. The extents are given in layout coordinates; layout coordinates begin at the top left corner of the layout.

Parameters
ink_rectRectangle used to store the extents of the layout as drawn.
logical_rectRectangle used to store the logical extents of the layout.

◆ get_font_description()

FontDescription Pango::Layout::get_font_description ( ) const

Gets the font description for the layout, if any.

Since pangomm 1.8:
Returns
A pointer to the layout's font description, or nullptr if the font description from the layout's context is inherited.

◆ get_height()

int Pango::Layout::get_height ( ) const

Gets the height of layout used for ellipsization.

See set_height() for details.

Since pangomm 1.20:
Returns
The height, in Pango units if positive, or number of lines if negative.

◆ get_indent()

int Pango::Layout::get_indent ( ) const

Gets the paragraph indent width in Pango units.

A negative value indicates a hanging indentation.

Returns
The indent in Pango units.

◆ get_ink_extents()

Rectangle Pango::Layout::get_ink_extents ( ) const

Compute the ink extents of layout.

Returns
The extents of the layout as drawn.

◆ get_iter()

LayoutIter Pango::Layout::get_iter ( )

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

Returns
The iterator.
Since pangomm 2.28:

◆ get_justify()

bool Pango::Layout::get_justify ( ) const

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

Returns
The justify value.

◆ get_line() [1/2]

Glib::RefPtr< LayoutLine > Pango::Layout::get_line ( int  line)

Retrieves a particular line from a Pango::Layout.

Use the faster get_const_line() if you do not plan to modify the contents of the line (glyphs, glyph widths, etc.).

Parameters
lineThe index of a line, which must be between 0 and get_line_count() - 1, inclusive.
Returns
The requested Pango::LayoutLine, or an empty RefPtr if the index is out of range. This layout line will become invalid if changes are made to the Pango::Layout.

◆ get_line() [2/2]

Glib::RefPtr< const LayoutLine > Pango::Layout::get_line ( int  line) const

Retrieves a particular line from a Pango::Layout.

Parameters
lineThe index of a line, which must be between 0 and get_line_count() - 1, inclusive.
Returns
The requested Pango::LayoutLine, or an empty RefPtr if the index is out of range. This layout line will become invalid if changes are made to the Pango::Layout. No changes should be made to the line.

◆ get_line_count()

int Pango::Layout::get_line_count ( ) const

Retrieves the count of lines for the layout.

Returns
The line count.

◆ get_line_spacing()

float Pango::Layout::get_line_spacing ( ) const

Gets the line spacing factor of layout.

See set_line_spacing().

Since pangomm 1.44:

◆ get_lines() [1/2]

std::vector< Glib::RefPtr< LayoutLine > > Pango::Layout::get_lines ( )

Returns the lines of the layout as a vector.

Use the faster get_const_lines() if you do not plan to modify the contents of the lines (glyphs, glyph widths, etc.).

Returns
A std::vector containing the lines in the layout. This points to internal data of the Pango::Layout and must be used with care. It will become invalid on any change to the layout's text or properties.

◆ get_lines() [2/2]

std::vector< Glib::RefPtr< const LayoutLine > > Pango::Layout::get_lines ( ) const

Returns the lines of the layout as a vector.

Returns
A std::vector containing the lines in the layout. This points to internal data of the Pango::Layout and must be used with care. It will become invalid on any change to the layout's text or properties. No changes should be made to the lines.

◆ get_log_attrs()

std::vector< LogAttr > Pango::Layout::get_log_attrs ( ) const

Retrieve a vector of logical attributes for each character in the layout.

The number of attributes returned will be one more than the total number of characters in the layout, since there need to be attributes corresponding to both the position before the first character and the position after the last character.

Returns
A vector of logical attributes.

◆ get_logical_extents()

Rectangle Pango::Layout::get_logical_extents ( ) const

Compute the logical extents of layout.

Returns
The logical extents of the layout.

◆ get_pixel_extents()

void Pango::Layout::get_pixel_extents ( Rectangle ink_rect,
Rectangle logical_rect 
) const

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

See get_extents(); this function just calls get_extents() and then converts the extents to pixels using the Pango::SCALE factor.

Parameters
ink_rectRectangle used to store the extents of the layout as drawn.
logical_rectRectangle used to store the logical extents of the layout.

◆ get_pixel_ink_extents()

Rectangle Pango::Layout::get_pixel_ink_extents ( ) const

Compute the ink extents of the layout in device units.

Returns
The extents of the layout as drawn.

◆ get_pixel_logical_extents()

Rectangle Pango::Layout::get_pixel_logical_extents ( ) const

Compute the logical extents of the layout in device units.

Returns
The logical extents of the layout.

◆ get_pixel_size()

void Pango::Layout::get_pixel_size ( int &  width,
int &  height 
) const

Determines the logical width and height of a Pango::Layout in device units.

get_size() returns the width and height scaled by Pango::SCALE. This is simply a convenience function around get_pixel_extents().

Parameters
widthLocation to store the logical width.
heightLocation to store the logical height.

◆ get_serial()

guint Pango::Layout::get_serial ( ) const

Returns the current serial number of layout.

The serial number is initialized to an small number larger than zero when a new layout is created and is increased whenever the layout is changed using any of the setter functions, or the Pango::Context it uses has changed. The serial may wrap, but will never have the value 0. Since it can wrap, never compare it with "less than", always use "not equals".

This can be used to automatically detect changes to a Pango::Layout, and is useful for example to decide whether a layout needs redrawing. To force the serial to be increased, use context_changed().

Since pangomm 1.32.4:
Returns
The current serial number of layout.

◆ get_single_paragraph_mode()

bool Pango::Layout::get_single_paragraph_mode ( ) const

Obtains whether layout is in single paragraph mode.

See set_single_paragraph_mode().

Returns
true if the layout does not break paragraphs at paragraph separator characters, false otherwise.

◆ get_size()

void Pango::Layout::get_size ( int &  width,
int &  height 
) const

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

This is simply a convenience function around get_extents().

Parameters
widthLocation to store the logical width.
heightLocation to store the logical height.

◆ get_spacing()

int Pango::Layout::get_spacing ( ) const

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

Returns
The spacing in Pango units.

◆ get_tabs()

TabArray Pango::Layout::get_tabs ( ) const

Get the current Pango::TabArray used by this layout.

If no Pango::TabArray has been set, then the default tabs are in use and an invalid instance is returned. Default tabs are every 8 spaces.

Returns
A copy of the tabs for this layout.

◆ get_text()

Glib::ustring Pango::Layout::get_text ( ) const

Gets the text in the layout.

The returned text should not be freed or modified.

Returns
The text in the layout.

◆ get_type()

static GType Pango::Layout::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ get_unknown_glyphs_count()

int Pango::Layout::get_unknown_glyphs_count ( ) const

Counts the number of unknown glyphs in layout.

This function can be used to determine if there are any fonts available to render all characters in a certain string, or when used in combination with Pango::AttrType::FALLBACK, to check if a certain font supports all the characters in the string.

Since pangomm 1.16:
Returns
The number of unknown glyphs in layout.

◆ get_width()

int Pango::Layout::get_width ( ) const

Gets the width to which the lines of the Pango::Layout should wrap.

Returns
The width in Pango units, or -1 if no width set.

◆ get_wrap()

WrapMode Pango::Layout::get_wrap ( ) const

Gets the wrap mode for the layout.

Use is_wrapped() to query whether any paragraphs were actually wrapped.

Returns
Active wrap mode.

◆ gobj() [1/2]

PangoLayout * Pango::Layout::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const PangoLayout * Pango::Layout::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

PangoLayout * Pango::Layout::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ index_to_line_x()

void Pango::Layout::index_to_line_x ( int  index_,
bool  trailing,
int &  line,
int &  x_pos 
) const

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

The X position is measured from the left edge of the line.

Parameters
indexThe byte index of a grapheme within the layout.
trailingAn integer indicating the edge of the grapheme to retrieve the position of. If > 0, the trailing edge of the grapheme, if 0, the leading of the grapheme.
lineLocation to store resulting line index. (which will between 0 and pango_layout_get_line_count(layout) - 1).
x_posLocation to store resulting position within line (Pango::SCALE units per device unit).

◆ index_to_pos()

Rectangle Pango::Layout::index_to_pos ( int  index) const

Convert from an index within the layout to the onscreen position corresponding to the grapheme at that index, which is represented as rectangle.

Note that x in the returned rectangle is always the leading edge of the grapheme and x + width the trailing edge of the grapheme. If the directionality of the grapheme is right-to-left, then width will be negative.

Parameters
indexByte index within layout.
Returns
The position of the grapheme.

◆ is_ellipsized()

bool Pango::Layout::is_ellipsized ( ) const

Queries whether the layout had to ellipsize any paragraphs.

This returns true if the ellipsization mode for layout is not Pango::EllipsizeMode::NONE, a positive width is set on layout, and there are paragraphs exceeding that width that have to be ellipsized.

Since pangomm 1.16:
Returns
true if any paragraphs had to be ellipsized, false otherwise.

◆ is_wrapped()

bool Pango::Layout::is_wrapped ( ) const

Queries whether the layout had to wrap any paragraphs.

This returns true if a positive width is set on layout, ellipsization mode of layout is set to Pango::EllipsizeMode::NONE, and there are paragraphs exceeding the layout width that have to be wrapped.

Since pangomm 1.16:
Returns
true if any paragraphs had to be wrapped, false otherwise.

◆ move_cursor_visually()

void Pango::Layout::move_cursor_visually ( bool  strong,
int  old_index,
int  old_trailing,
int  direction,
int &  new_index,
int &  new_trailing 
) const

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

If direction is positive, then the new position will cause the strong or weak cursor to be displayed one position to right of where it was with the old cursor position. If direction is negative, it will be moved to the left.

In the presence of bidirectional text, the correspondence between logical and visual order will depend on the direction of the current run, and there may be jumps when the cursor is moved off of the end of a run.

Motion here is in cursor positions, not in characters, so a single call to this function may move the cursor over multiple characters when multiple characters combine to form a single grapheme.

Parameters
strongWhether the moving cursor is the strong cursor or the weak cursor. The strong cursor is the cursor corresponding to text insertion in the base direction for the layout.
old_indexThe byte index of the current cursor position.
old_trailingIf 0, the cursor was at the leading edge of the grapheme indicated by old_index, if > 0, the cursor was at the trailing edge.
directionDirection to move cursor. A negative value indicates motion to the left.
new_indexLocation to store the new cursor byte index. A value of -1 indicates that the cursor has been moved off the beginning of the layout. A value of G_MAXINT indicates that the cursor has been moved off the end of the layout.
new_trailingNumber of characters to move forward from the location returned for new_index to get the position where the cursor should be displayed. This allows distinguishing the position at the beginning of one line from the position at the end of the preceding line. new_index is always on the line where the cursor should be displayed.

◆ operator=()

Layout & Pango::Layout::operator= ( Layout &&  src)
noexcept

◆ set_alignment()

void Pango::Layout::set_alignment ( Alignment  alignment)

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

The default alignment is Pango::Alignment::LEFT.

Parameters
alignmentThe alignment.

◆ set_attributes()

void Pango::Layout::set_attributes ( AttrList attrs)

Sets the text attributes for a layout object.

References attrs, so the caller can unref its reference.

Parameters
attrsA Pango::AttrList.

◆ set_auto_dir()

void Pango::Layout::set_auto_dir ( bool  auto_dir = true)

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

When this flag is on (the default), then paragraphs in layout that begin with strong right-to-left characters (Arabic and Hebrew principally), will have right-to-left layout, paragraphs with letters from other scripts will have left-to-right layout. Paragraphs with only neutral characters get their direction from the surrounding paragraphs.

When false, the choice between left-to-right and right-to-left layout is done according to the base direction of the layout's Pango::Context. (See Pango::Context::set_base_dir()).

When the auto-computed direction of a paragraph differs from the base direction of the context, the interpretation of Pango::Alignment::LEFT and Pango::Alignment::RIGHT are swapped.

Since pangomm 1.4:
Parameters
auto_dirIf true, compute the bidirectional base direction from the layout's contents.

◆ set_ellipsize()

void Pango::Layout::set_ellipsize ( EllipsizeMode  ellipsize)

Sets the type of ellipsization being performed for layout.

Depending on the ellipsization mode ellipsize text is removed from the start, middle, or end of text so they fit within the width and height of layout set with set_width() and set_height().

If the layout contains characters such as newlines that force it to be layed out in multiple paragraphs, then whether each paragraph is ellipsized separately or the entire layout is ellipsized as a whole depends on the set height of the layout.

The default value is Pango::EllipsizeMode::NONE.

See set_height() for details.

Since pangomm 1.6:
Parameters
ellipsizeThe new ellipsization mode for layout.

◆ set_font_description()

void Pango::Layout::set_font_description ( const FontDescription desc)

Set the default font description for the layout.

If no font description is set on the layout, the font description from the layout's context is used.

Parameters
descThe new pango font description.

◆ set_height()

void Pango::Layout::set_height ( int  height)

Sets the height to which the Pango::Layout should be ellipsized at.

There are two different behaviors, based on whether height is positive or negative.

If height is positive, it will be the maximum height of the layout. Only lines would be shown that would fit, and if there is any text omitted, an ellipsis added. At least one line is included in each paragraph regardless of how small the height value is. A value of zero will render exactly one line for the entire layout.

If height is negative, it will be the (negative of) maximum number of lines per paragraph. That is, the total number of lines shown may well be more than this value if the layout contains multiple paragraphs of text. The default value of -1 means that the first line of each paragraph is ellipsized. This behavior may be changed in the future to act per layout instead of per paragraph. File a bug against pango at https://gitlab.gnome.org/gnome/pango if your code relies on this behavior.

Height setting only has effect if a positive width is set on layout and ellipsization mode of layout is not Pango::EllipsizeMode::NONE. The behavior is undefined if a height other than -1 is set and ellipsization mode is set to Pango::EllipsizeMode::NONE, and may change in the future.

Since pangomm 1.20:
Parameters
heightThe desired height of the layout in Pango units if positive, or desired number of lines if negative.

◆ set_indent()

void Pango::Layout::set_indent ( int  indent)

Sets the width in Pango units to indent each paragraph.

A negative value of indent will produce a hanging indentation. That is, the first line will have the full width, and subsequent lines will be indented by the absolute value of indent.

The indent setting is ignored if layout alignment is set to Pango::Alignment::CENTER.

The default value is 0.

Parameters
indentThe amount by which to indent.

◆ set_justify()

void Pango::Layout::set_justify ( bool  justify = true)

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

Stretching is typically done by adding whitespace, but for some scripts (such as Arabic), the justification may be done in more complex ways, like extending the characters.

Note that this setting is not implemented and so is ignored in Pango older than 1.18.

Note that tabs and justification conflict with each other: Justification will move content away from its tab-aligned positions.

The default value is false.

Also see set_justify_last_line().

Parameters
justifyWhether the lines in the layout should be justified.

◆ set_line_spacing()

void Pango::Layout::set_line_spacing ( float  factor)

Sets a factor for line spacing.

Typical values are: 0, 1, 1.5, 2. The default values is 0.

If factor is non-zero, lines are placed so that

baseline2 = baseline1 + factor * height2

where height2 is the line height of the second line (as determined by the font(s)). In this case, the spacing set with set_spacing() is ignored.

If factor is zero (the default), spacing is applied as before.

Note
for semantics that are closer to the CSS line-height property, see pango_attr_line_height_new().
Since pangomm 1.44:
Parameters
factorThe new line spacing factor.

◆ set_markup() [1/2]

void Pango::Layout::set_markup ( const Glib::ustring &  markup)

Sets the layout text and attribute list from marked-up text (see markup format).

Replaces the current text and attribute list.

Parameters
markupSome marked-up text.

◆ set_markup() [2/2]

void Pango::Layout::set_markup ( const Glib::ustring &  markup,
gunichar  accel_marker,
gunichar &  accel_char 
)

Sets the layout text and attribute list from marked-up text (see markup format).

Replaces the current text and attribute list.

If accel_marker is nonzero, the given character will mark the character following it as an accelerator. For example, the accel marker might be an ampersand or underscore. All characters marked as an accelerator will receive a Pango::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.

Parameters
markupSome marked-up text.
accel_markerMarker for accelerators in the text.
accel_charReturn location for any located accelerators.

◆ set_single_paragraph_mode()

void Pango::Layout::set_single_paragraph_mode ( bool  setting = true)

Sets the single paragraph mode of layout.

If setting is true, do not treat newlines and similar characters as paragraph separators; instead, keep all text in a single paragraph, and display a glyph for paragraph separator characters. Used when you want to allow editing of newlines on a single text line.

The default value is false.

Parameters
settingNew setting.

◆ set_spacing()

void Pango::Layout::set_spacing ( int  spacing)

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

When placing lines with spacing, Pango arranges things so that

line2.top = line1.bottom + spacing

The default value is 0.

Note
Since 1.44, Pango is using the line height (as determined by the font) for placing lines when the line spacing factor is set to a non-zero value with set_line_spacing(). In that case, the spacing set with this function is ignored.
for semantics that are closer to the CSS line-height property, see pango_attr_line_height_new().
Parameters
spacingThe amount of spacing.

◆ set_tabs()

void Pango::Layout::set_tabs ( TabArray tabs)

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

Pango::Layout will place content at the next tab position whenever it meets a Tab character (U+0009).

By default, tabs are every 8 spaces. If tabs is nullptr, the default tabs are reinstated. tabs is copied into the layout; you must free your copy of tabs yourself.

Note that tabs and justification conflict with each other: Justification will move content away from its tab-aligned positions. The same is true for alignments other than Pango::Alignment::LEFT.

Parameters
tabsA Pango::TabArray.

◆ set_text()

void Pango::Layout::set_text ( const Glib::ustring &  text)

Set the text of the layout.

Parameters
textThe text for the layout.

◆ set_width()

void Pango::Layout::set_width ( int  width)

Sets the width to which the lines of the Pango::Layout should wrap or ellipsized.

The default value is -1: no width set.

Parameters
widthThe desired width in Pango units, or -1 to indicate that no wrapping or ellipsization should be performed.

◆ set_wrap()

void Pango::Layout::set_wrap ( WrapMode  wrap)

Sets the wrap mode.

The wrap mode only has effect if a width is set on the layout with set_width(). To turn off wrapping, set the width to -1.

The default value is Pango::WrapMode::WORD.

Parameters
wrapThe wrap mode.

◆ show_in_cairo_context()

void Pango::Layout::show_in_cairo_context ( const Cairo::RefPtr< Cairo::Context > &  context)

Draws a Layout in the specified Cairo context.

The top-left corner of the Layout will be drawn at the current point of the cairo context.

Parameters
contextA Cairo context.
Since pangomm 2.16:

◆ unset_font_description()

void Pango::Layout::unset_font_description ( )

◆ update_from_cairo_context()

void Pango::Layout::update_from_cairo_context ( const Cairo::RefPtr< Cairo::Context > &  context)

Updates the private Pango Context of a Pango Layout created with create(const Cairo::RefPtr<Cairo::Context>&) to match the current transformation and target surface of a Cairo Context.

Parameters
contextA Cairo context.

◆ xy_to_index()

bool Pango::Layout::xy_to_index ( int  x,
int  y,
int &  index,
int &  trailing 
) const

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

If the Y position is not inside the layout, the closest position is chosen (the position will be clamped inside the layout). If the X position is not within the layout, then the start or the end of the line is chosen as described for Pango::LayoutLine::x_to_index(). If either the X or Y positions were not inside the layout, then the function returns false; on an exact hit, it returns true.

Parameters
xThe X offset (in Pango units) from the left edge of the layout.
yThe Y offset (in Pango units) from the top edge of the layout.
indexLocation to store calculated byte index.
trailingLocation to store a integer indicating where in the grapheme the user clicked. It will either be zero, or the number of characters in the grapheme. 0 represents the leading edge of the grapheme.
Returns
true if the coordinates were inside text, false otherwise.

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Pango::Layout > wrap ( PangoLayout *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.