summaryrefslogtreecommitdiff
path: root/pango/pango-hbfont.c
diff options
context:
space:
mode:
Diffstat (limited to 'pango/pango-hbfont.c')
-rw-r--r--pango/pango-hbfont.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/pango/pango-hbfont.c b/pango/pango-hbfont.c
index ccfb2e61..916c466e 100644
--- a/pango/pango-hbfont.c
+++ b/pango/pango-hbfont.c
@@ -47,7 +47,7 @@
* matrix.
*/
- /* {{{ Utilities */
+/* {{{ Utilities */
static int
get_average_char_width (PangoFont *font,
@@ -763,6 +763,7 @@ static PangoFontMetrics *
pango_hb_font_get_metrics (PangoFont *font,
PangoLanguage *language)
{
+ PangoHbFont *self = PANGO_HB_FONT (font);
hb_font_t *hb_font = pango_font_get_hb_font (font);
PangoFontMetrics *metrics;
hb_font_extents_t extents;
@@ -796,8 +797,17 @@ pango_hb_font_get_metrics (PangoFont *font,
else
metrics->strikethrough_position = metrics->ascent / 2;
- metrics->approximate_char_width = get_average_char_width (font, pango_language_get_sample_string (language));
- get_max_char_size (font, "0123456789", &metrics->approximate_digit_width, NULL);
+ if (self->approximate_char_width == 0 || self->approximate_char_lang != language)
+ {
+ self->approximate_char_width = get_average_char_width (font, pango_language_get_sample_string (language));
+ self->approximate_char_lang = language;
+ }
+
+ if (self->approximate_digit_width == 0)
+ get_max_char_size (font, "0123456789", &self->approximate_digit_width, NULL);
+
+ metrics->approximate_char_width = self->approximate_char_width;
+ metrics->approximate_digit_width = self->approximate_digit_width;
return metrics;
}
@@ -806,7 +816,6 @@ static hb_font_t *
pango_hb_font_create_hb_font (PangoFont *font)
{
PangoHbFont *self = PANGO_HB_FONT (font);
- hb_face_t *hb_face;
hb_font_t *hb_font;
double x_scale, y_scale;
unsigned int n_axes;
@@ -814,8 +823,7 @@ pango_hb_font_create_hb_font (PangoFont *font)
float *coords;
int size;
- hb_face = pango_hb_face_get_hb_face (self->face);
- hb_font = hb_font_create (hb_face);
+ hb_font = hb_font_create (pango_hb_face_get_hb_face (self->face));
size = self->size * self->dpi / 72.f;
x_scale = self->face->x_scale;
@@ -843,7 +851,7 @@ pango_hb_font_create_hb_font (PangoFont *font)
axes = g_alloca (sizeof (hb_ot_var_axis_info_t) * n_axes);
coords = g_alloca (sizeof (float) * n_axes);
- hb_ot_var_get_axis_infos (hb_face, 0, &n_axes, axes);
+ hb_ot_var_get_axis_infos (self->face->face, 0, &n_axes, axes);
if (self->face->instance_id >= 0)
hb_ot_var_named_instance_get_design_coords (self->face->face, self->face->instance_id, &n_axes, coords);
@@ -1042,6 +1050,24 @@ pango_hb_font_new_for_description (PangoHbFace *face,
return pango_hb_font_new (face, size, features, n_features, variations, n_variations, gravity, dpi, matrix);
}
+/**
+ * pango_hb_font_get_size:
+ * @font: a `PangoHbFont`
+ *
+ * Returns the size of the font in points, scaled by `PANGO_SCALE`.
+ *
+ * This is the same value that was passed as size to [ctor@Pango.HbFont.new].
+ *
+ * Returns: the size of @font
+ */
+int
+pango_hb_font_get_size (PangoHbFont *font)
+{
+ g_return_val_if_fail (PANGO_IS_HB_FONT (font), 0);
+
+ return font->size;
+}
+
/* }}} */
/* vim:set foldmethod=marker expandtab: */