Pango Reference Manual | ||||
---|---|---|---|---|
PangoContext; PangoItem; PangoAnalysis; #define PANGO_ANALYSIS_FLAG_CENTERED_BASELINE enum PangoDirection; #define PANGO_TYPE_DIRECTION GList* pango_itemize (PangoContext *context, const char *text, int start_index, int length, PangoAttrList *attrs, PangoAttrIterator *cached_iter); GList* pango_itemize_with_base_dir (PangoContext *context, PangoDirection base_dir, 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); PangoFontMap* pango_context_get_font_map (PangoContext *context); 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); PangoGravity pango_context_get_base_gravity (PangoContext *context); void pango_context_set_base_gravity (PangoContext *context, PangoGravity gravity); PangoGravity pango_context_get_gravity (PangoContext *context); PangoGravityHint pango_context_get_gravity_hint (PangoContext *context); void pango_context_set_gravity_hint (PangoContext *context, PangoGravityHint hint); const PangoMatrix* pango_context_get_matrix (PangoContext *context); void pango_context_set_matrix (PangoContext *context, const PangoMatrix *matrix); 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); gboolean pango_get_mirror_char (gunichar ch, gunichar *mirrored_ch); PangoDirection pango_unichar_direction (gunichar ch); PangoDirection pango_find_base_dir (const gchar *text, gint length); 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); PangoLogAttr; void pango_shape (const gchar *text, gint length, const PangoAnalysis *analysis, PangoGlyphString *glyphs);
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.
typedef struct _PangoContext PangoContext;
The PangoContext structure stores global information used to control the itemization process.
typedef struct { gint offset; gint length; gint num_chars; PangoAnalysis analysis; } PangoItem;
The PangoItem structure stores information about a segment of text. It contains the following fields:
gint |
the offset of the segment from the beginning of the string in bytes. |
gint |
the length of the segment in bytes. |
gint |
the length of the segment in characters. |
PangoAnalysis |
the properties of the segment. |
typedef struct { PangoEngineShape *shape_engine; PangoEngineLang *lang_engine; PangoFont *font; guint8 level; guint8 gravity; /* PangoGravity */ guint8 flags; guint8 script; /* PangoScript */ PangoLanguage *language; GSList *extra_attrs; } PangoAnalysis;
The PangoAnalysis structure stores information about the properties of a segment of text. It has the following fields:
PangoEngineShape * |
the engine for doing rendering-system-dependent processing. |
PangoEngineLang * |
the engine for doing rendering-system-independent processing. |
PangoFont * |
the font for this segment. |
guint8 |
the bidirectional level for this segment. |
guint8 |
the glyph orientation for this segment (A PangoGravity). |
guint8 |
boolean flags for this segment (currently only one) (Since: 1.16). |
guint8 |
the detected script for this segment (A PangoScript) (Since: 1.18). |
PangoLanguage * |
the detected language for this segment. |
GSList * |
extra attributes for this segment. |
#define PANGO_ANALYSIS_FLAG_CENTERED_BASELINE (1 << 0)
Whether the segment should be shifted to center around the baseline. Used in vertical writing directions mostly. Since: 1.16
typedef enum { PANGO_DIRECTION_LTR, PANGO_DIRECTION_RTL, PANGO_DIRECTION_TTB_LTR, PANGO_DIRECTION_TTB_RTL, PANGO_DIRECTION_WEAK_LTR, PANGO_DIRECTION_WEAK_RTL, PANGO_DIRECTION_NEUTRAL } PangoDirection;
The PangoDirection type represents a direction in the
Unicode bidirectional algorithm; not every value in this
enumeration makes sense for every usage of PangoDirection;
for example, the return value of pango_unichar_direction()
and pango_find_base_dir()
cannot be PANGO_DIRECTION_WEAK_LTR
or PANGO_DIRECTION_WEAK_RTL
, since every character is either
neutral or has a strong direction; on the other hand
PANGO_DIRECTION_NEUTRAL
doesn't make sense to pass
to pango_itemize_with_base_dir()
.
The PANGO_DIRECTION_TTB_LTR
, PANGO_DIRECTION_TTB_RTL
values come from an earlier interpretation of this
enumeration as the writing direction of a block of
text and are no longer used; See PangoGravity for how
vertical text is handled in Pango.
A strong left-to-right direction | |
A strong right-to-left direction | |
Deprecated value; treated the
same as PANGO_DIRECTION_RTL .
|
|
Deprecated value; treated the
same as PANGO_DIRECTION_LTR
|
|
A weak left-to-right direction | |
A weak right-to-left direction | |
No direction specified |
#define PANGO_TYPE_DIRECTION (pango_direction_get_type())
The GObject type for PangoDirection.
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
).
|
a structure holding information that affects the itemization process. |
|
the text to itemize. |
|
first byte in text to process
|
|
the number of bytes (not characters) to process
after start_index .
This must be >= 0.
|
|
the set of attributes that apply to text .
|
|
Cached attribute iterator, or NULL
|
Returns : |
a GList of PangoItem structures. |
GList* pango_itemize_with_base_dir (PangoContext *context, PangoDirection base_dir, const char *text, int start_index, int length, PangoAttrList *attrs, PangoAttrIterator *cached_iter);
Like pango_itemize()
, but the base direction to use when
computing bidirectional levels (see pango_context_set_base_dir()
),
is specified explicitly rather than gotten from the PangoContext.
|
a structure holding information that affects the itemization process. |
|
base direction to use for bidirectional processing |
|
the text to itemize. |
|
first byte in text to process
|
|
the number of bytes (not characters) to process
after start_index .
This must be >= 0.
|
|
the set of attributes that apply to text .
|
|
Cached attribute iterator, or NULL
|
Returns : |
a GList of PangoItem structures. The items should be
freed using pango_item_free() probably in combination with g_list_foreach() ,
and the list itself using g_list_free() .
|
Since 1.4
void pango_item_free (PangoItem *item);
Free a PangoItem and all associated memory.
PangoItem* pango_item_copy (PangoItem *item);
Copy an existing PangoItem structure.
|
a PangoItem, may be NULL
|
Returns : |
the newly allocated PangoItem, which should
be freed with pango_item_free() , or NULL if
item was NULL.
|
PangoItem* pango_item_new (void);
Creates a new PangoItem structure initialized to default values.
Returns : |
the newly allocated PangoItem, which should
be freed with pango_item_free() .
|
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.
|
a PangoItem |
|
byte index of position to split item, relative to the start of the item |
|
number of chars between start of orig and split_index
|
Returns : |
new item representing text before split_index , which
should be freed with pango_item_free() .
|
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.
PangoContext* pango_context_new (void);
Creates a new PangoContext initialized to default value.
This function is only useful when implementing a new backend
for Pango, something applications won't do. You should use
the context creation function for the backend you are using,
for example, pango_cairo_font_map_create_context()
, pango_xft_get_context()
,
pango_win32_get_context()
or, pango_ft2_font_map_create_context()
.
If you are using Pango as part of a higher-level system,
that system may have it's own ways of create a PangoContext.
For instance, the GTK+ toolkit has, among others,
gdk_pango_context_get_for_screen()
, and
gtk_widget_get_pango_context()
.
Returns : |
the newly allocated PangoContext, which should
be freed with g_object_unref() .
|
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. This is only for internal use by Pango backends, a PangoContext obtained via one of the recommended methods should already have a suitable font map.
|
a PangoContext |
|
the PangoFontMap to set. |
PangoFontMap* pango_context_get_font_map (PangoContext *context);
Gets the PangoFontmap used to look up fonts for this context.
|
a PangoContext |
Returns : |
the font map for the PangoContext. This value is owned by Pango and should not be unreferenced. |
Since 1.6
PangoFontDescription* pango_context_get_font_description (PangoContext *context);
Retrieve the default font description for the context.
|
a PangoContext |
Returns : |
a pointer to the context's default font description. This value must not be modified or freed. |
void pango_context_set_font_description (PangoContext *context, const PangoFontDescription *desc);
Set the default font description for the context
|
a PangoContext |
|
the new pango font description |
PangoLanguage* pango_context_get_language (PangoContext *context);
Retrieves the global language tag for the context.
|
a PangoContext |
Returns : |
the global language tag. |
void pango_context_set_language (PangoContext *context, PangoLanguage *language);
Sets the global language tag for the context. The default language
for the locale of the running process can be found using
pango_language_get_default()
.
|
a PangoContext |
|
the new language tag. |
PangoDirection pango_context_get_base_dir (PangoContext *context);
Retrieves the base direction for the context. See
pango_context_set_base_dir()
.
|
a PangoContext |
Returns : |
the base direction for the context. |
void pango_context_set_base_dir (PangoContext *context, PangoDirection direction);
Sets the base direction for the context.
The base direction is used in applying the Unicode bidirectional
algorithm; if the direction
is PANGO_DIRECTION_LTR
or
PANGO_DIRECTION_RTL
, then the value will be used as the paragraph
direction in the Unicode bidirectional algorithm. A value of
PANGO_DIRECTION_WEAK_LTR
or PANGO_DIRECTION_WEAK_RTL
is used only
for paragraphs that do not contain any strong characters themselves.
|
a PangoContext |
|
the new base direction |
PangoGravity pango_context_get_base_gravity (PangoContext *context);
Retrieves the base gravity for the context. See
pango_context_set_base_gravity()
.
|
a PangoContext |
Returns : |
the base gravity for the context. |
Since 1.16
void pango_context_set_base_gravity (PangoContext *context, PangoGravity gravity);
Sets the base gravity for the context.
The base gravity is used in laying vertical text out.
|
a PangoContext |
|
the new base gravity |
Since 1.16
PangoGravity pango_context_get_gravity (PangoContext *context);
Retrieves the gravity for the context. This is similar to
pango_context_get_base_gravity()
, except for when the base gravity
is PANGO_GRAVITY_AUTO
for which pango_gravity_get_for_matrix()
is used
to return the gravity from the current context matrix.
|
a PangoContext |
Returns : |
the resolved gravity for the context. |
Since 1.16
PangoGravityHint pango_context_get_gravity_hint (PangoContext *context);
Retrieves the gravity hint for the context. See
pango_context_set_gravity_hint()
for details.
|
a PangoContext |
Returns : |
the gravity hint for the context. |
Since 1.16
void pango_context_set_gravity_hint (PangoContext *context, PangoGravityHint hint);
Sets the gravity hint for the context.
The gravity hint is used in laying vertical text out, and is only relevant
if gravity of the context as returned by pango_context_get_gravity()
is set PANGO_GRAVITY_EAST
or PANGO_GRAVITY_WEST
.
|
a PangoContext |
|
the new gravity hint |
Since 1.16
const PangoMatrix* pango_context_get_matrix (PangoContext *context);
Gets the transformation matrix that will be applied when
rendering with this context. See pango_context_set_matrix()
.
|
a PangoContext |
Returns : |
the matrix, or NULL if no matrix has been set
(which is the same as the identity matrix). The returned
matrix is owned by Pango and must not be modified or
freed.
|
Since 1.6
void pango_context_set_matrix (PangoContext *context, const PangoMatrix *matrix);
Sets the transformation matrix that will be applied when rendering with this context. Note that reported metrics are in the user space coordinates before the application of the matrix, not device-space coordinates after the application of the matrix. So, they don't scale with the matrix, though they may change slightly for different matrices, depending on how the text is fit to the pixel grid.
|
a PangoContext |
|
a PangoMatrix, or NULL to unset any existing matrix.
(No matrix set is the same as setting the identity matrix.)
|
Since 1.6
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
.
|
a PangoContext |
|
a PangoFontDescription describing the font to load |
Returns : |
the font loaded, or NULL if no font matched.
|
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
.
|
a PangoContext |
|
a PangoFontDescription describing the fonts to load |
|
a PangoLanguage the fonts will be used for |
Returns : |
the fontset, or NULL if no font matched.
|
PangoFontMetrics* pango_context_get_metrics (PangoContext *context, const PangoFontDescription *desc, PangoLanguage *language);
Get overall metric information for a 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.
|
a PangoContext |
|
a PangoFontDescription structure |
|
language tag used to determine which script to get the metrics
for. NULL means that the language tag from the context will
be used. If no language tag is set on the context, metrics
large enough to cover a range of languages will be returned.
The process of determining such metrics is slow, so it is best
to always make sure some real language tag will be used.
|
Returns : |
a PangoFontMetrics object. The caller must call pango_font_metrics_unref()
when finished using the object.
|
void pango_context_list_families (PangoContext *context, PangoFontFamily ***families, int *n_families);
List all families for a context.
|
a PangoContext |
|
location to store a pointer to an array of PangoFontFamily *.
This array should be freed with g_free() .
|
|
location to store the number of elements in descs
|
gboolean pango_get_mirror_char (gunichar ch, gunichar *mirrored_ch);
pango_get_mirror_char
is deprecated and should not be used in newly-written code.
If ch
has the Unicode mirrored property and there is another Unicode
character that typically has a glyph that is the mirror image of ch
's
glyph, puts that character in the address pointed to by mirrored_ch
.
Use g_unichar_get_mirror_char()
instead; the docs for that function
provide full details.
PangoDirection pango_unichar_direction (gunichar ch);
Determines the direction of a character; either
PANGO_DIRECTION_LTR
, PANGO_DIRECTION_RTL
, or
PANGO_DIRECTION_NEUTRAL
.
|
a Unicode character |
Returns : |
the direction of the character, as used in the Unicode bidirectional algorithm. |
PangoDirection pango_find_base_dir (const gchar *text, gint length);
Searches a string the first character that has a strong direction, according to the Unicode bidirectional algorithm.
|
the text to process |
|
length of text in bytes (may be -1 if text is nul-terminated)
|
Returns : |
The direction corresponding to the first strong character.
If no such character is found, then PANGO_DIRECTION_NEUTRAL is returned.
|
Since 1.4
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 with a single analysis. For most
purposes you may want to use pango_get_log_attrs()
.
|
the text to process |
|
length of text in bytes (may be -1 if text is nul-terminated)
|
|
PangoAnalysis structure from pango_itemize()
|
|
an array to store character information in |
|
size of the array passed as 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 to process |
|
length in bytes of text
|
|
embedding level, or -1 if unknown |
|
language tag |
|
array with one PangoLogAttr per character in text , plus one extra, to be filled in
|
|
length of log_attrs array
|
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).
|
UTF-8 text |
|
length of text in bytes, or -1 if nul-terminated
|
|
return location for index of delimiter |
|
return location for start of next paragraph |
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. 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()
. In most cases however you should
simply use pango_get_log_attrs()
.
|
text to break |
|
length of text in bytes (may be -1 if text is nul-terminated)
|
|
a PangoAnalysis for the text
|
|
logical attributes to fill in |
|
size of the array passed as attrs
|
typedef struct { 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 */ /* If set, backspace deletes one character rather than * the entire grapheme cluster. */ guint backspace_deletes_character : 1; /* Only few space variants (U+0020 and U+00A0) have variable * width during justification. */ guint is_expandable_space : 1; } PangoLogAttr;
The PangoLogAttr structure stores information about the attributes of a single character.
guint |
if set, can break line in front of character |
guint |
if set, must break line in front of character |
guint |
if set, can break here when doing character wrapping |
guint |
is whitespace character |
guint |
if set, cursor can appear in front of character. i.e. this is a grapheme boundary, or the first character in the text. |
guint |
is first character in a word |
guint |
is first non-word char after a word
Note that in degenerate cases, you could have both is_word_start
and is_word_end set for some character.
|
guint |
is a sentence boundary.
There are two ways to divide sentences. The first assigns all
inter-sentence 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 first character in a sentence |
guint |
is first char after a sentence.
Note that in degenerate cases, you could have both is_sentence_start
and is_sentence_end set for some character. (e.g. no space after a
period, so the next sentence starts right away)
|
guint |
if set, backspace deletes one character
rather than the entire grapheme cluster. This
field is only meaningful on grapheme
boundaries (where is_cursor_position is
set). In some languages, the full grapheme
(e.g. letter + diacritics) is considered a
unit, while in others, each decomposed
character in the grapheme is a unit. In the
default implementation of pango_break() , this
bit is set on all grapheme boundaries except
those following Latin, Cyrillic or Greek base
characters.
|
guint |
is a whitespace character that can possibly be expanded for justification purposes. (Since: 1.18) |
void pango_shape (const gchar *text, gint length, const 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()
.
|
the text to process |
|
the length (in bytes) of text
|
|
PangoAnalysis structure from pango_itemize()
|
|
glyph string in which to store results |