Xfce Foundation Classes
Main Page  | IndexNamespace List  |  Alphabetical List  |  Class List  |  File List


Xfc::Pango::Layout Class Reference

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

#include <xfc/pango/layout.hh>

Inheritance diagram for Xfc::Pango::Layout:

Xfc::G::Object Xfc::G::TypeInstance Xfc::Trackable List of all members.

Public Member Functions

Constructors
Accessors
Methods

Protected Member Functions

Constructors

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.

layout.png


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

Note: dynamically allocated objects must either be unreferenced or assigned to a smart pointer. Stack objects are automatically unreferenced when they go out of scope.


Constructor & Destructor Documentation

Xfc::Pango::Layout::Layout PangoLayout *  layout,
bool  owns_reference = true
[explicit, protected]
 

Construct a new Layout from an existing PangoLayout.

Parameters:
layout A pointer to a PangoLayout.
owns_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).

Xfc::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.
A Layout object is created with a reference count of 1 that the caller owns.


Member Function Documentation

void Xfc::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 Xfc::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.

AttrList* Xfc::Pango::Layout::get_attributes  )  const
 

Gets the attribute list for the layout, if any.

Returns:
A smart pointer to the attribute list for the layout, or null if none is in use.

bool Xfc::Pango::Layout::get_auto_dir  )  const
 

Gets whether to calculate the bidirectional base direction for the layout according to the contents of the layout (see set_auto_dir()).

Returns:
If true, the bidirectional base direction is computed from the layout's contents.

Pointer<Gdk::Region> Xfc::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* Xfc::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 Xfc::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.

EllipsizeMode Xfc::Pango::Layout::get_ellipsize  )  const
 

Gets the type of ellipsization being performed for layout (see set_ellipsize()).

Returns:
The current ellipsization mode for the layout.

void Xfc::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<FontDescription> Xfc::Pango::Layout::get_font_description  )  const
 

Gets the font description for the layout, if any.

Returns:
A smart pointer to the layout's font description.
This method returns a null pointer if the font description from the layout's context is inherited.

Pointer<LayoutIter> Xfc::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> Xfc::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 Xfc::Pango::Layout::get_line_count  )  const
 

Retrieve the count of lines for the layout.

Returns:
The line count.

bool Xfc::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 Xfc::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 Xfc::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 Xfc::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 Xfc::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 Xfc::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> Xfc::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 Xfc::Pango::Layout::get_text  )  const
 

Gets the text in the layout.

Returns:
The text in the layout.

int Xfc::Pango::Layout::get_width  )  const
 

Gets the width to which the lines of the layout should be wrapped.

Returns:
The width.

void Xfc::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 Xfc::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 Xfc::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 Xfc::Pango::Layout::set_attributes AttrList attrs  ) 
 

Sets the text attributes for a layout object.

Parameters:
attrs An AttrList the list the attributes.

void Xfc::Pango::Layout::set_auto_dir bool  auto_dir  ) 
 

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

Parameters:
auto_dir If true, compute the bidirectional base direction from the layout's contents.
When this flag is on (the default), then paragraphs in the 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 by according to the base direction of the layout's Pango::Context (see Pango::Context::set_base_dir()).

When the auto-computed direction or a paragraph differs from the base direction of the context, then the interpretation of Pango::ALIGN_LEFT and Pango::ALIGN_RIGHT are swapped.

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

Sets the type of ellipsization being performed for the layout.

Parameters:
ellipsize The new ellipsization mode for the layout.
Depending on the ellipsization mode ellipsize text is removed from the start, middle, or end of lines so they fit within the width of layout set with set_width(). If the layout contains characters such as newlines that force it to be layed out in multiple lines, then each line is ellipsized separately.

void Xfc::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 Xfc::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 Xfc::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 Xfc::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 Xfc::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 Xfc::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 Xfc::Pango::Layout::set_spacing int  spacing  ) 
 

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

Parameters:
spacing The amount of spacing.

void Xfc::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 Xfc::Pango::Layout::set_text const String text  ) 
 

Set the text of the layout.

Parameters:
text A UTF-8 String.

void Xfc::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 Xfc::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 Xfc::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: Xfce Foundation Classes
Copyright © 2004-2005 The XFC Development Team XFC 4.3