Reference Manual

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# Inti::Pango::Layout Class Reference

A PangoLayout C++ wrapper class. More...

`#include <inti/pango/layout.h>`

Inheritance diagram for Inti::Pango::Layout:

List of all members.

## Public Member Functions

Constructors

- Layout (const Context &context)
    Construct a new layout object with attributes initialized to the default values for the context.
- virtual ~Layout ()
    Destructor.

Accessors

- PangoLayout * pango_layout () const
    Get a pointer to the PangoLayout structure.
- PangoLayoutClass * pango_layout_class () const
    Get a pointer to the PangoLayoutClass structure.
- operator PangoLayout * () const
    Conversion operator; safely converts a Layout to a PangoLayout pointer.
- Context * get_context () const
    Returns the Context used for this layout.
- Pointer< AttrList > get_attributes () const
    Returns a smart pointer to the attribute list for the layout, if any.
- String get_text () const
    Gets the text in the layout.
- int get_width () const
    Gets the width to which the lines of the layout should be wrapped.
- WrapMode get_wrap () const
    Returns the active wrap mode for the layout.
- int get_indent () const
    Returns the amount by which the first line should be shorter than the rest of the lines.
- int get_spacing () const
    Gets the amount of spacing between the lines of the layout (in GlyphUnits).
- bool get_justify () const
    Returns whether or not each complete line should be stretched to fill the entire width of the layout.
- Alignment get_alignment () const
    Sets the alignment for the layout (how partial lines are positioned within the horizontal space available).
- Pointer< TabArray > get_tabs () const
    Get the current TabArray used by this layout.
- bool get_single_paragraph_mode () const
    Obtains the value set by set_single_paragraph_mode().
- bool get_logical_attributes (std::vector< LogAttr > &attrs) const
    Retrieve a list of logical attributes for each character in the layout.
- void get_cursor_pos (int index, Rectangle *strong_pos, Rectangle *weak_pos) const
    Given an index within the layout, determine the positions that of the strong and weak cursors if the insertion point is at that index.
- void get_extents (Rectangle *ink_rect, Rectangle *logical_rect) const
    Compute the logical and ink extents of the layout.
- void get_pixel_extents (Rectangle *ink_rect, Rectangle *logical_rect) const
    Compute the logical and ink extents of the layout in device units.
- void get_size (int *width, int *height) const
    Determine the logical width and height of the layout in Pango units (device units divided by PANGO_SCALE).
- void get_pixel_size (int *width, int *height) const
    Determine the logical width and height of the layout in device units.
- int get_line_count () const
    Retrieve the count of lines for the layout.
- Pointer< LayoutLine > get_line (int line) const
    Retrieves a particular line from the layout.
- bool get_lines (std::vector< Pointer< LayoutLine > > &lines) const
    Retrieves the lines of the layout.
- Pointer< LayoutIter > get_iter () const
    Obtains an iterator to iterate over the visual extents of the layout.
- Pointer< Gdk::Region > get_clip_region (int x_origin, int y_origin, const std::vector< std::pair< int, int > > &index_ranges) const
    Obtains a clip region which contains the areas where the given ranges of text would be drawn (see Pango::LayoutLine::get_x_ranges() for more on using std::pair).

Methods

- void set_attributes (AttrList &attrs)
    Sets the text attributes for a layout object.
- void set_text (const String &text)
    Set the text of the layout.
- void set_markup (const String &markup)
    Sets the layout text and attribute list from marked-up text (see markup format in the GTK+ documnetation).
- void set_markup (const String &markup, gunichar accel_marker, gunichar *accel_char)
    Sets the layout text and attribute list from marked-up text (see markup format in the Pango documnetation).
- void set_font_description (const FontDescription *desc)
    Set the default font description for the layout.
- void set_width (int width)
    Sets the width to which the lines of the layout should be wrapped.
- void set_wrap (WrapMode wrap)
    Sets the wrap style; the wrap style only has an effect if a width is set on the layout with Pango::Layout::set_width().
- void set_indent (int indent)
    Sets the amount by which the first line should be shorter than the rest of the lines.
- void set_spacing (int spacing)
    Sets the amount of spacing between the lines of the layout.
- void set_justify (bool justify)
    Sets whether or not each complete line should be stretched to fill the entire width of the layout.
- void set_alignment (Alignment alignment)
    Sets the alignment for the layout (how partial lines are positioned within the horizontal space available.).
