## Rendering

Rendering — Functions to run the rendering pipeline

## Synopsis

    struct      PangoContext;
    struct      PangoItem;
    struct      PangoAnalysis;
    enum        PangoDirection;
    #define     PANGO_TYPE_DIRECTION

    GList*      pango_itemize                   (PangoContext *context,
                                                 const char *text,
                                                 int start_index,
                                                 int length,
                                                 PangoAttrList *attrs,
                                                 PangoAttrIterator *cached_iter);
    void        pango_item_free                 (PangoItem *item);
    PangoItem*  pango_item_copy                 (PangoItem *item);
    PangoItem*  pango_item_new                  (void);
    PangoItem*  pango_item_split                (PangoItem *orig,
                                                 int split_index,
                                                 int split_offset);
    GList*      pango_reorder_items             (GList *logical_items);

    PangoContext* pango_context_new             (void);
    void        pango_context_set_font_map      (PangoContext *context,
                                                 PangoFontMap *font_map);
    PangoFontDescription* pango_context_get_font_description
                                                (PangoContext *context);
    void        pango_context_set_font_description
                                                (PangoContext *context,
                                                 const PangoFontDescription *desc);
    PangoLanguage* pango_context_get_language   (PangoContext *context);
    void        pango_context_set_language      (PangoContext *context,
                                                 PangoLanguage *language);
    PangoDirection pango_context_get_base_dir   (PangoContext *context);
    void        pango_context_set_base_dir      (PangoContext *context,
                                                 PangoDirection direction);
    PangoFont*  pango_context_load_font         (PangoContext *context,
                                                 const PangoFontDescription *desc);
    PangoFontset* pango_context_load_fontset    (PangoContext *context,
                                                 const PangoFontDescription *desc,
                                                 PangoLanguage *language);
    PangoFontMetrics* pango_context_get_metrics (PangoContext *context,
                                                 const PangoFontDescription *desc,
                                                 PangoLanguage *language);
    void        pango_context_list_families     (PangoContext *context,
                                                 PangoFontFamily ***families,
                                                 int *n_families);

    void        pango_break                     (const gchar *text,
                                                 int length,
                                                 PangoAnalysis *analysis,
                                                 PangoLogAttr *attrs,
                                                 int attrs_len);
    void        pango_get_log_attrs             (const char *text,
                                                 int length,
                                                 int level,
                                                 PangoLanguage *language,
                                                 PangoLogAttr *log_attrs,
                                                 int attrs_len);
    void        pango_find_paragraph_boundary   (const gchar *text,
                                                 gint length,
                                                 gint *paragraph_delimiter_index,
                                                 gint *next_paragraph_start);
    void        pango_default_break             (const gchar *text,
                                                 int length,
                                                 PangoAnalysis *analysis,
                                                 PangoLogAttr *attrs,
                                                 int attrs_len);
    struct      PangoLogAttr;

    void        pango_shape                     (const gchar *text,
                                                 gint length,
                                                 PangoAnalysis *analysis,
                                                 PangoGlyphString *glyphs);

## Object Hierarchy

      GObject
       +----PangoContext

## Description

The Pango rendering pipeline takes a string of Unicode characters and converts it into glyphs. The functions described in this section accomplish various steps of this process.

## Details

### struct PangoContext

    struct PangoContext;

The PangoContext structure stores global information used to control the itemization process.

### struct PangoItem

    struct PangoItem {

      gint offset;
      gint length;
      gint num_chars;
      PangoAnalysis analysis;
    };

The PangoItem structure stores information about a segment of text. It contains the following fields:

gint `offset` | the offset of the segment from the beginning of the string in bytes.
gint `length` | the length of the segment in bytes.
gint `num_chars` | the length of the segment in characters.
PangoAnalysis `analysis` | the properties of the segment.

### struct PangoAnalysis

    struct PangoAnalysis {

      PangoEngineShape *shape_engine;
      PangoEngineLang  *lang_engine;
      PangoFont *font;
      guint8 level;
      PangoLanguage *language;
      GSList *extra_attrs;
    };

The PangoAnalysis structure stores information about the properties of a segment of text. It has the following fields:

