summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Neumann <sven@gimp.org>2002-03-26 14:40:58 +0000
committerSven Neumann <neo@src.gnome.org>2002-03-26 14:40:58 +0000
commit6f623dc2dca270ef63f518a951411c1d614ffd4e (patch)
tree6980f1e973d0ed09c7fbabcc2f9087a926534973
parent233b328c26ea0ed3bccc9e93358549808531886a (diff)
downloadpango-6f623dc2dca270ef63f518a951411c1d614ffd4e.tar.gz
pango/pangoft2-private.h calculate average_char_width and
2002-03-26 Sven Neumann <sven@gimp.org> * pango/pangoft2-private.h * pango/pangoft2.c (pango_ft2_font_get_metrics): calculate average_char_width and average_digit_width by measuring sample layouts and cache font metrics per language just like PangoX does, #53425. * pango/pangoxft-font.c * pango/pangoxft-private.h: the same approach for average_char_width and average_digit_width as in PangoFT2, #53425.
-rw-r--r--ChangeLog11
-rw-r--r--ChangeLog.pre-1-1011
-rw-r--r--ChangeLog.pre-1-211
-rw-r--r--ChangeLog.pre-1-411
-rw-r--r--ChangeLog.pre-1-611
-rw-r--r--ChangeLog.pre-1-811
-rw-r--r--pango/pangoft2-private.h2
-rw-r--r--pango/pangoft2.c93
-rw-r--r--pango/pangoxft-font.c95
-rw-r--r--pango/pangoxft-private.h2
10 files changed, 232 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index 43b1ad44..c63b660f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2002-03-26 Sven Neumann <sven@gimp.org>
+
+ * pango/pangoft2-private.h
+ * pango/pangoft2.c (pango_ft2_font_get_metrics): calculate
+ average_char_width and average_digit_width by measuring sample layouts
+ and cache font metrics per language just like PangoX does, #53425.
+
+ * pango/pangoxft-font.c
+ * pango/pangoxft-private.h: the same approach for average_char_width
+ and average_digit_width as in PangoFT2, #53425.
+
Mon Mar 25 15:53:17 2002 Owen Taylor <otaylor@redhat.com>
* pango/modules.c (read_modules): Remove warning about
diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10
index 43b1ad44..c63b660f 100644
--- a/ChangeLog.pre-1-10
+++ b/ChangeLog.pre-1-10
@@ -1,3 +1,14 @@
+2002-03-26 Sven Neumann <sven@gimp.org>
+
+ * pango/pangoft2-private.h
+ * pango/pangoft2.c (pango_ft2_font_get_metrics): calculate
+ average_char_width and average_digit_width by measuring sample layouts
+ and cache font metrics per language just like PangoX does, #53425.
+
+ * pango/pangoxft-font.c
+ * pango/pangoxft-private.h: the same approach for average_char_width
+ and average_digit_width as in PangoFT2, #53425.
+
Mon Mar 25 15:53:17 2002 Owen Taylor <otaylor@redhat.com>
* pango/modules.c (read_modules): Remove warning about
diff --git a/ChangeLog.pre-1-2 b/ChangeLog.pre-1-2
index 43b1ad44..c63b660f 100644
--- a/ChangeLog.pre-1-2
+++ b/ChangeLog.pre-1-2
@@ -1,3 +1,14 @@
+2002-03-26 Sven Neumann <sven@gimp.org>
+
+ * pango/pangoft2-private.h
+ * pango/pangoft2.c (pango_ft2_font_get_metrics): calculate
+ average_char_width and average_digit_width by measuring sample layouts
+ and cache font metrics per language just like PangoX does, #53425.
+
+ * pango/pangoxft-font.c
+ * pango/pangoxft-private.h: the same approach for average_char_width
+ and average_digit_width as in PangoFT2, #53425.
+
Mon Mar 25 15:53:17 2002 Owen Taylor <otaylor@redhat.com>
* pango/modules.c (read_modules): Remove warning about
diff --git a/ChangeLog.pre-1-4 b/ChangeLog.pre-1-4
index 43b1ad44..c63b660f 100644
--- a/ChangeLog.pre-1-4
+++ b/ChangeLog.pre-1-4
@@ -1,3 +1,14 @@
+2002-03-26 Sven Neumann <sven@gimp.org>
+
+ * pango/pangoft2-private.h
+ * pango/pangoft2.c (pango_ft2_font_get_metrics): calculate
+ average_char_width and average_digit_width by measuring sample layouts
+ and cache font metrics per language just like PangoX does, #53425.
+
+ * pango/pangoxft-font.c
+ * pango/pangoxft-private.h: the same approach for average_char_width
+ and average_digit_width as in PangoFT2, #53425.
+
Mon Mar 25 15:53:17 2002 Owen Taylor <otaylor@redhat.com>
* pango/modules.c (read_modules): Remove warning about
diff --git a/ChangeLog.pre-1-6 b/ChangeLog.pre-1-6
index 43b1ad44..c63b660f 100644
--- a/ChangeLog.pre-1-6
+++ b/ChangeLog.pre-1-6
@@ -1,3 +1,14 @@
+2002-03-26 Sven Neumann <sven@gimp.org>
+
+ * pango/pangoft2-private.h
+ * pango/pangoft2.c (pango_ft2_font_get_metrics): calculate
+ average_char_width and average_digit_width by measuring sample layouts
+ and cache font metrics per language just like PangoX does, #53425.
+
+ * pango/pangoxft-font.c
+ * pango/pangoxft-private.h: the same approach for average_char_width
+ and average_digit_width as in PangoFT2, #53425.
+
Mon Mar 25 15:53:17 2002 Owen Taylor <otaylor@redhat.com>
* pango/modules.c (read_modules): Remove warning about
diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8
index 43b1ad44..c63b660f 100644
--- a/ChangeLog.pre-1-8
+++ b/ChangeLog.pre-1-8
@@ -1,3 +1,14 @@
+2002-03-26 Sven Neumann <sven@gimp.org>
+
+ * pango/pangoft2-private.h
+ * pango/pangoft2.c (pango_ft2_font_get_metrics): calculate
+ average_char_width and average_digit_width by measuring sample layouts
+ and cache font metrics per language just like PangoX does, #53425.
+
+ * pango/pangoxft-font.c
+ * pango/pangoxft-private.h: the same approach for average_char_width
+ and average_digit_width as in PangoFT2, #53425.
+
Mon Mar 25 15:53:17 2002 Owen Taylor <otaylor@redhat.com>
* pango/modules.c (read_modules): Remove warning about
diff --git a/pango/pangoft2-private.h b/pango/pangoft2-private.h
index 0a9ff03b..cbc06aac 100644
--- a/pango/pangoft2-private.h
+++ b/pango/pangoft2-private.h
@@ -71,6 +71,8 @@ struct _PangoFT2Font
PangoFontMap *fontmap;
PangoFontDescription *description;
+ GSList *metrics_by_lang;
+
/* If TRUE, font is in cache of recently unused fonts and not otherwise
* in use. */
gboolean in_cache;
diff --git a/pango/pangoft2.c b/pango/pangoft2.c
index 5c2aa891..aa5066cb 100644
--- a/pango/pangoft2.c
+++ b/pango/pangoft2.c
@@ -44,24 +44,29 @@
typedef struct _PangoFT2FontClass PangoFT2FontClass;
typedef struct _PangoFT2MetricsInfo PangoFT2MetricsInfo;
-typedef struct _PangoFT2ContextInfo PangoFT2ContextInfo;
struct _PangoFT2FontClass
{
PangoFontClass parent_class;
};
+struct _PangoFT2MetricsInfo
+{
+ const char *sample_str;
+ PangoFontMetrics *metrics;
+};
+
typedef struct
{
FT_Bitmap bitmap;
int bitmap_left;
int bitmap_top;
-} PangoFT2RenderedGlyph;
+} PangoFT2RenderedGlyph;
static PangoFontClass *parent_class; /* Parent class structure for PangoFT2Font */
static void pango_ft2_font_class_init (PangoFT2FontClass *class);
-static void pango_ft2_font_init (PangoFT2Font *xfont);
+static void pango_ft2_font_init (PangoFT2Font *ft2font);
static void pango_ft2_font_dispose (GObject *object);
static void pango_ft2_font_finalize (GObject *object);
@@ -282,6 +287,8 @@ pango_ft2_font_init (PangoFT2Font *ft2font)
ft2font->size = 0;
+ ft2font->metrics_by_lang = NULL;
+
ft2font->glyph_info = g_hash_table_new (NULL, NULL);
}
@@ -577,22 +584,68 @@ pango_ft2_font_get_kerning (PangoFont *font,
}
static PangoFontMetrics *
-pango_ft2_font_get_metrics (PangoFont *font,
- PangoLanguage *language)
+pango_ft2_font_get_metrics (PangoFont *font,
+ PangoLanguage *language)
{
- PangoFontMetrics *metrics;
- FT_Face face;
-
- face = pango_ft2_font_get_face (font);
+ PangoFT2Font *ft2font = PANGO_FT2_FONT (font);
+ PangoFT2MetricsInfo *info = NULL; /* Quiet gcc */
+ GSList *tmp_list;
- metrics = pango_font_metrics_new ();
+ const char *sample_str = pango_language_get_sample_string (language);
- metrics->ascent = PANGO_UNITS_26_6 (face->size->metrics.ascender);
- metrics->descent = PANGO_UNITS_26_6 (-face->size->metrics.descender);
- metrics->approximate_digit_width = PANGO_UNITS_26_6 (face->size->metrics.max_advance);
- metrics->approximate_char_width = PANGO_UNITS_26_6 (face->size->metrics.max_advance);
+ tmp_list = ft2font->metrics_by_lang;
+ while (tmp_list)
+ {
+ info = tmp_list->data;
+
+ if (info->sample_str == sample_str) /* We _don't_ need strcmp */
+ break;
+
+ tmp_list = tmp_list->next;
+ }
+
+ if (!tmp_list)
+ {
+ PangoContext *context;
+ PangoLayout *layout;
+ PangoRectangle extents;
+ FT_Face face = pango_ft2_font_get_face (font);
+
+ info = g_new (PangoFT2MetricsInfo, 1);
+ info->sample_str = sample_str;
+ info->metrics = pango_font_metrics_new ();
+
+ info->metrics->ascent = PANGO_UNITS_26_6 (face->size->metrics.ascender);
+ info->metrics->descent = PANGO_UNITS_26_6 (- face->size->metrics.descender);
+ info->metrics->approximate_char_width =
+ info->metrics->approximate_digit_width =
+ PANGO_UNITS_26_6 (face->size->metrics.max_advance);
- return pango_font_metrics_ref (metrics);
+ ft2font->metrics_by_lang = g_slist_prepend (ft2font->metrics_by_lang, info);
+
+ context = pango_context_new ();
+ pango_context_set_font_map (context, ft2font->fontmap);
+ pango_context_set_language (context, language);
+
+ layout = pango_layout_new (context);
+ pango_layout_set_font_description (layout, ft2font->description);
+
+ 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);
+
+ pango_layout_set_text (layout, "0123456789", -1);
+ pango_layout_get_extents (layout, NULL, &extents);
+
+ info->metrics->approximate_digit_width = extents.width / 10;
+
+ g_object_unref (G_OBJECT (layout));
+ g_object_unref (G_OBJECT (context));
+ }
+
+ return pango_font_metrics_ref (info->metrics);
}
static PangoCoverage *
@@ -665,6 +718,13 @@ pango_ft2_free_glyph_info_callback (gpointer key, gpointer value, gpointer data)
}
static void
+free_metrics_info (PangoFT2MetricsInfo *info)
+{
+ pango_font_metrics_unref (info->metrics);
+ g_free (info);
+}
+
+static void
pango_ft2_font_finalize (GObject *object)
{
PangoFT2Font *ft2font = (PangoFT2Font *)object;
@@ -682,6 +742,9 @@ pango_ft2_font_finalize (GObject *object)
g_object_unref (G_OBJECT (ft2font->fontmap));
+ g_slist_foreach (ft2font->metrics_by_lang, (GFunc)free_metrics_info, NULL);
+ g_slist_free (ft2font->metrics_by_lang);
+
g_hash_table_foreach_remove (ft2font->glyph_info,
pango_ft2_free_glyph_info_callback, object);
g_hash_table_destroy (ft2font->glyph_info);
diff --git a/pango/pangoxft-font.c b/pango/pangoxft-font.c
index 4ec646ac..ed35be84 100644
--- a/pango/pangoxft-font.c
+++ b/pango/pangoxft-font.c
@@ -25,7 +25,10 @@
#include "pangoxft-private.h"
#include "X11/Xft/XftFreetype.h"
+
+#include "pango-layout.h"
#include "pango-modules.h"
+#include "pango-utils.h"
#define PANGO_XFT_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_XFT_FONT, PangoXftFont))
#define PANGO_XFT_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_XFT_FONT, PangoXftFontClass))
@@ -34,11 +37,18 @@
#define PANGO_XFT_UNKNOWN_FLAG 0x10000000
-typedef struct _PangoXftFontClass PangoXftFontClass;
+typedef struct _PangoXftFontClass PangoXftFontClass;
+typedef struct _PangoXftMetricsInfo PangoXftMetricsInfo;
struct _PangoXftFontClass
{
- PangoFontClass parent_class;
+ PangoFontClass parent_class;
+};
+
+struct _PangoXftMetricsInfo
+{
+ const char *sample_str;
+ PangoFontMetrics *metrics;
};
static PangoFontClass *parent_class; /* Parent class structure for PangoXftFont */
@@ -93,6 +103,7 @@ pango_xft_font_get_type (void)
static void
pango_xft_font_init (PangoXftFont *xfont)
{
+ xfont->metrics_by_lang = NULL;
xfont->in_cache = FALSE;
}
@@ -386,18 +397,70 @@ pango_xft_picture_render (Display *display,
}
static PangoFontMetrics *
-pango_xft_font_get_metrics (PangoFont *font,
- PangoLanguage *language)
+pango_xft_font_get_metrics (PangoFont *font,
+ PangoLanguage *language)
{
- PangoFontMetrics *metrics = pango_font_metrics_new ();
- XftFont *xft_font = pango_xft_font_get_font (font);
+ PangoXftFont *xfont = PANGO_XFT_FONT (font);
+ PangoXftMetricsInfo *info = NULL; /* Quiet gcc */
+ GSList *tmp_list;
+
+ const char *sample_str = pango_language_get_sample_string (language);
+
+ tmp_list = xfont->metrics_by_lang;
+ while (tmp_list)
+ {
+ info = tmp_list->data;
+
+ if (info->sample_str == sample_str) /* We _don't_ need strcmp */
+ break;
+
+ tmp_list = tmp_list->next;
+ }
- metrics->ascent = PANGO_SCALE * xft_font->ascent;
- metrics->descent = PANGO_SCALE * xft_font->descent;
- metrics->approximate_digit_width = PANGO_SCALE * xft_font->max_advance_width;
- metrics->approximate_char_width = PANGO_SCALE * xft_font->max_advance_width;
+ if (!tmp_list)
+ {
+ PangoLayout *layout;
+ PangoRectangle extents;
+ PangoContext *context;
+ XftFont *xft_font = pango_xft_font_get_font (font);
+ Display *display;
+
+ _pango_xft_font_map_get_info (xfont->fontmap, &display, NULL);
+ context = pango_xft_get_context (display, 0);
- return metrics;
+ 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;
+
+ 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);
+
+ 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);
+
+ pango_layout_set_text (layout, "0123456789", -1);
+ pango_layout_get_extents (layout, NULL, &extents);
+
+ info->metrics->approximate_digit_width = extents.width / 10;
+
+ g_object_unref (G_OBJECT (layout));
+ g_object_unref (G_OBJECT (context));
+ }
+
+ return pango_font_metrics_ref (info->metrics);
}
static void
@@ -416,6 +479,13 @@ pango_xft_font_dispose (GObject *object)
}
static void
+free_metrics_info (PangoXftMetricsInfo *info)
+{
+ pango_font_metrics_unref (info->metrics);
+ g_free (info);
+}
+
+static void
pango_xft_font_finalize (GObject *object)
{
PangoXftFont *xfont = (PangoXftFont *)object;
@@ -433,6 +503,9 @@ pango_xft_font_finalize (GObject *object)
pango_font_description_free (xfont->description);
+ g_slist_foreach (xfont->metrics_by_lang, (GFunc)free_metrics_info, NULL);
+ g_slist_free (xfont->metrics_by_lang);
+
if (xfont->xft_font)
XftFontClose (display, xfont->xft_font);
else
diff --git a/pango/pangoxft-private.h b/pango/pangoxft-private.h
index 57db3efa..ac0bb44a 100644
--- a/pango/pangoxft-private.h
+++ b/pango/pangoxft-private.h
@@ -40,6 +40,8 @@ struct _PangoXftFont
PangoFontDescription *description;
PangoOTInfo *ot_info;
+ GSList *metrics_by_lang;
+
guint16 mini_width;
guint16 mini_height;
guint16 mini_pad;