summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2006-05-22 20:25:54 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2006-05-22 20:25:54 +0000
commitd0ca71f5d17074f8ed87f3f2e5d7536ab207830d (patch)
tree9093028842c1862dc76088e1237f7df011e2edec
parentec8d35bf511a8dcdd612850917e1e9ae9b36e1d0 (diff)
downloadpango-d0ca71f5d17074f8ed87f3f2e5d7536ab207830d.tar.gz
Bug 342525 – With PangoFc and PangoWin32, approximate digit width is not
2006-05-22 Behdad Esfahbod <behdad@gnome.org> Bug 342525 – With PangoFc and PangoWin32, approximate digit width is not what it says * pango/pangocairo-win32font.c (max_glyph_width), (create_metrics_for_context): Use max digit width instead of average. Reverted the following changes: * pango/pangofc-font.c (pango_fc_font_create_metrics_for_context): Likewise for PangoFc. Compute average instead of max. (max_glpyh_with): Now unused, drop. * pango/pangowin32.c (pango_win32_font_get_metrics): Calculate average digit width correctly, not as max of the digit widths. (#342525) Note that this code doesn't really get much used currently (instead the code in pangocairo-win32font.c is used), fixed only for completeness. (max_glpyh_with): Now unused, drop.
-rw-r--r--ChangeLog21
-rw-r--r--pango/pangocairo-win32font.c28
-rw-r--r--pango/pangofc-font.c31
-rw-r--r--pango/pangowin32.c28
4 files changed, 99 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index fe666f9b..d266d04c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
2006-05-22 Behdad Esfahbod <behdad@gnome.org>
+ Bug 342525 – With PangoFc and PangoWin32, approximate digit width is
+ not what it says
+
+ * pango/pangocairo-win32font.c (max_glyph_width),
+ (create_metrics_for_context): Use max digit width instead of average.
+
+ Reverted the following changes:
+
+ * pango/pangofc-font.c (pango_fc_font_create_metrics_for_context):
+ Likewise for PangoFc. Compute average instead of max.
+ (max_glpyh_with): Now unused, drop.
+
+ * pango/pangowin32.c (pango_win32_font_get_metrics): Calculate
+ average digit width correctly, not as max of the digit
+ widths. (#342525) Note that this code doesn't really get much used
+ currently (instead the code in pangocairo-win32font.c is used),
+ fixed only for completeness.
+ (max_glpyh_with): Now unused, drop.
+
+2006-05-22 Behdad Esfahbod <behdad@gnome.org>
+
* pango/pango-font.h, pango/fonts.c: New function
pango_font_describe_with_absolute_size().
diff --git a/pango/pangocairo-win32font.c b/pango/pangocairo-win32font.c
index a7ef250a..53ced191 100644
--- a/pango/pangocairo-win32font.c
+++ b/pango/pangocairo-win32font.c
@@ -268,6 +268,30 @@ pango_cairo_win32_font_get_glyph_extents (PangoFont *font,
*logical_rect = info->logical_rect;
}
+static int
+max_glyph_width (PangoLayout *layout)
+{
+ int max_width = 0;
+ GSList *l, *r;
+
+ for (l = pango_layout_get_lines (layout); l; l = l->next)
+ {
+ PangoLayoutLine *line = l->data;
+
+ for (r = line->runs; r; r = r->next)
+ {
+ PangoGlyphString *glyphs = ((PangoGlyphItem *)r->data)->glyphs;
+ int i;
+
+ for (i = 0; i < glyphs->num_glyphs; i++)
+ if (glyphs->glyphs[i].geometry.width > max_width)
+ max_width = glyphs->glyphs[i].geometry.width;
+ }
+ }
+
+ return max_width;
+}
+
static PangoFontMetrics *
create_metrics_for_context (PangoFont *font,
PangoContext *context)
@@ -316,9 +340,7 @@ create_metrics_for_context (PangoFont *font,
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);
-
- metrics->approximate_digit_width = extents.width / 10;
+ metrics->approximate_digit_width = max_glyph_width (layout);
pango_font_description_free (font_desc);
g_object_unref (layout);
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index da9b9754..b2abb694 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -407,6 +407,30 @@ get_face_metrics (PangoFcFont *fcfont,
PANGO_FC_FONT_UNLOCK_FACE (fcfont);
}
+static int
+max_glyph_width (PangoLayout *layout)
+{
+ int max_width = 0;
+ GSList *l, *r;
+
+ for (l = pango_layout_get_lines (layout); l; l = l->next)
+ {
+ PangoLayoutLine *line = l->data;
+
+ for (r = line->runs; r; r = r->next)
+ {
+ PangoGlyphString *glyphs = ((PangoGlyphItem *)r->data)->glyphs;
+ int i;
+
+ for (i = 0; i < glyphs->num_glyphs; i++)
+ if (glyphs->glyphs[i].geometry.width > max_width)
+ max_width = glyphs->glyphs[i].geometry.width;
+ }
+ }
+
+ return max_width;
+}
+
PangoFontMetrics *
pango_fc_font_create_metrics_for_context (PangoFcFont *fcfont,
PangoContext *context)
@@ -428,11 +452,12 @@ pango_fc_font_create_metrics_for_context (PangoFcFont *fcfont,
pango_layout_set_text (layout, sample_str, -1);
pango_layout_get_extents (layout, NULL, &extents);
- metrics->approximate_char_width = extents.width / g_utf8_strlen (sample_str, -1);
+
+ 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);
- metrics->approximate_digit_width = extents.width / 10;
+ metrics->approximate_digit_width = max_glyph_width (layout);
g_object_unref (layout);
diff --git a/pango/pangowin32.c b/pango/pangowin32.c
index 37d20be2..7e3a2c00 100644
--- a/pango/pangowin32.c
+++ b/pango/pangowin32.c
@@ -527,6 +527,30 @@ pango_win32_font_get_glyph_extents (PangoFont *font,
*logical_rect = info->logical_rect;
}
+static int
+max_glyph_width (PangoLayout *layout)
+{
+ int max_width = 0;
+ GSList *l, *r;
+
+ for (l = pango_layout_get_lines (layout); l; l = l->next)
+ {
+ PangoLayoutLine *line = l->data;
+
+ for (r = line->runs; r; r = r->next)
+ {
+ PangoGlyphString *glyphs = ((PangoGlyphItem *)r->data)->glyphs;
+ int i;
+
+ for (i = 0; i < glyphs->num_glyphs; i++)
+ if (glyphs->glyphs[i].geometry.width > max_width)
+ max_width = glyphs->glyphs[i].geometry.width;
+ }
+ }
+
+ return max_width;
+}
+
static PangoFontMetrics *
pango_win32_font_get_metrics (PangoFont *font,
PangoLanguage *language)
@@ -579,7 +603,6 @@ pango_win32_font_get_metrics (PangoFont *font,
PangoContext *context;
PangoFontDescription *font_desc;
PangoLayout *layout;
- PangoRectangle extents;
/* Get the average width of the chars in "0123456789" */
context = pango_win32_get_context ();
@@ -588,9 +611,8 @@ pango_win32_font_get_metrics (PangoFont *font,
pango_context_set_font_description (context, font_desc);
layout = pango_layout_new (context);
pango_layout_set_text (layout, "0123456789", -1);
- pango_layout_get_extents (layout, NULL, &extents);
- metrics->approximate_digit_width = extents.width / 10;
+ metrics->approximate_digit_width = max_glyph_width (layout);
pango_font_description_free (font_desc);
g_object_unref (layout);