Warn when a font larger than 31 points is selected, #97653. Caring

Sat Aug  2 01:16:16 2003  Jonathan Blandford  <jrb@gnome.org>

        * main.c (application_font_to_gconf): Warn when a font larger than
        31 points is selected, #97653.
Caring Desktop++
This commit is contained in:
Jonathan Blandford 2003-08-02 15:52:24 +00:00 committed by Jonathan Blandford
parent 170ffa5325
commit 532a9fae6a
5 changed files with 317 additions and 45 deletions

View file

@ -393,6 +393,12 @@ gconf_property_editor_get_key (GConfPropertyEditor *peditor)
return peditor->p->key;
}
GObject *
gconf_property_editor_get_ui_control (GConfPropertyEditor *peditor)
{
return peditor->p->ui_control;
}
static void
peditor_set_gconf_value (GConfPropertyEditor *peditor,
const gchar *key,

View file

@ -64,7 +64,8 @@ struct _GConfPropertyEditorClass
GType gconf_property_editor_get_type (void);
const gchar *gconf_property_editor_get_key (GConfPropertyEditor *peditor);
const gchar *gconf_property_editor_get_key (GConfPropertyEditor *peditor);
GObject *gconf_property_editor_get_ui_control (GConfPropertyEditor *peditor);
GObject *gconf_peditor_new_boolean (GConfChangeSet *changeset,
gchar *key,

View file

@ -1,3 +1,8 @@
Sat Aug 2 01:16:16 2003 Jonathan Blandford <jrb@gnome.org>
* main.c (application_font_to_gconf): Warn when a font larger than
31 points is selected, #97653.
2003-07-17 Dennis Cranston <dennis_cranston at yahoo com>
* font-properties.glade: Some HIGification of the dialog.

View file

@ -1478,4 +1478,166 @@
</child>
</widget>
<widget class="GtkDialog" id="font_size_warning_dialog">
<property name="title" translatable="yes"></property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox4">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area4">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button4">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="button5">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">1</property>
<child>
<widget class="GtkAlignment" id="alignment14">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<child>
<widget class="GtkHBox" id="hbox7">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="stock">gtk-ok</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label15">
<property name="visible">True</property>
<property name="label" translatable="yes">_Use Font</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox8">
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">12</property>
<child>
<widget class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="stock">gtk-dialog-warning</property>
<property name="icon_size">6</property>
<property name="xalign">0.5</property>
<property name="yalign">0</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="font_size_warning_label">
<property name="visible">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">True</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View file

@ -39,9 +39,13 @@ static void cb_show_details (GtkWidget *button,
#define FONT_RGBA_ORDER_KEY FONT_RENDER_DIR "/rgba_order"
#define FONT_DPI_KEY FONT_RENDER_DIR "/dpi"
static gboolean in_change = FALSE;
#endif /* HAVE_XFT2 */
static gboolean in_change = FALSE;
static gchar *old_font = NULL;
#define MAX_FONT_POINT_WITHOUT_WARNING 32
#define MAX_FONT_SIZE_WITHOUT_WARNING MAX_FONT_POINT_WITHOUT_WARNING*1024
#define PICKER_DIALOG_DATA_STRING "picker-dialog-data-string"
static GladeXML *
create_dialog (void)
{
@ -431,6 +435,96 @@ metacity_changed (GConfClient *client,
metacity_titlebar_load_sensitivity (client, user_data);
}
/* returns 0 if the font is safe, otherwise returns the size in points. */
static gint
new_font_dangerous (const char *new_font)
{
PangoFontDescription *pfd;
gboolean retval = 0;
pfd = pango_font_description_from_string (new_font);
if (pfd == NULL)
/* an invalid font was passed in. This isn't our problem. */
return 0;
if (pango_font_description_get_set_fields (pfd) & PANGO_FONT_MASK_SIZE) {
if (pango_font_description_get_size (pfd) >= MAX_FONT_SIZE_WITHOUT_WARNING) {
retval = pango_font_description_get_size (pfd)/1024;
}
}
pango_font_description_free (pfd);
return retval;
}
static GConfValue *
application_font_to_gconf (GConfPropertyEditor *peditor,
GConfValue *value)
{
GConfValue *new_value;
const char *new_font;
GtkWidget *font_picker;
GladeXML *dialog;
gint danger_level;
font_picker = (GtkWidget *) gconf_property_editor_get_ui_control (peditor);
g_assert (font_picker);
dialog = glade_xml_new (GLADEDIR "/font-properties.glade", "font_size_warning_dialog", NULL);
new_value = gconf_value_new (GCONF_VALUE_STRING);
new_font = gconf_value_get_string (value);
if (new_font_dangerous (old_font)) {
/* If we're already too large, we don't warn again. */
gconf_value_set_string (new_value, new_font);
return new_value;
}
danger_level = new_font_dangerous (new_font);
if (danger_level) {
GtkWidget *font_size_warning_dialog;
gchar *warning_label;
gchar *warning_label2;
font_size_warning_dialog = WID ("font_size_warning_dialog");
if (danger_level > MAX_FONT_POINT_WITHOUT_WARNING) {
warning_label = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
_("Font may be too large"),
_("The font selected is %d points large, and may make it difficult to effectively use the computer. It is recommended that you select a size smaller than %d."));
warning_label2 = g_strdup_printf (warning_label, danger_level, MAX_FONT_POINT_WITHOUT_WARNING);
} else {
warning_label = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
_("Font may be too large"),
_("The font selected is %d points large, and may make it difficult to effectively use the computer. It is recommended that you select a smaller sized font."));
warning_label2 = g_strdup_printf (warning_label, danger_level);
}
gtk_label_set_markup (GTK_LABEL (WID ("font_size_warning_label")), warning_label2);
if (gtk_dialog_run (GTK_DIALOG (font_size_warning_dialog)) == 1) {
gconf_value_set_string (new_value, new_font);
} else {
gconf_value_set_string (new_value, old_font);
gnome_font_picker_set_font_name (GNOME_FONT_PICKER (font_picker), old_font);
}
gtk_widget_destroy (font_size_warning_dialog);
} else {
gconf_value_set_string (new_value, new_font);
}
return new_value;
}
static void
application_font_changed (GtkWidget *font_picker)
{
const gchar *font;
font = gnome_font_picker_get_font_name (GNOME_FONT_PICKER (font_picker));
g_free (old_font);
old_font = g_strdup (font);
}
static void
setup_dialog (GladeXML *dialog)
{
@ -447,10 +541,14 @@ setup_dialog (GladeXML *dialog)
gconf_client_add_dir (client, FONT_RENDER_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
#endif /* HAVE_XFT2 */
g_object_set_data (G_OBJECT (WID ("application_font")), PICKER_DIALOG_DATA_STRING, dialog);
peditor = gconf_peditor_new_font (NULL, GTK_FONT_KEY,
WID ("application_font"),
PEDITOR_FONT_COMBINED, NULL);
PEDITOR_FONT_COMBINED,
"conv-from-widget-cb", application_font_to_gconf,
NULL);
g_signal_connect_swapped (G_OBJECT (peditor), "value-changed", (GCallback) application_font_changed, WID ("application_font"));
application_font_changed (WID ("application_font"));
peditor = gconf_peditor_new_font (NULL, DESKTOP_FONT_KEY,
WID ("desktop_font"),
PEDITOR_FONT_COMBINED, NULL);