summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2010-05-04 11:55:27 -0400
committerBehdad Esfahbod <behdad@behdad.org>2010-05-04 11:55:27 -0400
commit34e05035af0ce854df1cc2f77c0b11dbc1a3cb36 (patch)
treeefc507cbaddd116b17340270348a0dc6d9308010 /pango
parentfd31122c5a153c3a21ae015cdd1c72aef79671d0 (diff)
downloadpango-34e05035af0ce854df1cc2f77c0b11dbc1a3cb36.tar.gz
[cairo] Refactor common code in create_metrics_for_context()
Diffstat (limited to 'pango')
-rw-r--r--pango/pangocairo-atsuifont.c31
-rw-r--r--pango/pangocairo-fcfont.c8
-rw-r--r--pango/pangocairo-font.c48
-rw-r--r--pango/pangocairo-private.h4
-rw-r--r--pango/pangocairo-win32font.c31
-rw-r--r--pango/pangofc-font.c51
-rw-r--r--pango/pangofc-private.h4
7 files changed, 70 insertions, 107 deletions
diff --git a/pango/pangocairo-atsuifont.c b/pango/pangocairo-atsuifont.c
index 3abaffff..1c1ba550 100644
--- a/pango/pangocairo-atsuifont.c
+++ b/pango/pangocairo-atsuifont.c
@@ -46,15 +46,15 @@ struct _PangoCairoATSUIFontClass
-static cairo_font_face_t *pango_cairo_atsui_font_create_font_face (PangoCairoFont *font);
-static PangoFontMetrics *pango_cairo_atsui_font_create_metrics_for_context (PangoCairoFont *font,
- PangoContext *context);
+static cairo_font_face_t *pango_cairo_atsui_font_create_font_face (PangoCairoFont *font);
+static PangoFontMetrics *pango_cairo_atsui_font_create_base_metrics_for_context (PangoCairoFont *font,
+ PangoContext *context);
static void
cairo_font_iface_init (PangoCairoFontIface *iface)
{
iface->create_font_face = pango_cairo_atsui_font_create_font_face;
- iface->create_metrics_for_context = pango_cairo_atsui_font_create_metrics_for_context;
+ iface->create_base_metrics_for_context = pango_cairo_atsui_font_create_base_metrics_for_context;
iface->cf_priv_offset = G_STRUCT_OFFSET (PangoCairoATSUIFont, cf_priv);
}
@@ -113,19 +113,14 @@ max_glyph_width (PangoLayout *layout)
}
static PangoFontMetrics *
-pango_cairo_atsui_font_create_metrics_for_context (PangoCairoFont *font,
- PangoContext *context)
+pango_cairo_atsui_font_create_base_metrics_for_context (PangoCairoFont *font,
+ PangoContext *context)
{
PangoCairoATSUIFont *cafont = (PangoCairoATSUIFont *) font;
PangoATSUIFont *afont = (PangoATSUIFont *) font;
ATSFontRef ats_font;
ATSFontMetrics ats_metrics;
PangoFontMetrics *metrics;
- PangoFontDescription *font_desc;
- PangoLayout *layout;
- PangoRectangle extents;
- PangoLanguage *language = pango_context_get_language (context);
- const char *sample_str = pango_language_get_sample_string (language);
metrics = pango_font_metrics_new ();
@@ -141,20 +136,6 @@ pango_cairo_atsui_font_create_metrics_for_context (PangoCairoFont *font,
metrics->strikethrough_position = metrics->ascent / 3;
metrics->strikethrough_thickness = ats_metrics.underlineThickness * cafont->size * PANGO_SCALE;
- layout = pango_layout_new (context);
- font_desc = pango_font_describe_with_absolute_size ((PangoFont *) font);
- pango_layout_set_font_description (layout, font_desc);
- pango_layout_set_text (layout, sample_str, -1);
- pango_layout_get_extents (layout, NULL, &extents);
-
- metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str);
-
- 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);
-
return metrics;
}
diff --git a/pango/pangocairo-fcfont.c b/pango/pangocairo-fcfont.c
index 8401ed8d..1393ce8e 100644
--- a/pango/pangocairo-fcfont.c
+++ b/pango/pangocairo-fcfont.c
@@ -64,19 +64,19 @@ pango_cairo_fc_font_create_font_face (PangoCairoFont *cfont)
}
static PangoFontMetrics *
-pango_cairo_fc_font_create_metrics_for_context (PangoCairoFont *cfont,
- PangoContext *context)
+pango_cairo_fc_font_create_base_metrics_for_context (PangoCairoFont *cfont,
+ PangoContext *context)
{
PangoFcFont *fcfont = (PangoFcFont *) (cfont);
- return pango_fc_font_create_metrics_for_context (fcfont, context);
+ return pango_fc_font_create_base_metrics_for_context (fcfont, context);
}
static void
cairo_font_iface_init (PangoCairoFontIface *iface)
{
iface->create_font_face = pango_cairo_fc_font_create_font_face;
- iface->create_metrics_for_context = pango_cairo_fc_font_create_metrics_for_context;
+ iface->create_base_metrics_for_context = pango_cairo_fc_font_create_base_metrics_for_context;
iface->cf_priv_offset = G_STRUCT_OFFSET (PangoCairoFcFont, cf_priv);
}
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c
index 35da71ce..ace2a575 100644
--- a/pango/pangocairo-font.c
+++ b/pango/pangocairo-font.c
@@ -206,6 +206,30 @@ _pango_cairo_font_install (PangoFont *font,
}
+static int
+max_glyph_width (PangoLayout *layout)
+{
+ int max_width = 0;
+ GSList *l, *r;
+
+ for (l = pango_layout_get_lines_readonly (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;
+}
+
typedef struct _PangoCairoFontMetricsInfo
{
const char *sample_str;
@@ -239,6 +263,10 @@ _pango_cairo_font_get_metrics (PangoFont *font,
PangoFontMap *fontmap;
PangoContext *context;
cairo_font_options_t *font_options;
+ PangoLayout *layout;
+ PangoRectangle extents;
+ PangoFontDescription *desc;
+
int height, shift;
/* XXX this is racy. need a ref'ing getter... */
@@ -260,7 +288,25 @@ _pango_cairo_font_get_metrics (PangoFont *font,
pango_cairo_context_set_font_options (context, font_options);
cairo_font_options_destroy (font_options);
- info->metrics = (* PANGO_CAIRO_FONT_GET_IFACE (font)->create_metrics_for_context) (cfont, context);
+ info->metrics = (* PANGO_CAIRO_FONT_GET_IFACE (font)->create_base_metrics_for_context) (cfont, context);
+
+ /* Update approximate_*_width now */
+
+ layout = pango_layout_new (context);
+ desc = pango_font_describe_with_absolute_size (font);
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+
+ pango_layout_set_text (layout, sample_str, -1);
+ pango_layout_get_extents (layout, NULL, &extents);
+
+ info->metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str);
+
+ pango_layout_set_text (layout, "0123456789", -1);
+ info->metrics->approximate_digit_width = max_glyph_width (layout);
+
+ g_object_unref (layout);
+
/* We may actually reuse ascent/descent we got from cairo here. that's
* in cf_priv->font_extents.
diff --git a/pango/pangocairo-private.h b/pango/pangocairo-private.h
index 3a4a9d0e..4e64f25d 100644
--- a/pango/pangocairo-private.h
+++ b/pango/pangocairo-private.h
@@ -95,8 +95,8 @@ struct _PangoCairoFontIface
GTypeInterface g_iface;
cairo_font_face_t *(*create_font_face) (PangoCairoFont *cfont);
- PangoFontMetrics *(*create_metrics_for_context) (PangoCairoFont *cfont,
- PangoContext *context);
+ PangoFontMetrics *(*create_base_metrics_for_context) (PangoCairoFont *cfont,
+ PangoContext *context);
gssize cf_priv_offset;
};
diff --git a/pango/pangocairo-win32font.c b/pango/pangocairo-win32font.c
index 3493d582..59f7c0f6 100644
--- a/pango/pangocairo-win32font.c
+++ b/pango/pangocairo-win32font.c
@@ -54,16 +54,16 @@ struct _PangoCairoWin32FontClass
GType pango_cairo_win32_font_get_type (void);
-static cairo_font_face_t *pango_cairo_win32_font_create_font_face (PangoCairoFont *font);
-static PangoFontMetrics *pango_cairo_win32_font_create_metrics_for_context (PangoCairoFont *font,
- PangoContext *context);
+static cairo_font_face_t *pango_cairo_win32_font_create_font_face (PangoCairoFont *font);
+static PangoFontMetrics *pango_cairo_win32_font_create_base_metrics_for_context (PangoCairoFont *font,
+ PangoContext *context);
static void
cairo_font_iface_init (PangoCairoFontIface *iface)
{
iface->create_font_face = pango_cairo_win32_font_create_font_face;
- iface->create_metrics_for_context = pango_cairo_win32_font_create_metrics_for_context;
+ iface->create_base_metrics_for_context = pango_cairo_win32_font_create_base_metrics_for_context;
iface->cf_priv_offset = G_STRUCT_OFFSET (PangoCairoWin32Font, cf_priv);
}
@@ -104,15 +104,10 @@ max_glyph_width (PangoLayout *layout)
}
static PangoFontMetrics *
-pango_cairo_win32_font_create_metrics_for_context (PangoCairoFont *font,
- PangoContext *context)
+pango_cairo_win32_font_create_base_metrics_for_context (PangoCairoFont *font,
+ PangoContext *context)
{
PangoFontMetrics *metrics;
- PangoFontDescription *font_desc;
- PangoLayout *layout;
- PangoRectangle extents;
- PangoLanguage *language = pango_context_get_language (context);
- const char *sample_str = pango_language_get_sample_string (language);
cairo_scaled_font_t *scaled_font;
cairo_font_extents_t font_extents;
double height;
@@ -144,20 +139,6 @@ pango_cairo_win32_font_create_metrics_for_context (PangoCairoFont *font,
if (metrics->underline_position == 0)
metrics->underline_position = - metrics->underline_thickness;
- layout = pango_layout_new (context);
- font_desc = pango_font_describe_with_absolute_size ((PangoFont *) font);
- pango_layout_set_font_description (layout, font_desc);
- pango_layout_set_text (layout, sample_str, -1);
- pango_layout_get_extents (layout, NULL, &extents);
-
- metrics->approximate_char_width = extents.width / pango_utf8_strwidth (sample_str);
-
- 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);
-
return metrics;
}
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index ad234beb..7c38ab76 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -479,60 +479,15 @@ 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_readonly (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)
+pango_fc_font_create_base_metrics_for_context (PangoFcFont *fcfont,
+ PangoContext *context)
{
PangoFontMetrics *metrics;
- PangoLayout *layout;
- PangoRectangle extents;
- PangoLanguage *language = pango_context_get_language (context);
- const char *sample_str = pango_language_get_sample_string (language);
- PangoFontDescription *desc = pango_font_describe_with_absolute_size (PANGO_FONT (fcfont));
-
metrics = pango_font_metrics_new ();
get_face_metrics (fcfont, metrics);
- layout = pango_layout_new (context);
- pango_layout_set_font_description (layout, desc);
- pango_font_description_free (desc);
-
- pango_layout_set_text (layout, sample_str, -1);
- pango_layout_get_extents (layout, NULL, &extents);
-
- metrics->approximate_char_width =
- extents.width / pango_utf8_strwidth (sample_str);
-
- pango_layout_set_text (layout, "0123456789", -1);
- metrics->approximate_digit_width = max_glyph_width (layout);
-
- g_object_unref (layout);
-
return metrics;
}
@@ -581,7 +536,7 @@ pango_fc_font_get_metrics (PangoFont *font,
context = pango_font_map_create_context (fontmap);
pango_context_set_language (context, language);
- info->metrics = pango_fc_font_create_metrics_for_context (fcfont, context);
+ info->metrics = pango_fc_font_create_base_metrics_for_context (fcfont, context);
g_object_unref (context);
g_object_unref (fontmap);
diff --git a/pango/pangofc-private.h b/pango/pangofc-private.h
index e7c08bff..f200c8c0 100644
--- a/pango/pangofc-private.h
+++ b/pango/pangofc-private.h
@@ -90,8 +90,8 @@ void pango_fc_font_get_raw_extents (PangoFcFont *font,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect);
-PangoFontMetrics *pango_fc_font_create_metrics_for_context (PangoFcFont *font,
- PangoContext *context);
+PangoFontMetrics *pango_fc_font_create_base_metrics_for_context (PangoFcFont *font,
+ PangoContext *context);