Layout Objects

Name

Layout Objects -- Highlevel layout driver objects

Synopsis



struct      PangoLayout;
PangoLayout* pango_layout_new               (PangoContext *context);
PangoContext* pango_layout_get_context      (PangoLayout *layout);
void        pango_layout_context_changed    (PangoLayout *layout);
void        pango_layout_set_text           (PangoLayout *layout,
                                             const char *text,
                                             int length);
void        pango_layout_set_attributes     (PangoLayout *layout,
                                             PangoAttrList *attrs);
void        pango_layout_set_font_description
                                            (PangoLayout *layout,
                                             const PangoFontDescription *desc);
void        pango_layout_set_width          (PangoLayout *layout,
                                             int width);
int         pango_layout_get_width          (PangoLayout *layout);
void        pango_layout_set_indent         (PangoLayout *layout,
                                             int indent);
int         pango_layout_get_indent         (PangoLayout *layout);
int         pango_layout_get_spacing        (PangoLayout *layout);
void        pango_layout_set_spacing        (PangoLayout *layout,
                                             int spacing);
void        pango_layout_set_justify        (PangoLayout *layout,
                                             gboolean justify);
gboolean    pango_layout_get_justify        (PangoLayout *layout);
void        pango_layout_set_alignment      (PangoLayout *layout,
                                             PangoAlignment alignment);
PangoAlignment pango_layout_get_alignment   (PangoLayout *layout);
enum        PangoAlignment;
void        pango_layout_get_log_attrs      (PangoLayout *layout,
                                             PangoLogAttr **attrs,
                                             gint *n_attrs);
gboolean    pango_layout_xy_to_index        (PangoLayout *layout,
                                             int x,
                                             int y,
                                             int *index,
                                             gboolean *trailing);
void        pango_layout_index_to_pos       (PangoLayout *layout,
                                             int index,
                                             PangoRectangle *pos);
void        pango_layout_get_cursor_pos     (PangoLayout *layout,
                                             int index,
                                             PangoRectangle *strong_pos,
                                             PangoRectangle *weak_pos);
void        pango_layout_move_cursor_visually
                                            (PangoLayout *layout,
                                             int old_index,
                                             int old_trailing,
                                             int direction,
                                             int *new_index,
                                             int *new_trailing);
void        pango_layout_get_extents        (PangoLayout *layout,
                                             PangoRectangle *ink_rect,
                                             PangoRectangle *logical_rect);
void        pango_layout_get_pixel_extents  (PangoLayout *layout,
                                             PangoRectangle *ink_rect,
                                             PangoRectangle *logical_rect);
void        pango_layout_get_size           (PangoLayout *layout,
                                             int *width,
                                             int *height);
void        pango_layout_get_pixel_size     (PangoLayout *layout,
                                             int *width,
                                             int *height);
int         pango_layout_get_line_count     (PangoLayout *layout);
PangoLayoutLine* pango_layout_get_line      (PangoLayout *layout,
                                             int line);
GSList*     pango_layout_get_lines          (PangoLayout *layout);

struct      PangoLayoutLine;
struct      PangoLayoutRun;
void        pango_layout_line_ref           (PangoLayoutLine *line);
void        pango_layout_line_unref         (PangoLayoutLine *line);
void        pango_layout_line_get_extents   (PangoLayoutLine *line,
                                             PangoRectangle *ink_rect,
                                             PangoRectangle *logical_rect);
void        pango_layout_line_get_pixel_extents
                                            (PangoLayoutLine *layout_line,
                                             PangoRectangle *ink_rect,
                                             PangoRectangle *logical_rect);
void        pango_layout_line_index_to_x    (PangoLayoutLine *line,
                                             int index,
                                             gboolean trailing,
                                             int *x_pos);
void        pango_layout_line_x_to_index    (PangoLayoutLine *line,
                                             int x_pos,
                                             int *index,
                                             int *trailing);
void        pango_layout_line_get_x_ranges  (PangoLayoutLine *line,
                                             int start_index,
                                             int end_index,
                                             int **ranges,
                                             int *n_ranges);

Description

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. The objects and functions in this structure provide a high-level driver for formatting entire paragraphs of text at once.

Details

struct PangoLayout

struct PangoLayout;

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

Figure 1. Adjustable parameters for a PangoLayout

The PangoLayout structure is opaque, and has no user-visible fields.


pango_layout_new ()

PangoLayout* pango_layout_new               (PangoContext *context);

Create a new PangoLayout object with attributes initialized to default values for a particular PangoContext.

context : a PangoContext
Returns : a new PangoLayout, with a reference count of one.


pango_layout_get_context ()

PangoContext* pango_layout_get_context      (PangoLayout *layout);

