1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
/* GDK - The GIMP Drawing Kit
* Copyright © 2005 Red Hat, Inc
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Based on code from xftdpy.c
*
* Copyright © 2000 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <fontconfig/fontconfig.h>
#ifndef FC_HINT_STYLE
#define FC_HINT_NONE 0
#define FC_HINT_SLIGHT 1
#define FC_HINT_MEDIUM 2
#define FC_HINT_FULL 3
#endif
#include <gdkscreen-x11.h>
#include <gdkprivate-x11.h>
static gint
parse_boolean (char *v)
{
gchar c0, c1;
c0 = *v;
if (g_ascii_isupper ((int)c0))
c0 = g_ascii_tolower (c0);
if (c0 == 't' || c0 == 'y' || c0 == '1')
return 1;
if (c0 == 'f' || c0 == 'n' || c0 == '0')
return 0;
if (c0 == 'o')
{
c1 = v[1];
if (g_ascii_isupper ((int)c1))
c1 = g_ascii_tolower (c1);
if (c1 == 'n')
return 1;
if (c1 == 'f')
return 0;
}
return -1;
}
static gboolean
get_boolean_default (Display *dpy,
const gchar *option,
gboolean *value)
{
gchar *v;
gint i;
v = XGetDefault (dpy, "Xft", option);
if (v)
{
i = parse_boolean (v);
if (i >= 0)
{
*value = i;
return TRUE;
}
}
return FALSE;
}
static gboolean
get_double_default (Display *dpy,
const gchar *option,
gdouble *value)
{
gchar *v, *e;
v = XGetDefault (dpy, "Xft", option);
if (v)
{
/* Xft uses strtod, though localization probably wasn't
* desired. For compatibility, we use the conservative
* g_strtod() that accepts either localized or non-localized
* decimal separator.
*/
*value = g_strtod (v, &e);
if (e != v)
return TRUE;
}
return FALSE;
}
static gboolean
get_integer_default (Display *dpy,
const gchar *option,
gint *value)
{
gchar *v, *e;
v = XGetDefault (dpy, "Xft", option);
if (v)
{
if (FcNameConstant ((FcChar8 *) v, value))
return TRUE;
*value = strtol (v, &e, 0);
if (e != v)
return TRUE;
}
return FALSE;
}
static void
init_xft_settings (GdkX11Screen *x11_screen)
{
Display *xdisplay = GDK_SCREEN_XDISPLAY (x11_screen);
double dpi_double;
gboolean b;
if (x11_screen->xft_init)
return;
x11_screen->xft_init = TRUE;
if (!get_boolean_default (xdisplay, "antialias", &b))
b = TRUE;
x11_screen->xft_antialias = b;
if (!get_boolean_default (xdisplay, "hinting", &b))
b = TRUE;
x11_screen->xft_hinting = b;
if (!get_integer_default (xdisplay, "hintstyle", &x11_screen->xft_hintstyle))
x11_screen->xft_hintstyle = FC_HINT_MEDIUM;
if (!get_integer_default (xdisplay, "rgba", &x11_screen->xft_rgba))
x11_screen->xft_rgba = FC_RGBA_UNKNOWN;
if (!get_double_default (xdisplay, "dpi", &dpi_double))
dpi_double = 96.0;
x11_screen->xft_dpi = (int)(0.5 + PANGO_SCALE * dpi_double);
}
gboolean
_gdk_x11_screen_get_xft_setting (GdkX11Screen *x11_screen,
const char *name,
GValue *value)
{
if (strncmp (name, "gtk-xft-", 8) != 0)
return FALSE;
name += 8;
init_xft_settings (x11_screen);
if (strcmp (name, "antialias") == 0)
{
g_value_set_int (value, x11_screen->xft_antialias);
return TRUE;
}
else if (strcmp (name, "hinting") == 0)
{
g_value_set_int (value, x11_screen->xft_hinting);
return TRUE;
}
else if (strcmp (name, "hintstyle") == 0)
{
const char *str;
switch (x11_screen->xft_hintstyle)
{
case FC_HINT_NONE:
str = "hintnone";
break;
case FC_HINT_SLIGHT:
str = "hintslight";
break;
case FC_HINT_MEDIUM:
str = "hintmedium";
break;
case FC_HINT_FULL:
str = "hintfull";
break;
default:
return FALSE;
}
g_value_set_string (value, str);
return TRUE;
}
else if (strcmp (name, "rgba") == 0)
{
const char *str;
switch (x11_screen->xft_rgba)
{
case FC_RGBA_NONE:
str = "none";
break;
case FC_RGBA_RGB:
str = "rgb";
break;
case FC_RGBA_BGR:
str = "bgr";
break;
case FC_RGBA_VRGB:
str = "vrgb";
break;
case FC_RGBA_VBGR:
str = "vbgr";
break;
case FC_RGBA_UNKNOWN:
default:
return FALSE;
}
g_value_set_string (value, str);
return TRUE;
}
else if (strcmp (name, "dpi") == 0)
{
g_value_set_int (value, x11_screen->xft_dpi);
return TRUE;
}
return FALSE;
}
|