Glyph Storage

Name

Glyph Storage -- Structures for storing information about glyphs.

Synopsis



#define     PANGO_SCALE
#define     PANGO_PIXELS                    (d)
struct      PangoRectangle;
#define     PANGO_ASCENT                    (rect)
#define     PANGO_DESCENT                   (rect)
#define     PANGO_LBEARING                  (rect)
#define     PANGO_RBEARING                  (rect)
typedef     PangoGlyph;
struct      PangoGlyphInfo;
struct      PangoGlyphGeometry;
typedef     PangoGlyphUnit;
struct      PangoGlyphVisAttr;
struct      PangoGlyphString;
PangoGlyphString* pango_glyph_string_new    (void);
void        pango_glyph_string_set_size     (PangoGlyphString *string,
                                             gint new_len);
void        pango_glyph_string_free         (PangoGlyphString *string);
void        pango_glyph_string_extents      (PangoGlyphString *glyphs,
                                             PangoFont *font,
                                             PangoRectangle *ink_rect,
                                             PangoRectangle *logical_rect);
void        pango_glyph_string_index_to_x   (PangoGlyphString *glyphs,
                                             char *text,
                                             int length,
                                             PangoAnalysis *analysis,
                                             int index,
                                             gboolean trailing,
                                             int *x_pos);
void        pango_glyph_string_x_to_index   (PangoGlyphString *glyphs,
                                             char *text,
                                             int length,
                                             PangoAnalysis *analysis,
                                             int x_pos,
                                             int *index,
                                             int *trailing);
void        pango_glyph_string_get_logical_widths
                                            (PangoGlyphString *glyphs,
                                             const char *text,
                                             int length,
                                             int embedding_level,
                                             int *logical_widths);

Description

pango_shape() produces a string of glyphs which can be measured or drawn to the screen. The following structures are used to store information about glyphs.

Details

PANGO_SCALE

#define PANGO_SCALE 1024

The PANGO_SCALE macro represents the scale between dimensions used for pango distances and device units. (The definition of device units is dependent on the output device; it will typically be pixels for a screen, and points for a printer.) PANGO_SCALE is currently 1000, but this may be changed in the future.


PANGO_PIXELS()

#define     PANGO_PIXELS(d)

d : 


struct PangoRectangle

struct PangoRectangle
{
  int x;
  int y;
  int width;
  int height;
};

The PangoRectangle structure represents a rectangle. It is frequently used to represent the logical or ink extents of a single glyph or section of text. (See, for instance, pango_font_get_glyph_extents())

int xX coordinate of the left side of the rectangle.
int yY coordinate of the the top side of the rectangle.
int widthwidth of the rectangle.
int heightheight of the rectangle.


PANGO_ASCENT()

#define PANGO_ASCENT(rect) (-(rect).y)

Extracts the ascent from a PangoRectangle representing glyph extents. The ascent is the distance from the baseline to the highest point of the character. This is positive if the glyph ascends above the baseline.

rect :a PangoRectangle


PANGO_DESCENT()

#define PANGO_DESCENT(rect) ((rect).y + (rect).height)

Extracts the descent from a PangoRectangle representing glyph extents. The descent is the distance from the baseline to the lowest point of the character. This is positive if the glyph descends below the baseline.

rect :a PangoRectangle


PANGO_LBEARING()

#define PANGO_LBEARING(rect) ((rect).x)

Extracts the left bearing from a PangoRectangle representing glyph extents. The descent is the distance from the horizontal origin to the farthest left point of the character. This is positive for characters drawn completely to the right of the glyph origin.

rect :a PangoRectangle


PANGO_RBEARING()

#define PANGO_RBEARING(rect) ((rect).x + (rect).width)

Extracts the left bearing from a PangoRectangle representing glyph extents. The descent is the distance from the horizontal origin to the farthest left point of the character. This is positive except for characters drawn completely to the left of the horizontal origin.

rect :a PangoRectangle


PangoGlyph

typedef guint32 PangoGlyph;

The PangoGlyph structure represents a single glyph in the output form of a string. It contains the following fields.

PangoGlyphIndex glyph;the index of the glyph into the font. (Rendering system dependent).
PangoCFont *font;the rendering-system-specific font information for this glyph.


struct PangoGlyphInfo

struct PangoGlyphInfo
{
  PangoGlyph    glyph;
  PangoGlyphGeometry geometry;
  PangoGlyphVisAttr  attr;
};


struct PangoGlyphGeometry

struct PangoGlyphGeometry
{
  PangoGlyphUnit width;
  PangoGlyphUnit x_offset;  
  PangoGlyphUnit y_offset;
};

