PgCairo

The Cairo library is a vector graphics library with a powerful rendering model. It has such features as anti-aliased primitives, alpha-compositing, and gradients. Multiple backends for Cairo are available, to allow rendering to images, to PDF files, and to the screen on X and on other windowing systems. The functions in this section allow using Pango to render to Cairo surfaces.

Using Pango with Cairo is straightforward. A PangoContext created with pango_cairo_font_map_create_context() can be used on any Cairo context (cairo_t), but needs to be updated to match the current transformation matrix and target surface of the Cairo context using pango_cairo_update_context(). The convenience functions pango_cairo_create_layout() and pango_cairo_update_layout() handle the common case where the program doesn't need to manipulate the properties of the PangoContext.

When you get the metrics of a layout or of a piece of a layout using functions such as pango_layout_get_extents(), the reported metrics are in user-space coordinates. If a piece of text is 10 units long, and you call cairo_scale (cr, 2.0), it still is more-or-less 10 units long. However, the results will be affected by hinting (that is, the process of adjusting the text to look good on the pixel grid), so you shouldn't assume they are completely independent of the current transformation matrix. Note that the basic metrics functions in Pango report results in integer Pango units. To get to the floating point units used in Cairo divide by PANGO_SCALE.

Figure 2. Output of Example 1, “Using Pango with Cairo”

Members

Static functions

contextGetFontOptions
FontOption contextGetFontOptions(PgContext context)

Retrieves any font rendering options previously set with pango_cairo_font_map_set_font_options(). This function does not report options that are derived from the target surface by pango_cairo_update_context() Since 1.10

contextGetResolution
double contextGetResolution(PgContext context)

Gets the resolution for the context. See pango_cairo_context_set_resolution() Since 1.10

contextGetShapeRenderer
PangoCairoShapeRendererFunc contextGetShapeRenderer(PgContext context, void** data)

Sets callback function for context to use for rendering attributes of type PANGO_ATTR_SHAPE. See PangoCairoShapeRendererFunc for details. Retrieves callback function and associated user data for rendering attributes of type PANGO_ATTR_SHAPE as set by pango_cairo_context_set_shape_renderer(), if any. Since 1.18

contextSetFontOptions
void contextSetFontOptions(PgContext context, FontOption options)

Sets the font options used when rendering text with this context. These options override any options that pango_cairo_update_context() derives from the target surface. Since 1.10

contextSetResolution
void contextSetResolution(PgContext context, double dpi)

Sets the resolution for the context. This is a scale factor between points specified in a PangoFontDescription and Cairo units. The default value is 96, meaning that a 10 point font will be 13 units high. (10 * 96. / 72. = 13.3). Since 1.10

contextSetShapeRenderer
void contextSetShapeRenderer(PgContext context, PangoCairoShapeRendererFunc func, void* data, GDestroyNotify dnotify)

Sets callback function for context to use for rendering attributes of type PANGO_ATTR_SHAPE. See PangoCairoShapeRendererFunc for details. Since 1.18

createContext
PgContext createContext(Context cr)

Creates a context object set up to match the current transformation and target surface of the Cairo context. This context can then be used to create a layout using pango_layout_new(). This function is a convenience function that creates a context using the default font map, then updates it to cr. If you just need to create a layout for use with cr and do not need to access PangoContext directly, you can use pango_cairo_create_layout() instead. Since 1.22

createLayout
PgLayout createLayout(Context cr)

Creates a layout object set up to match the current transformation and target surface of the Cairo context. This layout can then be used for text measurement with functions like pango_layout_get_size() or drawing with functions like pango_cairo_show_layout(). If you change the transformation or target surface for cr, you need to call pango_cairo_update_layout() This function is the most convenient way to use Cairo with Pango, however it is slightly inefficient since it creates a separate PangoContext object for each layout. This might matter in an application that was laying out large amounts of text. Since 1.10

errorUnderlinePath
void errorUnderlinePath(Context cr, double x, double y, double width, double height)

Add a squiggly line to the current path in the specified cairo context that approximately covers the given rectangle in the style of an underline used to indicate a spelling error. (The width of the underline is rounded to an integer number of up/down segments and the resulting rectangle is centered in the original rectangle) Since 1.14

fontGetScaledFont
ScaledFont fontGetScaledFont(PangoCairoFont* font)

Gets the cairo_scaled_font_t used by font. The scaled font can be referenced and kept using cairo_scaled_font_reference(). Since 1.18

glyphStringPath
void glyphStringPath(Context cr, PgFont font, PgGlyphString glyphs)

Adds the glyphs in glyphs to the current path in the specified cairo context. The origin of the glyphs (the left edge of the baseline) will be at the current point of the cairo context. Since 1.10

layoutLinePath
void layoutLinePath(Context cr, PgLayoutLine line)

Adds the text in PangoLayoutLine to the current path in the specified cairo context. The origin of the glyphs (the left edge of the line) will be at the current point of the cairo context. Since 1.10

layoutPath
void layoutPath(Context cr, PgLayout layout)

Adds the text in a PangoLayout to the current path in the specified cairo context. The top-left corner of the PangoLayout will be at the current point of the cairo context. Since 1.10

showErrorUnderline
void showErrorUnderline(Context cr, double x, double y, double width, double height)

Draw a squiggly line in the specified cairo context that approximately covers the given rectangle in the style of an underline used to indicate a spelling error. (The width of the underline is rounded to an integer number of up/down segments and the resulting rectangle is centered in the original rectangle) Since 1.14

showGlyphItem
void showGlyphItem(Context cr, string text, PgGlyphItem glyphItem)

Draws the glyphs in glyph_item in the specified cairo context, embedding the text associated with the glyphs in the output if the output format supports it (PDF for example), otherwise it acts similar to pango_cairo_show_glyph_string(). The origin of the glyphs (the left edge of the baseline) will be drawn at the current point of the cairo context. Note that text is the start of the text for layout, which is then indexed by glyph_item->item->offset. Since 1.22

showGlyphString
void showGlyphString(Context cr, PgFont font, PgGlyphString glyphs)

Draws the glyphs in glyphs in the specified cairo context. The origin of the glyphs (the left edge of the baseline) will be drawn at the current point of the cairo context. Since 1.10

showLayout
void showLayout(Context cr, PgLayout layout)

Draws a PangoLayout in the specified cairo context. The top-left corner of the PangoLayout will be drawn at the current point of the cairo context. Since 1.10

showLayoutLine
void showLayoutLine(Context cr, PgLayoutLine line)

Draws a PangoLayoutLine in the specified cairo context. The origin of the glyphs (the left edge of the line) will be drawn at the current point of the cairo context. Since 1.10

updateContext
void updateContext(Context cr, PgContext context)

Updates a PangoContext previously created for use with Cairo to match the current transformation and target surface of a Cairo context. If any layouts have been created for the context, it's necessary to call pango_layout_context_changed() on those layouts. Since 1.10

updateLayout
void updateLayout(Context cr, PgLayout layout)

Updates the private PangoContext of a PangoLayout created with pango_cairo_create_layout() to match the current transformation and target surface of a Cairo context. Since 1.10

Meta