Upload tizen 2.0 beta source
[external/pango1.0.git] / pango-view / viewer-pangox.c
1 /* viewer-pangox.c: PangoX viewer backend.
2  *
3  * Copyright (C) 1999,2004,2005 Red Hat, Inc.
4  * Copyright (C) 2001 Sun Microsystems
5  *
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.
10  *
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.
15  *
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.
20  */
21 #include "config.h"
22
23 #include "viewer-render.h"
24 #include "viewer-x.h"
25
26 #include <pango/pangox.h>
27
28 static void
29 pangox_view_destroy (gpointer instance)
30 {
31   XViewer *x = (XViewer *)instance;
32
33   pango_x_shutdown_display (x->display);
34
35   x_view_destroy (instance);
36 }
37
38 static PangoContext *
39 pangox_view_get_context (gpointer instance)
40 {
41   XViewer *x = (XViewer *) instance;
42   PangoContext *context;
43   PangoMatrix matrix = {0., 0., 0., 0., 0., 0.};
44
45   context = pango_font_map_create_context (pango_x_font_map_for_display (x->display));
46
47   /* We set an all-zero matrix on the context, to negotiate that
48    * this backend doesn't support transformations.
49    */
50   pango_context_set_matrix (context, &matrix);
51
52   return context;
53 }
54
55 typedef struct
56 {
57   XViewer *x;
58   Drawable drawable;
59   GC gc;
60 } MyXContext;
61
62 static void
63 render_callback (PangoLayout *layout,
64                  int          x,
65                  int          y,
66                  gpointer     context,
67                  gpointer     state G_GNUC_UNUSED)
68 {
69   MyXContext *x_context = (MyXContext *) context;
70
71   pango_x_render_layout (x_context->x->display,
72                          x_context->drawable,
73                          x_context->gc,
74                          layout,
75                          x, y);
76 }
77
78 static void
79 pangox_view_render (gpointer      instance,
80                     gpointer      surface,
81                     PangoContext *context,
82                     int          *width,
83                     int          *height,
84                     gpointer      state)
85 {
86   XViewer *x = (XViewer *) instance;
87   Pixmap pixmap = (Pixmap) surface;
88   GC gc;
89   MyXContext x_context;
90
91   gc = XCreateGC (x->display, pixmap, 0, NULL);
92
93   XSetForeground(x->display, gc, WhitePixel(x->display, x->screen));
94   XFillRectangle (x->display, pixmap, gc, 0, 0, *width, *height);
95
96   x_context.x = x;
97   x_context.drawable = pixmap;
98   x_context.gc = gc;
99
100   XSetForeground(x->display, gc, BlackPixel(x->display, x->screen));
101   do_output (context, render_callback, NULL, &x_context, state, width, height);
102
103   XFlush(x->display);
104
105   XFreeGC (x->display, gc);
106 }
107
108 const PangoViewer pangox_viewer = {
109   "PangoX",
110   "x",
111   NULL,
112   x_view_create,
113   pangox_view_destroy,
114   pangox_view_get_context,
115   x_view_create_surface,
116   x_view_destroy_surface,
117   pangox_view_render,
118   NULL,
119   x_view_create_window,
120   x_view_destroy_window,
121   x_view_display
122 };