PangoEngineShape *`shape_engine` | the engine for doing rendering-system-dependent processing.
PangoEngineLang *`lang_engine` | the engine for doing rendering-system-independent processing.
PangoFont *`font` |
guint8 `level` | the bidrectional level for this segment.
PangoLanguage *`language` |
GSList *`extra_attrs` |

### enum PangoDirection

    typedef enum {
      PANGO_DIRECTION_LTR,
      PANGO_DIRECTION_RTL,
      PANGO_DIRECTION_TTB_LTR,
      PANGO_DIRECTION_TTB_RTL
    } PangoDirection;

The PangoDirection type represents the direction of writing for text.

`PANGO_DIRECTION_LTR` | The text is written left-to-right
`PANGO_DIRECTION_RTL` | The text is written right-to-left
`PANGO_DIRECTION_TTB_LTR` | The text is written vertically top-to-bottom, with the rows ordered from left to right.
`PANGO_DIRECTION_TTB_RTL` | The text is written vertically top-to-bottom, with the rows ordered from right to left.

### PANGO_TYPE_DIRECTION

    #define PANGO_TYPE_DIRECTION (pango_direction_get_type())

The GObject type for PangoDirection.

### pango_itemize ()

    GList*      pango_itemize                   (PangoContext *context,
                                                 const char *text,
                                                 int start_index,
                                                 int length,
                                                 PangoAttrList *attrs,
                                                 PangoAttrIterator *cached_iter);

Breaks a piece of text into segments with consistent directional level and shaping engine. Each byte of `text` will be contained in exactly one of the items in the returned list; the generated list of items will be in logical order (the start offsets of the items are ascending).

`cached_iter` should be an iterator over `attrs` currently positioned at a range before or containing `start_index`; `cached_iter` will be advanced to the range covering the position just after `start_index` + `length`. (i.e. if itemizing in a loop, just keep passing in the same `cached_iter`).

`context` : | a structure holding information that affects the itemization process.
`text` : | the text to itemize.
`start_index` : | first byte in `text` to process
`length` : | the number of bytes (not characters) to process after `start_index`. This must be >= 0.
`attrs` : | the set of attributes that apply to `text`.
`cached_iter` : | Cached attribute iterator, or NULL
Returns : | a GList of PangoItem structures.

### pango_item_free ()

    void        pango_item_free                 (PangoItem *item);

Free a PangoItem and all associated memory.

`item` : | a PangoItem

### pango_item_copy ()

    PangoItem*  pango_item_copy                 (PangoItem *item);

Copy an existing PangoItem structure.

`item` : | a PangoItem
Returns : | the new PangoItem

### pango_item_new ()

    PangoItem*  pango_item_new                  (void);

Creates a new PangoItem structure initialized to default values.

Returns : | the new PangoItem

### pango_item_split ()

    PangoItem*  pango_item_split                (PangoItem *orig,
                                                 int split_index,
                                                 int split_offset);

