| GDK Reference Manual |
|---|
#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;
GdkPangoAttrStipple;
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,
gint *index_ranges,
gint n_ranges);
GdkRegion* gdk_pango_layout_line_get_clip_region
(PangoLayoutLine *line,
gint x_origin,
gint y_origin,
gint *index_ranges,
gint n_ranges);
Pango 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 gtk_widget_get_pango_context()gtk_widget_create_pango_layout()gdk_pango_context_get_for_screen(). Once you have a pango_layout_set_text()pango_layout_get_size()PANGO_PIXELS()
Rendering a Pango layout is done most simply with gdk_draw_layout();
you can also draw pieces of the layout with gdk_draw_layout() or
gdk_draw_glyphs(). GdkPangoRenderer is a subclass of
Example 7. Using GdkPangoRenderer to draw transformed text
define RADIUS 100define N_WORDS 10define 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);
typedef struct _GdkPangoRenderer GdkPangoRenderer;
GdkPangoRenderer is a subclass of gdk_pango_renderer_get_default(); Pango
functions like pango_renderer_draw_layout()pango_renderer_draw_layout_line()
In most simple cases, applications can just use gdk_draw_layout(), and
don't need to directly use GdkPangoRenderer at all. Using the
GdkPangoRenderer directly is most useful when working with a
transformation such as a rotation, because the Pango drawing functions
take user space coordinates (coordinates before the transformation)
instead of device coordinates.
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
typedef struct {
} GdkPangoRendererClass;
GdkPangoRenderer is the class structure for GdkPangoRenderer.
Since 2.6
PangoRenderer * gdk_pango_renderer_new (GdkScreen *screen);
Creates a new screen. Normally you can use the
results of gdk_pango_renderer_get_default() rather than creating a new
renderer.
screen : |
a GdkScreen |
| Returns : | a newly created g_object_unref() |
Since 2.6
PangoRenderer * gdk_pango_renderer_get_default (GdkScreen *screen);
Gets the default gdk_draw_layout().
Before using the renderer, you need to call gdk_pango_renderer_set_drawable()
and gdk_pango_renderer_set_gc() to set the drawable and graphics context
to use for drawing.
screen : |
a GdkScreen |
| Returns : | the default screen. The
renderer is owned by GTK+ and will be kept around until the
screen is closed.
|
Since 2.6
void gdk_pango_renderer_set_drawable (GdkPangoRenderer *gdk_renderer, GdkDrawable *drawable);
Sets the drawable the renderer draws to.
gdk_renderer : |
a GdkPangoRenderer |
drawable : |
the new target drawable, or NULL |
Since 2.6
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
NULLgc parameter, since GDK may make internal copies
of the GC which won't be updated to follow changes to the
original GC.
gdk_renderer : |
a GdkPangoRenderer |
gc : |
the new GC to use for drawing, or NULL |
Since 2.6
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 pango_renderer_draw_glyphs()
gdk_renderer : |
a GdkPangoRenderer |
part : |
the part to render with the stipple |
stipple : |
the new stipple value. |
Since 2.6
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.
gdk_renderer : |
a GdkPangoRenderer |
part : |
the part to render to set the color of |
color : |
the color to use, or NULL |
Since 2.6
PangoContext * gdk_pango_context_get (void);
Creates a
The context must be freed when you're finished with it.
When using GTK+, normally you should use gtk_widget_get_pango_context()
The newly created context will have the default font options (see
gtk_widget_get_pango_context()
| Returns : | a new |
PangoContext * gdk_pango_context_get_for_screen (GdkScreen *screen);
Creates a screen.
The context must be freed when you're finished with it.
When using GTK+, normally you should use gtk_widget_get_pango_context()
The newly created context will have the default font options
(see gtk_widget_get_pango_context()
screen : |
the GdkScreen for which the context is to be created. |
| Returns : | a new screen
|
Since 2.2
void gdk_pango_context_set_colormap (PangoContext *context, GdkColormap *colormap);
gdk_pango_context_set_colormap is deprecated and should not be used in newly-written code.
This function used to set the colormap to be used for drawing with
context. The colormap is now always derived from the graphics
context used for drawing, so calling this function is no longer
necessary.
context : |
a |
colormap : |
a GdkColormap |
typedef struct {
PangoAttribute attr;
gboolean embossed;
} GdkPangoAttrEmbossed;
A Pango text attribute containing a embossed bitmap to be used when rendering the text.
attr; |
the |
embossed; |
the embossed bitmap. |
typedef struct {
PangoAttribute attr;
GdkBitmap *stipple;
} GdkPangoAttrStipple;
A Pango text attribute containing a stipple bitmap to be used when rendering the text.
attr; |
the |
GdkBitmap *stipple; |
the stipple bitmap. |
PangoAttribute * gdk_pango_attr_embossed_new (gboolean embossed);
Creates a new attribute containing a embossed bitmap to be used when rendering the text.
embossed : |
a bitmap to be set as embossed |
| Returns : | new |
PangoAttribute * gdk_pango_attr_stipple_new (GdkBitmap *stipple);
Creates a new attribute containing a stipple bitmap to be used when rendering the text.
stipple : |
a bitmap to be set as stipple |
| Returns : | new |
GdkRegion* gdk_pango_layout_get_clip_region (PangoLayout *layout,gint x_origin,gint y_origin,gint *index_ranges,gint n_ranges);
Obtains a clip region which contains the areas where the given ranges
of text would be drawn. x_origin and y_origin are the same position
you would pass to gdk_draw_layout_line(). index_ranges should contain
ranges of bytes in the layout's text.
layout : |
a |
x_origin : |
X pixel where you intend to draw the layout with this clip |
y_origin : |
Y pixel where you intend to draw the layout with this clip |
index_ranges : |
array of byte indexes into the layout, where even members of array are start indexes and odd elements are end indexes |
n_ranges : |
number of ranges in index_ranges, i.e. half the size of index_ranges
|
| Returns : | a clip region containing the given ranges |
GdkRegion* gdk_pango_layout_line_get_clip_region (PangoLayoutLine *line,gint x_origin,gint y_origin,gint *index_ranges,gint n_ranges);
Obtains a clip region which contains the areas where the given
ranges of text would be drawn. x_origin and y_origin are the same
position you would pass to gdk_draw_layout_line(). index_ranges
should contain ranges of bytes in the layout's text. The clip
region will include space to the left or right of the line (to the
layout bounding box) if you have indexes above or below the indexes
contained inside the line. This is to draw the selection all the way
to the side of the layout. However, the clip region is in line coordinates,
not layout coordinates.
line : |
a |
x_origin : |
X pixel where you intend to draw the layout line with this clip |
y_origin : |
baseline pixel where you intend to draw the layout line with this clip |
index_ranges : |
array of byte indexes into the layout, where even members of array are start indexes and odd elements are end indexes |
n_ranges : |
number of ranges in index_ranges, i.e. half the size of index_ranges
|
| Returns : | a clip region containing the given ranges |
screen" property"screen" GdkScreen : Read / Write / Construct Only
the GdkScreen for the renderer.