diff --git a/src/fontations/lib.rs b/src/fontations/lib.rs index bfcf95f4e..9314e9909 100644 --- a/src/fontations/lib.rs +++ b/src/fontations/lib.rs @@ -523,7 +523,7 @@ impl OutlinePen for HbPen { } extern "C" fn _hb_fontations_draw_glyph( - font: *mut hb_font_t, + _font: *mut hb_font_t, font_data: *mut ::std::os::raw::c_void, glyph: hb_codepoint_t, draw_funcs: *mut hb_draw_funcs_t, @@ -543,21 +543,7 @@ extern "C" fn _hb_fontations_draw_glyph( }; let draw_settings = DrawSettings::unhinted(*size, location); - let slant = unsafe { hb_font_get_synthetic_slant(font) }; - let mut x_scale: i32 = 0; - let mut y_scale: i32 = 0; - unsafe { - hb_font_get_scale(font, &mut x_scale, &mut y_scale); - } - let slant = if y_scale != 0 { - slant as f32 * x_scale as f32 / y_scale as f32 - } else { - 0. - }; - let mut draw_state = hb_draw_state_t { - slant_xy: slant, - ..unsafe { std::mem::zeroed() } - }; + let mut draw_state = unsafe { std::mem::zeroed::() }; let mut pen = HbPen { x_mult: data.x_mult, diff --git a/src/hb-coretext-font.cc b/src/hb-coretext-font.cc index 9a6bf0bf9..038865dab 100644 --- a/src/hb-coretext-font.cc +++ b/src/hb-coretext-font.cc @@ -385,7 +385,7 @@ hb_coretext_draw_glyph (hb_font_t *font, if (!path) return; - hb_draw_session_t drawing = {draw_funcs, draw_data, font->slant}; + hb_draw_session_t drawing {draw_funcs, draw_data}; CGPathApply (path, &drawing, ct_apply_func); diff --git a/src/hb-directwrite-font.cc b/src/hb-directwrite-font.cc index 9752110e4..40ba9cf91 100644 --- a/src/hb-directwrite-font.cc +++ b/src/hb-directwrite-font.cc @@ -238,7 +238,7 @@ public: GeometrySink(hb_font_t *font, hb_draw_funcs_t *draw_funcs, void *draw_data) - : font (font), drawing ({draw_funcs, draw_data, font->slant}) {} + : font (font), drawing ({draw_funcs, draw_data}) {} virtual ~GeometrySink() {} diff --git a/src/hb-draw.h b/src/hb-draw.h index 021078455..76aa93f11 100644 --- a/src/hb-draw.h +++ b/src/hb-draw.h @@ -41,16 +41,9 @@ HB_BEGIN_DECLS * @path_start_y: Y component of the start of current path * @current_x: X component of current point * @current_y: Y component of current point - * @slant_xy: Slanting factor for synthetic oblique, Since: 11.0.0 * * Current drawing state. * - * The @slant_xy is a slanting factor for synthetic oblique. If the font's - * oblique angle is not 0, this factor is used to slant the drawing. For - * fonts with uniform x and y scales, this factor is calculated as - * tan(oblique_angle). For fonts with non-uniform scales, this factor is - * calculated as tan(oblique_angle) * x_scale / y_scale, or 0 if y_scale is 0. - * * Since: 4.0.0 **/ typedef struct hb_draw_state_t { @@ -62,8 +55,6 @@ typedef struct hb_draw_state_t { float current_x; float current_y; - float slant_xy; - /*< private >*/ hb_var_num_t reserved1; hb_var_num_t reserved2; @@ -71,6 +62,7 @@ typedef struct hb_draw_state_t { hb_var_num_t reserved4; hb_var_num_t reserved5; hb_var_num_t reserved6; + hb_var_num_t reserved7; } hb_draw_state_t; /** @@ -78,7 +70,7 @@ typedef struct hb_draw_state_t { * * The default #hb_draw_state_t at the start of glyph drawing. */ -#define HB_DRAW_STATE_DEFAULT {0, 0.f, 0.f, 0.f, 0.f, 0.f, {0.}, {0.}, {0.}, {0.}, {0.}, {0.}} +#define HB_DRAW_STATE_DEFAULT {0, 0.f, 0.f, 0.f, 0.f, {0}, {0}, {0}, {0}, {0}, {0}, {0}} /** diff --git a/src/hb-draw.hh b/src/hb-draw.hh index f5985b898..201f2202e 100644 --- a/src/hb-draw.hh +++ b/src/hb-draw.hh @@ -100,9 +100,6 @@ struct hb_draw_funcs_t { if (unlikely (st.path_open)) close_path (draw_data, st); - if (st.slant_xy) - to_x += to_y * st.slant_xy; - st.current_x = to_x; st.current_y = to_y; } @@ -114,9 +111,6 @@ struct hb_draw_funcs_t { if (unlikely (!st.path_open)) start_path (draw_data, st); - if (st.slant_xy) - to_x += to_y * st.slant_xy; - emit_line_to (draw_data, st, to_x, to_y); st.current_x = to_x; @@ -131,12 +125,6 @@ struct hb_draw_funcs_t { if (unlikely (!st.path_open)) start_path (draw_data, st); - if (st.slant_xy) - { - control_x += control_y * st.slant_xy; - to_x += to_y * st.slant_xy; - } - emit_quadratic_to (draw_data, st, control_x, control_y, to_x, to_y); st.current_x = to_x; @@ -152,13 +140,6 @@ struct hb_draw_funcs_t { if (unlikely (!st.path_open)) start_path (draw_data, st); - if (st.slant_xy) - { - control1_x += control1_y * st.slant_xy; - control2_x += control2_y * st.slant_xy; - to_x += to_y * st.slant_xy; - } - emit_cubic_to (draw_data, st, control1_x, control1_y, control2_x, control2_y, to_x, to_y); st.current_x = to_x; @@ -194,9 +175,9 @@ DECLARE_NULL_INSTANCE (hb_draw_funcs_t); struct hb_draw_session_t { - hb_draw_session_t (hb_draw_funcs_t *funcs_, void *draw_data_, float slant_xy = 0.f) + hb_draw_session_t (hb_draw_funcs_t *funcs_, void *draw_data_) : funcs {funcs_}, draw_data {draw_data_}, st HB_DRAW_STATE_DEFAULT - { st.slant_xy = slant_xy; } + {} ~hb_draw_session_t () { close_path (); } diff --git a/src/hb-font.hh b/src/hb-font.hh index 808551987..5233b8f0c 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -512,11 +512,13 @@ struct hb_font_t { #ifndef HB_NO_OUTLINE bool embolden = x_strength || y_strength; + bool slanted = slant_xy; + bool synthetic = embolden || slanted; #else - constexpr bool embolden = false; + constexpr bool synthetic = false; #endif - if (!embolden) + if (!synthetic) { klass->get.f.draw_glyph (this, user_data, glyph, @@ -526,18 +528,26 @@ struct hb_font_t } #ifndef HB_NO_OUTLINE - /* Emboldening. */ + hb_outline_t outline; klass->get.f.draw_glyph (this, user_data, glyph, hb_outline_recording_pen_get_funcs (), &outline, !klass->user_data ? nullptr : klass->user_data->draw_glyph); - float x_shift = embolden_in_place ? 0 : (float) x_strength / 2; - float y_shift = (float) y_strength / 2; - if (x_scale < 0) x_shift = -x_shift; - if (y_scale < 0) y_shift = -y_shift; - outline.embolden (x_strength, y_strength, x_shift, y_shift); + // Slant before embolden; produces nicer results. + + if (slanted) + outline.slant (slant_xy); + + if (embolden) + { + float x_shift = embolden_in_place ? 0 : (float) x_strength / 2; + float y_shift = (float) y_strength / 2; + if (x_scale < 0) x_shift = -x_shift; + if (y_scale < 0) y_shift = -y_shift; + outline.embolden (x_strength, y_strength, x_shift, y_shift); + } outline.replay (draw_funcs, draw_data); #endif diff --git a/src/hb-ft.cc b/src/hb-ft.cc index cfb8634bf..32d8b5153 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -877,7 +877,7 @@ hb_ft_draw_glyph (hb_font_t *font, 0, /* delta */ }; - hb_draw_session_t draw_session (draw_funcs, draw_data, font->slant_xy); + hb_draw_session_t draw_session {draw_funcs, draw_data}; FT_Outline_Decompose (&ft_face->glyph->outline, &outline_funcs, diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 66d7d55dd..a0b8a83e2 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -498,7 +498,7 @@ hb_ot_draw_glyph (hb_font_t *font, hb_draw_funcs_t *draw_funcs, void *draw_data, void *user_data) { - hb_draw_session_t draw_session (draw_funcs, draw_data, font->slant_xy); + hb_draw_session_t draw_session {draw_funcs, draw_data}; #ifndef HB_NO_VAR_COMPOSITES if (!font->face->table.VARC->get_path (font, glyph, draw_session)) #endif diff --git a/src/hb-outline.cc b/src/hb-outline.cc index 29b1f530d..d180e7c4f 100644 --- a/src/hb-outline.cc +++ b/src/hb-outline.cc @@ -84,6 +84,12 @@ void hb_outline_t::replay (hb_draw_funcs_t *pen, void *pen_data) const } } +void hb_outline_t::slant (float slant_xy) +{ + for (auto &p : points) + p.x += slant_xy * p.y; +} + float hb_outline_t::control_area () const { float a = 0; diff --git a/src/hb-outline.hh b/src/hb-outline.hh index c43c06596..060ad775f 100644 --- a/src/hb-outline.hh +++ b/src/hb-outline.hh @@ -69,6 +69,7 @@ struct hb_outline_t HB_INTERNAL void replay (hb_draw_funcs_t *pen, void *pen_data) const; HB_INTERNAL float control_area () const; + HB_INTERNAL void slant (float slant_xy); HB_INTERNAL void embolden (float x_strength, float y_strength, float x_shift, float y_shift);