2 * pangoxft-render.c: Rendering routines for the Xft library
4 * Copyright (C) 2004 Red Hat Software
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
25 #include "pangoxft-render.h"
26 #include "pangoxft-private.h"
34 struct _PangoXftRendererPrivate
36 PangoColor default_color;
42 XRenderPictFormat *mask_format;
45 PangoRenderPart trapezoid_part;
48 PangoFont *glyph_font;
51 static void pango_xft_renderer_finalize (GObject *object);
52 static void pango_xft_renderer_set_property (GObject *object,
57 static void pango_xft_renderer_real_composite_trapezoids (PangoXftRenderer *xftrenderer,
59 XTrapezoid *trapezoids,
61 static void pango_xft_renderer_real_composite_glyphs (PangoXftRenderer *xftrenderer,
66 static void pango_xft_renderer_draw_glyphs (PangoRenderer *renderer,
68 PangoGlyphString *glyphs,
71 static void pango_xft_renderer_draw_trapezoid (PangoRenderer *renderer,
79 static void pango_xft_renderer_part_changed (PangoRenderer *renderer,
80 PangoRenderPart part);
81 static void pango_xft_renderer_end (PangoRenderer *renderer);
83 static void flush_trapezoids (PangoXftRenderer *xftrenderer);
84 static void flush_glyphs (PangoXftRenderer *xftrenderer);
86 G_DEFINE_TYPE (PangoXftRenderer, pango_xft_renderer, PANGO_TYPE_RENDERER)
89 pango_xft_renderer_init (PangoXftRenderer *xftrenderer)
91 xftrenderer->priv = G_TYPE_INSTANCE_GET_PRIVATE (xftrenderer,
92 PANGO_TYPE_XFT_RENDERER,
93 PangoXftRendererPrivate);
94 xftrenderer->priv->alpha = 0xffff;
98 pango_xft_renderer_class_init (PangoXftRendererClass *klass)
100 GObjectClass *object_class = G_OBJECT_CLASS (klass);
101 PangoRendererClass *renderer_class = PANGO_RENDERER_CLASS (klass);
103 klass->composite_glyphs = pango_xft_renderer_real_composite_glyphs;
104 klass->composite_trapezoids = pango_xft_renderer_real_composite_trapezoids;
106 renderer_class->draw_glyphs = pango_xft_renderer_draw_glyphs;
107 renderer_class->draw_trapezoid = pango_xft_renderer_draw_trapezoid;
108 renderer_class->part_changed = pango_xft_renderer_part_changed;
109 renderer_class->end = pango_xft_renderer_end;
111 object_class->finalize = pango_xft_renderer_finalize;
112 object_class->set_property = pango_xft_renderer_set_property;
114 g_object_class_install_property (object_class, PROP_DISPLAY,
115 g_param_spec_pointer ("display",
117 "The display being rendered to",
118 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
119 g_object_class_install_property (object_class, PROP_SCREEN,
120 g_param_spec_int ("screen",
122 "The screen being rendered to",
124 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
126 g_type_class_add_private (object_class, sizeof (PangoXftRendererPrivate));
130 pango_xft_renderer_finalize (GObject *object)
132 PangoXftRenderer *renderer = PANGO_XFT_RENDERER (object);
134 if (renderer->priv->glyphs)
135 g_array_free (renderer->priv->glyphs, TRUE);
136 if (renderer->priv->trapezoids)
137 g_array_free (renderer->priv->trapezoids, TRUE);
139 G_OBJECT_CLASS (pango_xft_renderer_parent_class)->finalize (object);
143 pango_xft_renderer_set_property (GObject *object,
148 PangoXftRenderer *xftrenderer = PANGO_XFT_RENDERER (object);
153 xftrenderer->display = g_value_get_pointer (value);
154 /* We possibly should use ARGB format when subpixel-AA is turned
155 * on for the fontmap; we could discover that using the technique
156 * for FC_DPI in pango_fc_face_list_sizes.
158 xftrenderer->priv->mask_format = XRenderFindStandardFormat (xftrenderer->display,
162 xftrenderer->screen = g_value_get_int (value);
165 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
171 pango_xft_renderer_set_pictures (PangoXftRenderer *renderer,
173 Picture dest_picture)
175 renderer->priv->src_picture = src_picture;
176 renderer->priv->dest_picture = dest_picture;
180 flush_glyphs (PangoXftRenderer *xftrenderer)
184 if (!xftrenderer->priv->glyphs ||
185 xftrenderer->priv->glyphs->len == 0)
188 xft_font = pango_xft_font_get_font (xftrenderer->priv->glyph_font);
190 PANGO_XFT_RENDERER_GET_CLASS (xftrenderer)->composite_glyphs (xftrenderer,
192 (XftGlyphSpec *)xftrenderer->priv->glyphs->data,
193 xftrenderer->priv->glyphs->len);
195 g_array_set_size (xftrenderer->priv->glyphs, 0);
196 g_object_unref (xftrenderer->priv->glyph_font);
197 xftrenderer->priv->glyph_font = NULL;
200 #define MAX_GLYPHS 1024
203 draw_glyph (PangoRenderer *renderer,
209 PangoXftRenderer *xftrenderer = PANGO_XFT_RENDERER (renderer);
211 int pixel_x, pixel_y;
213 if (renderer->matrix)
215 pixel_x = floor (0.5 + (x * renderer->matrix->xx + y * renderer->matrix->xy) / PANGO_SCALE + renderer->matrix->x0);
216 pixel_y = floor (0.5 + (x * renderer->matrix->yx + y * renderer->matrix->yy) / PANGO_SCALE + renderer->matrix->y0);
220 pixel_x = PANGO_PIXELS (x);
221 pixel_y = PANGO_PIXELS (y);
224 /* Clip glyphs into the X coordinate range; we really
225 * want to clip glyphs with an ink rect outside the
226 * [0,32767] x [0,32767] rectangle but looking up
227 * the ink rect here would be a noticeable speed hit.
228 * This is close enough.
230 if (pixel_x < -32768 || pixel_x > 32767 ||
231 pixel_y < -32768 || pixel_y > 32767)
234 flush_trapezoids (xftrenderer);
236 if (!xftrenderer->priv->glyphs)
237 xftrenderer->priv->glyphs = g_array_new (FALSE, FALSE,
238 sizeof (XftGlyphSpec));
240 if (xftrenderer->priv->glyph_font != font ||
241 xftrenderer->priv->glyphs->len == MAX_GLYPHS)
243 flush_glyphs (xftrenderer);
245 xftrenderer->priv->glyph_font = g_object_ref (font);
252 g_array_append_val (xftrenderer->priv->glyphs, gs);
256 point_in_bounds (PangoRenderer *renderer,
260 gdouble pixel_x = (x * renderer->matrix->xx + y * renderer->matrix->xy) / PANGO_SCALE + renderer->matrix->x0;
261 gdouble pixel_y = (x * renderer->matrix->yx + y * renderer->matrix->yy) / PANGO_SCALE + renderer->matrix->y0;
263 return (pixel_x >= -32768. && pixel_x < 32768. &&
264 pixel_y >= -32768. && pixel_y < 32768.);
268 box_in_bounds (PangoRenderer *renderer,
274 if (!renderer->matrix)
276 #define COORD_MIN (PANGO_SCALE * -16384 - PANGO_SCALE / 2)
277 #define COORD_MAX (PANGO_SCALE * 32767 + PANGO_SCALE / 2 - 1)
278 return (x >= COORD_MIN && x + width <= COORD_MAX &&
279 y >= COORD_MIN && y + width <= COORD_MAX);
285 return (point_in_bounds (renderer, x, y) &&
286 point_in_bounds (renderer, x + width, y) &&
287 point_in_bounds (renderer, x + width, y + height) &&
288 point_in_bounds (renderer, x, y + height));
293 get_total_matrix (PangoMatrix *total,
294 const PangoMatrix *global,
300 PangoMatrix local = PANGO_MATRIX_INIT;
301 gdouble angle = atan2 (height, width);
303 pango_matrix_translate (&local, x, y);
304 pango_matrix_rotate (&local, -angle * (180. / G_PI));
307 pango_matrix_concat (total, &local);
311 draw_box (PangoRenderer *renderer,
319 pango_renderer_draw_rectangle (renderer, PANGO_RENDER_PART_FOREGROUND,
320 x, y, width, line_width);
321 pango_renderer_draw_rectangle (renderer, PANGO_RENDER_PART_FOREGROUND,
322 x, y + line_width, line_width, height - line_width * 2);
323 pango_renderer_draw_rectangle (renderer, PANGO_RENDER_PART_FOREGROUND,
324 x + width - line_width, y + line_width, line_width, height - line_width * 2);
325 pango_renderer_draw_rectangle (renderer, PANGO_RENDER_PART_FOREGROUND,
326 x, y + height - line_width, width, line_width);
331 double in_width, in_height;
332 PangoMatrix orig_matrix = PANGO_MATRIX_INIT, new_matrix;
333 const PangoMatrix *porig_matrix;
335 in_width = pango_units_to_double (width - 2 * line_width);
336 in_height = pango_units_to_double (height - 2 * line_width);
337 length = PANGO_SCALE * sqrt (in_width*in_width + in_height*in_height);
339 porig_matrix = pango_renderer_get_matrix (renderer);
342 orig_matrix = *porig_matrix;
343 porig_matrix = &orig_matrix;
346 get_total_matrix (&new_matrix, &orig_matrix,
347 pango_units_to_double (x + line_width), pango_units_to_double (y + line_width),
348 in_width, in_height);
349 pango_renderer_set_matrix (renderer, &new_matrix);
350 pango_renderer_draw_rectangle (renderer, PANGO_RENDER_PART_FOREGROUND,
351 0, -line_width / 2, length, line_width);
353 get_total_matrix (&new_matrix, &orig_matrix,
354 pango_units_to_double (x + line_width), pango_units_to_double (y + height - line_width),
355 in_width, -in_height);
356 pango_renderer_set_matrix (renderer, &new_matrix);
357 pango_renderer_draw_rectangle (renderer, PANGO_RENDER_PART_FOREGROUND,
358 0, -line_width / 2, length, line_width);
360 pango_renderer_set_matrix (renderer, porig_matrix);
365 _pango_xft_renderer_draw_box_glyph (PangoRenderer *renderer,
371 int x = glyph_x + PANGO_SCALE;
372 int y = glyph_y - PANGO_SCALE * (PANGO_UNKNOWN_GLYPH_HEIGHT - 1);
373 int width = gi->geometry.width - PANGO_SCALE * 2;
374 int height = PANGO_SCALE * (PANGO_UNKNOWN_GLYPH_HEIGHT - 2);
376 if (box_in_bounds (renderer, x, y, width, height))
377 draw_box (renderer, PANGO_SCALE, x, y, width, height, invalid);
381 _pango_xft_renderer_draw_unknown_glyph (PangoRenderer *renderer,
394 gboolean invalid_input;
396 PangoFont *mini_font;
397 XftFont *mini_xft_font;
399 ch = gi->glyph & ~PANGO_GLYPH_UNKNOWN_FLAG;
400 if (G_UNLIKELY (gi->glyph == PANGO_GLYPH_INVALID_INPUT || ch > 0x10FFFF))
402 invalid_input = TRUE;
407 invalid_input = FALSE;
408 cols = ch > 0xffff ? 3 : 2;
409 g_snprintf (buf, sizeof(buf), (ch > 0xffff) ? "%06X" : "%04X", ch);
412 mini_font = _pango_xft_font_get_mini_font (xfont);
413 mini_xft_font = pango_xft_font_get_font (mini_font);
416 _pango_xft_renderer_draw_box_glyph (renderer, gi, glyph_x, glyph_y, invalid_input);
421 ys[0] = glyph_y - PANGO_SCALE * xft_font->ascent + PANGO_SCALE * (((xft_font->ascent + xft_font->descent) - (xfont->mini_height * 2 + xfont->mini_pad * 5 + PANGO_SCALE / 2) / PANGO_SCALE) / 2);
422 ys[1] = ys[0] + 2 * xfont->mini_pad + xfont->mini_height;
423 ys[2] = ys[1] + xfont->mini_height + xfont->mini_pad;
426 xs[1] = xs[0] + 2 * xfont->mini_pad;
427 xs[2] = xs[1] + xfont->mini_width + xfont->mini_pad;
428 xs[3] = xs[2] + xfont->mini_width + xfont->mini_pad;
430 if (box_in_bounds (renderer,
432 xfont->mini_width * cols + xfont->mini_pad * (2 * cols + 1),
433 xfont->mini_height * 2 + xfont->mini_pad * 5))
436 draw_box (renderer, xfont->mini_pad,
438 xfont->mini_width * cols + xfont->mini_pad * (2 * cols + 1),
439 xfont->mini_height * 2 + xfont->mini_pad * 5,
445 for (row = 0; row < 2; row++)
446 for (col = 0; col < cols; col++)
448 draw_glyph (renderer, mini_font,
449 XftCharIndex (NULL, mini_xft_font,
450 buf[row * cols + col] & 0xff),
458 pango_xft_renderer_draw_glyphs (PangoRenderer *renderer,
460 PangoGlyphString *glyphs,
464 PangoXftFont *xfont = PANGO_XFT_FONT (font);
465 PangoFcFont *fcfont = PANGO_FC_FONT (font);
466 XftFont *xft_font = pango_xft_font_get_font (font);
472 for (i=0; i<glyphs->num_glyphs; i++)
474 PangoGlyphInfo *gi = &glyphs->glyphs[i];
476 if (gi->glyph != PANGO_GLYPH_EMPTY)
478 int glyph_x = x + x_off + gi->geometry.x_offset;
479 int glyph_y = y + gi->geometry.y_offset;
481 _pango_xft_renderer_draw_unknown_glyph (renderer,
489 x_off += gi->geometry.width;
494 if (!fcfont->fontmap) /* Display closed */
497 for (i=0; i<glyphs->num_glyphs; i++)
499 PangoGlyphInfo *gi = &glyphs->glyphs[i];
501 if (gi->glyph != PANGO_GLYPH_EMPTY)
503 int glyph_x = x + x_off + gi->geometry.x_offset;
504 int glyph_y = y + gi->geometry.y_offset;
506 if (gi->glyph & PANGO_GLYPH_UNKNOWN_FLAG)
508 _pango_xft_renderer_draw_unknown_glyph (renderer,
517 draw_glyph (renderer, font, gi->glyph, glyph_x, glyph_y);
521 x_off += gi->geometry.width;
526 flush_trapezoids (PangoXftRenderer *xftrenderer)
528 if (!xftrenderer->priv->trapezoids ||
529 xftrenderer->priv->trapezoids->len == 0)
532 PANGO_XFT_RENDERER_GET_CLASS (xftrenderer)->composite_trapezoids (xftrenderer,
533 xftrenderer->priv->trapezoid_part,
534 (XTrapezoid *)xftrenderer->priv->trapezoids->data,
535 xftrenderer->priv->trapezoids->len);
537 g_array_set_size (xftrenderer->priv->trapezoids, 0);
541 pango_xft_renderer_draw_trapezoid (PangoRenderer *renderer,
542 PangoRenderPart part,
550 PangoXftRenderer *xftrenderer = PANGO_XFT_RENDERER (renderer);
553 flush_glyphs (xftrenderer);
555 if (!xftrenderer->priv->trapezoids)
556 xftrenderer->priv->trapezoids = g_array_new (FALSE, FALSE,
557 sizeof (XTrapezoid));
559 if (xftrenderer->draw)
561 if (xftrenderer->priv->trapezoids->len > 0 &&
562 xftrenderer->priv->trapezoid_part != part)
563 flush_trapezoids (xftrenderer);
565 xftrenderer->priv->trapezoid_part = part;
568 trap.top = XDoubleToFixed (y1);
569 trap.bottom = XDoubleToFixed (y2);
570 trap.left.p1.x = XDoubleToFixed (x11);
571 trap.left.p1.y = XDoubleToFixed (y1);
572 trap.left.p2.x = XDoubleToFixed (x12);
573 trap.left.p2.y = XDoubleToFixed (y2);
574 trap.right.p1.x = XDoubleToFixed (x21);
575 trap.right.p1.y = XDoubleToFixed (y1);
576 trap.right.p2.x = XDoubleToFixed (x22);
577 trap.right.p2.y = XDoubleToFixed (y2);
579 g_array_append_val (xftrenderer->priv->trapezoids, trap);
583 pango_xft_renderer_part_changed (PangoRenderer *renderer,
584 PangoRenderPart part)
586 PangoXftRenderer *xftrenderer = PANGO_XFT_RENDERER (renderer);
588 if (part == PANGO_RENDER_PART_FOREGROUND)
589 flush_glyphs (xftrenderer);
591 if (part == xftrenderer->priv->trapezoid_part)
592 flush_trapezoids (xftrenderer);
596 pango_xft_renderer_end (PangoRenderer *renderer)
598 PangoXftRenderer *xftrenderer = PANGO_XFT_RENDERER (renderer);
600 flush_glyphs (xftrenderer);
601 flush_trapezoids (xftrenderer);
605 pango_xft_renderer_real_composite_trapezoids (PangoXftRenderer *xftrenderer,
606 PangoRenderPart part,
607 XTrapezoid *trapezoids,
611 Picture dest_picture;
613 if (!XftDefaultHasRender (xftrenderer->display))
616 if (xftrenderer->priv->src_picture != None)
618 src_picture = xftrenderer->priv->src_picture;
619 dest_picture = xftrenderer->priv->dest_picture;
624 PangoColor *color = pango_renderer_get_color (PANGO_RENDERER (xftrenderer),
627 color = &xftrenderer->priv->default_color;
629 xft_color.color.red = color->red;
630 xft_color.color.green = color->green;
631 xft_color.color.blue = color->blue;
632 xft_color.color.alpha = xftrenderer->priv->alpha;
634 src_picture = XftDrawSrcPicture (xftrenderer->draw, &xft_color);
635 dest_picture = XftDrawPicture (xftrenderer->draw);
638 XRenderCompositeTrapezoids (xftrenderer->display,
640 src_picture, dest_picture,
641 xftrenderer->priv->mask_format,
643 trapezoids, n_trapezoids);
647 pango_xft_renderer_real_composite_glyphs (PangoXftRenderer *xftrenderer,
649 XftGlyphSpec *glyphs,
652 if (xftrenderer->priv->src_picture != None)
654 XftGlyphSpecRender (xftrenderer->display, PictOpOver,
655 xftrenderer->priv->src_picture,
657 xftrenderer->priv->dest_picture, 0, 0,
663 PangoColor *color = pango_renderer_get_color (PANGO_RENDERER (xftrenderer),
664 PANGO_RENDER_PART_FOREGROUND);
666 color = &xftrenderer->priv->default_color;
668 xft_color.color.red = color->red;
669 xft_color.color.green = color->green;
670 xft_color.color.blue = color->blue;
671 xft_color.color.alpha = xftrenderer->priv->alpha;
673 XftDrawGlyphSpec (xftrenderer->draw, &xft_color,
679 static PangoRenderer *
680 get_renderer (PangoFontMap *fontmap,
684 PangoRenderer *renderer;
685 PangoXftRenderer *xftrenderer;
686 PangoColor pango_color;
688 renderer = _pango_xft_font_map_get_renderer (PANGO_XFT_FONT_MAP (fontmap));
689 xftrenderer = PANGO_XFT_RENDERER (renderer);
691 pango_xft_renderer_set_draw (xftrenderer, draw);
693 pango_color.red = color->color.red;
694 pango_color.green = color->color.green;
695 pango_color.blue = color->color.blue;
696 pango_xft_renderer_set_default_color (xftrenderer, &pango_color);
697 xftrenderer->priv->alpha = color->color.alpha;
703 release_renderer (PangoRenderer *renderer)
705 PangoXftRenderer *xftrenderer = PANGO_XFT_RENDERER (renderer);
707 xftrenderer->priv->alpha = 0xffff;
711 * pango_xft_render_layout:
713 * @color: the foreground color in which to draw the layout
714 * (may be overridden by color attributes)
715 * @layout: a #PangoLayout
716 * @x: the X position of the left of the layout (in Pango units)
717 * @y: the Y position of the top of the layout (in Pango units)
719 * Render a #PangoLayout onto a #XftDraw
724 pango_xft_render_layout (XftDraw *draw,
730 PangoContext *context;
731 PangoFontMap *fontmap;
732 PangoRenderer *renderer;
734 g_return_if_fail (draw != NULL);
735 g_return_if_fail (color != NULL);
736 g_return_if_fail (PANGO_IS_LAYOUT (layout));
738 context = pango_layout_get_context (layout);
739 fontmap = pango_context_get_font_map (context);
740 renderer = get_renderer (fontmap, draw, color);
742 pango_renderer_draw_layout (renderer, layout, x, y);
744 release_renderer (renderer);
748 * pango_xft_render_layout_line:
750 * @color: the foreground color in which to draw the layout line
751 * (may be overridden by color attributes)
752 * @line: a #PangoLayoutLine
753 * @x: the x position of start of string (in Pango units)
754 * @y: the y position of baseline (in Pango units)
756 * Render a #PangoLayoutLine onto a #XftDraw
761 pango_xft_render_layout_line (XftDraw *draw,
763 PangoLayoutLine *line,
767 PangoContext *context;
768 PangoFontMap *fontmap;
769 PangoRenderer *renderer;
771 g_return_if_fail (draw != NULL);
772 g_return_if_fail (color != NULL);
773 g_return_if_fail (line != NULL);
775 context = pango_layout_get_context (line->layout);
776 fontmap = pango_context_get_font_map (context);
777 renderer = get_renderer (fontmap, draw, color);
779 pango_renderer_draw_layout_line (renderer, line, x, y);
781 release_renderer (renderer);
785 * pango_xft_render_transformed:
787 * @color: the color in which to draw the glyphs
788 * @font: the font in which to draw the string
789 * @matrix: a #PangoMatrix, or %NULL to use an identity transformation
790 * @glyphs: the glyph string to draw
791 * @x: the x position of the start of the string (in Pango
792 * units in user space coordinates)
793 * @y: the y position of the baseline (in Pango units
794 * in user space coordinates)
796 * Renders a #PangoGlyphString onto a #XftDraw, possibly
797 * transforming the layed-out coordinates through a transformation
798 * matrix. Note that the transformation matrix for @font is not
799 * changed, so to produce correct rendering results, the @font
800 * must have been loaded using a #PangoContext with an identical
801 * transformation matrix to that passed in to this function.
806 pango_xft_render_transformed (XftDraw *draw,
810 PangoGlyphString *glyphs,
814 PangoFontMap *fontmap;
815 PangoRenderer *renderer;
817 g_return_if_fail (draw != NULL);
818 g_return_if_fail (color != NULL);
819 g_return_if_fail (PANGO_XFT_IS_FONT (font));
820 g_return_if_fail (glyphs != NULL);
822 fontmap = PANGO_FC_FONT (font)->fontmap;
823 renderer = get_renderer (fontmap, draw, color);
825 pango_renderer_set_matrix (renderer, matrix);
827 pango_renderer_draw_glyphs (renderer, font, glyphs, x, y);
829 release_renderer (renderer);
834 * @draw: the <type>XftDraw</type> object.
835 * @color: the color in which to draw the string
836 * @font: the font in which to draw the string
837 * @glyphs: the glyph string to draw
838 * @x: the x position of start of string (in pixels)
839 * @y: the y position of baseline (in pixels)
841 * Renders a #PangoGlyphString onto an <type>XftDraw</type> object wrapping an X drawable.
844 pango_xft_render (XftDraw *draw,
847 PangoGlyphString *glyphs,
851 g_return_if_fail (draw != NULL);
852 g_return_if_fail (color != NULL);
853 g_return_if_fail (PANGO_XFT_IS_FONT (font));
854 g_return_if_fail (glyphs != NULL);
856 pango_xft_render_transformed (draw, color, NULL, font, glyphs,
857 x * PANGO_SCALE, y * PANGO_SCALE);
861 * pango_xft_picture_render:
862 * @display: an X display
863 * @src_picture: the source picture to draw the string with
864 * @dest_picture: the destination picture to draw the string onto
865 * @font: the font in which to draw the string
866 * @glyphs: the glyph string to draw
867 * @x: the x position of start of string (in pixels)
868 * @y: the y position of baseline (in pixels)
870 * Renders a #PangoGlyphString onto an Xrender <type>Picture</type> object.
873 pango_xft_picture_render (Display *display,
875 Picture dest_picture,
877 PangoGlyphString *glyphs,
881 PangoFontMap *fontmap;
882 PangoRenderer *renderer;
884 g_return_if_fail (display != NULL);
885 g_return_if_fail (src_picture != None);
886 g_return_if_fail (dest_picture != None);
887 g_return_if_fail (PANGO_XFT_IS_FONT (font));
888 g_return_if_fail (glyphs != NULL);
890 fontmap = PANGO_FC_FONT (font)->fontmap;
891 renderer = _pango_xft_font_map_get_renderer (PANGO_XFT_FONT_MAP (fontmap));
893 pango_xft_renderer_set_pictures (PANGO_XFT_RENDERER (renderer),
894 src_picture, dest_picture);
895 pango_renderer_set_matrix (renderer, NULL);
897 pango_renderer_draw_glyphs (renderer, font, glyphs, x * PANGO_SCALE, y * PANGO_SCALE);
899 pango_xft_renderer_set_pictures (PANGO_XFT_RENDERER (renderer),
904 * pango_xft_renderer_new:
905 * @display: an X display
906 * @screen: the index of the screen for @display to which rendering will be done
908 * Create a new #PangoXftRenderer to allow rendering Pango objects
909 * with the Xft library. You must call pango_xft_renderer_set_draw() before
910 * using the renderer.
912 * Return value: the newly created #PangoXftRenderer, which should
913 * be freed with g_object_unref().
918 pango_xft_renderer_new (Display *display,
921 PangoXftRenderer *xftrenderer;
923 xftrenderer = g_object_new (PANGO_TYPE_XFT_RENDERER,
928 return PANGO_RENDERER (xftrenderer);
932 * pango_xft_renderer_set_draw:
933 * @xftrenderer: a #PangoXftRenderer
936 * Sets the #XftDraw object that the renderer is drawing to.
937 * The renderer must not be currently active.
942 pango_xft_renderer_set_draw (PangoXftRenderer *xftrenderer,
945 g_return_if_fail (PANGO_IS_XFT_RENDERER (xftrenderer));
947 xftrenderer->draw = draw;
951 * pango_xft_renderer_set_default_color:
952 * @xftrenderer: a #XftRenderer
953 * @default_color: the default foreground color
955 * Sets the default foreground color for a #XftRenderer.
960 pango_xft_renderer_set_default_color (PangoXftRenderer *xftrenderer,
961 PangoColor *default_color)
963 g_return_if_fail (PANGO_IS_XFT_RENDERER (xftrenderer));
965 xftrenderer->priv->default_color = *default_color;