diff --git a/src/hb-font.hh b/src/hb-font.hh index 7c1c4c441..f745633fb 100644 --- a/src/hb-font.hh +++ b/src/hb-font.hh @@ -34,6 +34,7 @@ #include "hb-face.hh" #include "hb-atomic.hh" #include "hb-shaper.hh" +#include "hb-outline.hh" /* @@ -485,10 +486,30 @@ struct hb_font_t void draw_glyph (hb_codepoint_t glyph, hb_draw_funcs_t *draw_funcs, void *draw_data) { + bool embolden = x_strength || y_strength; + if (!embolden) + { + klass->get.f.draw_glyph (this, user_data, + glyph, + draw_funcs, draw_data, + !klass->user_data ? nullptr : klass->user_data->draw_glyph); + return; + } + + /* Emboldening. */ + hb_outline_t outline; klass->get.f.draw_glyph (this, user_data, glyph, - draw_funcs, draw_data, + 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); + + outline.replay (draw_funcs, draw_data); } void paint_glyph (hb_codepoint_t glyph, diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 0f497d770..5d979603f 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -879,38 +879,6 @@ hb_ft_draw_glyph (hb_font_t *font, hb_draw_session_t draw_session (draw_funcs, draw_data, font->slant_xy); - /* Embolden */ - if (font->x_strength || font->y_strength) - { - FT_Outline_EmboldenXY (&ft_face->glyph->outline, font->x_strength, font->y_strength); - - int x_shift = 0; - int y_shift = 0; - if (font->embolden_in_place) - { - /* Undo the FreeType shift. */ - x_shift = -font->x_strength / 2; - y_shift = 0; - if (font->y_scale < 0) y_shift = -font->y_strength; - } - else - { - /* FreeType applied things in the wrong direction for negative scale; fix up. */ - if (font->x_scale < 0) x_shift = -font->x_strength; - if (font->y_scale < 0) y_shift = -font->y_strength; - } - if (x_shift || y_shift) - { - auto &outline = ft_face->glyph->outline; - for (auto &point : hb_iter (outline.points, outline.contours[outline.n_contours - 1] + 1)) - { - point.x += x_shift; - point.y += y_shift; - } - } - } - - FT_Outline_Decompose (&ft_face->glyph->outline, &outline_funcs, &draw_session); diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index a94189b5f..2907d3bf2 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -34,7 +34,6 @@ #include "hb-font.hh" #include "hb-machinery.hh" #include "hb-ot-face.hh" -#include "hb-outline.hh" #include "hb-ot-cmap-table.hh" #include "hb-ot-glyf-table.hh" @@ -493,35 +492,17 @@ hb_ot_draw_glyph (hb_font_t *font, hb_draw_funcs_t *draw_funcs, void *draw_data, void *user_data) { - bool embolden = font->x_strength || font->y_strength; - hb_outline_t outline; - - { // Need draw_session to be destructed before emboldening. - hb_draw_session_t draw_session (embolden ? hb_outline_recording_pen_get_funcs () : draw_funcs, - embolden ? &outline : draw_data, font->slant_xy); + hb_draw_session_t draw_session (draw_funcs, draw_data, font->slant_xy); #ifndef HB_NO_VAR_COMPOSITES - if (!font->face->table.VARC->get_path (font, glyph, draw_session)) + if (!font->face->table.VARC->get_path (font, glyph, draw_session)) #endif - // Keep the following in synch with VARC::get_path_at() - if (!font->face->table.glyf->get_path (font, glyph, draw_session)) + // Keep the following in synch with VARC::get_path_at() + if (!font->face->table.glyf->get_path (font, glyph, draw_session)) #ifndef HB_NO_CFF - if (!font->face->table.cff2->get_path (font, glyph, draw_session)) - if (!font->face->table.cff1->get_path (font, glyph, draw_session)) + if (!font->face->table.cff2->get_path (font, glyph, draw_session)) + if (!font->face->table.cff1->get_path (font, glyph, draw_session)) #endif - {} - } - - if (embolden) - { - float x_shift = font->embolden_in_place ? 0 : (float) font->x_strength / 2; - float y_shift = (float) font->y_strength / 2; - if (font->x_scale < 0) x_shift = -x_shift; - if (font->y_scale < 0) y_shift = -y_shift; - outline.embolden (font->x_strength, font->y_strength, - x_shift, y_shift); - - outline.replay (draw_funcs, draw_data); - } + {} } #endif