diff options
author | Owen Taylor <otaylor@redhat.com> | 2002-08-06 03:10:05 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2002-08-06 03:10:05 +0000 |
commit | 4b1d623ea4e751b2038588c894a19c0589840f4b (patch) | |
tree | a0e18bf1e34121d5af3fad5298e5277fc5b741ff /pango | |
parent | 315a290c808d06d8502020e35c68925ee5f1afa5 (diff) | |
download | pango-4b1d623ea4e751b2038588c894a19c0589840f4b.tar.gz |
Export.
Mon Aug 5 21:54:21 2002 Owen Taylor <otaylor@redhat.com>
* pango/pangoxft-fontmap.c (pango_xft_get_font_map): Export.
* pango/pango-context.[ch]: Add pango_context_get_fontmap(),
allow fontmap = NULL for pango_context_set_fontmap().
* pango/pangoxft-font.c pango/pangoxft-fontmap.c
(pango_xft_font_get_metrics): More work on allowing
displays to be shut down, while leaving basically
working fonts behind.
Diffstat (limited to 'pango')
-rw-r--r-- | pango/pango-context.c | 8 | ||||
-rw-r--r-- | pango/pangoxft-font.c | 81 | ||||
-rw-r--r-- | pango/pangoxft-fontmap.c | 71 | ||||
-rw-r--r-- | pango/pangoxft.h | 2 |
4 files changed, 122 insertions, 40 deletions
diff --git a/pango/pango-context.c b/pango/pango-context.c index 7ed5b5ef..da41b435 100644 --- a/pango/pango-context.c +++ b/pango/pango-context.c @@ -157,13 +157,15 @@ void pango_context_set_font_map (PangoContext *context, PangoFontMap *font_map) { - g_return_if_fail (context != NULL); - g_return_if_fail (font_map != NULL); + g_return_if_fail (PANGO_IS_CONTEXT (context)); + g_return_if_fail (!font_map || PANGO_IS_FONT_MAP (font_map)); if (context->font_map) g_object_unref (G_OBJECT (context->font_map)); - g_object_ref (G_OBJECT (font_map)); + if (font_map) + g_object_ref (G_OBJECT (font_map)); + context->font_map = font_map; } diff --git a/pango/pangoxft-font.c b/pango/pangoxft-font.c index 9f505a7e..f24e385e 100644 --- a/pango/pangoxft-font.c +++ b/pango/pangoxft-font.c @@ -151,6 +151,8 @@ get_mini_font (PangoFont *font) { PangoXftFont *xfont = (PangoXftFont *)font; + g_assert (xfont->fontmap); + if (!xfont->mini_font) { Display *display; @@ -263,6 +265,9 @@ pango_xft_real_render (Display *display, XftCharSpec chars[4]; /* for unknown */ int n_xft_glyph = 0; + if (!xfont->fontmap) /* Display closed */ + return; + #define FLUSH_GLYPHS() G_STMT_START { \ if (n_xft_glyph) \ { \ @@ -435,42 +440,48 @@ pango_xft_font_get_metrics (PangoFont *font, PangoLayout *layout; PangoRectangle extents; PangoContext *context; - XftFont *xft_font = pango_xft_font_get_font (font); + XftFont *xft_font; Display *display; - - _pango_xft_font_map_get_info (xfont->fontmap, &display, NULL); - context = pango_xft_get_context (display, 0); - - info = g_new (PangoXftMetricsInfo, 1); - info->sample_str = sample_str; - info->metrics = pango_font_metrics_new (); - - info->metrics->ascent = PANGO_SCALE * xft_font->ascent; - info->metrics->descent = PANGO_SCALE * xft_font->descent; - info->metrics->approximate_char_width = - info->metrics->approximate_digit_width = - PANGO_SCALE * xft_font->max_advance_width; + info = g_new0 (PangoXftMetricsInfo, 1); xfont->metrics_by_lang = g_slist_prepend (xfont->metrics_by_lang, info); - pango_context_set_language (context, language); - layout = pango_layout_new (context); - pango_layout_set_font_description (layout, xfont->description); + + if (xfont->fontmap) + { + xft_font = pango_xft_font_get_font (font); + + _pango_xft_font_map_get_info (xfont->fontmap, &display, NULL); + context = pango_xft_get_context (display, 0); + + info->sample_str = sample_str; + info->metrics = pango_font_metrics_new (); + + info->metrics->ascent = PANGO_SCALE * xft_font->ascent; + info->metrics->descent = PANGO_SCALE * xft_font->descent; + info->metrics->approximate_char_width = + info->metrics->approximate_digit_width = + PANGO_SCALE * xft_font->max_advance_width; + + pango_context_set_language (context, language); + layout = pango_layout_new (context); + pango_layout_set_font_description (layout, xfont->description); - pango_layout_set_text (layout, sample_str, -1); - pango_layout_get_extents (layout, NULL, &extents); + pango_layout_set_text (layout, sample_str, -1); + pango_layout_get_extents (layout, NULL, &extents); - info->metrics->approximate_char_width = - extents.width / g_utf8_strlen (sample_str, -1); + info->metrics->approximate_char_width = + extents.width / g_utf8_strlen (sample_str, -1); - pango_layout_set_text (layout, "0123456789", -1); - pango_layout_get_extents (layout, NULL, &extents); + pango_layout_set_text (layout, "0123456789", -1); + pango_layout_get_extents (layout, NULL, &extents); - info->metrics->approximate_digit_width = extents.width / 10; + info->metrics->approximate_digit_width = extents.width / 10; - g_object_unref (G_OBJECT (layout)); - g_object_unref (G_OBJECT (context)); + g_object_unref (G_OBJECT (layout)); + g_object_unref (G_OBJECT (context)); + } } return pango_font_metrics_ref (info->metrics); @@ -502,11 +513,9 @@ static void pango_xft_font_finalize (GObject *object) { PangoXftFont *xfont = (PangoXftFont *)object; - Display *display; - - _pango_xft_font_map_get_info (xfont->fontmap, &display, NULL); - _pango_xft_font_map_remove (xfont->fontmap, xfont); + if (xfont->fontmap) + _pango_xft_font_map_remove (xfont->fontmap, xfont); if (xfont->mini_font) g_object_unref (xfont->mini_font); @@ -517,7 +526,12 @@ pango_xft_font_finalize (GObject *object) g_slist_free (xfont->metrics_by_lang); if (xfont->xft_font) - XftFontClose (display, xfont->xft_font); + { + Display *display; + + _pango_xft_font_map_get_info (xfont->fontmap, &display, NULL); + XftFontClose (display, xfont->xft_font); + } FcPatternDestroy (xfont->font_pattern); @@ -594,6 +608,9 @@ pango_xft_font_get_glyph_extents (PangoFont *font, XGlyphInfo extents; Display *display; + if (!xfont->fontmap) /* Display closed */ + goto fallback; + _pango_xft_font_map_get_info (xfont->fontmap, &display, NULL); if (glyph == (PangoGlyph)-1) @@ -642,6 +659,8 @@ pango_xft_font_get_glyph_extents (PangoFont *font, } else { + fallback: + if (ink_rect) { ink_rect->x = 0; diff --git a/pango/pangoxft-fontmap.c b/pango/pangoxft-fontmap.c index abbe2791..eee35a9b 100644 --- a/pango/pangoxft-fontmap.c +++ b/pango/pangoxft-fontmap.c @@ -237,7 +237,18 @@ pango_xft_find_font_map (Display *display, return NULL; } -static PangoFontMap * +/** + * pango_xft_get_font_map: + * @display: an X display + * @screen: the screen number of a screen within @display + * + * Returns the PangoXftFontmap for the given display and screen. + * The fontmap is owned by Pango and will be valid until + * the display is closed. + * + * Return value: a #PangoFontMap object, owned by Pango. + **/ +PangoFontMap * pango_xft_get_font_map (Display *display, int screen) { @@ -282,6 +293,17 @@ pango_xft_get_font_map (Display *display, return PANGO_FONT_MAP (xfontmap); } +static void +cleanup_font (gpointer key, + PangoXftFont *xfont, + PangoXftFontMap *xfontmap) +{ + if (xfont->xft_font) + XftFontClose (xfontmap->display, xfont->xft_font); + + xfont->fontmap = NULL; +} + /** * pango_xft_shutdown_display: * @display: an X display @@ -295,11 +317,20 @@ pango_xft_shutdown_display (Display *display, int screen) { PangoFontMap *fontmap; - + fontmap = pango_xft_find_font_map (display, screen); if (fontmap) { + PangoXftFontMap *xfontmap = PANGO_XFT_FONT_MAP (fontmap); + fontmaps = g_slist_remove (fontmaps, fontmap); + pango_xft_font_map_cache_clear (xfontmap); + + g_hash_table_foreach (xfontmap->fonts, (GHFunc)cleanup_font, fontmap); + g_hash_table_destroy (xfontmap->fonts); + xfontmap->fonts = NULL; + + xfontmap->display = NULL; g_object_unref (G_OBJECT (fontmap)); } } @@ -394,6 +425,9 @@ pango_xft_font_map_finalize (GObject *object) g_queue_free (xfontmap->freed_fonts); g_hash_table_destroy (xfontmap->fontset_hash); g_hash_table_destroy (xfontmap->coverage_hash); + + if (xfontmap->fonts) + g_hash_table_destroy (xfontmap->fonts); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -460,6 +494,16 @@ pango_xft_font_map_list_families (PangoFontMap *fontmap, int i; int count; + if (!xfontmap->display) + { + if (families) + *families = NULL; + if (n_families) + n_families = 0; + + return; + } + if (xfontmap->n_families < 0) { fontset = XftListFonts (xfontmap->display, xfontmap->screen, @@ -573,6 +617,15 @@ pango_xft_font_map_new_font (PangoFontMap *fontmap, { PangoXftFontMap *xfontmap = (PangoXftFontMap *)fontmap; PangoXftFont *font; + + /* Returning NULL here actually violates a contract + * that loading load_font() will never return NULL. + * We probably should actually create a dummy + * font that doesn't draw anything and has empty + * metrics. + */ + if (!xfontmap->display) + return NULL; /* Look up cache */ font = g_hash_table_lookup (xfontmap->fonts, match); @@ -672,6 +725,8 @@ pango_xft_font_map_load_font (PangoFontMap *fontmap, const PangoFontDescription *description) { PangoXftPatternSet *patterns = pango_xft_font_map_get_patterns (fontmap, context, description); + if (!patterns) + return NULL; if (patterns->n_patterns > 0) return pango_xft_font_map_new_font (fontmap, patterns->patterns[0]); @@ -700,12 +755,17 @@ pango_xft_font_map_load_fontset (PangoFontMap *fontmap, PangoFontsetSimple *simple; int i; PangoXftPatternSet *patterns = pango_xft_font_map_get_patterns (fontmap, context, desc); + if (!patterns) + return NULL; simple = pango_fontset_simple_new (language); for (i = 0; i < patterns->n_patterns; i++) - pango_fontset_simple_append (simple, - pango_xft_font_map_new_font (fontmap, patterns->patterns[i])); + { + PangoFont *font = pango_xft_font_map_new_font (fontmap, patterns->patterns[i]); + if (font) + pango_fontset_simple_append (simple, font); + } return PANGO_FONTSET (simple); } @@ -790,7 +850,6 @@ _pango_xft_font_map_get_info (PangoFontMap *fontmap, *display = xfontmap->display; if (screen) *screen = xfontmap->screen; - } @@ -986,7 +1045,7 @@ pango_xft_family_list_faces (PangoFontFamily *family, FcFontSet *fontset; int i; - if (is_alias_family (xfamily->family_name)) + if (is_alias_family (xfamily->family_name) || !xfontmap->display) { xfamily->n_faces = 4; xfamily->faces = g_new (PangoXftFace *, xfamily->n_faces); diff --git a/pango/pangoxft.h b/pango/pangoxft.h index d6b08f2a..25cb30b5 100644 --- a/pango/pangoxft.h +++ b/pango/pangoxft.h @@ -44,6 +44,8 @@ typedef void (*PangoXftSubstituteFunc) (FcPattern *pattern, /* Calls for applications */ +PangoFontMap *pango_xft_get_font_map (Display *display, + int screen); PangoContext *pango_xft_get_context (Display *display, int screen); void pango_xft_shutdown_display (Display *display, |