diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 18 | ||||
-rw-r--r-- | ChangeLog.pre-2-8 | 18 | ||||
-rw-r--r-- | gdk/gdk.symbols | 4 | ||||
-rw-r--r-- | gdk/gdkpango.c | 25 | ||||
-rw-r--r-- | gdk/gdkscreen.c | 113 | ||||
-rw-r--r-- | gdk/gdkscreen.h | 12 | ||||
-rw-r--r-- | gtk/gtksettings.c | 115 | ||||
-rw-r--r-- | gtk/gtkwidget.c | 96 |
9 files changed, 331 insertions, 88 deletions
@@ -1,3 +1,21 @@ +2005-08-23 Owen Taylor <otaylor@redhat.com> + + Fix for #314004, reported by Michael Reinsch: + + * gdk/gdk.symbols: + * gdk/gdkscreen.[ch]: Add gdk_screen_get/set_font_options_libgtk_only() + Add gdk_screen_get/set_resolution_libgtk_only() + + * gdk/gdkpango.c (gdk_pango_context_get_for_screen): Set + the options for the screen on the newly created context. + + * gtk/gtksettings.c (settings_update_font_options/dpi) gtkwidget.c: + Move font options and dpi code from gtkwidget.c to gtksettings.c, set + the font options on the screen. + + * gtk/gtkwidget.c (gtk_widget_update_pango_context): Just get + the font options from the screen and set them on the context. + 2005-08-23 Kristian Rietveld <kris@gtk.org> * gtk/gtktreemodelsort.c (gtk_tree_model_sort_row_inserted): don't diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 2581077c9..16ccd7227 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,21 @@ +2005-08-23 Owen Taylor <otaylor@redhat.com> + + Fix for #314004, reported by Michael Reinsch: + + * gdk/gdk.symbols: + * gdk/gdkscreen.[ch]: Add gdk_screen_get/set_font_options_libgtk_only() + Add gdk_screen_get/set_resolution_libgtk_only() + + * gdk/gdkpango.c (gdk_pango_context_get_for_screen): Set + the options for the screen on the newly created context. + + * gtk/gtksettings.c (settings_update_font_options/dpi) gtkwidget.c: + Move font options and dpi code from gtkwidget.c to gtksettings.c, set + the font options on the screen. + + * gtk/gtkwidget.c (gtk_widget_update_pango_context): Just get + the font options from the screen and set them on the context. + 2005-08-23 Kristian Rietveld <kris@gtk.org> * gtk/gtktreemodelsort.c (gtk_tree_model_sort_row_inserted): don't diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 2581077c9..16ccd7227 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,21 @@ +2005-08-23 Owen Taylor <otaylor@redhat.com> + + Fix for #314004, reported by Michael Reinsch: + + * gdk/gdk.symbols: + * gdk/gdkscreen.[ch]: Add gdk_screen_get/set_font_options_libgtk_only() + Add gdk_screen_get/set_resolution_libgtk_only() + + * gdk/gdkpango.c (gdk_pango_context_get_for_screen): Set + the options for the screen on the newly created context. + + * gtk/gtksettings.c (settings_update_font_options/dpi) gtkwidget.c: + Move font options and dpi code from gtkwidget.c to gtksettings.c, set + the font options on the screen. + + * gtk/gtkwidget.c (gtk_widget_update_pango_context): Just get + the font options from the screen and set them on the context. + 2005-08-23 Kristian Rietveld <kris@gtk.org> * gtk/gtktreemodelsort.c (gtk_tree_model_sort_row_inserted): don't diff --git a/gdk/gdk.symbols b/gdk/gdk.symbols index 06bb4256e..c8c25e88c 100644 --- a/gdk/gdk.symbols +++ b/gdk/gdk.symbols @@ -962,6 +962,10 @@ gdk_draw_rgb_image_dithalign gdk_screen_get_type G_GNUC_CONST gdk_screen_get_monitor_at_point gdk_screen_get_monitor_at_window +gdk_screen_set_font_options_libgtk_only +gdk_screen_get_font_options_libgtk_only +gdk_screen_set_resolution_libgtk_only +gdk_screen_get_resolution_libgtk_only #endif #endif diff --git a/gdk/gdkpango.c b/gdk/gdkpango.c index 52dcfebd4..d1649e1ef 100644 --- a/gdk/gdkpango.c +++ b/gdk/gdkpango.c @@ -1333,6 +1333,12 @@ gdk_pango_layout_get_clip_region (PangoLayout *layout, * instead of this function, to get the appropriate context for * the widget you intend to render text onto. * + * The newly created context will have the default font options (see + * #cairo_font_options_t) for the default screen; if these options + * change it will not be updated. Using gtk_widget_get_pango_context() + * is more convenient if you want to keep a context around and track + * changes to the screen's font rendering settings. + * * Return value: a new #PangoContext for the default display **/ PangoContext * @@ -1353,6 +1359,12 @@ gdk_pango_context_get (void) * instead of this function, to get the appropriate context for * the widget you intend to render text onto. * + * The newly created context will have the default font options + * (see #cairo_font_options_t) for the screen; if these options + * change it will not be updated. Using gtk_widget_get_pango_context() + * is more convenient if you want to keep a context around and track + * changes to the screen's font rendering settings. + * * Return value: a new #PangoContext for @screen * * Since: 2.2 @@ -1361,12 +1373,23 @@ PangoContext * gdk_pango_context_get_for_screen (GdkScreen *screen) { PangoFontMap *fontmap; + PangoContext *context; + const cairo_font_options_t *options; + double dpi; g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); fontmap = pango_cairo_font_map_get_default (); - return pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap)); + context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap)); + + options = gdk_screen_get_font_options_libgtk_only (screen); + pango_cairo_context_set_font_options (context, options); + + dpi = gdk_screen_get_resolution_libgtk_only (screen); + pango_cairo_context_set_resolution (context, dpi); + + return context; } #define __GDK_PANGO_C__ diff --git a/gdk/gdkscreen.c b/gdk/gdkscreen.c index 8e08e5363..b08cf725a 100644 --- a/gdk/gdkscreen.c +++ b/gdk/gdkscreen.c @@ -29,7 +29,9 @@ #include "gdkalias.h" static void gdk_screen_class_init (GdkScreenClass *klass); +static void gdk_screen_init (GdkScreen *screen); static void gdk_screen_dispose (GObject *object); +static void gdk_screen_finalize (GObject *object); enum { @@ -51,7 +53,7 @@ gdk_screen_get_type (void) static const GTypeInfo object_info = { sizeof (GdkScreenClass), - (GBaseInitFunc) NULL, + (GBaseInitFunc) gdk_screen_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gdk_screen_class_init, NULL, /* class_finalize */ @@ -76,6 +78,7 @@ gdk_screen_class_init (GdkScreenClass *klass) parent_class = g_type_class_peek_parent (klass); object_class->dispose = gdk_screen_dispose; + object_class->finalize = gdk_screen_finalize; /** * GdkScreen::size-changed: @@ -98,6 +101,12 @@ gdk_screen_class_init (GdkScreenClass *klass) } static void +gdk_screen_init (GdkScreen *screen) +{ + screen->resolution = -1; +} + +static void gdk_screen_dispose (GObject *object) { GdkScreen *screen = GDK_SCREEN (object); @@ -115,6 +124,17 @@ gdk_screen_dispose (GObject *object) G_OBJECT_CLASS (parent_class)->dispose (object); } +static void +gdk_screen_finalize (GObject *object) +{ + GdkScreen *screen = GDK_SCREEN (object); + + if (screen->font_options) + cairo_font_options_destroy (screen->font_options); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + void _gdk_screen_close (GdkScreen *screen) { @@ -317,5 +337,96 @@ gdk_screen_height_mm (void) return gdk_screen_get_height_mm (gdk_screen_get_default ()); } +/** + * gdk_screen_set_font_options_libgtk_only: + * @screen: a #GdkScreen + * @options: a #cairo_font_options_t, or %NULL to unset any + * previously set default font options. + * + * Sets the default font options for the screen. These + * options will be set on any #PangoContext's newly created + * with gdk_pango_context_get_for_screen(). Changing the + * default set of font options does not affect contexts that + * have already been created. + * + * This function is not part of the GDK public API and is only + * for use by GTK+. + **/ +void +gdk_screen_set_font_options_libgtk_only (GdkScreen *screen, + const cairo_font_options_t *options) +{ + g_return_if_fail (GDK_IS_SCREEN (screen)); + + if (screen->font_options) + cairo_font_options_destroy (screen->font_options); + + if (options) + screen->font_options = cairo_font_options_copy (options); + else + screen->font_options = NULL; +} + +/** + * gdk_screen_get_font_options_libgtk_only: + * @screen: a #GdkScreen + * + * Gets any options previously set with gdk_screen_set_font_options_libgtk_only(). + * + * Return value: the current font options, or %NULL if no default + * font options have been set. + **/ +const cairo_font_options_t * +gdk_screen_get_font_options_libgtk_only (GdkScreen *screen) +{ + g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); + + return screen->font_options; +} + +/** + * gdk_screen_set_resolution_libgtk_only: + * @screen: a #GdkScreen + * @dpi: the resolution in "dots per inch". (Physical inches aren't actually + * involved; the terminology is conventional.) + + * Sets the resolution for font handling on the screen. This is a + * scale factor between points specified in a #PangoFontDescription + * and cairo units. The default value is 96, meaning that a 10 point + * font will be 13 units high. (10 * 96. / 72. = 13.3). + * + * This function is not part of the GDK public API and is only + * for use by GTK+. + **/ +void +gdk_screen_set_resolution_libgtk_only (GdkScreen *screen, + gdouble dpi) +{ + g_return_if_fail (GDK_IS_SCREEN (screen)); + + if (dpi >= 0) + screen->resolution = dpi; + else + screen->resolution = -1; +} + +/** + * gdk_screen_get_resolution_libgtk_only: + * @screen: a #GdkScreen + * + * Gets the resolution for font handling on the screen; see + * gdk_screen_set_resolution_libgtk_only() for full details. + * + * Return value: the current resolution, or -1 if no resolution + * has been set. + **/ +gdouble +gdk_screen_get_resolution_libgtk_only (GdkScreen *screen) +{ + g_return_val_if_fail (GDK_IS_SCREEN (screen), -1); + + return screen->resolution; +} + #define __GDK_SCREEN_C__ #include "gdkaliasdef.c" diff --git a/gdk/gdkscreen.h b/gdk/gdkscreen.h index 5a27cbe23..2d93a4194 100644 --- a/gdk/gdkscreen.h +++ b/gdk/gdkscreen.h @@ -24,6 +24,7 @@ #ifndef __GDK_SCREEN_H__ #define __GDK_SCREEN_H__ +#include <cairo.h> #include "gdk/gdktypes.h" #include "gdk/gdkdisplay.h" @@ -46,6 +47,9 @@ struct _GdkScreen GdkGC *normal_gcs[32]; GdkGC *exposure_gcs[32]; + + cairo_font_options_t *font_options; + double resolution; /* pixels/points scale factor for fonts */ }; struct _GdkScreenClass @@ -98,6 +102,14 @@ gboolean gdk_screen_get_setting (GdkScreen *screen, const gchar *name, GValue *value); +void gdk_screen_set_font_options_libgtk_only (GdkScreen *screen, + const cairo_font_options_t *options); +const cairo_font_options_t *gdk_screen_get_font_options_libgtk_only (GdkScreen *screen); + +void gdk_screen_set_resolution_libgtk_only (GdkScreen *screen, + gdouble dpi); +gdouble gdk_screen_get_resolution_libgtk_only (GdkScreen *screen); + G_END_DECLS #endif /* __GDK_SCREEN_H__ */ diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c index d4474c078..009916109 100644 --- a/gtk/gtksettings.c +++ b/gtk/gtksettings.c @@ -17,6 +17,9 @@ */ #include <config.h> + +#include <string.h> + #include "gtkmodules.h" #include "gtksettings.h" #include "gtkrc.h" @@ -100,6 +103,8 @@ static void settings_update_modules (GtkSettings *setting #ifdef GDK_WINDOWING_X11 static void settings_update_cursor_theme (GtkSettings *settings); +static void settings_update_resolution (GtkSettings *settings); +static void settings_update_font_options (GtkSettings *settings); #endif @@ -553,16 +558,20 @@ gtk_settings_notify (GObject *object, break; #ifdef GDK_WINDOWING_X11 case PROP_XFT_DPI: - case PROP_XFT_ANTIALIAS: - case PROP_XFT_HINTING: - case PROP_XFT_HINTSTYLE: - case PROP_XFT_RGBA: + settings_update_resolution (settings); /* This is a hack because with gtk_rc_reset_styles() doesn't get * widgets with gtk_widget_style_set(), and also causes more * recomputation than necessary. */ gtk_rc_reset_styles (GTK_SETTINGS (object)); break; + case PROP_XFT_ANTIALIAS: + case PROP_XFT_HINTING: + case PROP_XFT_HINTSTYLE: + case PROP_XFT_RGBA: + settings_update_font_options (settings); + gtk_rc_reset_styles (GTK_SETTINGS (object)); + break; case PROP_CURSOR_THEME_NAME: case PROP_CURSOR_THEME_SIZE: settings_update_cursor_theme (settings); @@ -1358,6 +1367,104 @@ settings_update_cursor_theme (GtkSettings *settings) gdk_x11_display_set_cursor_theme (display, theme, size); } + +static void +settings_update_font_options (GtkSettings *settings) +{ + gint hinting; + gchar *hint_style_str; + cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_DEFAULT; + gint antialias; + cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_DEFAULT; + gchar *rgba_str; + cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; + gint dpi_int; + double dpi; + cairo_font_options_t *options; + + g_object_get (settings, + "gtk-xft-antialias", &antialias, + "gtk-xft-hinting", &hinting, + "gtk-xft-hintstyle", &hint_style_str, + "gtk-xft-rgba", &rgba_str, + "gtk-xft-dpi", &dpi_int, + NULL); + + if (dpi_int > 0) + dpi = dpi_int / 1024.; + else + dpi = -1.; + + options = cairo_font_options_create (); + + if (hinting >= 0 && !hinting) + { + hint_style = CAIRO_HINT_STYLE_NONE; + } + else if (hint_style_str) + { + if (strcmp (hint_style_str, "hintnone") == 0) + hint_style = CAIRO_HINT_STYLE_NONE; + else if (strcmp (hint_style_str, "hintslight") == 0) + hint_style = CAIRO_HINT_STYLE_SLIGHT; + else if (strcmp (hint_style_str, "hintmedium") == 0) + hint_style = CAIRO_HINT_STYLE_MEDIUM; + else if (strcmp (hint_style_str, "hintfull") == 0) + hint_style = CAIRO_HINT_STYLE_FULL; + } + + if (hint_style_str) + g_free (hint_style_str); + + cairo_font_options_set_hint_style (options, hint_style); + + if (rgba_str) + { + if (strcmp (rgba_str, "rgb") == 0) + subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB; + else if (strcmp (rgba_str, "bgr") == 0) + subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR; + else if (strcmp (rgba_str, "vrgb") == 0) + subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB; + else if (strcmp (rgba_str, "vbgr") == 0) + subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR; + + g_free (rgba_str); + } + + cairo_font_options_set_subpixel_order (options, subpixel_order); + + if (antialias >= 0 && !antialias) + antialias_mode = CAIRO_ANTIALIAS_NONE; + else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT) + antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL; + else if (antialias >= 0) + antialias_mode = CAIRO_ANTIALIAS_GRAY; + + cairo_font_options_set_antialias (options, antialias_mode); + + gdk_screen_set_font_options_libgtk_only (settings->screen, options); + + cairo_font_options_destroy (options); +} + +static void +settings_update_resolution (GtkSettings *settings) +{ + gint dpi_int; + double dpi; + + g_object_get (settings, + "gtk-xft-dpi", &dpi_int, + NULL); + + if (dpi_int > 0) + dpi = dpi_int / 1024.; + else + dpi = -1.; + + gdk_screen_set_resolution_libgtk_only (settings->screen, dpi); +} #endif #define __GTK_SETTINGS_C__ diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index cb763b850..4125db088 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -5197,91 +5197,10 @@ static void update_pango_context (GtkWidget *widget, PangoContext *context) { -#ifdef GDK_WINDOWING_X11 - GtkSettings *settings; - gint hinting; - gchar *hint_style_str; - cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_DEFAULT; - gint antialias; - cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_DEFAULT; - gchar *rgba_str; - cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT; - gint dpi; - cairo_font_options_t *options; -#endif - pango_context_set_font_description (context, widget->style->font_desc); pango_context_set_base_dir (context, gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ? PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL); - -#ifdef GDK_WINDOWING_X11 - settings = gtk_widget_get_settings (widget); - g_object_get (settings, - "gtk-xft-antialias", &antialias, - "gtk-xft-hinting", &hinting, - "gtk-xft-hintstyle", &hint_style_str, - "gtk-xft-rgba", &rgba_str, - "gtk-xft-dpi", &dpi, - NULL); - - if (dpi > 0) - pango_cairo_context_set_resolution (context, dpi / 1024.); - else - pango_cairo_context_set_resolution (context, -1.); - - options = cairo_font_options_create (); - - if (hinting >= 0 && !hinting) - { - hint_style = CAIRO_HINT_STYLE_NONE; - } - else if (hint_style_str) - { - if (strcmp (hint_style_str, "hintnone") == 0) - hint_style = CAIRO_HINT_STYLE_NONE; - else if (strcmp (hint_style_str, "hintslight") == 0) - hint_style = CAIRO_HINT_STYLE_SLIGHT; - else if (strcmp (hint_style_str, "hintmedium") == 0) - hint_style = CAIRO_HINT_STYLE_MEDIUM; - else if (strcmp (hint_style_str, "hintfull") == 0) - hint_style = CAIRO_HINT_STYLE_FULL; - } - - if (hint_style_str) - g_free (hint_style_str); - - cairo_font_options_set_hint_style (options, hint_style); - - if (rgba_str) - { - if (strcmp (rgba_str, "rgb") == 0) - subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB; - else if (strcmp (rgba_str, "bgr") == 0) - subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR; - else if (strcmp (rgba_str, "vrgb") == 0) - subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB; - else if (strcmp (rgba_str, "vbgr") == 0) - subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR; - - g_free (rgba_str); - } - - cairo_font_options_set_subpixel_order (options, subpixel_order); - - if (antialias >= 0 && !antialias) - antialias_mode = CAIRO_ANTIALIAS_NONE; - else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT) - antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL; - else if (antialias >= 0) - antialias_mode = CAIRO_ANTIALIAS_GRAY; - - cairo_font_options_set_antialias (options, antialias_mode); - - pango_cairo_context_set_font_options (context, options); - - cairo_font_options_destroy (options); -#endif } static void @@ -5290,7 +5209,20 @@ gtk_widget_update_pango_context (GtkWidget *widget) PangoContext *context = gtk_widget_peek_pango_context (widget); if (context) - update_pango_context (widget, context); + { + GdkScreen *screen; + + update_pango_context (widget, context); + + screen = gtk_widget_get_screen_unchecked (widget); + if (screen) + { + pango_cairo_context_set_resolution (context, + gdk_screen_get_resolution_libgtk_only (screen)); + pango_cairo_context_set_font_options (context, + gdk_screen_get_font_options_libgtk_only (screen)); + } + } } /** |