Retrieves the PangoContext used for this layout.

layout : a PangoLayout
Returns : The PangoContext for the layout. This does not have an additional refcount added, so if you want to keep a copy of this around, you must reference it yourself.


pango_layout_context_changed ()

void        pango_layout_context_changed    (PangoLayout *layout);

Forces recomputation of any state in the PangoLayout 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.

layout : a PangoLayout


pango_layout_set_text ()

void        pango_layout_set_text           (PangoLayout *layout,
                                             const char *text,
                                             int length);

Set the text of the layout.

layout : a PangoLayout
text : a UTF8-string
length : the length of text, in bytes. -1 indicates that the string is null terminated and the length should be calculated.


pango_layout_set_attributes ()

void        pango_layout_set_attributes     (PangoLayout *layout,
                                             PangoAttrList *attrs);

Sets the text attributes for a layout object

layout : a PangoLayout
attrs : a PangoAttrList


pango_layout_set_font_description ()

void        pango_layout_set_font_description
                                            (PangoLayout *layout,
                                             const PangoFontDescription *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.

layout : a PangoLayout
desc : the new pango font description, or NULL to unset the current font description.


pango_layout_set_width ()

void        pango_layout_set_width          (PangoLayout *layout,
                                             int width);

Sets the width to which the lines of the PangoLayout should be wrapped.

layout : a PangoLayout.
width : the desired width, or -1 to indicate that no wrapping should be performed.


pango_layout_get_width ()

int         pango_layout_get_width          (PangoLayout *layout);

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

layout : a PangoLayout
Returns : the width


pango_layout_set_indent ()

void        pango_layout_set_indent         (PangoLayout *layout,
                                             int indent);

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

layout : a PangoLayout.
indent : the amount of spacing


pango_layout_get_indent ()

int         pango_layout_get_indent         (PangoLayout *layout);

Gets the amount by which the first line should be shorter than the rest of the lines.

layout : a PangoLayout
Returns : the indent


pango_layout_get_spacing ()

int         pango_layout_get_spacing        (PangoLayout *layout);

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

layout : a PangoLayout
Returns : the spacing (in thousandths of a device unit)


pango_layout_set_spacing ()

void        pango_layout_set_spacing        (PangoLayout *layout,
                                             int spacing);

layout : 
spacing : 


pango_layout_set_justify ()

void        pango_layout_set_justify        (PangoLayout *layout,
                                             gboolean justify);

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

layout : a PangoLayout
justify : whether the lines in the layout should be justified.


pango_layout_get_justify ()

gboolean    pango_layout_get_justify        (PangoLayout *layout);

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

layout : a PangoLayout
Returns : the justify


pango_layout_set_alignment ()

void        pango_layout_set_alignment      (PangoLayout *layout,
                                             PangoAlignment alignment);

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

layout : a PangoLayout
alignment : the new alignment


pango_layout_get_alignment ()

PangoAlignment pango_layout_get_alignment   (PangoLayout *layout);

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

layout : a PangoLayout
Returns : the alignment value


enum PangoAlignment

typedef enum {
  PANGO_ALIGN_LEFT,
  PANGO_ALIGN_CENTER,
  PANGO_ALIGN_RIGHT
} PangoAlignment;

describes how to align the lines of a PangoLayout within the available space. If the PangoLayout is set to justify using pango_layout_set_justify(), then this only has an effect for partial lines.

PANGO_ALIGN_LEFTPut all available space on the right
PANGO_ALIGN_CENTERCenter the line within the available space
PANGO_ALIGN_RIGHTPut all available space on the left


pango_layout_get_log_attrs ()

void        pango_layout_get_log_attrs      (PangoLayout *layout,
                                             PangoLogAttr **attrs,
                                             gint *n_attrs);

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

layout : a PangoLayout
attrs : location to store a pointer to an array of logical attributes This value must be freed with g_free().
n_attrs : location to store the number of the attributes in the array. (The stored value will be equal to the total number of characters in the layout.)


pango_layout_xy_to_index ()

gboolean    pango_layout_xy_to_index        (PangoLayout *layout,
                                             int x,
                                             int y,
                                             int *index,
                                             gboolean *trailing);

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

layout : a PangoLayout
x : the X offset (in thousandths of a device unit) from the left edge of the layout.
y : the Y offset (in thousandths of a device unit) from the top edge of the layout
index : location to store calculated byte index
trailing : location to store a integer indicating where in the cluster the user clicked. If the script allows positioning within the cluster, it is either 0 or 1; otherwise it is either 0 or the number of characters in the cluster. In either case 0 represents the trailing edge of the cluster.
Returns : TRUE if the position was within the layout


pango_layout_index_to_pos ()

void        pango_layout_index_to_pos       (PangoLayout *layout,
                                             int index,
                                             PangoRectangle *pos);

Convert from an index within a PangoLayout to the onscreen position corresponding to that character, which is represented as rectangle. Note that pos->x is always the leading edge of the character. If the and pos->x + pos->width the trailing edge of the character. If the directionality of the character is right-to-left, then pos->width will be negative.

layout : a PangoLayout
index : byte index within layout
pos : rectangle in which to store the position of the character


pango_layout_get_cursor_pos ()

void        pango_layout_get_cursor_pos     (PangoLayout *layout,
                                             int index,
                                             PangoRectangle *strong_pos,
                                             PangoRectangle *weak_pos);

Given an index within a layout, determine 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. 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.

layout : a PangoLayout
index : the byte index of the cursor
strong_pos : location to store the strong cursor position (may be NULL)
weak_pos : location to store the weak cursor position (may be NULL)


pango_layout_move_cursor_visually ()

void        pango_layout_move_cursor_visually
                                            (PangoLayout *layout,
                                             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. If count is positive, then the new strong cursor position will be one position to the right of the old cursor position. If count is position then the new strong cursor position will be one position to the left of the old cursor position.

In the presence of bidirection 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.

layout : a PangoLayout.
old_index : the old cursor byte index
old_trailing : 
direction : direction to move cursor. A negative value indicates motion to the left.
new_index : 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 : 


pango_layout_get_extents ()

void        pango_layout_get_extents        (PangoLayout *layout,
                                             PangoRectangle *ink_rect,
                                             PangoRectangle *logical_rect);

Compute the logical and ink extents of a layout. See the documentation for pango_font_get_glyph_extents() for details about the interpretation of the rectangles.

layout : a PangoLayout
ink_rect : rectangle used to store the extents of the glyph string as drawn or NULL to indicate that the result is not needed.
logical_rect : rectangle used to store the logical extents of the glyph string or NULL to indicate that the result is not needed.


pango_layout_get_pixel_extents ()

void        pango_layout_get_pixel_extents  (PangoLayout *layout,
                                             PangoRectangle *ink_rect,
                                             PangoRectangle *logical_rect);

Compute the logical and ink extents of a layout. See the documentation for pango_font_get_glyph_extents() for details about the interpretation of the rectangles. The returned rectangles are in device units, as opposed to pango_layout_get_extents(), which returns the extents in units of device unit / PANGO_SCALE.

layout : a PangoLayout
ink_rect : rectangle used to store the extents of the glyph string as drawn or NULL to indicate that the result is not needed.
logical_rect : rectangle used to store the logical extents of the glyph string or NULL to indicate that the result is not needed.


pango_layout_get_size ()

void        pango_layout_get_size           (PangoLayout *layout,
                                             int *width,
                                             int *height);

Determine the logical width and height of a PangoLayout in Pango units. (device units divided by PANGO_SCALE). This is simply a convenience function around pango_layout_get_extents.

layout : a PangoLayout
width : location to store the logical width, or NULL
height : location to store the logical height, or NULL


pango_layout_get_pixel_size ()

void        pango_layout_get_pixel_size     (PangoLayout *layout,
                                             int *width,
                                             int *height);

Determine the logical width and height of a PangoLayout in device units. (pango_layout_get_size() returns the width and height in thousandths of a device unit.) This is simply a convenience function around pango_layout_get_extents.

layout : a PangoLayout
width : location to store the logical width, or NULL
height : location to store the logical height, or NULL


pango_layout_get_line_count ()

int         pango_layout_get_line_count     (PangoLayout *layout);

Retrieve the count of lines for the PangoLayout

layout : PangoLayout
Returns : the line count


pango_layout_get_line ()

PangoLayoutLine* pango_layout_get_line      (PangoLayout *layout,
                                             int line);

Retrieves a particular line from a PangoLayout

layout : a PangoLayout
line : the index of a line, which must be between 0 and pango_layout_get_line_count(layout) - 1, inclusive.
Returns : the requested PangoLayoutLine, or NULL if the index is out of range. This layout line can be ref'ed and retained, but will become invalid if changes are made to the PangoLayout.


pango_layout_get_lines ()

GSList*     pango_layout_get_lines          (PangoLayout *layout);

Return the lines of the layout as a list

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


struct PangoLayoutLine

struct PangoLayoutLine
{
  PangoLayout *layout;
  gint         length;		/* length of line in bytes*/
  GSList      *runs;
};

The PangoLayoutLine structure represents one of the lines resulting from laying out a paragraph via PangoLayout. PangoLayoutLine structures are obtained by calling pango_layout_get_line() and are only valid until the text, attributes, or settings of the parent PangoLayout are modified.

Routines for rendering PangoLayout objects are provided in code specific to each rendering system.

PangoLayout *layoutthe parent layout for this line.
gint lengththe length of the line in bytes.
GSList *runsa list containing the runs of the line in visual order.


struct PangoLayoutRun

struct PangoLayoutRun
{
  PangoItem        *item;
  PangoGlyphString *glyphs;
};

The PangoLayoutRun structure represents a single run within a PangoLayoutLine.

PangoItem *itema PangoItem structure that provides information about the segment of text in this run.
PangoGlyphString *glyphsthe glyphs obtained by shaping the text for this item.


pango_layout_line_ref ()

void        pango_layout_line_ref           (PangoLayoutLine *line);

Increase the reference count of a PangoLayoutLine by one.

line : a PangoLayoutLine


pango_layout_line_unref ()

void        pango_layout_line_unref         (PangoLayoutLine *line);

Decrease the reference count of a PangoLayoutLine by one. if the result is zero, the line and all associated memory will be freed.

line : a PangoLayoutLine


pango_layout_line_get_extents ()

void        pango_layout_line_get_extents   (PangoLayoutLine *line,
                                             PangoRectangle *ink_rect,
                                             PangoRectangle *logical_rect);

Compute the logical and ink extents of a layout line. See the documentation for pango_font_get_glyph_extents() for details about the interpretation of the rectangles.

line : a PangoLayoutLine
ink_rect : rectangle used to store the extents of the glyph string as drawn or NULL to indicate that the result is not needed.
logical_rect : rectangle used to store the logical extents of the glyph string or NULL to indicate that the result is not needed.


pango_layout_line_get_pixel_extents ()

void        pango_layout_line_get_pixel_extents
                                            (PangoLayoutLine *layout_line,
                                             PangoRectangle *ink_rect,
                                             PangoRectangle *logical_rect);

Compute the logical and ink extents of a layout line. See the documentation for pango_font_get_glyph_extents() for details about the interpretation of the rectangles. The returned rectangles are in device units, as opposed to pango_layout_line_get_extents(), which returns the extents in units of device unit / PANGO_SCALE.

layout_line : a PangoLayoutLine
ink_rect : rectangle used to store the extents of the glyph string as drawn or NULL to indicate that the result is not needed.
logical_rect : rectangle used to store the logical extents of the glyph string or NULL to indicate that the result is not needed.


pango_layout_line_index_to_x ()

void        pango_layout_line_index_to_x    (PangoLayoutLine *line,
                                             int index,
                                             gboolean trailing,
                                             int *x_pos);

Convert index within a line to X pos

line : a PangoLayoutLine
index : byte offset within the Layout's text
trailing : integer indicating where in the cluster the user clicked. If the script allows positioning within the cluster, it is either 0 or 1; otherwise it is either 0 or the number of characters in the cluster. In either case 0 represents the trailing edge of the cluster.
x_pos : location to store the x_offset (in thousandths of a device unit)


pango_layout_line_x_to_index ()

void        pango_layout_line_x_to_index    (PangoLayoutLine *line,
                                             int x_pos,
                                             int *index,
                                             int *trailing);

Convert from x offset to the byte index of the corresponding character within the text of the layout. If the x_pos is negative or greater than the length of the line, then then the result will be 0, or the last index in the line depending on the base direction of the layout.

line : a PangoLayoutLine
x_pos : the x offset (in thousands of a device unit) from the left edge of the line.
index : location to store calculated byte offset.
trailing : location to store a integer indicating where in the cluster the user clicked. If the script allows positioning within the cluster, it is either 0 or 1; otherwise it is either 0 or the number of characters in the cluster. In either case 0 represents the trailing edge of the cluster.


pango_layout_line_get_x_ranges ()

void        pango_layout_line_get_x_ranges  (PangoLayoutLine *line,
                                             int start_index,
                                             int end_index,
                                             int **ranges,
                                             int *n_ranges);

Get a list of visual ranges corresponding to a given logical range. This list is not necessarily minimal - there may be consecutive ranges which are adjacent. The ranges will be sorted from left to right.

line : a PangoLayoutLine
start_index : Start byte index of the logical range. If this value is less than the start index for the line, then the first range will extend all the way to the leading edge of the layout. Otherwise it will start at the leading edge of the first character.
end_index : Ending byte index of the logical range. If this value is greater than the end index for the line, then the last range will extend all the way to the trailing edge of the layout. Otherwise, it will end at the trailing edge of the last character.
ranges : location to store a pointer to an array of arranges. The array will be of length 2*n_ranges, with each range including the pixels from (*ranges)[2*n] to (*ranges)[2*n + 1] - 1. This array must be freed with g_free.
n_ranges : The number of ranges stored in ranges.