From 148038f3f6122a0c1335bf1e43f5d5ab94945df4 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Thu, 24 Mar 2005 16:57:24 +0000 Subject: Yeah, I suppose this branch isn't really supposed to be maintained any longer. But just for completeness' sake... 2005-03-24 Tor Lillqvist * modules/*/Makefile.am (INCLUDES): Remove extra slash. 2004-12-18 Tor Lillqvist * pango/pangowin32-private.h * pango/pangowin32.c (pango_win32_font_get_metrics): Cache metrics by language, like the other backends do. Don't try to get the width of the 0..9 digit string if the font doesn't cover digits. --- ChangeLog | 11 ++++ ChangeLog.pre-1-10 | 11 ++++ modules/arabic/Makefile.am | 2 +- modules/basic/Makefile.am | 2 +- modules/hangul/Makefile.am | 2 +- modules/hebrew/Makefile.am | 2 +- modules/indic/Makefile.am | 2 +- modules/thai/Makefile.am | 2 +- pango/pangowin32-private.h | 2 + pango/pangowin32.c | 137 +++++++++++++++++++++++++++++---------------- 10 files changed, 120 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index efe0092f..c60bcf45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-03-24 Tor Lillqvist + + * modules/*/Makefile.am (INCLUDES): Remove extra slash. + +2004-12-18 Tor Lillqvist + + * pango/pangowin32-private.h + * pango/pangowin32.c (pango_win32_font_get_metrics): Cache metrics + by language, like the other backends do. Don't try to get the + width of the 0..9 digit string if the font doesn't cover digits. + Wed Dec 15 18:50:18 2004 Owen Taylor * modules/indic/indic-fc.c modules/indic/indic-ot.h: diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10 index efe0092f..c60bcf45 100644 --- a/ChangeLog.pre-1-10 +++ b/ChangeLog.pre-1-10 @@ -1,3 +1,14 @@ +2005-03-24 Tor Lillqvist + + * modules/*/Makefile.am (INCLUDES): Remove extra slash. + +2004-12-18 Tor Lillqvist + + * pango/pangowin32-private.h + * pango/pangowin32.c (pango_win32_font_get_metrics): Cache metrics + by language, like the other backends do. Don't try to get the + width of the 0..9 digit string if the font doesn't cover digits. + Wed Dec 15 18:50:18 2004 Owen Taylor * modules/indic/indic-fc.c modules/indic/indic-ot.h: diff --git a/modules/arabic/Makefile.am b/modules/arabic/Makefile.am index 3fe6fd38..217f362f 100644 --- a/modules/arabic/Makefile.am +++ b/modules/arabic/Makefile.am @@ -8,7 +8,7 @@ INCLUDES = \ -DG_DISABLE_DEPRECATED \ $(PANGO_DEBUG_FLAGS) \ -I$(top_srcdir) \ - -I$(top_srcdir)/pango/ \ + -I$(top_srcdir)/pango \ $(GLIB_CFLAGS) moduledir = $(libdir)/pango/$(PANGO_MODULE_VERSION)/modules diff --git a/modules/basic/Makefile.am b/modules/basic/Makefile.am index b35e8e1a..440cafa4 100644 --- a/modules/basic/Makefile.am +++ b/modules/basic/Makefile.am @@ -12,7 +12,7 @@ INCLUDES = \ -DG_DISABLE_DEPRECATED \ $(PANGO_DEBUG_FLAGS) \ -I$(top_srcdir) \ - -I$(top_srcdir)/pango/ \ + -I$(top_srcdir)/pango \ $(GLIB_CFLAGS) if PLATFORM_WIN32 diff --git a/modules/hangul/Makefile.am b/modules/hangul/Makefile.am index e6f82b45..0804ae62 100644 --- a/modules/hangul/Makefile.am +++ b/modules/hangul/Makefile.am @@ -8,7 +8,7 @@ INCLUDES = \ -DG_DISABLE_DEPRECATED \ $(PANGO_DEBUG_FLAGS) \ -I$(top_srcdir) \ - -I$(top_srcdir)/pango/ \ + -I$(top_srcdir)/pango \ $(GLIB_CFLAGS) if PLATFORM_WIN32 diff --git a/modules/hebrew/Makefile.am b/modules/hebrew/Makefile.am index 7f9297d1..5bc7e36f 100644 --- a/modules/hebrew/Makefile.am +++ b/modules/hebrew/Makefile.am @@ -8,7 +8,7 @@ INCLUDES = \ -DG_DISABLE_DEPRECATED \ $(PANGO_DEBUG_FLAGS) \ -I$(top_srcdir) \ - -I$(top_srcdir)/pango/ \ + -I$(top_srcdir)/pango \ $(GLIB_CFLAGS) moduledir = $(libdir)/pango/$(PANGO_MODULE_VERSION)/modules diff --git a/modules/indic/Makefile.am b/modules/indic/Makefile.am index 38614d72..035ca4a6 100644 --- a/modules/indic/Makefile.am +++ b/modules/indic/Makefile.am @@ -8,7 +8,7 @@ INCLUDES = \ -DG_DISABLE_DEPRECATED \ $(PANGO_DEBUG_FLAGS) \ -I$(top_srcdir) \ - -I$(top_srcdir)/pango/ \ + -I$(top_srcdir)/pango \ $(GLIB_CFLAGS) if PLATFORM_WIN32 diff --git a/modules/thai/Makefile.am b/modules/thai/Makefile.am index 2db1bee5..571e54c5 100644 --- a/modules/thai/Makefile.am +++ b/modules/thai/Makefile.am @@ -8,7 +8,7 @@ INCLUDES = \ -DG_DISABLE_DEPRECATED \ $(PANGO_DEBUG_FLAGS) \ -I$(top_srcdir) \ - -I$(top_srcdir)/pango/ \ + -I$(top_srcdir)/pango \ $(GLIB_CFLAGS) if PLATFORM_WIN32 diff --git a/pango/pangowin32-private.h b/pango/pangowin32-private.h index b1014214..e51f2d55 100644 --- a/pango/pangowin32-private.h +++ b/pango/pangowin32-private.h @@ -75,6 +75,8 @@ struct _PangoWin32Font LOGFONT logfont; int size; + GSList *metrics_by_lang; + PangoFontMap *fontmap; /* Written by pango_win32_get_hfont: */ diff --git a/pango/pangowin32.c b/pango/pangowin32.c index 9b95730d..05a8357f 100644 --- a/pango/pangowin32.c +++ b/pango/pangowin32.c @@ -46,12 +46,19 @@ OSVERSIONINFO pango_win32_os_version_info; gboolean pango_win32_debug = FALSE; typedef struct _PangoWin32FontClass PangoWin32FontClass; +typedef struct _PangoWin32MetricsInfo PangoWin32MetricsInfo; struct _PangoWin32FontClass { PangoFontClass parent_class; }; +struct _PangoWin32MetricsInfo +{ + const char *sample_str; + PangoFontMetrics *metrics; +}; + static void pango_win32_font_dispose (GObject *object); static void pango_win32_font_finalize (GObject *object); @@ -145,6 +152,8 @@ pango_win32_font_init (PangoWin32Font *win32font) { win32font->size = -1; + win32font->metrics_by_lang = NULL; + win32font->glyph_info = g_hash_table_new_full (NULL, NULL, NULL, g_free); } @@ -500,61 +509,85 @@ static PangoFontMetrics * pango_win32_font_get_metrics (PangoFont *font, PangoLanguage *language) { - HFONT hfont; - TEXTMETRIC tm; - PangoLayout *layout; - PangoRectangle extents; - PangoContext *context; - PangoFontMetrics *metrics; - - metrics = pango_font_metrics_new (); - - metrics->ascent = 0; - metrics->descent = 0; - metrics->approximate_digit_width = 0; - metrics->approximate_char_width = 0; + PangoWin32MetricsInfo *info = NULL; /* Quiet gcc */ + PangoWin32Font *win32font = (PangoWin32Font *)font; + GSList *tmp_list; + + const char *sample_str = pango_language_get_sample_string (language); - hfont = pango_win32_get_hfont (font); + tmp_list = win32font->metrics_by_lang; + while (tmp_list) + { + info = tmp_list->data; + + if (info->sample_str == sample_str) /* We _don't_ need strcmp */ + break; - if (hfont != NULL) + tmp_list = tmp_list->next; + } + + if (!tmp_list) { - PangoFontDescription *font_desc; + HFONT hfont; + PangoFontMetrics *metrics; + + info = g_new (PangoWin32MetricsInfo, 1); + win32font->metrics_by_lang = g_slist_prepend (win32font->metrics_by_lang, info); + + info->sample_str = sample_str; + info->metrics = metrics = pango_font_metrics_new (); + + hfont = pango_win32_get_hfont (font); + if (hfont != NULL) + { + PangoCoverage *coverage; + TEXTMETRIC tm; - SelectObject (pango_win32_hdc, hfont); - GetTextMetrics (pango_win32_hdc, &tm); + SelectObject (pango_win32_hdc, hfont); + GetTextMetrics (pango_win32_hdc, &tm); - metrics->ascent = tm.tmAscent * PANGO_SCALE; - metrics->descent = tm.tmDescent * PANGO_SCALE; - metrics->approximate_char_width = tm.tmAveCharWidth * PANGO_SCALE; + metrics->ascent = tm.tmAscent * PANGO_SCALE; + metrics->descent = tm.tmDescent * PANGO_SCALE; + metrics->approximate_char_width = tm.tmAveCharWidth * PANGO_SCALE; - /* lovely copy&paste programming (from pangox.c) FIXME: This is - * sort of a sledgehammer solution, if we cached the results, - * like the other backends did, it wouldn't big a huge performance - * problem. Get the avg. width of the chars in "0123456789" - */ - context = pango_win32_get_context (); - pango_context_set_language (context, language); - font_desc = pango_font_describe (font); - pango_context_set_font_description (context, font_desc); - layout = pango_layout_new (context); - pango_layout_set_text (layout, "0123456789", -1); - metrics->approximate_digit_width = max_glyph_width (layout); - - /* FIXME: Should get the real values from the TrueType font file */ - metrics->underline_position = -2 * PANGO_SCALE; - metrics->underline_thickness = 1 * PANGO_SCALE; - metrics->strikethrough_thickness = metrics->underline_thickness; - /* Really really wild guess */ - metrics->strikethrough_position = metrics->ascent / 3; - - pango_font_description_free (font_desc); - g_object_unref (layout); - g_object_unref (context); - } + coverage = pango_win32_font_get_coverage (font, language); + if (pango_coverage_get (coverage, '0') != PANGO_COVERAGE_NONE && + pango_coverage_get (coverage, '9') != PANGO_COVERAGE_NONE) + { + PangoContext *context; + PangoFontDescription *font_desc; + PangoLayout *layout; + + /* Get the average width of the chars in "0123456789" */ + context = pango_win32_get_context (); + pango_context_set_language (context, language); + font_desc = pango_font_describe (font); + pango_context_set_font_description (context, font_desc); + layout = pango_layout_new (context); + pango_layout_set_text (layout, "0123456789", -1); + + metrics->approximate_digit_width = max_glyph_width (layout); + + pango_font_description_free (font_desc); + g_object_unref (layout); + g_object_unref (context); + } + else + metrics->approximate_digit_width = metrics->approximate_char_width; - return metrics; -} + pango_coverage_unref (coverage); + /* FIXME: Should get the real values from the TrueType font file */ + metrics->underline_position = -2 * PANGO_SCALE; + metrics->underline_thickness = 1 * PANGO_SCALE; + metrics->strikethrough_thickness = metrics->underline_thickness; + /* Really really wild guess */ + metrics->strikethrough_position = metrics->ascent / 3; + } + } + + return pango_font_metrics_ref (info->metrics); +} /** * pango_win32_font_logfont: @@ -595,6 +628,13 @@ pango_win32_font_dispose (GObject *object) G_OBJECT_CLASS (pango_win32_font_parent_class)->dispose (object); } +static void +free_metrics_info (PangoWin32MetricsInfo *info) +{ + pango_font_metrics_unref (info->metrics); + g_free (info); +} + static void pango_win32_font_finalize (GObject *object) { @@ -604,6 +644,9 @@ pango_win32_font_finalize (GObject *object) if (win32font->hfont != NULL) pango_win32_font_cache_unload (cache, win32font->hfont); + g_slist_foreach (win32font->metrics_by_lang, (GFunc)free_metrics_info, NULL); + g_slist_free (win32font->metrics_by_lang); + if (win32font->win32face) pango_win32_font_entry_remove (win32font->win32face, PANGO_FONT (win32font)); -- cgit v1.2.1