From da975419884a535281745f30f4b32fee0bc8a7a1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 21 Apr 2011 15:08:01 -0400 Subject: [PATCH] [API] Allow negative font x_scale/y_scale I was reconsidering whether y should grow down, since all three/four times I've used this API I was tricked and got that wrong in my use. So I was very inclined to make y grow down instead of up. However, considering that the font space has y up and it would be very confusing for callbacks to work against that, I decided that what I really want is for the user to be able to set y_scale to a negative number to imply that user-space y grows down. Changing x_scale/y_scale from unsigned int to int allows that, and I've made pango to use that instead of negating glyph y_offset later. hb-ft however still has y group up. I *guess* that's how FreeType works? I'm not sure, FreeType docs don't make this clear... I'm happy with the resolution :-). --- src/hb-font.cc | 8 ++++---- src/hb-font.h | 8 ++++---- src/hb-ot-layout-common-private.hh | 6 +----- src/hb-ot-layout-private.hh | 2 +- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/hb-font.cc b/src/hb-font.cc index a84dde4..733eb3b 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -523,8 +523,8 @@ hb_font_unset_funcs (hb_font_t *font, void hb_font_set_scale (hb_font_t *font, - unsigned int x_scale, - unsigned int y_scale) + int x_scale, + int y_scale) { if (HB_OBJECT_IS_INERT (font)) return; @@ -535,8 +535,8 @@ hb_font_set_scale (hb_font_t *font, void hb_font_get_scale (hb_font_t *font, - unsigned int *x_scale, - unsigned int *y_scale) + int *x_scale, + int *y_scale) { if (x_scale) *x_scale = font->x_scale; if (y_scale) *y_scale = font->y_scale; diff --git a/src/hb-font.h b/src/hb-font.h index 397b586..d9d6090 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -231,13 +231,13 @@ hb_font_unset_funcs (hb_font_t *font, */ void hb_font_set_scale (hb_font_t *font, - unsigned int x_scale, - unsigned int y_scale); + int x_scale, + int y_scale); void hb_font_get_scale (hb_font_t *font, - unsigned int *x_scale, - unsigned int *y_scale); + int *x_scale, + int *y_scale); /* * A zero value means "no hinting in that direction" diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 9ff5ca9..00a1432 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -532,7 +532,7 @@ struct Device inline hb_position_t get_y_delta (hb_ot_layout_context_t *c) const { return get_delta (c->font->y_ppem, c->font->y_scale); } - inline int get_delta (unsigned int ppem, unsigned int scale) const + inline int get_delta (unsigned int ppem, int scale) const { if (!ppem) return 0; @@ -540,10 +540,6 @@ struct Device if (!pixels) return 0; - /* pixels is at most in the -8..7 range. So 64-bit arithmetic is - * not really necessary here. A simple cast to int may just work - * as well. But since this code is not reached that often and - * for the sake of correctness, we do a 64bit operation. */ return pixels * (int64_t) scale / ppem; } diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index a802c63..b032a7a 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -77,7 +77,7 @@ struct hb_ot_layout_context_t inline hb_position_t scale_y (int16_t v) { return scale (v, this->font->y_scale); } private: - inline hb_position_t scale (int16_t v, unsigned int scale) { return v * (int64_t) scale / this->face->head_table->get_upem (); } + inline hb_position_t scale (int16_t v, int scale) { return v * (int64_t) scale / this->face->head_table->get_upem (); } }; -- 2.7.4