- void set_tabs (TabArray *tabs)
    Sets the tabs to use for the layout, overriding the default tabs (by default, tabs are every 8 spaces).
- void set_single_paragraph_mode (bool setting)
    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.
- void context_changed ()
    Forces recomputation of any state in the Layout that might depend on the layout's context.
- void index_to_pos (int index, Rectangle &pos)
    Convert from an index within a layout to the onscreen position corresponding to the grapheme at that index, which is represented as a rectangle.
- void move_cursor_visually (bool strong, int old_index, int old_trailing, int direction, int *new_index, int *new_trailing)
    Computes a new cursor position from an old position and a count of positions to move visually.
- bool xy_to_index (int x, int y, int *index, int *trailing)
    Convert from X and Y position within a layout to the byte index to the character at that logical position.

## Protected Member Functions

Constructors

- Layout (PangoLayout *layout, bool reference=true)
    Construct a new Layout from an existing PangoLayout.

## Detailed Description

A PangoLayout C++ wrapper class.

The Layout object represents and entire paragraph of text. It is initialized with a Context, UTF-8 string and a 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 also a number of parameters to adjust the formatting of a Layout, which are illustrated in Figure 1. It is possible, as well, to ignore the 2-D setup, and simply treat the results of a Layout as a list of lines.

Figure 1: Adjustable parameters for a Layout.

The Layout object provides a high-level driver for formatting entire paragraphs of text at once. 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.

Note: <layout.h> is the main Pango header file that your application will include, so for convenience, it includes all the required header files, except <break.h> (LogAttr) and <glyph.h> (GlyphString).

## Constructor & Destructor Documentation

Inti::Pango::Layout::Layout | ( | PangoLayout * | layout,
|  | bool | reference = true
| ) | `[explicit, protected]`

  | Construct a new Layout from an existing PangoLayout. Parameters:
  layout | A pointer to a PangoLayout.
  reference | Set false if the initial reference count is floating, set true if it's not.
The layout can be a newly created PangoLayout or an existing PangoLayout. (see G::Object::Object).

Inti::Pango::Layout::Layout | ( | const Context & | context | ) | `[explicit]`

  | Construct a new layout object with attributes initialized to the default values for the context. Parameters:
  context | A Context.

## Member Function Documentation

void Inti::Pango::Layout::context_changed | ( |  | ) |

| Forces recomputation of any state in the Layout that might depend on the layout's context. This method should be called if you make changes to the context subsequent to creating the layout.

Alignment Inti::Pango::Layout::get_alignment | ( |  | ) | const

| Sets the alignment for the layout (how partial lines are positioned within the horizontal space available). Returns: The alignment value.

Pointer<Gdk::Region> Inti::Pango::Layout::get_clip_region | ( | int | x_origin,
|  | int | y_origin,
|  | const std::vector< std::pair< int, int > > & | index_ranges
| ) | const

  | Obtains a clip region which contains the areas where the given ranges of text would be drawn (see Pango::LayoutLine::get_x_ranges() for more on using std::pair). Parameters:
  x_origin | The X pixel where you intend to draw the layout with this clip.
  y_origin | The Y pixel where you intend to draw the layout with this clip.
  index_ranges | A reference to a vector of int/int pairs that holds the index ranges. The first value of each pair is the start index and the second value is the end index.
Returns: A smart pointer to a new clip region containing the given ranges. x_origin and y_origin are the same position you would pass to Gdk::Drawable::draw_layout_line(). index_ranges should contain ranges of bytes in the layout's text. Pango::LayoutLine::get_x_ranges() shows you how to access the values returned in a vector of int/int pairs. The easiest way to create a vector of int/int pairs is to assign a pair to each vector element using the subscriipt operator, something like this:
                 typedef std::pair<int, int> Range;
                 std::vector<Range> ranges(count);

                 for (int i = 0; i < count; i++)
                 {
                    // calculate start_index and end_index here
                    ...
                    ranges[i] = Range(start_index, end_index));
                    ...
                 }
                 layout->get_clip_region(x_origin, y_origin, ranges);

Context* Inti::Pango::Layout::get_context | ( |  | ) | const

| Returns the Context used for this layout. This does not have an additional reference count added, so if you want to keep a copy of this around, you must reference it yourself, or use a smart pointer.

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

  | Given an index within the layout, determine the positions that of the strong and weak cursors if the insertion point is at that index. Parameters:
  index | The byte index of the cursor.
  strong_pos | The location to store the strong cursor position (may be null).
  weak_pos | The location to store the weak cursor position (may be null).
The position of each cursor is stored as a zero-width rectangle. 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.

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

  | Compute the logical and ink extents of the layout. Parameters:
  ink_rect | The rectangle used to store the extents of the layout as drawn, or null to indicate that the result is not needed.
  logical_rect | The rectangle used to store the logical extents of the layout, or null to indicate that the result is not needed.
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.

Pointer<LayoutIter> Inti::Pango::Layout::get_iter | ( |  | ) | const

| Obtains an iterator to iterate over the visual extents of the layout. Returns: A smart pointer to a new LayoutIter.

Pointer<LayoutLine> Inti::Pango::Layout::get_line | ( | int | line | ) | const

  | Retrieves a particular line from the layout. Parameters:
  line | The index of a line, which must be between 0 and get_line_count() - 1, inclusive.
Returns: The requested LayoutLine, or null if the index is out of range. This layout line can be retained, but will become invalid if changes are made to the layout.

int Inti::Pango::Layout::get_line_count | ( |  | ) | const

| Retrieve the count of lines for the layout. Returns: The line count.

bool Inti::Pango::Layout::get_lines | ( | std::vector< Pointer< LayoutLine > > & | lines | ) | const

  | Retrieves the lines of the layout. Parameters:
  lines | A reference to a vector of LayoutLine to hold the lines.
Returns: true if the vector is not empty. This returned lines will become invalid on any change to the layout's text or properties.

bool Inti::Pango::Layout::get_logical_attributes | ( | std::vector< LogAttr > & | attrs | ) | const

  | Retrieve a list of logical attributes for each character in the layout. Parameters:
  attrs | A reference to a vector of LogAttr to store the logical attributes.
When this method returns the size of the vector will be equal to the total number of characters in the layout.

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

  | Compute the logical and ink extents of the layout in device units. Parameters:
  ink_rect | The rectangle used to store the extents of the layout as drawn, or null to indicate that the result is not needed.
  logical_rect | The rectangle used to store the logical extents of the layout, or null to indicate that the result is not needed.
See get_extents(); this method just calls get_extents() and then converts the extents to device units using the PANGO_SCALE factor.

void Inti::Pango::Layout::get_pixel_size | ( | int * | width,
|  | int * | height
| ) | const

  | Determine the logical width and height of the layout in device units. Parameters:
  width | The location to store the logical width, or null.
  height | The location to store the logical height, or null.
get_size() returns the width and height in thousandths of a device unit. This is simply a convenience function around get_extents().

bool Inti::Pango::Layout::get_single_paragraph_mode | ( |  | ) | const

| Obtains the value set by set_single_paragraph_mode(). Returns: true if the layout does not break paragraphs at paragraph separator characters.

void Inti::Pango::Layout::get_size | ( | int * | width,
|  | int * | height
| ) | const

  | Determine the logical width and height of the layout in Pango units (device units divided by PANGO_SCALE). Parameters:
  width | The location to store the logical width, or null.
  height | The location to store the logical height, or null.
This is simply a convenience method around get_extents.

Pointer<TabArray> Inti::Pango::Layout::get_tabs | ( |  | ) | const

| Get the current TabArray used by this layout. Returns: A copy of the tabs for this layout, or null. If no TabArray has been set, then the default tabs are in use and null is returned. Default tabs are every 8 spaces.

String Inti::Pango::Layout::get_text | ( |  | ) | const

| Gets the text in the layout. Returns: The text in the layout.

int Inti::Pango::Layout::get_width | ( |  | ) | const

| Gets the width to which the lines of the layout should be wrapped. Returns: The width.

void Inti::Pango::Layout::index_to_pos | ( | int | index,
|  | Rectangle & | pos
| ) |

  | Convert from an index within a layout to the onscreen position corresponding to the grapheme at that index, which is represented as a rectangle. Parameters:
  index | The byte index within layout.
  pos | The rectangle in which to store the position of the grapheme.
Note that pos.x() is always the leading edge of the grapheme and pos.x() + pos.width() the trailing edge of the grapheme. If the directionality of the grapheme is right-to-left, then pos.width() will be negative.

void Inti::Pango::Layout::move_cursor_visually | ( | bool | strong,
|  | int | old_index,
|  | int | old_trailing,
|  | int | direction,
|  | int * | new_index,
|  | int * | new_trailing
| ) |

  | Computes a new cursor position from an old position and a count of positions to move visually. Parameters:
  strong | Whether 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_index | The byte index of the grapheme for the old index.
  old_trailing | If 0, the cursor was at the trailing edge of the grapheme indicated by old_index, if > 0, the cursor was at the leading edge.
  direction | The direction to move cursor. A negative value indicates motion to the left.
  new_index | The location 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_trailing | The number 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.
