summaryrefslogtreecommitdiff
path: root/examples/xftview.c
blob: f9ba6f6aed3412f7198a75774baa2222ba5281e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Pango
 * xftview.c: Example program to view a UTF-8 encoding file
 *            using PangoXft to render result
 *
 * Copyright (C) 1999,2004,2005 Red Hat, Inc.
 * Copyright (C) 2001 Sun Microsystems
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "renderdemo.h"
#include "viewer-x.h"

#include <pango/pangoxft.h>

static void
render_callback (PangoLayout *layout,
		 int          x,
		 int          y,
		 gpointer     data,
		 gboolean     show_borders)
{
  XftDraw *draw = (XftDraw *)data;
  XftColor color;

  color.color.red = 0x0;
  color.color.green = 0x0;
  color.color.blue = 0x0;
  color.color.alpha = 0xffff;

  pango_xft_render_layout (draw, &color, layout, x, y);

  /*
  if (show_borders)
    {
      PangoContext *context;
      PangoXftFontMap *fontmap;
      PangoRenderer *renderer;
      PangoRectangle ink, logical;
      
      pango_layout_get_extents (layout, &ink, &logical);

      context = pango_layout_get_context (layout);
      fontmap = (PangoXftFontMap *)pango_context_get_font_map (context);

      humm, we cannot go on, as the following is private api.
      need to implement pango_font_map_get_renderer...

      renderer = _pango_xft_font_map_get_renderer (fontmap);
    }
  */
}

void
do_init (Display *display,
	 int screen,
	 /* output */
	 PangoContext **context,
	 int *width,
	 int *height)
{
  XftInit (NULL);
  *context = pango_xft_get_context (display, screen);
  do_output (*context, NULL, NULL, NULL, width, height, FALSE);
}

void
do_render (Display *display,
	   int screen,
	   Window window,
	   Pixmap pixmap,
	   PangoContext *context,
	   int width,
	   int height,
	   gboolean show_borders)
{
  XftDraw *draw;
  XftColor color;

  draw = XftDrawCreate (display, pixmap,
			DefaultVisual (display, screen),
			DefaultColormap (display, screen));

  color.color.red = 0xffff;
  color.color.blue = 0xffff;
  color.color.green = 0xffff;
  color.color.alpha = 0xffff;

  XftDrawRect (draw, &color, 0, 0, width, height);

  do_output (context, render_callback, NULL, draw, NULL, NULL, show_borders);

  XftDrawDestroy (draw);
}