The PangoGlyphGeometry structure contains width and positioning information for a single glyph. Distances are in 1/64ths of a point.

PangoGlyphUnit width;the logical width to use for the the character.
PangoCFont *x_offset;horizontal offset from nominal character position.
PangoCFont *y_offset;vertical offset from nominal character position.


PangoGlyphUnit

typedef gint32 PangoGlyphUnit;

The PangoGlyphUnit type is used to store dimensions within Pango. Dimensions are stored in 1/64ths of a point.


struct PangoGlyphVisAttr

struct PangoGlyphVisAttr
{
  guint is_cluster_start : 1;
};

The PangoGlyphVisAttr is used to communicate information between the shaping phase and the rendering phase. It's contents are still evolving.

guint is_cluster_start : 1;set for the first logical glyph in each cluster. (Clusters are stored in visual order, within the cluster, glyphs are always ordered in logical order, since visual order is meaningless; that is, in Arabic text, accent glyphs follow the glyphs for the base character.)


struct PangoGlyphString

struct PangoGlyphString {
  gint num_glyphs;

  PangoGlyphInfo *glyphs;

  /* This is a memory inefficient way of representing the
   * information here - each value gives the character index
   * of the start of the cluster to which the glyph belongs.
   */
  gint *log_clusters;

  /*< private >*/
  gint space;
};

The PangoGlyphString structure is used to store strings of glyphs with geometry and visual attribute information. The storage for the glyph information is owned by the structure which simplifies memory management.

PangoGlyphString contains the following publically accessible fields

gint num_glyphs;the number of glyphs in the string.
PangoGlyph *glyphs;an array of glyphs of length num_glyphs.
PangoGlyphGeometry *geometry;an array of PangoGlyphGeometry structures corresponding to glyphs.
PangoGlyphVisAttr *attrs;an array of PangoGlyphVisAttr structures corresponding to glyphs.
gint *log_clusters;for each glyph, the character index (should this be byte index?) of the starting character for the cluster.


pango_glyph_string_new ()

PangoGlyphString* pango_glyph_string_new    (void);

Create a new PangoGlyphString.

Returns :the new PangoGlyphString


pango_glyph_string_set_size ()

void        pango_glyph_string_set_size     (PangoGlyphString *string,
                                             gint new_len);

Resize a glyph string to the given length.

string : a PangoGlyphString.
new_len : the new length of the string.


pango_glyph_string_free ()

void        pango_glyph_string_free         (PangoGlyphString *string);

Free a glyph string and associated storage.

string : a PangoGlyphString.


pango_glyph_string_extents ()

void        pango_glyph_string_extents      (PangoGlyphString *glyphs,
                                             PangoFont *font,
                                             PangoRectangle *ink_rect,
                                             PangoRectangle *logical_rect);

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

glyphs : a PangoGlyphString
font : a PangoFont
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_glyph_string_index_to_x ()

void        pango_glyph_string_index_to_x   (PangoGlyphString *glyphs,
                                             char *text,
                                             int length,
                                             PangoAnalysis *analysis,
                                             int index,
                                             gboolean trailing,
                                             int *x_pos);

Converts from character position to x position. (X position is measured from the left edge of the run)

glyphs : the glyphs return from pango_shape()
text : the text for the run
length : the number of bytes (not characters) in text.
analysis : the analysis information return from pango_itemize()
index : the byte index within text
trailing : whether we should compute the result for the beginning or end of the character (or cluster - the decision for which may be script dependent).
x_pos : location to store result


pango_glyph_string_x_to_index ()

void        pango_glyph_string_x_to_index   (PangoGlyphString *glyphs,
                                             char *text,
                                             int length,
                                             PangoAnalysis *analysis,
                                             int x_pos,
                                             int *index,
                                             int *trailing);

Convert from x offset to position.

glyphs : the glyphs return from pango_shape()
text : the text for the run
length : the number of bytes (not characters) in text.
analysis : the analysis information return from pango_itemize()
x_pos : the x offset (in thousands of a device unit)
index : location to store calculated byte index within text
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_glyph_string_get_logical_widths ()

void        pango_glyph_string_get_logical_widths
                                            (PangoGlyphString *glyphs,
                                             const char *text,
                                             int length,
                                             int embedding_level,
                                             int *logical_widths);

Given a PangoGlyphString resulting from pango_shape() and the corresponding text, determine the screen width corresponding to each character. When multiple characters compose a single cluster, the width of the entire cluster is divided equally among the characters.

glyphs : a PangoGlyphString
text : the text corresponding to the glyphs
length : the length of text, in bytes
embedding_level : the embedding level of the string
logical_widths : an array whose length is g_utf8_strlen (text, length) to be filled in with the resulting character widths.