-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);
}
}
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 ();
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;
}
}
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);
}
}
+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;
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... */
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.
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;
};
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);
}
}
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;
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;
}
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;
}
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);
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);