1 /* viewer-pangoxft.c: PangoXft viewer backend.
3 * Copyright (C) 1999,2004,2005 Red Hat, Inc.
4 * Copyright (C) 2001 Sun Microsystems
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.
23 #include "viewer-render.h"
26 #include <pango/pangoxft.h>
29 default_substitute (FcPattern *pattern,
30 gpointer data G_GNUC_UNUSED)
32 FcPatternDel (pattern, FC_DPI);
33 FcPatternAddInteger (pattern, FC_DPI, opt_dpi);
35 if (opt_hinting != HINT_DEFAULT)
37 FcPatternDel (pattern, FC_HINTING);
38 FcPatternAddBool (pattern, FC_HINTING, opt_hinting != HINT_NONE);
40 FcPatternDel (pattern, FC_AUTOHINT);
41 FcPatternAddBool (pattern, FC_AUTOHINT, opt_hinting == HINT_AUTO);
46 pangoxft_view_create (const PangoViewer *klass)
50 instance = x_view_create (klass);
54 pango_xft_set_default_substitute (instance->display, instance->screen,
55 default_substitute, NULL, NULL);
61 pangoxft_view_destroy (gpointer instance)
63 XViewer *x = (XViewer *)instance;
65 pango_xft_shutdown_display (x->display, x->screen);
67 x_view_destroy (instance);
71 pangoxft_view_get_context (gpointer instance)
73 XViewer *x = (XViewer *) instance;
75 return pango_font_map_create_context (pango_xft_get_font_map (x->display, x->screen));
85 render_callback (PangoLayout *layout,
89 gpointer state G_GNUC_UNUSED)
91 MyXftContext *xft_context = (MyXftContext *) context;
93 pango_xft_render_layout (xft_context->draw,
96 x * PANGO_SCALE, y * PANGO_SCALE);
100 pangoxft_view_render (gpointer instance,
102 PangoContext *context,
107 XViewer *x = (XViewer *) instance;
108 Pixmap pixmap = (Pixmap) surface;
109 MyXftContext xft_context;
113 draw = XftDrawCreate (x->display, pixmap,
114 DefaultVisual (x->display, x->screen),
115 DefaultColormap (x->display, x->screen));
117 /* XftDrawRect only fills solid.
118 * Flatten with white.
120 color.color.red = ((opt_bg_color.red * opt_bg_alpha) >> 16) + (65535 - opt_bg_alpha);
121 color.color.green = ((opt_bg_color.green * opt_bg_alpha) >> 16) + (65535 - opt_bg_alpha);
122 color.color.blue = ((opt_bg_color.blue * opt_bg_alpha) >> 16) + (65535 - opt_bg_alpha);
123 color.color.alpha = 65535;
125 XftDrawRect (draw, &color, 0, 0, *width, *height);
127 color.color.red = opt_fg_color.red;
128 color.color.blue = opt_fg_color.green;
129 color.color.green = opt_fg_color.blue;
130 color.color.alpha = opt_fg_alpha;
132 xft_context.draw = draw;
133 xft_context.color = color;
135 do_output (context, render_callback, NULL, &xft_context, state, width, height);
137 XftDrawDestroy (draw);
140 const PangoViewer pangoxft_viewer = {
144 pangoxft_view_create,
145 pangoxft_view_destroy,
146 pangoxft_view_get_context,
147 x_view_create_surface,
148 x_view_destroy_surface,
149 pangoxft_view_render,
151 x_view_create_window,
152 x_view_destroy_window,