PgCairoFontMap

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”

Constructors

this
this(PangoCairoFontMap* pangoCairoFontMap)

Sets our main struct and passes it to the parent class

this
this()

Creates a new PangoCairoFontMap object; a fontmap is used to cache information about available fonts, and holds certain global parameters such as the resolution. In most cases, you can use pango_cairo_font_map_get_default() instead. Note that the type of the returned object will depend on the particular font backend Cairo was compiled to use; You generally should only use the PangoFontMap and PangoCairoFontMap interfaces on the returned object. Since 1.10

this
this(cairo_font_type_t fonttype)

Creates a new PangoCairoFontMap object of the type suitable to be used with cairo font backend of type fonttype. In most cases one should simply use pango_cairo_font_map_new(), or in fact in most of those cases, just use pango_cairo_font_map_get_default(). Since 1.18

Members

Functions

createContext
PgContext createContext()

Warning pango_cairo_font_map_create_context has been deprecated since version 1.22 and should not be used in newly-written code. Use pango_font_map_create_context() instead. Create a PangoContext for the given fontmap. Since 1.10

getFontType
cairo_font_type_t getFontType()

Gets the type of Cairo font backend that fontmap uses. Since 1.18

getPgCairoFontMapStruct
PangoCairoFontMap* getPgCairoFontMapStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getResolution
double getResolution()

Gets the resolution for the fontmap. See pango_cairo_font_map_set_resolution() Since 1.10

getStruct
void* getStruct()

the main Gtk struct as a void*

setDefault
void setDefault()

Sets a default PangoCairoFontMap to use with Cairo. This can be used to change the Cairo font backend that the default fontmap uses for example. The old default font map is unreffed and the new font map referenced. Note that since Pango 1.32.6, the default fontmap is per-thread. This function only changes the default fontmap for the current thread. Default fontmaps of exisiting threads are not changed. Default fontmaps of any new threads will still be created using pango_cairo_font_map_new(). A value of NULL for fontmap will cause the current default font map to be released and a new default font map to be created on demand, using pango_cairo_font_map_new(). Since 1.22

setResolution
void setResolution(double dpi)

Sets the resolution for the fontmap. 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

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

getDefault
PgFontMap getDefault()

Gets a default PangoCairoFontMap to use with Cairo. Note that the type of the returned object will depend on the particular font backend Cairo was compiled to use; You generally should only use the PangoFontMap and PangoCairoFontMap interfaces on the returned object. The default Cairo fontmap can be changed by using pango_cairo_font_map_set_default(). This can be used to change the Cairo font backend that the default fontmap uses for example. Note that since Pango 1.32.6, the default fontmap is per-thread. Each thread gets its own default fontmap. In this way, PangoCairo can be used safely from multiple threads. Since 1.10

Variables

pangoCairoFontMap
PangoCairoFontMap* pangoCairoFontMap;

the main Gtk struct

Inherited Members

From PgFontMap

pangoFontMap
PangoFontMap* pangoFontMap;

the main Gtk struct

getPgFontMapStruct
PangoFontMap* getPgFontMapStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getStruct
void* getStruct()

the main Gtk struct as a void*

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.
createContext
PgContext createContext()

Creates a PangoContext connected to fontmap. This is equivalent to pango_context_new() followed by pango_context_set_font_map(). If you are using Pango as part of a higher-level system, that system may have it's own way of create a PangoContext. For instance, the GTK+ toolkit has, among others, gdk_pango_context_get_for_screen(), and gtk_widget_get_pango_context(). Use those instead. Since 1.22

loadFont
PgFont loadFont(PgContext context, PgFontDescription desc)

Load the font in the fontmap that is the closest match for desc.

loadFontset
PgFontset loadFontset(PgContext context, PgFontDescription desc, PgLanguage language)

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

listFamilies
void listFamilies(PgFontFamily[] families)

List all families for a fontmap.

getShapeEngineType
string getShapeEngineType()

Returns the render ID for shape engines for this fontmap. See the render_type field of PangoEngineInfo. Since 1.4

getSerial
uint getSerial()

Returns the current serial number of fontmap. The serial number is initialized to an small number larger than zero when a new fontmap is created and is increased whenever the fontmap is changed. It may wrap, but will never have the value 0. Since it can wrap, never compare it with "less than", always use "not equals". The fontmap can only be changed using backend-specific API, like changing fontmap resolution. This can be used to automatically detect changes to a PangoFontMap, like in PangoContext. Since 1.32.4

Meta