diff options
Diffstat (limited to 'gdk')
-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 |
4 files changed, 152 insertions, 2 deletions
diff --git a/gdk/gdk.symbols b/gdk/gdk.symbols index 06bb4256e5..c8c25e88c9 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 52dcfebd41..d1649e1ef9 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 8e08e5363b..b08cf725a6 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 5a27cbe232..2d93a41944 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__ */ |