From b57f18da700837a57df9606290160ea6e96accc8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 11 Oct 2017 11:47:47 +0200 Subject: [PATCH] Add hb_font_[sg]et_ptem() to set/get point size on font New API: hb_font_set_ptem() hb_font_get_ptem() Needed for hb-coretext optical sizing: https://github.com/behdad/harfbuzz/issues/360 --- docs/harfbuzz-sections.txt | 2 ++ src/hb-font-private.hh | 5 ++++- src/hb-font.cc | 41 ++++++++++++++++++++++++++++++++++++++ src/hb-font.h | 10 ++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 6ceefd250..6d86d9418 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -246,6 +246,7 @@ hb_font_get_nominal_glyph hb_font_get_nominal_glyph_func_t hb_font_get_parent hb_font_get_ppem +hb_font_get_ptem hb_font_get_scale hb_font_get_user_data hb_font_get_variation_glyph @@ -261,6 +262,7 @@ hb_font_set_funcs hb_font_set_funcs_data hb_font_set_parent hb_font_set_ppem +hb_font_set_ptem hb_font_set_scale hb_font_set_user_data hb_variation_t diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index ed9f2c54a..30661c322 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -108,6 +108,8 @@ struct hb_font_t { unsigned int x_ppem; unsigned int y_ppem; + float ptem; + /* Font variation coordinates. */ unsigned int num_coords; int *coords; @@ -123,7 +125,8 @@ struct hb_font_t { DIRTY_FUNCS = 0x0004, DIRTY_SCALE = 0x0008, DIRTY_PPEM = 0x0010, - DIRTY_VARIATIONS = 0x0020, + DIRTY_PTEM = 0x0020, + DIRTY_VARIATIONS = 0x0040, } dirty; struct hb_shaper_data_t shaper_data; diff --git a/src/hb-font.cc b/src/hb-font.cc index 50da49e74..c47e2c14a 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -1157,6 +1157,7 @@ hb_font_create_sub_font (hb_font_t *parent) font->y_scale = parent->y_scale; font->x_ppem = parent->x_ppem; font->y_ppem = parent->y_ppem; + font->ptem = parent->ptem; font->num_coords = parent->num_coords; if (!font->num_coords) @@ -1199,6 +1200,7 @@ hb_font_get_empty (void) 0, /* x_ppem */ 0, /* y_ppem */ + -1, /* ptem */ 0, /* num_coords */ NULL, /* coords */ @@ -1597,6 +1599,45 @@ hb_font_get_ppem (hb_font_t *font, if (y_ppem) *y_ppem = font->y_ppem; } +/** + * hb_font_set_ptem: + * @font: a font. + * @ptem: + * + * Sets "point size" of the font. + * + * Since: 1.6.0 + **/ +void +hb_font_set_ptem (hb_font_t *font, float ptem) +{ + if (font->immutable) + return; + + if (font->ptem == ptem) + return; + + font->dirty |= font->DIRTY_PTEM; + + font->ptem = ptem; +} + +/** + * hb_font_get_ptem: + * @font: a font. + * + * Gets the "point size" of the font. A value of -1 means unset. + * + * Return value: Point size. + * + * Since: 0.9.2 + **/ +float +hb_font_get_ptem (hb_font_t *font) +{ + return font->ptem; +} + /* * Variations */ diff --git a/src/hb-font.h b/src/hb-font.h index 85fb56d5b..8fb1849de 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -607,6 +607,16 @@ hb_font_get_ppem (hb_font_t *font, unsigned int *x_ppem, unsigned int *y_ppem); +/* + * Point size per EM. Used for optical-sizing in CoreText. + * A -1 means "not set". + */ +HB_EXTERN void +hb_font_set_ptem (hb_font_t *font, float ptem); + +HB_EXTERN float +hb_font_get_ptem (hb_font_t *font); + HB_EXTERN void hb_font_set_variations (hb_font_t *font, const hb_variation_t *variations,