]> Pileus Git - ~andy/gtk/blob - gdk/gdkpango.c
Fix a typo in the docs. (#303940, Masao Mutoh)
[~andy/gtk] / gdk / gdkpango.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 2000 Red Hat, Inc. 
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <config.h>
21 #include <math.h>
22 #include <pango/pangocairo.h>
23 #include "gdkcairo.h"
24 #include "gdkcolor.h"
25 #include "gdkgc.h"
26 #include "gdkinternals.h"
27 #include "gdkpango.h"
28 #include "gdkrgb.h"
29 #include "gdkprivate.h"
30 #include "gdkscreen.h"
31 #include "gdkalias.h"
32
33 /* This is for P_() ... a bit non-kosher, but works fine */
34 #include "gtk/gtkintl.h"
35
36 #define GDK_INFO_KEY "gdk-info"
37
38 /* We have various arrays indexed by render part; if PangoRenderPart
39  * is extended, we want to make sure not to overwrite the end of
40  * those arrays.
41  */
42 #define MAX_RENDER_PART  PANGO_RENDER_PART_STRIKETHROUGH
43
44 struct _GdkPangoRendererPrivate
45 {
46   GdkScreen *screen;
47
48   /* GdkPangoRenderer specific state */
49   PangoColor override_color[MAX_RENDER_PART + 1];
50   gboolean override_color_set[MAX_RENDER_PART + 1];
51   
52   GdkBitmap *stipple[MAX_RENDER_PART + 1];
53   gboolean embossed;
54
55   cairo_t *cr;
56   PangoRenderPart last_part;
57
58   /* Current target */
59   GdkDrawable *drawable;
60   GdkGC *base_gc;
61 };
62
63 static PangoAttrType gdk_pango_attr_stipple_type;
64 static PangoAttrType gdk_pango_attr_embossed_type;
65
66 enum {
67   PROP_0,
68   PROP_SCREEN
69 };
70
71 G_DEFINE_TYPE (GdkPangoRenderer, gdk_pango_renderer, PANGO_TYPE_RENDERER)
72
73 static void
74 gdk_pango_renderer_finalize (GObject *object)
75 {
76   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (object);
77   GdkPangoRendererPrivate *priv = gdk_renderer->priv;
78   int i;
79
80   if (priv->base_gc)
81     g_object_unref (priv->base_gc);
82   if (priv->drawable)
83     g_object_unref (priv->drawable);
84
85   for (i = 0; i <= MAX_RENDER_PART; i++)
86     if (priv->stipple[i])
87       g_object_unref (priv->stipple[i]);
88
89   G_OBJECT_CLASS (gdk_pango_renderer_parent_class)->finalize (object);
90 }
91
92 static GObject*
93 gdk_pango_renderer_constructor (GType                  type,
94                                 guint                  n_construct_properties,
95                                 GObjectConstructParam *construct_params)
96 {
97   GObject *object;
98   GdkPangoRenderer *gdk_renderer;
99
100   object = (* G_OBJECT_CLASS (gdk_pango_renderer_parent_class)->constructor) (type,
101                                                                               n_construct_properties,
102                                                                               construct_params);
103
104   gdk_renderer = GDK_PANGO_RENDERER (object);
105   
106   if (!gdk_renderer->priv->screen)
107     {
108       g_warning ("Screen must be specified at construct time for GdkPangoRenderer");
109       gdk_renderer->priv->screen = gdk_screen_get_default ();
110     }
111
112   return object;
113 }
114
115 /* Adjusts matrix and color for the renderer to draw the secondary
116  * "shadow" copy for embossed text */
117 static void
118 emboss_context (cairo_t *cr)
119 {
120   cairo_matrix_t tmp_matrix;
121
122   /* The gymnastics here to adjust the matrix are because we want
123    * to offset by +1,+1 in device-space, not in user-space,
124    * so we can't just draw the layout at x + 1, y + 1
125    */
126   cairo_get_matrix (cr, &tmp_matrix);
127   tmp_matrix.x0 += 1.0;
128   tmp_matrix.y0 += 1.0;
129   cairo_set_matrix (cr, &tmp_matrix);
130
131   cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
132 }
133
134 static cairo_t *
135 get_cairo_context (GdkPangoRenderer *gdk_renderer,
136                    PangoRenderPart   part)
137 {
138   PangoRenderer *renderer = PANGO_RENDERER (gdk_renderer);
139   GdkPangoRendererPrivate *priv = gdk_renderer->priv;
140
141   if (!priv->cr)
142     {
143       const PangoMatrix *matrix;
144       
145       priv->cr = gdk_cairo_create (priv->drawable);
146
147       matrix = pango_renderer_get_matrix (renderer);
148       if (matrix)
149         {
150           cairo_matrix_t cairo_matrix;
151           
152           cairo_matrix_init (&cairo_matrix,
153                              matrix->xx, matrix->yx,
154                              matrix->xy, matrix->yy,
155                              matrix->x0, matrix->y0);
156           cairo_set_matrix (priv->cr, &cairo_matrix);
157         }
158     }
159   
160   priv->last_part = (PangoRenderPart)-1;
161   if (part != priv->last_part)
162     {
163       PangoColor *pango_color = pango_renderer_get_color (renderer,
164                                                           part);
165       GdkColor *color = NULL;
166       GdkColor tmp_color;
167       if (pango_color)
168         {
169           tmp_color.red = pango_color->red;
170           tmp_color.green = pango_color->green;
171           tmp_color.blue = pango_color->blue;
172           
173           color = &tmp_color;
174         }
175
176       _gdk_gc_update_context (priv->base_gc,
177                               priv->cr,
178                               color,
179                               priv->stipple[part]);
180       priv->last_part = part;
181     }
182
183   return priv->cr;
184 }
185
186 static void
187 gdk_pango_renderer_draw_glyphs (PangoRenderer    *renderer,
188                                 PangoFont        *font,
189                                 PangoGlyphString *glyphs,
190                                 int               x,
191                                 int               y)
192 {
193   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (renderer);
194   GdkPangoRendererPrivate *priv = gdk_renderer->priv;
195   cairo_t *cr;
196
197   cr = get_cairo_context (gdk_renderer, 
198                           PANGO_RENDER_PART_FOREGROUND);
199
200   if (priv->embossed)
201     {
202       cairo_save (cr);
203       emboss_context (cr);
204       cairo_move_to (cr, x / PANGO_SCALE, y / PANGO_SCALE);
205       pango_cairo_show_glyph_string (cr, font, glyphs);
206       cairo_restore (cr);
207     }
208   
209   cairo_move_to (cr, x / PANGO_SCALE, y / PANGO_SCALE);
210   pango_cairo_show_glyph_string (cr, font, glyphs);
211 }
212
213 /* Draws an error underline that looks like one of:
214  *              H       E                H
215  *     /\      /\      /\        /\      /\               -
216  *   A/  \    /  \    /  \     A/  \    /  \              |
217  *    \   \  /    \  /   /D     \   \  /    \             |
218  *     \   \/  C   \/   /        \   \/   C  \            | height = HEIGHT_SQUARES * square
219  *      \      /\  F   /          \  F   /\   \           | 
220  *       \    /  \    /            \    /  \   \G         |
221  *        \  /    \  /              \  /    \  /          |
222  *         \/      \/                \/      \/           -
223  *         B                         B       
224  *    |----|
225  *   unit_width = (HEIGHT_SQUARES - 1) * square
226  *
227  * The x, y, width, height passed in give the desired bounding box;
228  * x/width are adjusted to make the underline a integer number of units
229  * wide.
230  */
231 #define HEIGHT_SQUARES 2.5
232
233 static void
234 draw_error_underline (cairo_t *cr,
235                       double  x,
236                       double  y,
237                       double  width,
238                       double  height)
239 {
240   double square = height / HEIGHT_SQUARES;
241   double unit_width = (HEIGHT_SQUARES - 1) * square;
242   int width_units = (width + unit_width / 2) / unit_width;
243   double y_top, y_bottom;
244   int i;
245
246   x += (width - width_units * unit_width);
247   width = width_units * unit_width;
248
249   y_top = y;
250   y_bottom = y + height;
251   
252   /* Bottom of squiggle */
253   cairo_move_to (cr, x - square / 2, y_top + square / 2); /* A */
254   for (i = 0; i < width_units; i += 2)
255     {
256       double x_middle = x + (i + 1) * unit_width;
257       double x_right = x + (i + 2) * unit_width;
258     
259       cairo_line_to (cr, x_middle, y_bottom); /* B */
260       
261       if (i + 1 == width_units)
262         /* Nothing */;
263       else if (i + 2 == width_units)
264         cairo_line_to (cr, x_right + square / 2, y_top + square / 2); /* D */
265       else
266         cairo_line_to (cr, x_right, y_top + square); /* C */
267     }
268   
269   /* Top of squiggle */
270   for (i -= 2; i >= 0; i -= 2)
271     {
272       double x_left = x + i * unit_width;
273       double x_middle = x + (i + 1) * unit_width;
274       double x_right = x + (i + 2) * unit_width;
275       
276       if (i + 1 == width_units)
277         cairo_line_to (cr, x_middle + square / 2, y_bottom - square / 2); /* G */
278       else {
279         if (i + 2 == width_units)
280           cairo_line_to (cr, x_right, y_top); /* E */
281         cairo_line_to (cr, x_middle, y_bottom - square); /* F */
282       }
283       
284       cairo_line_to (cr, x_left, y_top);   /* H */
285     }
286
287   cairo_close_path (cr);
288   cairo_fill (cr);
289 }
290
291 static void
292 gdk_pango_renderer_draw_rectangle (PangoRenderer    *renderer,
293                                    PangoRenderPart   part,
294                                    int               x,
295                                    int               y,
296                                    int               width,
297                                    int               height)
298 {
299   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (renderer);
300   GdkPangoRendererPrivate *priv = gdk_renderer->priv;
301   cairo_t *cr;
302   
303   cr = get_cairo_context (gdk_renderer, part);
304
305   if (priv->embossed && part != PANGO_RENDER_PART_BACKGROUND)
306     {
307       cairo_save (cr);
308       emboss_context (cr);
309       cairo_rectangle (cr,
310                        (double)x / PANGO_SCALE, (double)y / PANGO_SCALE,
311                        (double)width / PANGO_SCALE, (double)height / PANGO_SCALE);
312
313       cairo_fill (cr);
314       cairo_restore (cr);
315     }
316
317   cairo_rectangle (cr,
318                    (double)x / PANGO_SCALE, (double)y / PANGO_SCALE,
319                    (double)width / PANGO_SCALE, (double)height / PANGO_SCALE);
320   cairo_fill (cr);
321 }
322
323 static void
324 gdk_pango_renderer_draw_error_underline (PangoRenderer    *renderer,
325                                          int               x,
326                                          int               y,
327                                          int               width,
328                                          int               height)
329 {
330   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (renderer);
331   GdkPangoRendererPrivate *priv = gdk_renderer->priv;
332   cairo_t *cr;
333   
334   cr = get_cairo_context (gdk_renderer, PANGO_RENDER_PART_UNDERLINE);
335   
336   if (priv->embossed)
337     {
338       cairo_save (cr);
339       emboss_context (cr);
340       draw_error_underline (cr,
341                             (double)x / PANGO_SCALE, (double)y / PANGO_SCALE,
342                             (double)width / PANGO_SCALE, (double)height / PANGO_SCALE);
343       cairo_restore (cr);
344     }
345
346   draw_error_underline (cr,
347                         (double)x / PANGO_SCALE, (double)y / PANGO_SCALE,
348                         (double)width / PANGO_SCALE, (double)height / PANGO_SCALE);
349 }
350
351 static void
352 gdk_pango_renderer_part_changed (PangoRenderer   *renderer,
353                                  PangoRenderPart  part)
354 {
355   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (renderer);
356
357   if (gdk_renderer->priv->last_part == part)
358     gdk_renderer->priv->last_part = (PangoRenderPart)-1;
359 }
360
361 static void
362 gdk_pango_renderer_begin (PangoRenderer *renderer)
363 {
364   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (renderer);
365   GdkPangoRendererPrivate *priv = gdk_renderer->priv;
366   
367   if (!priv->drawable || !priv->base_gc)
368     {
369       g_warning ("gdk_pango_renderer_set_drawable() and gdk_pango_renderer_set_drawable()"
370                  "must be used to set the target drawable and GC before using the renderer\n");
371     }
372 }
373
374 static void
375 gdk_pango_renderer_end (PangoRenderer *renderer)
376 {
377   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (renderer);
378   GdkPangoRendererPrivate *priv = gdk_renderer->priv;
379
380   if (priv->cr)
381     {
382       cairo_destroy (priv->cr);
383       priv->cr = NULL;
384     }
385   priv->last_part = (PangoRenderPart)-1;
386 }
387
388 static void
389 gdk_pango_renderer_prepare_run (PangoRenderer  *renderer,
390                                 PangoLayoutRun *run)
391 {
392   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (renderer);
393   gboolean embossed = FALSE;
394   GdkBitmap *stipple = NULL;
395   GSList *l;
396   int i;
397   
398   embossed = FALSE;
399   stipple = NULL;
400   
401   for (l = run->item->analysis.extra_attrs; l; l = l->next)
402     {
403       PangoAttribute *attr = l->data;
404
405       /* stipple_type and embossed_type aren't necessarily
406        * initialized, but they are 0, which is an
407        * invalid type so won't occur. 
408        */
409       if (attr->klass->type == gdk_pango_attr_stipple_type)
410         {
411           stipple = ((GdkPangoAttrStipple*)attr)->stipple;
412         }
413       else if (attr->klass->type == gdk_pango_attr_embossed_type)
414         {
415           embossed = ((GdkPangoAttrEmbossed*)attr)->embossed;
416         }
417     }
418
419   gdk_pango_renderer_set_stipple (gdk_renderer, PANGO_RENDER_PART_FOREGROUND, stipple);
420   gdk_pango_renderer_set_stipple (gdk_renderer, PANGO_RENDER_PART_BACKGROUND, stipple);
421   gdk_pango_renderer_set_stipple (gdk_renderer, PANGO_RENDER_PART_UNDERLINE, stipple);
422   gdk_pango_renderer_set_stipple (gdk_renderer, PANGO_RENDER_PART_STRIKETHROUGH, stipple);
423
424   if (embossed != gdk_renderer->priv->embossed)
425     {
426       gdk_renderer->priv->embossed = embossed;
427       pango_renderer_part_changed (renderer, PANGO_RENDER_PART_FOREGROUND);
428     }
429
430   PANGO_RENDERER_CLASS (gdk_pango_renderer_parent_class)->prepare_run (renderer, run);
431
432   for (i = 0; i <= MAX_RENDER_PART; i++)
433     {
434       if (gdk_renderer->priv->override_color_set[i])
435         pango_renderer_set_color (renderer, i, &gdk_renderer->priv->override_color[i]);
436     }
437 }
438
439 static void
440 gdk_pango_renderer_set_property (GObject         *object,
441                                  guint            prop_id,
442                                  const GValue    *value,
443                                  GParamSpec      *pspec)
444 {
445   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (object);
446
447   switch (prop_id)
448     {
449     case PROP_SCREEN:
450       gdk_renderer->priv->screen = g_value_get_object (value);
451       break;
452     default:
453       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
454       break;
455     }
456 }
457
458 static void
459 gdk_pango_renderer_get_property (GObject    *object,
460                                  guint       prop_id,
461                                  GValue     *value,
462                                  GParamSpec *pspec)
463 {
464   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (object);
465
466   switch (prop_id)
467     {
468     case PROP_SCREEN:
469       g_value_set_object (value, gdk_renderer->priv->screen);
470       break;
471     default:
472       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
473       break;
474     }
475 }
476
477 static void
478 gdk_pango_renderer_init (GdkPangoRenderer *renderer)
479 {
480   renderer->priv = G_TYPE_INSTANCE_GET_PRIVATE (renderer,
481                                                 GDK_TYPE_PANGO_RENDERER,
482                                                 GdkPangoRendererPrivate);
483
484   renderer->priv->last_part = (PangoRenderPart)-1;
485 }
486
487 static void
488 gdk_pango_renderer_class_init (GdkPangoRendererClass *klass)
489 {
490   GObjectClass *object_class = G_OBJECT_CLASS (klass);
491   
492   PangoRendererClass *renderer_class = PANGO_RENDERER_CLASS (klass);
493   
494   renderer_class->draw_glyphs = gdk_pango_renderer_draw_glyphs;
495   renderer_class->draw_rectangle = gdk_pango_renderer_draw_rectangle;
496   renderer_class->draw_error_underline = gdk_pango_renderer_draw_error_underline;
497   renderer_class->part_changed = gdk_pango_renderer_part_changed;
498   renderer_class->begin = gdk_pango_renderer_begin;
499   renderer_class->end = gdk_pango_renderer_end;
500   renderer_class->prepare_run = gdk_pango_renderer_prepare_run;
501
502   object_class->finalize = gdk_pango_renderer_finalize;
503   object_class->constructor = gdk_pango_renderer_constructor;
504   object_class->set_property = gdk_pango_renderer_set_property;
505   object_class->get_property = gdk_pango_renderer_get_property;
506   
507   g_object_class_install_property (object_class,
508                                    PROP_SCREEN,
509                                    g_param_spec_object ("screen",
510                                                         P_("Screen"),
511                                                         P_("the GdkScreen for the renderer"),
512                                                         GDK_TYPE_SCREEN,
513                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
514                                                         G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | 
515                                                         G_PARAM_STATIC_BLURB));
516
517   g_type_class_add_private (object_class, sizeof (GdkPangoRendererPrivate));  
518 }
519
520 /**
521  * gdk_pango_renderer_new:
522  * @screen: a #GdkScreen
523  * 
524  * Creates a new #PangoRenderer for @screen. Normally you can use the
525  * results of gdk_pango_renderer_get_default() rather than creating a new
526  * renderer.
527  * 
528  * Return value: a newly created #PangoRenderer. Free with g_object_unref().
529  *
530  * Since: 2.6
531  **/
532 PangoRenderer *
533 gdk_pango_renderer_new (GdkScreen *screen)
534 {
535   g_return_val_if_fail (screen != NULL, NULL);
536   
537   return g_object_new (GDK_TYPE_PANGO_RENDERER,
538                        "screen", screen,
539                        NULL);
540 }
541
542 static void
543 on_renderer_display_closed (GdkDisplay       *display,
544                             GdkPangoRenderer *renderer)
545 {
546   g_signal_handlers_disconnect_by_func (renderer->priv->screen,
547                                         (gpointer)on_renderer_display_closed,
548                                         renderer);
549   g_object_set_data (G_OBJECT (renderer->priv->screen), "gdk-pango-renderer", NULL);
550 }
551
552 /**
553  * gdk_pango_renderer_get_default:
554  * @screen: a #GdkScreen
555  * 
556  * Gets the default #PangoRenderer for a screen. This default renderer
557  * is shared by all users of the display, so properties such as the color
558  * or transformation matrix set for the renderer may be overwritten
559  * by functions such as gdk_draw_layout().
560  *
561  * Before using the renderer, you need to call gdk_pango_renderer_set_drawable()
562  * and gdk_pango_renderer_set_gc() to set the drawable and graphics context
563  * to use for drawing.
564  * 
565  * Return value: the default #PangoRenderer for @screen. The
566  *  renderer is owned by GTK+ and will be kept around until the
567  *  screen is closed.
568  *
569  * Since: 2.6
570  **/
571 PangoRenderer *
572 gdk_pango_renderer_get_default (GdkScreen *screen)
573 {
574   PangoRenderer *renderer;
575
576   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
577   
578   renderer = g_object_get_data (G_OBJECT (screen), "gdk-pango-renderer");
579   if (!renderer)
580     {
581       renderer = gdk_pango_renderer_new (screen);
582       g_object_set_data_full (G_OBJECT (screen), "gdk-pango-renderer", renderer,
583                               (GDestroyNotify)g_object_unref);
584
585       g_signal_connect (gdk_screen_get_display (screen), "closed",
586                         G_CALLBACK (on_renderer_display_closed), renderer);
587     }
588
589   return renderer;
590 }
591
592 /**
593  * gdk_pango_renderer_set_drawable:
594  * @gdk_renderer: a #GdkPangoRenderer
595  * @drawable: the new target drawable, or %NULL
596  * 
597  * Sets the drawable the renderer draws to.
598  *
599  * Since: 2.6
600  **/
601 void
602 gdk_pango_renderer_set_drawable (GdkPangoRenderer *gdk_renderer,
603                                  GdkDrawable      *drawable)
604 {
605   GdkPangoRendererPrivate *priv;
606   
607   g_return_if_fail (GDK_IS_PANGO_RENDERER (gdk_renderer));
608   g_return_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable));
609
610   priv = gdk_renderer->priv;
611   
612   if (priv->drawable != drawable)
613     {
614       if (priv->drawable)
615         g_object_unref (priv->drawable);
616       priv->drawable = drawable;
617       if (priv->drawable)
618         g_object_ref (priv->drawable);
619     }
620 }
621
622 /**
623  * gdk_pango_renderer_set_gc:
624  * @gdk_renderer: a #GdkPangoRenderer
625  * @gc: the new GC to use for drawing, or %NULL
626  * 
627  * Sets the GC the renderer draws with. Note that the GC must not be
628  * modified until it is unset by calling the function again with
629  * %NULL for the @gc parameter, since GDK may make internal copies
630  * of the GC which won't be updated to follow changes to the
631  * original GC.
632  *
633  * Since: 2.6
634  **/
635 void
636 gdk_pango_renderer_set_gc (GdkPangoRenderer *gdk_renderer,
637                            GdkGC            *gc)
638 {
639   GdkPangoRendererPrivate *priv;
640   
641   g_return_if_fail (GDK_IS_PANGO_RENDERER (gdk_renderer));
642   g_return_if_fail (gc == NULL || GDK_IS_GC (gc));
643
644   priv = gdk_renderer->priv;
645   
646   if (priv->base_gc != gc)
647     {
648       if (priv->base_gc)
649         g_object_unref (priv->base_gc);
650       priv->base_gc = gc;
651       if (priv->base_gc)
652         g_object_ref (priv->base_gc);
653     }
654 }
655
656
657 /**
658  * gdk_pango_renderer_set_stipple:
659  * @gdk_renderer: a #GdkPangoRenderer
660  * @part: the part to render with the stipple
661  * @stipple: the new stipple value.
662  * 
663  * Sets the stipple for one render part (foreground, background, underline,
664  * etc.) Note that this is overwritten when iterating through the individual
665  * styled runs of a #PangoLayout or #PangoLayoutLine. This function is thus
666  * only useful when you call low level functions like pango_renderer_draw_glyphs()
667  * directly, or in the 'prepare_run' virtual function of a subclass of
668  * #GdkPangoRenderer.
669  *
670  * Since: 2.6
671  **/
672 void
673 gdk_pango_renderer_set_stipple (GdkPangoRenderer *gdk_renderer,
674                                 PangoRenderPart   part,
675                                 GdkBitmap        *stipple)
676 {
677   g_return_if_fail (GDK_IS_PANGO_RENDERER (gdk_renderer));
678
679   if (part > MAX_RENDER_PART)   /* Silently ignore unknown parts */
680     return;
681
682   if (stipple != gdk_renderer->priv->stipple[part])
683     {
684       if (gdk_renderer->priv->stipple[part])
685         g_object_unref (gdk_renderer->priv->stipple[part]);
686
687       gdk_renderer->priv->stipple[part] = stipple;
688       
689       if (gdk_renderer->priv->stipple[part])
690         g_object_ref (gdk_renderer->priv->stipple[part]);
691
692       pango_renderer_part_changed (PANGO_RENDERER (gdk_renderer), part);
693     }
694 }
695
696 /**
697  * gdk_pango_renderer_set_override_color:
698  * @gdk_renderer: a #GdkPangoRenderer
699  * @part: the part to render to set the color of
700  * @color: the color to use, or %NULL to unset a previously
701  *         set override color.
702  * 
703  * Sets the color for a particular render part (foreground,
704  * background, underline, etc.), overriding any attributes on the layouts
705  * renderered with this renderer.
706  * 
707  * Since: 2.6
708  **/
709 void
710 gdk_pango_renderer_set_override_color (GdkPangoRenderer *gdk_renderer,
711                                        PangoRenderPart   part,
712                                        const GdkColor   *color)
713 {
714   GdkPangoRendererPrivate *priv;
715   
716   g_return_if_fail (GDK_IS_PANGO_RENDERER (gdk_renderer));
717
718   priv = gdk_renderer->priv;
719   
720   if (part > MAX_RENDER_PART)   /* Silently ignore unknown parts */
721     return;
722
723   if (color)
724     {
725       priv->override_color[part].red = color->red;
726       priv->override_color[part].green = color->green;
727       priv->override_color[part].blue = color->blue;
728       priv->override_color_set[part] = TRUE;
729     }
730   else
731     priv->override_color_set[part] = FALSE;
732 }
733
734 /**
735  * gdk_pango_context_set_colormap:
736  * @context: a #PangoContext
737  * @colormap: a #GdkColormap
738  *
739  * This function used to set the colormap to be used for drawing with
740  * @context. The colormap is now always derived from the graphics
741  * context used for drawing, so calling this function is no longer
742  * necessary.
743  **/
744 void
745 gdk_pango_context_set_colormap (PangoContext *context,
746                                 GdkColormap  *colormap)
747 {
748   g_return_if_fail (PANGO_IS_CONTEXT (context));
749   g_return_if_fail (colormap == NULL || GDK_IS_COLORMAP (colormap));
750 }
751
752 /* Gets a renderer to draw with, setting the properties of the
753  * renderer and activating it. Note that since we activate the
754  * renderer here, the implicit setting of the matrix that
755  * pango_renderer_draw_layout_[line] normally do when they
756  * activate the renderer is suppressed. */
757 static PangoRenderer *
758 get_renderer (GdkDrawable     *drawable,
759               GdkGC           *gc,
760               const GdkColor  *foreground,
761               const GdkColor  *background)
762 {
763   GdkScreen *screen = gdk_drawable_get_screen (drawable);
764   PangoRenderer *renderer = gdk_pango_renderer_get_default (screen);
765   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (renderer);
766
767   gdk_pango_renderer_set_drawable (gdk_renderer, drawable);
768   gdk_pango_renderer_set_gc (gdk_renderer, gc);  
769
770   gdk_pango_renderer_set_override_color (gdk_renderer,
771                                          PANGO_RENDER_PART_FOREGROUND,
772                                          foreground);
773   gdk_pango_renderer_set_override_color (gdk_renderer,
774                                          PANGO_RENDER_PART_UNDERLINE,
775                                          foreground);
776   gdk_pango_renderer_set_override_color (gdk_renderer,
777                                          PANGO_RENDER_PART_STRIKETHROUGH,
778                                          foreground);
779
780   gdk_pango_renderer_set_override_color (gdk_renderer,
781                                          PANGO_RENDER_PART_BACKGROUND,
782                                          background);
783
784   pango_renderer_activate (renderer);
785
786   return renderer;
787 }
788
789 /* Cleans up the renderer obtained with get_renderer() */
790 static void
791 release_renderer (PangoRenderer *renderer)
792 {
793   GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (renderer);
794   
795   pango_renderer_deactivate (renderer);
796   
797   gdk_pango_renderer_set_override_color (gdk_renderer,
798                                          PANGO_RENDER_PART_FOREGROUND,
799                                          NULL);
800   gdk_pango_renderer_set_override_color (gdk_renderer,
801                                          PANGO_RENDER_PART_UNDERLINE,
802                                          NULL);
803   gdk_pango_renderer_set_override_color (gdk_renderer,
804                                          PANGO_RENDER_PART_STRIKETHROUGH,
805                                          NULL);
806   gdk_pango_renderer_set_override_color (gdk_renderer,
807                                          PANGO_RENDER_PART_BACKGROUND,
808                                          NULL);
809   
810   gdk_pango_renderer_set_drawable (gdk_renderer, NULL);
811   gdk_pango_renderer_set_gc (gdk_renderer, NULL);
812 }
813
814 /**
815  * gdk_draw_layout_line_with_colors:
816  * @drawable:  the drawable on which to draw the line
817  * @gc:        base graphics to use
818  * @x:         the x position of start of string (in pixels)
819  * @y:         the y position of baseline (in pixels)
820  * @line:      a #PangoLayoutLine
821  * @foreground: foreground override color, or %NULL for none
822  * @background: background override color, or %NULL for none
823  *
824  * Render a #PangoLayoutLine onto a #GdkDrawable, overriding the
825  * layout's normal colors with @foreground and/or @background.
826  * @foreground and @background need not be allocated.
827  *
828  * If the layout's #PangoContext has a transformation matrix set, then
829  * @x and @y specify the position of the left edge of the baseline
830  * (left is in before-tranform user coordinates) in after-transform
831  * device coordinates.
832  */
833 void 
834 gdk_draw_layout_line_with_colors (GdkDrawable      *drawable,
835                                   GdkGC            *gc,
836                                   gint              x, 
837                                   gint              y,
838                                   PangoLayoutLine  *line,
839                                   const GdkColor   *foreground,
840                                   const GdkColor   *background)
841 {
842   PangoRenderer *renderer;
843   const PangoMatrix *matrix;
844   
845   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
846   g_return_if_fail (GDK_IS_GC (gc));
847   g_return_if_fail (line != NULL);
848
849   renderer = get_renderer (drawable, gc, foreground, background);
850
851   /* When we have a matrix, we do positioning by adjusting the matrix, and
852    * clamp just pass x=0, y=0 to the lower levels. We don't want to introduce
853    * a matrix when the caller didn't provide one, however, since that adds
854    * lots of floating point arithmetic for each glyph.
855    */
856   matrix = pango_context_get_matrix (pango_layout_get_context (line->layout));
857   if (matrix)
858     {
859       PangoMatrix tmp_matrix;
860       
861       tmp_matrix = *matrix;
862       tmp_matrix.x0 = x;
863       tmp_matrix.y0 = y;
864       pango_renderer_set_matrix (renderer, &tmp_matrix);
865
866       x = 0;
867       y = 0;
868     }
869   else
870     pango_renderer_set_matrix (renderer, NULL);
871
872   pango_renderer_draw_layout_line (renderer, line, x * PANGO_SCALE, y * PANGO_SCALE);
873
874   release_renderer (renderer);
875 }
876
877 /* Gets the bounds of a layout in device coordinates. Note cut-and-paste
878  * between here and gtklabel.c */
879 static void
880 get_rotated_layout_bounds (PangoLayout  *layout,
881                            GdkRectangle *rect)
882 {
883   PangoContext *context = pango_layout_get_context (layout);
884   const PangoMatrix *matrix = pango_context_get_matrix (context);
885   gdouble x_min = 0, x_max = 0, y_min = 0, y_max = 0; /* quiet gcc */
886   PangoRectangle logical_rect;
887   gint i, j;
888
889   pango_layout_get_extents (layout, NULL, &logical_rect);
890   
891   for (i = 0; i < 2; i++)
892     {
893       gdouble x = (i == 0) ? logical_rect.x : logical_rect.x + logical_rect.width;
894       for (j = 0; j < 2; j++)
895         {
896           gdouble y = (j == 0) ? logical_rect.y : logical_rect.y + logical_rect.height;
897           
898           gdouble xt = (x * matrix->xx + y * matrix->xy) / PANGO_SCALE + matrix->x0;
899           gdouble yt = (x * matrix->yx + y * matrix->yy) / PANGO_SCALE + matrix->y0;
900           
901           if (i == 0 && j == 0)
902             {
903               x_min = x_max = xt;
904               y_min = y_max = yt;
905             }
906           else
907             {
908               if (xt < x_min)
909                 x_min = xt;
910               if (yt < y_min)
911                 y_min = yt;
912               if (xt > x_max)
913                 x_max = xt;
914               if (yt > y_max)
915                 y_max = yt;
916             }
917         }
918     }
919   
920   rect->x = floor (x_min);
921   rect->width = ceil (x_max) - rect->x;
922   rect->y = floor (y_min);
923   rect->height = floor (y_max) - rect->y;
924 }
925
926 /**
927  * gdk_draw_layout_with_colors:
928  * @drawable:  the drawable on which to draw string
929  * @gc:        base graphics context to use
930  * @x:         the X position of the left of the layout (in pixels)
931  * @y:         the Y position of the top of the layout (in pixels)
932  * @layout:    a #PangoLayout
933  * @foreground: foreground override color, or %NULL for none
934  * @background: background override color, or %NULL for none
935  *
936  * Render a #PangoLayout onto a #GdkDrawable, overriding the
937  * layout's normal colors with @foreground and/or @background.
938  * @foreground and @background need not be allocated.
939  *
940  * If the layout's #PangoContext has a transformation matrix set, then
941  * @x and @y specify the position of the top left corner of the
942  * bounding box (in device space) of the transformed layout.
943  *
944  * If you're using GTK+, the ususal way to obtain a #PangoLayout
945  * is gtk_widget_create_pango_layout().
946  */
947 void 
948 gdk_draw_layout_with_colors (GdkDrawable     *drawable,
949                              GdkGC           *gc,
950                              int              x, 
951                              int              y,
952                              PangoLayout     *layout,
953                              const GdkColor  *foreground,
954                              const GdkColor  *background)
955 {
956   PangoRenderer *renderer;
957   const PangoMatrix *matrix;
958   
959   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
960   g_return_if_fail (GDK_IS_GC (gc));
961   g_return_if_fail (PANGO_IS_LAYOUT (layout));
962
963   renderer = get_renderer (drawable, gc, foreground, background);
964
965   /* When we have a matrix, we do positioning by adjusting the matrix, and
966    * clamp just pass x=0, y=0 to the lower levels. We don't want to introduce
967    * a matrix when the caller didn't provide one, however, since that adds
968    * lots of floating point arithmetic for each glyph.
969    */
970   matrix = pango_context_get_matrix (pango_layout_get_context (layout));
971   if (matrix)
972     {
973       PangoMatrix tmp_matrix;
974       GdkRectangle rect;
975
976       get_rotated_layout_bounds (layout, &rect);
977       
978       tmp_matrix = *matrix;
979       tmp_matrix.x0 += x - rect.x;
980       tmp_matrix.y0 += y - rect.y;
981       pango_renderer_set_matrix (renderer, &tmp_matrix);
982       
983       x = 0;
984       y = 0;
985     }
986   else
987     pango_renderer_set_matrix (renderer, NULL);
988
989   pango_renderer_draw_layout (renderer, layout, x * PANGO_SCALE, y * PANGO_SCALE);
990   
991   release_renderer (renderer);
992 }
993
994 /**
995  * gdk_draw_layout_line:
996  * @drawable:  the drawable on which to draw the line
997  * @gc:        base graphics to use
998  * @x:         the x position of start of string (in pixels)
999  * @y:         the y position of baseline (in pixels)
1000  * @line:      a #PangoLayoutLine
1001  *
1002  * Render a #PangoLayoutLine onto an GDK drawable
1003  *
1004  * If the layout's #PangoContext has a transformation matrix set, then
1005  * @x and @y specify the position of the left edge of the baseline
1006  * (left is in before-tranform user coordinates) in after-transform
1007  * device coordinates.
1008  */
1009 void 
1010 gdk_draw_layout_line (GdkDrawable      *drawable,
1011                       GdkGC            *gc,
1012                       gint              x, 
1013                       gint              y,
1014                       PangoLayoutLine  *line)
1015 {
1016   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
1017   g_return_if_fail (GDK_IS_GC (gc));
1018   g_return_if_fail (line != NULL);
1019   
1020   gdk_draw_layout_line_with_colors (drawable, gc, x, y, line, NULL, NULL);
1021 }
1022
1023 /**
1024  * gdk_draw_layout:
1025  * @drawable:  the drawable on which to draw string
1026  * @gc:        base graphics context to use
1027  * @x:         the X position of the left of the layout (in pixels)
1028  * @y:         the Y position of the top of the layout (in pixels)
1029  * @layout:    a #PangoLayout
1030  *
1031  * Render a #PangoLayout onto a GDK drawable
1032  *
1033  * If the layout's #PangoContext has a transformation matrix set, then
1034  * @x and @y specify the position of the top left corner of the
1035  * bounding box (in device space) of the transformed layout.
1036  *
1037  * If you're using GTK+, the usual way to obtain a #PangoLayout
1038  * is gtk_widget_create_pango_layout().
1039  */
1040 void 
1041 gdk_draw_layout (GdkDrawable     *drawable,
1042                  GdkGC           *gc,
1043                  int              x, 
1044                  int              y,
1045                  PangoLayout     *layout)
1046 {
1047   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
1048   g_return_if_fail (GDK_IS_GC (gc));
1049   g_return_if_fail (PANGO_IS_LAYOUT (layout));
1050
1051   gdk_draw_layout_with_colors (drawable, gc, x, y, layout, NULL, NULL);
1052 }
1053
1054 static PangoAttribute *
1055 gdk_pango_attr_stipple_copy (const PangoAttribute *attr)
1056 {
1057   const GdkPangoAttrStipple *src = (const GdkPangoAttrStipple*) attr;
1058
1059   return gdk_pango_attr_stipple_new (src->stipple);
1060 }
1061
1062 static void
1063 gdk_pango_attr_stipple_destroy (PangoAttribute *attr)
1064 {
1065   GdkPangoAttrStipple *st = (GdkPangoAttrStipple*) attr;
1066
1067   if (st->stipple)
1068     g_object_unref (st->stipple);
1069   
1070   g_free (attr);
1071 }
1072
1073 static gboolean
1074 gdk_pango_attr_stipple_compare (const PangoAttribute *attr1,
1075                                     const PangoAttribute *attr2)
1076 {
1077   const GdkPangoAttrStipple *a = (const GdkPangoAttrStipple*) attr1;
1078   const GdkPangoAttrStipple *b = (const GdkPangoAttrStipple*) attr2;
1079
1080   return a->stipple == b->stipple;
1081 }
1082
1083 /**
1084  * gdk_pango_attr_stipple_new:
1085  * @stipple: a bitmap to be set as stipple
1086  *
1087  * Creates a new attribute containing a stipple bitmap to be used when
1088  * rendering the text.
1089  *
1090  * Return value: new #PangoAttribute
1091  **/
1092
1093 PangoAttribute *
1094 gdk_pango_attr_stipple_new (GdkBitmap *stipple)
1095 {
1096   GdkPangoAttrStipple *result;
1097   
1098   static PangoAttrClass klass = {
1099     0,
1100     gdk_pango_attr_stipple_copy,
1101     gdk_pango_attr_stipple_destroy,
1102     gdk_pango_attr_stipple_compare
1103   };
1104
1105   if (!klass.type)
1106     klass.type = gdk_pango_attr_stipple_type =
1107       pango_attr_type_register ("GdkPangoAttrStipple");
1108
1109   result = g_new (GdkPangoAttrStipple, 1);
1110   result->attr.klass = &klass;
1111
1112   if (stipple)
1113     g_object_ref (stipple);
1114   
1115   result->stipple = stipple;
1116
1117   return (PangoAttribute *)result;
1118 }
1119
1120 static PangoAttribute *
1121 gdk_pango_attr_embossed_copy (const PangoAttribute *attr)
1122 {
1123   const GdkPangoAttrEmbossed *e = (const GdkPangoAttrEmbossed*) attr;
1124
1125   return gdk_pango_attr_embossed_new (e->embossed);
1126 }
1127
1128 static void
1129 gdk_pango_attr_embossed_destroy (PangoAttribute *attr)
1130 {
1131   g_free (attr);
1132 }
1133
1134 static gboolean
1135 gdk_pango_attr_embossed_compare (const PangoAttribute *attr1,
1136                                  const PangoAttribute *attr2)
1137 {
1138   const GdkPangoAttrEmbossed *e1 = (const GdkPangoAttrEmbossed*) attr1;
1139   const GdkPangoAttrEmbossed *e2 = (const GdkPangoAttrEmbossed*) attr2;
1140
1141   return e1->embossed == e2->embossed;
1142 }
1143
1144 /**
1145  * gdk_pango_attr_embossed_new:
1146  * @embossed: a bitmap to be set as embossed
1147  *
1148  * Creates a new attribute containing a embossed bitmap to be used when
1149  * rendering the text.
1150  *
1151  * Return value: new #PangoAttribute
1152  **/
1153
1154 PangoAttribute *
1155 gdk_pango_attr_embossed_new (gboolean embossed)
1156 {
1157   GdkPangoAttrEmbossed *result;
1158   
1159   static PangoAttrClass klass = {
1160     0,
1161     gdk_pango_attr_embossed_copy,
1162     gdk_pango_attr_embossed_destroy,
1163     gdk_pango_attr_embossed_compare
1164   };
1165
1166   if (!klass.type)
1167     klass.type = gdk_pango_attr_embossed_type =
1168       pango_attr_type_register ("GdkPangoAttrEmbossed");
1169
1170   result = g_new (GdkPangoAttrEmbossed, 1);
1171   result->attr.klass = &klass;
1172   result->embossed = embossed;
1173   
1174   return (PangoAttribute *)result;
1175 }
1176
1177 /* Get a clip region to draw only part of a layout. index_ranges
1178  * contains alternating range starts/stops. The region is the
1179  * region which contains the given ranges, i.e. if you draw with the
1180  * region as clip, only the given ranges are drawn.
1181  */
1182
1183 /**
1184  * gdk_pango_layout_line_get_clip_region:
1185  * @line: a #PangoLayoutLine 
1186  * @x_origin: X pixel where you intend to draw the layout line with this clip
1187  * @y_origin: baseline pixel where you intend to draw the layout line with this clip
1188  * @index_ranges: array of byte indexes into the layout, where even members of array are start indexes and odd elements are end indexes
1189  * @n_ranges: number of ranges in @index_ranges, i.e. half the size of @index_ranges
1190  * 
1191  * Obtains a clip region which contains the areas where the given
1192  * ranges of text would be drawn. @x_origin and @y_origin are the same
1193  * position you would pass to gdk_draw_layout_line(). @index_ranges
1194  * should contain ranges of bytes in the layout's text. The clip
1195  * region will include space to the left or right of the line (to the
1196  * layout bounding box) if you have indexes above or below the indexes
1197  * contained inside the line. This is to draw the selection all the way
1198  * to the side of the layout. However, the clip region is in line coordinates,
1199  * not layout coordinates.
1200  * 
1201  * Return value: a clip region containing the given ranges
1202  **/
1203 GdkRegion*
1204 gdk_pango_layout_line_get_clip_region (PangoLayoutLine *line,
1205                                        gint             x_origin,
1206                                        gint             y_origin,
1207                                        gint            *index_ranges,
1208                                        gint             n_ranges)
1209 {
1210   GdkRegion *clip_region;
1211   gint i;
1212   PangoRectangle logical_rect;
1213   PangoLayoutIter *iter;
1214   gint baseline;
1215   
1216   g_return_val_if_fail (line != NULL, NULL);
1217   g_return_val_if_fail (index_ranges != NULL, NULL);
1218   
1219   clip_region = gdk_region_new ();
1220
1221   iter = pango_layout_get_iter (line->layout);
1222   while (pango_layout_iter_get_line (iter) != line)
1223     pango_layout_iter_next_line (iter);
1224   
1225   pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
1226   baseline = pango_layout_iter_get_baseline (iter);
1227   
1228   pango_layout_iter_free (iter);
1229   
1230   i = 0;
1231   while (i < n_ranges)
1232     {  
1233       gint *pixel_ranges = NULL;
1234       gint n_pixel_ranges = 0;
1235       gint j;
1236
1237       /* Note that get_x_ranges returns layout coordinates
1238        */
1239       if (index_ranges[i*2+1] >= line->start_index &&
1240           index_ranges[i*2] < line->start_index + line->length)
1241         pango_layout_line_get_x_ranges (line,
1242                                         index_ranges[i*2],
1243                                         index_ranges[i*2+1],
1244                                         &pixel_ranges, &n_pixel_ranges);
1245   
1246       for (j = 0; j < n_pixel_ranges; j++)
1247         {
1248           GdkRectangle rect;
1249           
1250           rect.x = x_origin + pixel_ranges[2*j] / PANGO_SCALE - logical_rect.x / PANGO_SCALE;
1251           rect.y = y_origin - (baseline / PANGO_SCALE - logical_rect.y / PANGO_SCALE);
1252           rect.width = (pixel_ranges[2*j + 1] - pixel_ranges[2*j]) / PANGO_SCALE;
1253           rect.height = logical_rect.height / PANGO_SCALE;
1254           
1255           gdk_region_union_with_rect (clip_region, &rect);
1256         }
1257
1258       g_free (pixel_ranges);
1259       ++i;
1260     }
1261
1262   return clip_region;
1263 }
1264
1265 /**
1266  * gdk_pango_layout_get_clip_region:
1267  * @layout: a #PangoLayout 
1268  * @x_origin: X pixel where you intend to draw the layout with this clip
1269  * @y_origin: Y pixel where you intend to draw the layout with this clip
1270  * @index_ranges: array of byte indexes into the layout, where even members of array are start indexes and odd elements are end indexes
1271  * @n_ranges: number of ranges in @index_ranges, i.e. half the size of @index_ranges
1272  * 
1273  * Obtains a clip region which contains the areas where the given ranges
1274  * of text would be drawn. @x_origin and @y_origin are the same position
1275  * you would pass to gdk_draw_layout_line(). @index_ranges should contain
1276  * ranges of bytes in the layout's text.
1277  * 
1278  * Return value: a clip region containing the given ranges
1279  **/
1280 GdkRegion*
1281 gdk_pango_layout_get_clip_region (PangoLayout *layout,
1282                                   gint         x_origin,
1283                                   gint         y_origin,
1284                                   gint        *index_ranges,
1285                                   gint         n_ranges)
1286 {
1287   PangoLayoutIter *iter;  
1288   GdkRegion *clip_region;
1289   
1290   g_return_val_if_fail (PANGO_IS_LAYOUT (layout), NULL);
1291   g_return_val_if_fail (index_ranges != NULL, NULL);
1292   
1293   clip_region = gdk_region_new ();
1294   
1295   iter = pango_layout_get_iter (layout);
1296   
1297   do
1298     {
1299       PangoRectangle logical_rect;
1300       PangoLayoutLine *line;
1301       GdkRegion *line_region;
1302       gint baseline;
1303       
1304       line = pango_layout_iter_get_line (iter);      
1305
1306       pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
1307       baseline = pango_layout_iter_get_baseline (iter);      
1308
1309       line_region = gdk_pango_layout_line_get_clip_region (line,
1310                                                            x_origin + logical_rect.x / PANGO_SCALE,
1311                                                            y_origin + baseline / PANGO_SCALE,
1312                                                            index_ranges,
1313                                                            n_ranges);
1314
1315       gdk_region_union (clip_region, line_region);
1316       gdk_region_destroy (line_region);
1317     }
1318   while (pango_layout_iter_next_line (iter));
1319
1320   pango_layout_iter_free (iter);
1321
1322   return clip_region;
1323 }
1324
1325 /**
1326  * gdk_pango_context_get:
1327  * 
1328  * Creates a #PangoContext for the default GDK screen.
1329  *
1330  * The context must be freed when you're finished with it.
1331  * 
1332  * When using GTK+, normally you should use gtk_widget_get_pango_context()
1333  * instead of this function, to get the appropriate context for
1334  * the widget you intend to render text onto.
1335  * 
1336  * Return value: a new #PangoContext for the default display
1337  **/
1338 PangoContext *
1339 gdk_pango_context_get (void)
1340 {
1341   return gdk_pango_context_get_for_screen (gdk_screen_get_default ());
1342 }
1343
1344 /**
1345  * gdk_pango_context_get_for_screen:
1346  * @screen: the #GdkScreen for which the context is to be created.
1347  * 
1348  * Creates a #PangoContext for @screen.
1349  *
1350  * The context must be freed when you're finished with it.
1351  * 
1352  * When using GTK+, normally you should use gtk_widget_get_pango_context()
1353  * instead of this function, to get the appropriate context for
1354  * the widget you intend to render text onto.
1355  * 
1356  * Return value: a new #PangoContext for @screen
1357  *
1358  * Since: 2.2
1359  **/
1360 PangoContext *
1361 gdk_pango_context_get_for_screen (GdkScreen *screen)
1362 {
1363   PangoFontMap *fontmap;
1364   
1365   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1366
1367   fontmap = pango_cairo_font_map_get_default ();
1368   
1369   return pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap));
1370 }
1371
1372 #define __GDK_PANGO_C__
1373 #include "gdkaliasdef.c"