]> Pileus Git - ~andy/gtk/blob - gdk/x11/gdkpango-x11.c
d674889478e5d1cd4867b76562b8041ccd0167c9
[~andy/gtk] / gdk / x11 / gdkpango-x11.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 <stdlib.h>
22
23 #include "gdkx.h"
24 #include "gdkdisplay-x11.h"
25 #include "gdkpango.h"
26 #include <pango/pangox.h>
27 #ifdef HAVE_XFT
28 #include <pango/pangoxft.h>
29 #endif
30
31 /**
32  * gdk_pango_context_get_for_screen:
33  * @screen: the #GdkScreen for which the context is to be created.
34  * 
35  * Creates a #PangoContext for @screen.
36  *
37  * The context must be freed when you're finished with it.
38  * 
39  * When using GTK+, normally you should use gtk_widget_get_pango_context()
40  * instead of this function, to get the appropriate context for
41  * the widget you intend to render text onto.
42  * 
43  * Return value: a new #PangoContext for @screen
44  **/
45 PangoContext *
46 gdk_pango_context_get_for_screen (GdkScreen *screen)
47 {
48   PangoContext *context;
49   GdkDisplayX11 *display_x11;
50   
51   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
52
53   if (screen->closed)
54     return NULL;
55   
56   display_x11 = GDK_DISPLAY_X11 (GDK_SCREEN_DISPLAY (screen));
57   
58 #ifdef HAVE_XFT
59   if (display_x11->use_xft == -1)
60     {
61       const char *val = g_getenv ("GDK_USE_XFT");
62       
63       /* Version 2 of Xft supports rendering FreeType fonts via
64        * the core X protocol, so we default to it everywhere.
65        *
66        * For Xft1, we only enable Xft if the user explicitely
67        * specifies it, and we have the RENDER extension
68        */
69 #  ifdef HAVE_XFT2      
70       display_x11->use_xft = !val || (atoi (val) != 0);
71 #  else
72       display_x11->use_xft = val && (atoi (val) != 0) && 
73         _gdk_x11_have_render (GDK_SCREEN_DISPLAY (screen));
74 #  endif /* HAVE_XFT2 */      
75     }
76   
77   if (display_x11->use_xft)
78     context = pango_xft_get_context (GDK_SCREEN_XDISPLAY (screen),
79                                      GDK_SCREEN_X11 (screen)->screen_num);
80   else
81 #endif /* HAVE_XFT */
82     context = pango_x_get_context (GDK_SCREEN_XDISPLAY (screen));
83   
84   g_object_set_data (G_OBJECT (context), "gdk-pango-screen", screen);
85   
86   return context;
87 }