Modifies `orig` to cover only the text after `split_index`, and returns a new item that covers the text before `split_index` that used to be in `orig`. You can think of `split_index` as the length of the returned item. `split_index` may not be 0, and it may not be greater than or equal to the length of `orig` (that is, there must be at least one byte assigned to each item, you can't create a zero-length item). `split_offset` is the length of the first item in chars, and must be provided because the text used to generate the item isn't available, so `pango_item_split()` can't count the char length of the split items itself.

`orig` : | a PangoItem
`split_index` : | byte index of position to split item, relative to the start of the item
`split_offset` : | number of chars between start of `orig` and `split_index`
Returns : | new item representing text before `split_index`

### pango_reorder_items ()

    GList*      pango_reorder_items             (GList *logical_items);

From a list of items in logical order and the associated directional levels, produce a list in visual order. The original list is unmodified.

`logical_items` : | a GList of PangoItem in logical order.
Returns : | a GList of PangoItem structures in visual order. (Please mail otaylor`redhat.com` if you use this function. It is not a particularly convenient interface, and the code is duplicated elsewhere in Pango for that reason.)

### pango_context_new ()

    PangoContext* pango_context_new             (void);

Creates a new PangoContext initialized to default value.

Returns : | the new PangoContext

### pango_context_set_font_map ()

    void        pango_context_set_font_map      (PangoContext *context,
                                                 PangoFontMap *font_map);

Sets the font map to be searched when fonts are looked-up in this context.

`context` : | a PangoContext
`font_map` : | the PangoFontMap to set.

### pango_context_get_font_description ()

    PangoFontDescription* pango_context_get_font_description
                                                (PangoContext *context);

Retrieve the default font description for the context.

`context` : | a PangoContext
Returns : | a pointer to the context's default font description. This value must not be modified or freed.

### pango_context_set_font_description ()

    void        pango_context_set_font_description
                                                (PangoContext *context,
                                                 const PangoFontDescription *desc);

Set the default font description for the context

`context` : | a PangoContext
`desc` : | the new pango font description

### pango_context_get_language ()

    PangoLanguage* pango_context_get_language   (PangoContext *context);

Retrieves the global language tag for the context.

`context` : | a PangoContext
Returns : | the global language tag.

### pango_context_set_language ()

    void        pango_context_set_language      (PangoContext *context,
                                                 PangoLanguage *language);

Sets the global language tag for the context.

`context` : | a PangoContext
`language` : | the new language tag.

### pango_context_get_base_dir ()

    PangoDirection pango_context_get_base_dir   (PangoContext *context);

Retrieves the base direction for the context.

`context` : |
Returns : | the base direction for the context.

### pango_context_set_base_dir ()

    void        pango_context_set_base_dir      (PangoContext *context,
                                                 PangoDirection direction);

Sets the base direction for the context.

`context` : | a PangoContext
`direction` : | the new base direction

### pango_context_load_font ()

    PangoFont*  pango_context_load_font         (PangoContext *context,
                                                 const PangoFontDescription *desc);

Loads the font in one of the fontmaps in the context that is the closest match for `desc`.

`context` : | a PangoContext
`desc` : | a PangoFontDescription describing the font to load
Returns : | the font loaded, or `NULL` if no font matched.

### pango_context_load_fontset ()

    PangoFontset* pango_context_load_fontset    (PangoContext *context,
                                                 const PangoFontDescription *desc,
                                                 PangoLanguage *language);

Load a set of fonts in the context that can be used to render a font matching `desc`.

`context` : | a PangoContext
`desc` : | a PangoFontDescription describing the fonts to load
`language` : | a PangoLanguage the fonts will be used for
Returns : | the fontset, or `NULL` if no font matched.

### pango_context_get_metrics ()

    PangoFontMetrics* pango_context_get_metrics (PangoContext *context,
                                                 const PangoFontDescription *desc,
                                                 PangoLanguage *language);

Get overall metric information for a font particular font description. Since the metrics may be substantially different for different scripts, a language tag can be provided to indicate that the metrics should be retrieved that correspond to the script(s) used by that language.

The PangoFontDescription is interpreted in the same way as by `pango_itemize()`, and the family name may be a comma separated list of figures. If characters from multiple of these families would be used to render the string, then the returned fonts would be a composite of the metrics for the fonts loaded for the individual families.

`context` : | a PangoContext
`desc` : | a PangoFontDescription structure
`language` : | language tag used to determine which script to get the metrics for, or `NULL` to indicate to get the metrics for the entire font.
Returns : | a PangoMetrics object. The caller must call `pango_font_metrics_unref()` when finished using the object.

### pango_context_list_families ()

    void        pango_context_list_families     (PangoContext *context,
                                                 PangoFontFamily ***families,
                                                 int *n_families);

List all families for a context.

`context` : | a PangoContext
`families` : | location to store a pointer to an array of PangoFontFamily *. This array should be freed with `g_free()`.
`n_families` : | location to store the number of elements in `descs`

### pango_break ()

    void        pango_break                     (const gchar *text,
                                                 int length,
                                                 PangoAnalysis *analysis,
                                                 PangoLogAttr *attrs,
                                                 int attrs_len);

Determines possible line, word, and character breaks for a string of Unicode text.

`text` : | the text to process
`length` : | length of `text` in bytes (may be -1 if `text` is nul-terminated)
`analysis` : | PangoAnalysis structure from `pango_itemize()`
`attrs` : | an array to store character information in
`attrs_len` : | size of the array passed as `attrs`

### pango_get_log_attrs ()

    void        pango_get_log_attrs             (const char *text,
                                                 int length,
                                                 int level,
                                                 PangoLanguage *language,
                                                 PangoLogAttr *log_attrs,
                                                 int attrs_len);

Computes a PangoLogAttr for each character in `text`. The `log_attrs` array must have one PangoLogAttr for each position in `text`; if `text` contains N characters, it has N+1 positions, including the last position at the end of the text. `text` should be an entire paragraph; logical attributes can't be computed without context (for example you need to see spaces on either side of a word to know the word is a word).

`text` : | text to process
`length` : | length in bytes of `text`
`level` : | embedding level, or -1 if unknown
`language` : | language tag
`log_attrs` : | array with one PangoLogAttr per character in `text`, plus one extra, to be filled in
`attrs_len` : | length of `log_attrs` array

### pango_find_paragraph_boundary ()

    void        pango_find_paragraph_boundary   (const gchar *text,
                                                 gint length,
                                                 gint *paragraph_delimiter_index,
                                                 gint *next_paragraph_start);

Locates a paragraph boundary in `text`. A boundary is caused by delimiter characters, such as a newline, carriage return, carriage return-newline pair, or Unicode paragraph separator character. The index of the run of delimiters is returned in `paragraph_delimiter_index`. The index of the start of the paragraph (index after all delimiters) is stored in `next_paragraph_start`.

If no delimiters are found, both `paragraph_delimiter_index` and `next_paragraph_start` are filled with the length of `text` (an index one off the end).

`text` : | UTF-8 text
`length` : | length of `text` in bytes, or -1 if nul-terminated
`paragraph_delimiter_index` : | return location for index of delimiter
`next_paragraph_start` : | return location for start of next paragraph

### pango_default_break ()

    void        pango_default_break             (const gchar *text,
                                                 int length,
                                                 PangoAnalysis *analysis,
                                                 PangoLogAttr *attrs,
                                                 int attrs_len);

This is the default break algorithm, used if no language engine overrides it. Normally you should use `pango_break()` instead; this function is mostly useful for chaining up from a language engine override. Unlike `pango_break()`, `analysis` can be NULL, but only do that if you know what you're doing. (If you need an analysis to pass to `pango_break()`, you need to `pango_itemize()` or use `pango_get_log_attrs()`.)

`text` : | text to break
`length` : | length of text in bytes (may be -1 if `text` is nul-terminated)
`analysis` : | a PangoAnalysis for the `text`
`attrs` : | logical attributes to fill in
`attrs_len` : | size of the array passed as `attrs`

### struct PangoLogAttr

    struct PangoLogAttr {

      guint is_line_break : 1;      /* Can break line in front of character */

      guint is_mandatory_break : 1; /* Must break line in front of character */

      guint is_char_break : 1;      /* Can break here when doing char wrap */

      guint is_white : 1;           /* Whitespace character */

      /* cursor can appear in front of character (i.e. this is a grapheme
       * boundary, or the first character in the text)
       */
      guint is_cursor_position : 1;

      /* Note that in degenerate cases, you could have both start/end set on
       * some text, most likely for sentences (e.g. no space after a period, so
       * the next sentence starts right away)
       */

      guint is_word_start : 1;      /* first character in a word */
      guint is_word_end   : 1;      /* is first non-word char after a word */

      /* There are two ways to divide sentences. The first assigns all
       * intersentence whitespace/control/format chars to some sentence,
       * so all chars are in some sentence; is_sentence_boundary denotes
       * the boundaries there. The second way doesn't assign
       * between-sentence spaces, etc. to any sentence, so
       * is_sentence_start/is_sentence_end mark the boundaries of those
       * sentences.
       */
      guint is_sentence_boundary : 1;
      guint is_sentence_start : 1;  /* first character in a sentence */
      guint is_sentence_end : 1;    /* first non-sentence char after a sentence */
    };

The PangoLogAttr structure stores information about the attributes of a single character.

### pango_shape ()

    void        pango_shape                     (const gchar *text,
                                                 gint length,
                                                 PangoAnalysis *analysis,
                                                 PangoGlyphString *glyphs);

Given a segment of text and the corresponding PangoAnalysis structure returned from `pango_itemize()`, convert the characters into glyphs. You may also pass in only a substring of the item from `pango_itemize()`.

`text` : | the text to process
`length` : | the length (in bytes) of `text`
`analysis` : | PangoAnalysis structure from PangoItemize
`glyphs` : | glyph string in which to store results