If the position count is positive, then the new strong cursor position will be one position to the right of the old cursor position. If the count is negative then the new strong cursor position will be one position to the left of the old cursor position. 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 move_cursor_visually() may move the cursor over multiple characters when multiple characters combine to form a single grapheme.

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

  | Sets the alignment for the layout (how partial lines are positioned within the horizontal space available.). Parameters:
  alignment | The new alignment.

void Inti::Pango::Layout::set_attributes | ( | AttrList & | attrs | ) |

  | Sets the text attributes for a layout object. Parameters:
  attrs | An AttrList the list the attributes.

void Inti::Pango::Layout::set_font_description | ( | const FontDescription * | desc | ) |

  | Set the default font description for the layout. Parameters:
  desc | The new pango font description, or null to unset the current font description.
If no font description is set on the layout, the font description from the layout's context is used.

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

  | Sets the amount by which the first line should be shorter than the rest of the lines. Parameters:
  indent | The amount by which to indent.
The indent may be negative, in which case the subsequent lines will be shorter than the first line.

void Inti::Pango::Layout::set_justify | ( | bool | justify | ) |

  | Sets whether or not each complete line should be stretched to fill the entire width of the layout. Parameters:
  justify | Whether the lines in the layout should be justified.
This stretching is typically done by adding whitespace, but for some scripts (such as Arabic), the justification is done by extending the characters.

void Inti::Pango::Layout::set_markup | ( | const String & | markup,
|  | gunichar | accel_marker,
|  | gunichar * | accel_char
| ) |

  | Sets the layout text and attribute list from marked-up text (see markup format in the Pango documnetation). Parameters:
  markup | Some marked-up text (see markup format in the GTK+ documnetation).
  accel_marker | The marker for accelerators in the text.
  accel_char | The return location for any located accelerators.
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.

void Inti::Pango::Layout::set_markup | ( | const String & | markup | ) |

  | Sets the layout text and attribute list from marked-up text (see markup format in the GTK+ documnetation). Parameters:
  markup | The marked-up text.
Replaces the current text and attribute list. This method doesn't scan the text for accelerators.

void Inti::Pango::Layout::set_single_paragraph_mode | ( | bool | setting | ) |

  | 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. Parameters:
  setting | The new setting.
This is used when you want to allow editing of newlines on a single text line.

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

  | Sets the amount of spacing between the lines of the layout. Parameters:
  spacing | The amount of spacing.

void Inti::Pango::Layout::set_tabs | ( | TabArray * | tabs | ) |

  | Sets the tabs to use for the layout, overriding the default tabs (by default, tabs are every 8 spaces). Parameters:
  tabs | A TabArray.
If tabs is null, the default tabs are reinstated. tabs is copied into the layout so you must unreference your copy of tabs yourself, or create it using a smart pointer.

void Inti::Pango::Layout::set_text | ( | const String & | text | ) |

  | Set the text of the layout. Parameters:
  text | A UTF-8 String.

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

  | Sets the width to which the lines of the layout should be wrapped. Parameters:
  width | The desired width, or -1 to indicate that no wrapping should be performed.

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

  | Sets the wrap style; the wrap style only has an effect if a width is set on the layout with Pango::Layout::set_width(). Parameters:
  wrap | The wrap mode.
To turn off wrapping, set the width to -1.

bool Inti::Pango::Layout::xy_to_index | ( | int | x,
|  | int | y,
|  | int * | index,
|  | int * | trailing
| ) |

  | Convert from X and Y position within a layout to the byte index to the character at that logical position. Parameters:
  x | The X offset (in GlyphUnits) from the left edge of the layout.
  y | The Y offset (in GlyphUnits) from the top edge of the layout.
  index | The location to store calculated byte index.
  trailing | The location to store a integer indicating where in the grapheme the user clicked.
Returns: true if the coordinates were inside text. If the position is not inside the layout, the closest position is chosen (the x/y position will be clamped inside the layout). If a closest position is chosen, then the method returns false; on an exact hit, it returns true. trailing will either be zero, or the number of characters in the grapheme. 0 represents the trailing edge of the grapheme.

The documentation for this class was generated from the following file:

- pango/layout.h

Main Page - Footer