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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Based on code from xftdpy.c
21 * Copyright © 2000 Keith Packard
23 * Permission to use, copy, modify, distribute, and sell this software and its
24 * documentation for any purpose is hereby granted without fee, provided that
25 * the above copyright notice appear in all copies and that both that
26 * copyright notice and this permission notice appear in supporting
27 * documentation, and that the name of Keith Packard not be used in
28 * advertising or publicity pertaining to distribution of the software without
29 * specific, written prior permission. Keith Packard makes no
30 * representations about the suitability of this software for any purpose. It
31 * is provided "as is" without express or implied warranty.
33 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
34 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
35 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
36 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
37 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
38 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39 * PERFORMANCE OF THIS SOFTWARE.
44 #include <fontconfig/fontconfig.h>
47 #define FC_HINT_NONE 0
48 #define FC_HINT_SLIGHT 1
49 #define FC_HINT_MEDIUM 2
50 #define FC_HINT_FULL 3
53 #include <gdkscreen-x11.h>
57 parse_boolean (char *v)
62 if (g_ascii_isupper ((int)c0))
63 c0 = g_ascii_tolower (c0);
64 if (c0 == 't' || c0 == 'y' || c0 == '1')
66 if (c0 == 'f' || c0 == 'n' || c0 == '0')
71 if (g_ascii_isupper ((int)c1))
72 c1 = g_ascii_tolower (c1);
83 get_boolean_default (Display *dpy,
90 v = XGetDefault (dpy, "Xft", option);
93 i = parse_boolean (v);
105 get_double_default (Display *dpy,
111 v = XGetDefault (dpy, "Xft", option);
114 /* Xft uses strtod, though localization probably wasn't
115 * desired. For compatibility, we use the conservative
116 * g_strtod() that accepts either localized or non-localized
119 *value = g_strtod (v, &e);
128 get_integer_default (Display *dpy,
134 v = XGetDefault (dpy, "Xft", option);
137 if (FcNameConstant ((FcChar8 *) v, value))
140 *value = strtol (v, &e, 0);
149 init_xft_settings (GdkScreen *screen)
151 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
152 Display *xdisplay = GDK_SCREEN_XDISPLAY (screen);
153 int xscreen = GDK_SCREEN_XNUMBER (screen);
156 if (screen_x11->xft_init)
159 screen_x11->xft_init = TRUE;
161 if (!get_boolean_default (xdisplay, "antialias", &screen_x11->xft_antialias))
162 screen_x11->xft_antialias = TRUE;
164 if (!get_boolean_default (xdisplay, "hinting", &screen_x11->xft_hinting))
165 screen_x11->xft_hinting = TRUE;
167 if (!get_integer_default (xdisplay, "hintstyle", &screen_x11->xft_hintstyle))
168 screen_x11->xft_hintstyle = FC_HINT_FULL;
170 if (!get_integer_default (xdisplay, "rgba", &screen_x11->xft_rgba))
173 int subpixel = FC_RGBA_UNKNOWN;
175 #if RENDER_MAJOR > 0 || RENDER_MINOR >= 6
176 if (_gdk_x11_have_render (screen_x11->display))
178 int render_order = XRenderQuerySubpixelOrder (xdisplay, xscreen);
180 switch (render_order)
183 case SubPixelUnknown:
184 subpixel = FC_RGBA_UNKNOWN;
186 case SubPixelHorizontalRGB:
187 subpixel = FC_RGBA_RGB;
189 case SubPixelHorizontalBGR:
190 subpixel = FC_RGBA_BGR;
192 case SubPixelVerticalRGB:
193 subpixel = FC_RGBA_VRGB;
195 case SubPixelVerticalBGR:
196 subpixel = FC_RGBA_VBGR;
199 subpixel = FC_RGBA_NONE;
205 screen_x11->xft_rgba = subpixel;
208 if (!get_double_default (xdisplay, "dpi", &dpi_double))
209 dpi_double = (((double) DisplayHeight (xdisplay, xscreen) * 25.4) /
210 (double) DisplayHeightMM (xdisplay, xscreen));
212 screen_x11->xft_dpi = (int)(0.5 + PANGO_SCALE * dpi_double);
216 _gdk_x11_get_xft_setting (GdkScreen *screen,
220 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
222 if (strncmp (name, "gtk-xft-", 8) != 0)
227 init_xft_settings (screen);
229 if (strcmp (name, "antialias") == 0)
231 g_value_set_int (value, screen_x11->xft_antialias);
234 else if (strcmp (name, "hinting") == 0)
236 g_value_set_int (value, screen_x11->xft_hinting);
239 else if (strcmp (name, "hintstyle") == 0)
243 switch (screen_x11->xft_hintstyle)
261 g_value_set_string (value, str);
264 else if (strcmp (name, "rgba") == 0)
268 switch (screen_x11->xft_rgba)
285 case FC_RGBA_UNKNOWN:
290 g_value_set_string (value, str);
293 else if (strcmp (name, "dpi") == 0)
295 g_value_set_int (value, screen_x11->xft_dpi);