1 /* GDK - The GIMP Drawing Kit
2 * Copyright © 2005 Red Hat, Inc
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.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 * Based on code from xftdpy.c
19 * Copyright © 2000 Keith Packard
21 * Permission to use, copy, modify, distribute, and sell this software and its
22 * documentation for any purpose is hereby granted without fee, provided that
23 * the above copyright notice appear in all copies and that both that
24 * copyright notice and this permission notice appear in supporting
25 * documentation, and that the name of Keith Packard not be used in
26 * advertising or publicity pertaining to distribution of the software without
27 * specific, written prior permission. Keith Packard makes no
28 * representations about the suitability of this software for any purpose. It
29 * is provided "as is" without express or implied warranty.
31 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
32 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
33 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
34 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
35 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
36 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
37 * PERFORMANCE OF THIS SOFTWARE.
45 #include <fontconfig/fontconfig.h>
48 #define FC_HINT_NONE 0
49 #define FC_HINT_SLIGHT 1
50 #define FC_HINT_MEDIUM 2
51 #define FC_HINT_FULL 3
54 #include <gdkscreen-x11.h>
55 #include <gdkprivate-x11.h>
58 parse_boolean (char *v)
63 if (g_ascii_isupper ((int)c0))
64 c0 = g_ascii_tolower (c0);
65 if (c0 == 't' || c0 == 'y' || c0 == '1')
67 if (c0 == 'f' || c0 == 'n' || c0 == '0')
72 if (g_ascii_isupper ((int)c1))
73 c1 = g_ascii_tolower (c1);
84 get_boolean_default (Display *dpy,
91 v = XGetDefault (dpy, "Xft", option);
94 i = parse_boolean (v);
106 get_double_default (Display *dpy,
112 v = XGetDefault (dpy, "Xft", option);
115 /* Xft uses strtod, though localization probably wasn't
116 * desired. For compatibility, we use the conservative
117 * g_strtod() that accepts either localized or non-localized
120 *value = g_strtod (v, &e);
129 get_integer_default (Display *dpy,
135 v = XGetDefault (dpy, "Xft", option);
138 if (FcNameConstant ((FcChar8 *) v, value))
141 *value = strtol (v, &e, 0);
150 init_xft_settings (GdkScreen *screen)
152 GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
153 Display *xdisplay = GDK_SCREEN_XDISPLAY (screen);
157 if (x11_screen->xft_init)
160 x11_screen->xft_init = TRUE;
162 if (!get_boolean_default (xdisplay, "antialias", &b))
164 x11_screen->xft_antialias = b;
166 if (!get_boolean_default (xdisplay, "hinting", &b))
168 x11_screen->xft_hinting = b;
170 if (!get_integer_default (xdisplay, "hintstyle", &x11_screen->xft_hintstyle))
171 x11_screen->xft_hintstyle = FC_HINT_FULL;
173 if (!get_integer_default (xdisplay, "rgba", &x11_screen->xft_rgba))
174 x11_screen->xft_rgba = FC_RGBA_UNKNOWN;
176 if (!get_double_default (xdisplay, "dpi", &dpi_double))
177 dpi_double = (((double) DisplayHeight (xdisplay, x11_screen->screen_num) * 25.4) /
178 (double) DisplayHeightMM (xdisplay, x11_screen->screen_num));
180 x11_screen->xft_dpi = (int)(0.5 + PANGO_SCALE * dpi_double);
184 _gdk_x11_get_xft_setting (GdkScreen *screen,
188 GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen);
190 if (strncmp (name, "gtk-xft-", 8) != 0)
195 init_xft_settings (screen);
197 if (strcmp (name, "antialias") == 0)
199 g_value_set_int (value, x11_screen->xft_antialias);
202 else if (strcmp (name, "hinting") == 0)
204 g_value_set_int (value, x11_screen->xft_hinting);
207 else if (strcmp (name, "hintstyle") == 0)
211 switch (x11_screen->xft_hintstyle)
229 g_value_set_string (value, str);
232 else if (strcmp (name, "rgba") == 0)
236 switch (x11_screen->xft_rgba)
253 case FC_RGBA_UNKNOWN:
258 g_value_set_string (value, str);
261 else if (strcmp (name, "dpi") == 0)
263 g_value_set_int (value, x11_screen->xft_dpi);