Commit ca7af3cc authored by Nalin Dahyabhai's avatar Nalin Dahyabhai

add routines for pulling Xft antialiasing and hinting options from the

* src/vterdb.c, src/vterdb.h: add routines for pulling Xft antialiasing and
	hinting options from the resource database.
* src/vtefc.c(_vte_fc_patterns_from_pango_font_desc): apply settings from the
	resource database after applying settings from GTK+.
* src/vtefc.c(_vte_fc_defaults_from_rdb): added, for adding default settings
	based on the resource database.
parent fab57ffc
2003-04-28 nalin
* src/vterdb.c, src/vterdb.h: add routines for pulling Xft antialiasing
and hinting options from the resource database.
* src/vtefc.c(_vte_fc_patterns_from_pango_font_desc): apply settings
from the resource database after applying settings from GTK+.
* src/vtefc.c(_vte_fc_defaults_from_rdb): added, for adding default
settings based on the resource database.
2003-04-27 nalin
* src/vtefc.c(_vte_fc_defaults_from_gtk): complain when the installed
version of GTK+ doesn't support reporting Xft antialiasing and hinting
......
......@@ -70,6 +70,8 @@ libvte_la_SOURCES = \
vtepango.h \
vtepangox.c \
vtepangox.h \
vterdb.c \
vterdb.h \
vtergb.c \
vtergb.h \
vteskel.c \
......
......@@ -27,18 +27,7 @@
#include <fontconfig/fontconfig.h>
#include <glib.h>
#include "vtefc.h"
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(String) dgettext(PACKAGE, String)
#else
#define _(String) String
#define bindtextdomain(package,dir)
#endif
#include "vterdb.h"
static int
_vte_fc_weight_from_pango_weight(int weight)
......@@ -139,9 +128,7 @@ _vte_fc_defaults_from_gtk(FcPattern *pattern)
#endif
GObjectClass *klass;
int i, antialias = -1, hinting = -1, dpi = -1;
double d;
char *rgba = NULL, *hintstyle = NULL;
FcResult result;
/* Add any defaults configured for GTK+. */
#if GTK_CHECK_VERSION(2,2,0)
......@@ -157,10 +144,6 @@ _vte_fc_defaults_from_gtk(FcPattern *pattern)
/* Check that the properties we're looking at are defined. */
klass = G_OBJECT_CLASS(GTK_SETTINGS_GET_CLASS(settings));
if (g_object_class_find_property(klass, "gtk-xft-antialias") == NULL) {
g_warning(_("The installed version of GTK+ does not support "
"dynamic setting of antialiasing and hinting "
"options. Font selection will not work "
"correctly."));
return;
}
......@@ -191,23 +174,23 @@ _vte_fc_defaults_from_gtk(FcPattern *pattern)
i = FC_RGBA_NONE;
if (strcmp(rgba, "none") == 0) {
if (g_ascii_strcasecmp(rgba, "none") == 0) {
i = FC_RGBA_NONE;
found = TRUE;
} else
if (strcmp(rgba, "rgb") == 0) {
if (g_ascii_strcasecmp(rgba, "rgb") == 0) {
i = FC_RGBA_RGB;
found = TRUE;
} else
if (strcmp(rgba, "bgr") == 0) {
if (g_ascii_strcasecmp(rgba, "bgr") == 0) {
i = FC_RGBA_BGR;
found = TRUE;
} else
if (strcmp(rgba, "vrgb") == 0) {
if (g_ascii_strcasecmp(rgba, "vrgb") == 0) {
i = FC_RGBA_VRGB;
found = TRUE;
} else
if (strcmp(rgba, "vbgr") == 0) {
if (g_ascii_strcasecmp(rgba, "vbgr") == 0) {
i = FC_RGBA_VBGR;
found = TRUE;
} else {
......@@ -232,19 +215,19 @@ _vte_fc_defaults_from_gtk(FcPattern *pattern)
i = FC_HINT_NONE;
if (strcmp(hintstyle, "hintnone") == 0) {
if (g_ascii_strcasecmp(hintstyle, "hintnone") == 0) {
i = FC_HINT_NONE;
found = TRUE;
} else
if (strcmp(hintstyle, "hintslight") == 0) {
if (g_ascii_strcasecmp(hintstyle, "hintslight") == 0) {
i = FC_HINT_SLIGHT;
found = TRUE;
} else
if (strcmp(hintstyle, "hintmedium") == 0) {
if (g_ascii_strcasecmp(hintstyle, "hintmedium") == 0) {
i = FC_HINT_MEDIUM;
found = TRUE;
} else
if (strcmp(hintstyle, "hintfull") == 0) {
if (g_ascii_strcasecmp(hintstyle, "hintfull") == 0) {
i = FC_HINT_FULL;
found = TRUE;
} else {
......@@ -258,6 +241,86 @@ _vte_fc_defaults_from_gtk(FcPattern *pattern)
#endif
}
static void
_vte_fc_defaults_from_rdb(FcPattern *pattern)
{
FcBool fcb;
double fcd;
int antialias = -1, hinting = -1, fci;
double dpi;
const char *rgba = NULL, *hintstyle = NULL;
/* Read the settings. */
hintstyle = _vte_rdb_get_hintstyle();
rgba = _vte_rdb_get_rgba();
/* Pick up the antialiasing setting. */
if (FcPatternGetBool(pattern, FC_ANTIALIAS, 0,
&fcb) == FcResultNoMatch) {
antialias = _vte_rdb_get_antialias();
FcPatternAddBool(pattern, FC_ANTIALIAS, antialias);
}
/* Pick up the hinting setting. */
if (FcPatternGetBool(pattern, FC_HINTING, 0,
&fcb) == FcResultNoMatch) {
hinting = _vte_rdb_get_hinting();
FcPatternAddBool(pattern, FC_HINTING, hinting);
}
/* Pick up the configured DPI setting. */
if (FcPatternGetDouble(pattern, FC_DPI, 0,
&fcd) == FcResultNoMatch) {
dpi = _vte_rdb_get_dpi();
FcPatternAddDouble(pattern, FC_DPI, dpi);
}
/* Pick up the configured subpixel rendering setting. */
if (FcPatternGetInteger(pattern, FC_RGBA, 0,
&fci) == FcResultNoMatch) {
rgba = _vte_rdb_get_rgba();
if (g_ascii_strcasecmp(rgba, "none") == 0) {
FcPatternAddInteger(pattern, FC_RGBA, FC_RGBA_NONE);
} else
if (g_ascii_strcasecmp(rgba, "rgb") == 0) {
FcPatternAddInteger(pattern, FC_RGBA, FC_RGBA_RGB);
} else
if (g_ascii_strcasecmp(rgba, "bgr") == 0) {
FcPatternAddInteger(pattern, FC_RGBA, FC_RGBA_BGR);
} else
if (g_ascii_strcasecmp(rgba, "vrgb") == 0) {
FcPatternAddInteger(pattern, FC_RGBA, FC_RGBA_VRGB);
} else
if (g_ascii_strcasecmp(rgba, "vbgr") == 0) {
FcPatternAddInteger(pattern, FC_RGBA, FC_RGBA_VBGR);
}
}
#ifdef FC_HINT_STYLE
/* Pick up the default hinting style. */
if (FcPatternGetInteger(pattern, FC_HINT_STYLE, 0,
&fci) == FcResultNoMatch) {
hintstyle = _vte_rdb_get_hintstyle();
if (g_ascii_strcasecmp(hintstyle, "hintnone") == 0) {
FcPatternAddInteger(pattern, FC_HINT_STYLE,
FC_HINT_NONE);
} else
if (g_ascii_strcasecmp(hintstyle, "hintslight") == 0) {
FcPatternAddInteger(pattern, FC_HINT_STYLE,
FC_HINT_SLIGHT);
} else
if (g_ascii_strcasecmp(hintstyle, "hintmedium") == 0) {
FcPatternAddInteger(pattern, FC_HINT_STYLE,
FC_HINT_MEDIUM);
} else
if (g_ascii_strcasecmp(hintstyle, "hintfull") == 0) {
FcPatternAddInteger(pattern, FC_HINT_STYLE,
FC_HINT_FULL);
}
}
#endif
}
/* Create a sorted set of fontconfig patterns from a Pango font description
* and append them to the array. */
gboolean
......@@ -284,6 +347,9 @@ _vte_fc_patterns_from_pango_font_desc(const PangoFontDescription *font_desc,
/* Add any defaults configured for GTK+. */
_vte_fc_defaults_from_gtk(pattern);
/* Add defaults configured via the resource database. */
_vte_fc_defaults_from_rdb(pattern);
/* Add any defaults which are hard-coded in fontconfig. */
FcDefaultSubstitute(pattern);
......
/*
* Copyright (C) 2003 Red Hat, Inc.
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ident "$Id$"
#include "../config.h"
#include <limits.h>
#include <string.h>
#include <gtk/gtk.h>
#include "vterdb.h"
#define DEFAULT_ANTIALIAS TRUE
#define DEFAULT_DPI -1
#define DEFAULT_RGBA "none"
#define DEFAULT_HINTING TRUE
#define DEFAULT_HINTSTYLE "hintfull"
static gchar **
_vte_rdb_get(void)
{
GdkWindow *root;
char *prop_data;
gchar **ret;
GdkAtom atom, prop_type;
/* Retrieve the window and the property which we're going to read. */
root = gdk_get_default_root_window();
atom = gdk_atom_intern("RESOURCE_MANAGER", TRUE);
if (atom == 0) {
return NULL;
}
/* Read the string property off of the window. */
prop_data = NULL;
gdk_error_trap_push();
gdk_property_get(root, atom, GDK_TARGET_STRING, 0, LONG_MAX, FALSE,
&prop_type, NULL, NULL,
(guchar**) &prop_data);
gdk_error_trap_pop();
/* Only parse the information if we got a string. */
if ((prop_type == GDK_TARGET_STRING) && (prop_data != NULL)) {
ret = g_strsplit(prop_data, "\n", -1);
g_free(prop_data);
return ret;
}
return NULL;
}
static gchar *
_vte_rdb_search(const char *setting)
{
gchar *ret = NULL;
int i, l;
gchar **rdb;
rdb = _vte_rdb_get();
if (rdb != NULL) {
l = strlen(setting);
for (i = 0; rdb[i] != NULL; i++) {
if ((strncmp(rdb[i], setting, l) == 0) &&
(rdb[i][l] == ':') &&
(rdb[i][l + 1] == '\t')) {
ret = g_strdup(rdb[i] + l + 2);
break;
}
}
g_strfreev(rdb);
}
return ret;
}
static double
_vte_rdb_double(const char *setting, double default_value)
{
char *start, *endptr = NULL;
double dbl;
start = _vte_rdb_search(setting);
if (start == NULL) {
return default_value;
}
dbl = g_ascii_strtod(start, &endptr);
if ((endptr == NULL) || (*endptr != '\0')) {
dbl = default_value;
}
g_free(start);
return dbl;
}
static int
_vte_rdb_integer(const char *setting, int default_value)
{
char *start, *endptr = NULL;
int n;
start = _vte_rdb_search(setting);
if (start == NULL) {
return default_value;
}
n = CLAMP(g_ascii_strtoull(start, &endptr, 10), 0, INT_MAX);
if ((endptr == NULL) || (*endptr != '\0')) {
n = default_value;
}
g_free(start);
return n;
}
static gboolean
_vte_rdb_boolean(const char *setting, gboolean default_value)
{
char *start, *endptr = NULL;
int n;
start = _vte_rdb_search(setting);
if (start == NULL) {
return default_value;
}
n = CLAMP(g_ascii_strtoull(start, &endptr, 10), 0, INT_MAX);
if ((endptr != NULL) && (*endptr == '\0')) {
n = (n != 0) ? TRUE : FALSE;
} else
if (g_ascii_strcasecmp(start, "true") == 0) {
n = TRUE;
} else
if (g_ascii_strcasecmp(start, "false") == 0) {
n = FALSE;
} else {
n = default_value;
}
g_free(start);
return n;
}
static GQuark
_vte_rdb_quark(const char *setting, GQuark default_value)
{
char *start;
GQuark q = 0;
start = _vte_rdb_search(setting);
if (start == NULL) {
return default_value;
}
q = g_quark_from_string(start);
g_free(start);
return q;
}
double
_vte_rdb_get_dpi(void)
{
return _vte_rdb_double("Xft.dpi", DEFAULT_DPI);
}
gboolean
_vte_rdb_get_antialias(void)
{
return _vte_rdb_boolean("Xft.antialias", DEFAULT_ANTIALIAS);
}
gboolean
_vte_rdb_get_hinting(void)
{
return _vte_rdb_boolean("Xft.hinting", DEFAULT_HINTING);
}
const char *
_vte_rdb_get_rgba(void)
{
GQuark q;
q = g_quark_from_string(DEFAULT_RGBA);
return g_quark_to_string(_vte_rdb_quark("Xft.rgba", q));
}
const char *
_vte_rdb_get_hintstyle(void)
{
GQuark q;
q = g_quark_from_string(DEFAULT_HINTSTYLE);
return g_quark_to_string(_vte_rdb_quark("Xft.hintstyle", q));
}
#ifdef VTERDB_MAIN
int
main(int argc, char **argv)
{
gtk_init(&argc, &argv);
g_print("DPI: %lf\n", _vte_rdb_get_dpi());
g_print("Antialias: %s\n", _vte_rdb_get_antialias() ? "TRUE" : "FALSE");
g_print("Hinting: %s\n", _vte_rdb_get_hinting() ? "TRUE" : "FALSE");
g_print("Hint style: %s\n", _vte_rdb_get_hintstyle());
g_print("RGBA: %s\n", _vte_rdb_get_rgba());
return 0;
}
#endif
/*
* Copyright (C) 2003 Red Hat, Inc.
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ident "$Id$"
#ifndef vte_rdb_h_included
#define vte_rdb_h_included
#include <glib.h>
G_BEGIN_DECLS
double _vte_rdb_get_dpi(void);
gboolean _vte_rdb_get_antialias(void);
gboolean _vte_rdb_get_hinting(void);
const char *_vte_rdb_get_rgba(void);
const char *_vte_rdb_get_hintstyle(void);
G_END_DECLS
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment