2005-07-21 13:59:22 +00:00
|
|
|
/* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2005-07-21 13:59:22 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-10-15 02:05:51 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2005-07-21 13:59:22 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <fontconfig/fontconfig.h>
|
|
|
|
|
2005-08-01 16:11:38 +00:00
|
|
|
#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
|
|
|
|
|
2005-07-21 13:59:22 +00:00
|
|
|
#include <gdkscreen-x11.h>
|
2010-12-16 03:09:35 +00:00
|
|
|
#include <gdkprivate-x11.h>
|
2005-07-21 13:59:22 +00:00
|
|
|
|
|
|
|
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
|
2020-02-03 14:11:35 +00:00
|
|
|
get_boolean_default (GdkX11Screen *x11_screen,
|
2017-10-06 14:01:19 +00:00
|
|
|
const gchar *option,
|
|
|
|
gboolean *value)
|
2005-07-21 13:59:22 +00:00
|
|
|
{
|
2020-02-03 14:11:35 +00:00
|
|
|
Display *dpy = GDK_SCREEN_XDISPLAY (x11_screen);
|
2005-07-21 13:59:22 +00:00
|
|
|
gchar *v;
|
|
|
|
gint i;
|
2020-02-03 14:11:35 +00:00
|
|
|
|
|
|
|
if (GDK_DISPLAY_DEBUG_CHECK (GDK_SCREEN_DISPLAY (x11_screen), DEFAULT_SETTINGS))
|
|
|
|
return FALSE;
|
|
|
|
|
2005-07-21 13:59:22 +00:00
|
|
|
v = XGetDefault (dpy, "Xft", option);
|
|
|
|
if (v)
|
|
|
|
{
|
|
|
|
i = parse_boolean (v);
|
|
|
|
if (i >= 0)
|
|
|
|
{
|
|
|
|
*value = i;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2020-02-03 14:11:35 +00:00
|
|
|
get_double_default (GdkX11Screen *x11_screen,
|
2017-10-06 14:01:19 +00:00
|
|
|
const gchar *option,
|
|
|
|
gdouble *value)
|
2005-07-21 13:59:22 +00:00
|
|
|
{
|
2020-02-03 14:11:35 +00:00
|
|
|
Display *dpy = GDK_SCREEN_XDISPLAY (x11_screen);
|
2005-07-21 13:59:22 +00:00
|
|
|
gchar *v, *e;
|
2020-02-03 14:11:35 +00:00
|
|
|
|
|
|
|
if (GDK_DISPLAY_DEBUG_CHECK (GDK_SCREEN_DISPLAY (x11_screen), DEFAULT_SETTINGS))
|
|
|
|
return FALSE;
|
|
|
|
|
2005-07-21 13:59:22 +00:00
|
|
|
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
|
2020-02-03 14:11:35 +00:00
|
|
|
get_integer_default (GdkX11Screen *x11_screen,
|
2017-10-06 14:01:19 +00:00
|
|
|
const gchar *option,
|
|
|
|
gint *value)
|
2005-07-21 13:59:22 +00:00
|
|
|
{
|
2020-02-03 14:11:35 +00:00
|
|
|
Display *dpy = GDK_SCREEN_XDISPLAY (x11_screen);
|
2005-07-21 13:59:22 +00:00
|
|
|
gchar *v, *e;
|
2020-02-03 14:11:35 +00:00
|
|
|
|
|
|
|
if (GDK_DISPLAY_DEBUG_CHECK (GDK_SCREEN_DISPLAY (x11_screen), DEFAULT_SETTINGS))
|
|
|
|
return FALSE;
|
|
|
|
|
2005-07-21 13:59:22 +00:00
|
|
|
v = XGetDefault (dpy, "Xft", option);
|
|
|
|
if (v)
|
|
|
|
{
|
|
|
|
if (FcNameConstant ((FcChar8 *) v, value))
|
|
|
|
return TRUE;
|
|
|
|
|
2005-09-13 19:14:51 +00:00
|
|
|
*value = strtol (v, &e, 0);
|
2005-07-21 13:59:22 +00:00
|
|
|
if (e != v)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-11-17 15:18:20 +00:00
|
|
|
init_xft_settings (GdkX11Screen *x11_screen)
|
2005-07-21 13:59:22 +00:00
|
|
|
{
|
|
|
|
double dpi_double;
|
2011-04-12 14:38:38 +00:00
|
|
|
gboolean b;
|
2005-07-21 13:59:22 +00:00
|
|
|
|
2010-12-21 01:32:13 +00:00
|
|
|
if (x11_screen->xft_init)
|
2005-07-21 13:59:22 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-21 01:32:13 +00:00
|
|
|
x11_screen->xft_init = TRUE;
|
2005-07-21 13:59:22 +00:00
|
|
|
|
2020-02-03 14:11:35 +00:00
|
|
|
if (!get_boolean_default (x11_screen, "antialias", &b))
|
2011-04-12 14:38:38 +00:00
|
|
|
b = TRUE;
|
|
|
|
x11_screen->xft_antialias = b;
|
2005-07-21 13:59:22 +00:00
|
|
|
|
2020-02-03 14:11:35 +00:00
|
|
|
if (!get_boolean_default (x11_screen, "hinting", &b))
|
2011-04-12 14:38:38 +00:00
|
|
|
b = TRUE;
|
|
|
|
x11_screen->xft_hinting = b;
|
2005-07-21 13:59:22 +00:00
|
|
|
|
2020-02-03 14:11:35 +00:00
|
|
|
if (!get_integer_default (x11_screen, "hintstyle", &x11_screen->xft_hintstyle))
|
2015-07-08 00:39:45 +00:00
|
|
|
x11_screen->xft_hintstyle = FC_HINT_MEDIUM;
|
2005-07-21 13:59:22 +00:00
|
|
|
|
2020-02-03 14:11:35 +00:00
|
|
|
if (!get_integer_default (x11_screen, "rgba", &x11_screen->xft_rgba))
|
2010-12-21 01:32:13 +00:00
|
|
|
x11_screen->xft_rgba = FC_RGBA_UNKNOWN;
|
2005-07-21 13:59:22 +00:00
|
|
|
|
2020-02-03 14:11:35 +00:00
|
|
|
if (!get_double_default (x11_screen, "dpi", &dpi_double))
|
2015-07-08 00:39:45 +00:00
|
|
|
dpi_double = 96.0;
|
2005-07-21 13:59:22 +00:00
|
|
|
|
2010-12-21 01:32:13 +00:00
|
|
|
x11_screen->xft_dpi = (int)(0.5 + PANGO_SCALE * dpi_double);
|
2005-07-21 13:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2017-11-17 15:18:20 +00:00
|
|
|
_gdk_x11_screen_get_xft_setting (GdkX11Screen *x11_screen,
|
|
|
|
const char *name,
|
|
|
|
GValue *value)
|
2005-07-21 13:59:22 +00:00
|
|
|
{
|
|
|
|
if (strncmp (name, "gtk-xft-", 8) != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
name += 8;
|
|
|
|
|
2017-11-17 15:18:20 +00:00
|
|
|
init_xft_settings (x11_screen);
|
2005-07-21 13:59:22 +00:00
|
|
|
|
|
|
|
if (strcmp (name, "antialias") == 0)
|
|
|
|
{
|
2010-12-21 01:32:13 +00:00
|
|
|
g_value_set_int (value, x11_screen->xft_antialias);
|
2005-07-21 13:59:22 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (strcmp (name, "hinting") == 0)
|
|
|
|
{
|
2010-12-21 01:32:13 +00:00
|
|
|
g_value_set_int (value, x11_screen->xft_hinting);
|
2005-07-21 13:59:22 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (strcmp (name, "hintstyle") == 0)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
|
2010-12-21 01:32:13 +00:00
|
|
|
switch (x11_screen->xft_hintstyle)
|
2005-07-21 13:59:22 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2010-12-21 01:32:13 +00:00
|
|
|
switch (x11_screen->xft_rgba)
|
2005-07-21 13:59:22 +00:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2010-12-21 01:32:13 +00:00
|
|
|
g_value_set_int (value, x11_screen->xft_dpi);
|
2005-07-21 13:59:22 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|