Synopsis#include <gdk/gdk.h> GdkPangoRenderer; GdkPangoRendererClass; PangoRenderer* gdk_pango_renderer_new (GdkScreen *screen); PangoRenderer* gdk_pango_renderer_get_default (GdkScreen *screen); void gdk_pango_renderer_set_drawable (GdkPangoRenderer *gdk_renderer, GdkDrawable *drawable); void gdk_pango_renderer_set_gc (GdkPangoRenderer *gdk_renderer, GdkGC *gc); void gdk_pango_renderer_set_stipple (GdkPangoRenderer *gdk_renderer, PangoRenderPart part, GdkBitmap *stipple); void gdk_pango_renderer_set_override_color (GdkPangoRenderer *gdk_renderer, PangoRenderPart part, const GdkColor *color); PangoContext* gdk_pango_context_get (void); PangoContext* gdk_pango_context_get_for_screen (GdkScreen *screen); void gdk_pango_context_set_colormap (PangoContext *context, GdkColormap *colormap); GdkPangoAttrEmbossed; GdkPangoAttrEmbossColor; GdkPangoAttrStipple; PangoAttribute* gdk_pango_attr_emboss_color_new (const GdkColor *color); PangoAttribute* gdk_pango_attr_embossed_new (gboolean embossed); PangoAttribute* gdk_pango_attr_stipple_new (GdkBitmap *stipple); GdkRegion* gdk_pango_layout_get_clip_region (PangoLayout *layout, gint x_origin, gint y_origin, const gint *index_ranges, gint n_ranges); GdkRegion* gdk_pango_layout_line_get_clip_region (PangoLayoutLine *line, gint x_origin, gint y_origin, const gint *index_ranges, gint n_ranges); DescriptionPango is the text layout system used by GDK and GTK+. The functions and types in this section are used to render Pango objects to GDK. drawables, and also extend the set of Pango attributes to include stippling and embossing.
Creating a PangoLayout object is the first step in rendering text,
and requires getting a handle to a PangoContext. For GTK+ programs,
you'll usually want to use
Rendering a Pango layout is done most simply with Example 8. Using GdkPangoRenderer to draw transformed text #define RADIUS 100 #define N_WORDS 10 #define FONT "Sans Bold 18" GdkScreen *screen = gdk_drawable_get_screen (drawable); PangoRenderer *renderer; GdkGC *gc; PangoMatrix matrix = PANGO_MATRIX_INIT; PangoContext *context; PangoLayout *layout; PangoFontDescription *desc; double device_radius; int width, height; int i; /* Get the default renderer for the screen, and set it up for drawing */ renderer = gdk_pango_renderer_get_default (screen); gdk_pango_renderer_set_drawable (GDK_PANGO_RENDERER (renderer), drawable); gc = gdk_gc_new (drawable); gdk_pango_renderer_set_gc (GDK_PANGO_RENDERER (renderer), gc); /* Set up a transformation matrix so that the user space coordinates for * where we are drawing are [-RADIUS, RADIUS], [-RADIUS, RADIUS] * We first center, then change the scale */ gdk_drawable_get_size (drawable, &width, &height); device_radius = MIN (width, height) / 2.; pango_matrix_translate (&matrix, device_radius + (width - 2 * device_radius) / 2, device_radius + (height - 2 * device_radius) / 2); pango_matrix_scale (&matrix, device_radius / RADIUS, device_radius / RADIUS); /* Create a PangoLayout, set the font and text */ context = gdk_pango_context_get_for_screen (screen); layout = pango_layout_new (context); pango_layout_set_text (layout, "Text", -1); desc = pango_font_description_from_string (FONT); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); /* Draw the layout N_WORDS times in a circle */ for (i = 0; i < N_WORDS; i++) { GdkColor color; PangoMatrix rotated_matrix = matrix; int width, height; double angle = (360. * i) / N_WORDS; /* Gradient from red at angle == 60 to blue at angle == 300 */ color.red = 65535 * (1 + cos ((angle - 60) * M_PI / 180.)) / 2; color.green = 0; color.blue = 65535 - color.red; gdk_pango_renderer_set_override_color (GDK_PANGO_RENDERER (renderer), PANGO_RENDER_PART_FOREGROUND, &color); pango_matrix_rotate (&rotated_matrix, angle); pango_context_set_matrix (context, &rotated_matrix); /* Inform Pango to re-layout the text with the new transformation matrix */ pango_layout_context_changed (layout); pango_layout_get_size (layout, &width, &height); pango_renderer_draw_layout (renderer, layout, - width / 2, - RADIUS * PANGO_SCALE); } /* Clean up default renderer, since it is shared */ gdk_pango_renderer_set_override_color (GDK_PANGO_RENDERER (renderer), PANGO_RENDER_PART_FOREGROUND, NULL); gdk_pango_renderer_set_drawable (GDK_PANGO_RENDERER (renderer), NULL); gdk_pango_renderer_set_gc (GDK_PANGO_RENDERER (renderer), NULL); /* free the objects we created */ g_object_unref (layout); g_object_unref (context); g_object_unref (gc); DetailsGdkPangoRenderertypedef struct _GdkPangoRenderer GdkPangoRenderer;
GdkPangoRenderer is a subclass of PangoRenderer used for rendering
Pango objects into GDK drawables. The default renderer for a particular
screen is obtained with
In most simple cases, applications can just use In certain cases it can be useful to subclass GdkPangoRenderer. Examples of reasons to do this are to add handling of custom attributes by overriding 'prepare_run' or to do custom drawing of embedded objects by overriding 'draw_shape'.
Since 2.6 GdkPangoRendererClasstypedef struct { } GdkPangoRendererClass; GdkPangoRenderer is the class structure for GdkPangoRenderer.
Since 2.6 gdk_pango_renderer_new ()PangoRenderer* gdk_pango_renderer_new (GdkScreen *screen);
Creates a new PangoRenderer for
Since 2.6 gdk_pango_renderer_get_default ()PangoRenderer* gdk_pango_renderer_get_default (GdkScreen *screen);
Gets the default PangoRenderer for a screen. This default renderer
is shared by all users of the display, so properties such as the color
or transformation matrix set for the renderer may be overwritten
by functions such as
Before using the renderer, you need to call
Since 2.6 gdk_pango_renderer_set_drawable ()void gdk_pango_renderer_set_drawable (GdkPangoRenderer *gdk_renderer, GdkDrawable *drawable); Sets the drawable the renderer draws to.
Since 2.6 gdk_pango_renderer_set_gc ()void gdk_pango_renderer_set_gc (GdkPangoRenderer *gdk_renderer, GdkGC *gc);
Sets the GC the renderer draws with. Note that the GC must not be
modified until it is unset by calling the function again with
Since 2.6 gdk_pango_renderer_set_stipple ()void gdk_pango_renderer_set_stipple (GdkPangoRenderer *gdk_renderer, PangoRenderPart part, GdkBitmap *stipple);
Sets the stipple for one render part (foreground, background, underline,
etc.) Note that this is overwritten when iterating through the individual
styled runs of a PangoLayout or PangoLayoutLine. This function is thus
only useful when you call low level functions like
Since 2.6 gdk_pango_renderer_set_override_color ()void gdk_pango_renderer_set_override_color (GdkPangoRenderer *gdk_renderer, PangoRenderPart part, const GdkColor *color); Sets the color for a particular render part (foreground, background, underline, etc.), overriding any attributes on the layouts renderered with this renderer.
Since 2.6 gdk_pango_context_get ()PangoContext* gdk_pango_context_get (void); Creates a PangoContext for the default GDK screen. The context must be freed when you're finished with it.
When using GTK+, normally you should use
The newly created context will have the default font options (see
cairo_font_options_t) for the default screen; if these options
change it will not be updated. Using
gdk_pango_context_get_for_screen ()PangoContext* gdk_pango_context_get_for_screen (GdkScreen *screen);
Creates a PangoContext for The context must be freed when you're finished with it.
When using GTK+, normally you should use
The newly created context will have the default font options
(see cairo_font_options_t) for the screen; if these options
change it will not be updated. Using
Since 2.2 gdk_pango_context_set_colormap ()void gdk_pango_context_set_colormap (PangoContext *context, GdkColormap *colormap); Warning
This function used to set the colormap to be used for drawing with
GdkPangoAttrEmbossedtypedef struct { PangoAttribute attr; gboolean embossed; } GdkPangoAttrEmbossed; A Pango text attribute containing a embossed bitmap to be used when rendering the text.
GdkPangoAttrEmbossColortypedef struct { PangoAttribute attr; PangoColor color; } GdkPangoAttrEmbossColor; A Pango text attribute specifying the color to emboss text with.
GdkPangoAttrStippletypedef struct { PangoAttribute attr; GdkBitmap *stipple; } GdkPangoAttrStipple; A Pango text attribute containing a stipple bitmap to be used when rendering the text.
gdk_pango_attr_emboss_color_new ()PangoAttribute* gdk_pango_attr_emboss_color_new (const GdkColor *color); Creates a new attribute specifying the color to emboss text with.
Since 2.12 gdk_pango_attr_embossed_new ()PangoAttribute* gdk_pango_attr_embossed_new (gboolean embossed); Creates a new attribute flagging a region as embossed or not.
gdk_pango_attr_stipple_new ()PangoAttribute* gdk_pango_attr_stipple_new (GdkBitmap *stipple); Creates a new attribute containing a stipple bitmap to be used when rendering the text.
gdk_pango_layout_get_clip_region ()GdkRegion* gdk_pango_layout_get_clip_region (PangoLayout *layout, gint x_origin, gint y_origin, const gint *index_ranges, gint n_ranges);
Obtains a clip region which contains the areas where the given ranges
of text would be drawn. Note that the regions returned correspond to logical extents of the text ranges, not ink extents. So the drawn layout may in fact touch areas out of the clip region. The clip region is mainly useful for highlightling parts of text, such as when text is selected.
gdk_pango_layout_line_get_clip_region ()GdkRegion* gdk_pango_layout_line_get_clip_region (PangoLayoutLine *line, gint x_origin, gint y_origin, const gint *index_ranges, gint n_ranges);
Obtains a clip region which contains the areas where the given
ranges of text would be drawn. Note that the regions returned correspond to logical extents of the text ranges, not ink extents. So the drawn line may in fact touch areas out of the clip region. The clip region is mainly useful for highlightling parts of text, such as when text is selected.
Property DetailsThe
|