diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 749d9b0222..3f6f8f189e 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,14 @@ +Sat Nov 20 16:01:51 2004 Owen Taylor + + * gdk/gdk-sections.txt gdk/gdk.types : Update for GdkPangoRenderer + * gdk/Makefile.am gdk/images/rotated-text.png: + + * gdk/tmpl/pango_interaction.sgml: Add a long + description and an extensive example (more or less the same as + demos/gtk-demo/rotated_text.c) + + * gtk/gtk-sections.txt: Add gtk_label_set/get_angle. + 2004-11-20 Matthias Clasen * gtk/gtk-sections.txt: Add gtk_dialog_set_alternative_button_order_from_array diff --git a/docs/reference/gdk/Makefile.am b/docs/reference/gdk/Makefile.am index dafa39fa45..92b2cfd277 100644 --- a/docs/reference/gdk/Makefile.am +++ b/docs/reference/gdk/Makefile.am @@ -59,6 +59,8 @@ content_files = \ # Images to copy into HTML directory HTML_IMAGES = \ + images/rotated-text.png \ + \ images/X_cursor.png \ images/arrow.png \ images/based_arrow_down.png \ diff --git a/docs/reference/gdk/gdk-sections.txt b/docs/reference/gdk/gdk-sections.txt index 9d7ea2d5d1..825c0a0a84 100644 --- a/docs/reference/gdk/gdk-sections.txt +++ b/docs/reference/gdk/gdk-sections.txt @@ -464,7 +464,10 @@ GdkSegment gdk_draw_rectangle gdk_draw_arc gdk_draw_polygon +gdk_draw_trapezoids +GdkTrapezoid gdk_draw_glyphs +gdk_draw_glyphs_transformed gdk_draw_layout_line gdk_draw_layout_line_with_colors gdk_draw_layout @@ -827,6 +830,14 @@ GDK_TYPE_PROP_MODE
Pango Interaction pango_interaction +GdkPangoRenderer +GdkPangoRendererClass +gdk_pango_renderer_new +gdk_pango_renderer_get_default +gdk_pango_renderer_set_drawable +gdk_pango_renderer_set_gc +gdk_pango_renderer_set_stipple +gdk_pango_renderer_set_override_color gdk_pango_context_get gdk_pango_context_get_for_screen gdk_pango_context_set_colormap @@ -836,6 +847,17 @@ gdk_pango_attr_embossed_new gdk_pango_attr_stipple_new gdk_pango_layout_get_clip_region gdk_pango_layout_line_get_clip_region + +GDK_TYPE_PANGO_RENDERER +GDK_PANGO_RENDERER +GDK_IS_PANGO_RENDERER +GDK_PANGO_RENDERER_CLASS +GDK_IS_PANGO_RENDERER_CLASS +GDK_PANGO_RENDERER_GET_CLASS + + +gdk_pango_renderer_get_type +GdkPangoRendererPrivate
diff --git a/docs/reference/gdk/gdk.types b/docs/reference/gdk/gdk.types index da34cd89d0..12b0f8d356 100644 --- a/docs/reference/gdk/gdk.types +++ b/docs/reference/gdk/gdk.types @@ -5,6 +5,7 @@ gdk_display_manager_get_type gdk_screen_get_type gdk_drawable_get_type gdk_window_object_get_type +gdk_pango_renderer_get_type gdk_pixmap_get_type gdk_gc_get_type gdk_keymap_get_type diff --git a/docs/reference/gdk/images/rotated-text.png b/docs/reference/gdk/images/rotated-text.png new file mode 100644 index 0000000000..1952314b07 Binary files /dev/null and b/docs/reference/gdk/images/rotated-text.png differ diff --git a/docs/reference/gdk/tmpl/drawing.sgml b/docs/reference/gdk/tmpl/drawing.sgml index 0443146ad8..87475aeeee 100644 --- a/docs/reference/gdk/tmpl/drawing.sgml +++ b/docs/reference/gdk/tmpl/drawing.sgml @@ -285,6 +285,29 @@ function. @npoints: + + + + + +@drawable: +@gc: +@trapezoids: +@n_trapezoids: + + + + + + + +@y1: +@x11: +@x21: +@y2: +@x12: +@x22: + @@ -298,6 +321,20 @@ function. @glyphs: + + + + + +@drawable: +@gc: +@matrix: +@font: +@x: +@y: +@glyphs: + + diff --git a/docs/reference/gdk/tmpl/pango_interaction.sgml b/docs/reference/gdk/tmpl/pango_interaction.sgml index dc6c71af70..16ee04a5f7 100644 --- a/docs/reference/gdk/tmpl/pango_interaction.sgml +++ b/docs/reference/gdk/tmpl/pango_interaction.sgml @@ -2,18 +2,206 @@ Pango Interaction -Low-level access to Pango +Using Pango in GDK - +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 #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 gtk_widget_get_context(), or +gtk_widget_create_pango_layout(), rather than using the lowlevel +gdk_pango_context_get_for_screen(). Once you have a #PangoLayout, you +can set the text and attributes of it with Pango functions like +pango_layout_set_text() and get its size with pango_layout_get_size(). +(Note that Pango uses a fixed point system internally, so converting +between Pango units and pixels using PANGO_SCALE or the PANGO_PIXELS() macro.) + + +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 #PangoRenderer +that is used internally to implement these functions. Using it +directly or subclassing it can be useful in some cases. See the +#GdkPangoRenderer documentation for details. + + +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); + + +
+ Output of <xref linkend="rotated-example"/> + +
+ + + + + + + + + + + + + + + + + + + + + + +@screen: +@Returns: + + + + + + + +@screen: +@Returns: + + + + + + + +@gdk_renderer: +@drawable: + + + + + + + +@gdk_renderer: +@gc: + + + + + + + +@gdk_renderer: +@part: +@stipple: + + + + + + + +@gdk_renderer: +@part: +@color: + + diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 6479e102c0..ba601e69a9 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -1935,10 +1935,12 @@ gtk_label_get_selection_bounds gtk_label_get_use_markup gtk_label_get_use_underline gtk_label_get_single_line_mode +gtk_label_get_angle gtk_label_set_label gtk_label_set_use_markup gtk_label_set_use_underline gtk_label_set_single_line_mode +gtk_label_set_angle GTK_LABEL GTK_IS_LABEL diff --git a/docs/reference/gtk/tmpl/gtklabel.sgml b/docs/reference/gtk/tmpl/gtklabel.sgml index ecd9d06c60..fb46d301c9 100644 --- a/docs/reference/gtk/tmpl/gtklabel.sgml +++ b/docs/reference/gtk/tmpl/gtklabel.sgml @@ -170,6 +170,11 @@ described below. @label: the object which received the signal. @arg1: + + + + + @@ -564,6 +569,15 @@ Gtk+ 1.0.x. @Returns: + + + + + +@label: +@Returns: + + @@ -600,3 +614,12 @@ Gtk+ 1.0.x. @single_line_mode: + + + + + +@label: +@angle: + +