From 0cf050a7b13703e0d665f8dd263cc0d22a95c4f1 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sun, 23 Feb 2020 23:00:48 +0330 Subject: [PATCH] [draw] Merge consequent move-to commands of CFF/CFF2 --- src/hb-ot-cff1-table.cc | 4 ++-- src/hb-ot-cff2-table.cc | 7 ++----- test/api/fonts/Stroking.otf | Bin 0 -> 1060 bytes test/api/test-draw.c | 26 +++++++++++++++++++++++++- 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 test/api/fonts/Stroking.otf diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index 9f03aa526..6ffa24f1c 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -365,6 +365,8 @@ struct cff1_path_param_t void start_path () { path_open = true; + funcs->move_to (font->em_scalef_x (path_start_x), font->em_scalef_y (path_start_y), + user_data); } bool is_path_open () const { return path_open; } @@ -374,8 +376,6 @@ struct cff1_path_param_t if (delta) point.move (*delta); path_last_x = path_start_x = point.x.to_real (); path_last_y = path_start_y = point.y.to_real (); - funcs->move_to (font->em_scalef_x (path_start_x), font->em_scalef_y (path_start_y), - user_data); } void line_to (const point_t &p) diff --git a/src/hb-ot-cff2-table.cc b/src/hb-ot-cff2-table.cc index 3f8508332..98ff52d4c 100644 --- a/src/hb-ot-cff2-table.cc +++ b/src/hb-ot-cff2-table.cc @@ -161,6 +161,8 @@ struct cff2_path_param_t void start_path () { path_open = true; + funcs->move_to (font->em_scalef_x (path_start_x), font->em_scalef_y (path_start_y), + user_data); } bool is_path_open () const { return path_open; } @@ -168,8 +170,6 @@ struct cff2_path_param_t { path_last_x = path_start_x = p.x.to_real (); path_last_y = path_start_y = p.y.to_real (); - funcs->move_to (font->em_scalef_x (path_start_x), font->em_scalef_y (path_start_y), - user_data); } void line_to (const point_t &p) @@ -211,9 +211,6 @@ struct cff2_path_param_t hb_font_t *font; const hb_draw_funcs_t *funcs; void *user_data; - point_t *delta; - - const OT::cff2::accelerator_t *cff; }; struct cff2_path_procs_path_t : path_procs_t diff --git a/test/api/fonts/Stroking.otf b/test/api/fonts/Stroking.otf new file mode 100644 index 0000000000000000000000000000000000000000..a14c3618c2dc96c1f6768abf178e53cb088c51bf GIT binary patch literal 1060 zcmZWoUr1A76hHUgZO!fGmgP*sb=3)O2+cVS!35n@w1$!*C4pOWZ9}(vSre3ABBCTm z`A~0xJp?@!L1=%-H($a>>mhrngeVYvO72}VZohkHGV~n2`#ZniIo~U5{1~e( z0m1l(yNviFmMf9U&T#AWj>upKuSi8^Br*>nBn8Wqj-+Dd_ETHv7Y2VQiPy90HW@Kr zD-!gv7`-me-5$4f?2wiF1)VlV#g{sU3s&->`X{>zZYG>uH|)`sF|HcCll@ZsfxWB- zsK5yP85y{0W?vPgc tcHj#vI0}Av6OIRtmZfnc6O2=0N0oL16b4BkwM(?5{7015yA literal 0 HcmV?d00001 diff --git a/test/api/test-draw.c b/test/api/test-draw.c index 1df40c7d1..903fd8aeb 100644 --- a/test/api/test-draw.c +++ b/test/api/test-draw.c @@ -243,7 +243,6 @@ test_hb_draw_cff1 (void) .consumed = 0 }; g_assert (hb_font_draw_glyph (font, 3, funcs, &user_data)); - puts (str); char expected[] = "M203,367C227,440 248,512 268,588L272,588C293,512 314,440 338,367L369,267L172,267L203,367Z" "M3,0L88,0L151,200L390,200L452,0L541,0L319,656L225,656L3,0Z" "M300,653L342,694L201,861L143,806L300,653Z"; @@ -763,6 +762,7 @@ test_hb_draw_stroking (void) .size = sizeof (str) }; { + /* See https://github.com/google/skia/blob/d38f00a1/gm/stroketext.cpp#L115-L124 */ hb_face_t *face = hb_test_open_font_file ("fonts/Stroking.ttf"); hb_font_t *font = hb_font_create (face); hb_face_destroy (face); @@ -800,6 +800,30 @@ test_hb_draw_stroking (void) "Q256,1342 256,1528Z"; g_assert_cmpmem (str, user_data.consumed, expected2, sizeof (expected2) - 1); + hb_font_destroy (font); + } + { + /* https://github.com/google/skia/blob/d38f00a1/gm/stroketext.cpp#L131-L138 */ + hb_face_t *face = hb_test_open_font_file ("fonts/Stroking.otf"); + hb_font_t *font = hb_font_create (face); + hb_face_destroy (face); + + user_data.consumed = 0; + g_assert (hb_font_draw_glyph (font, 4, funcs, &user_data)); + char expected[] = "M397,372L397,372Z" /* TODO: Do we like to fold this path? */ + "M106,372C106,532 237,662 397,662C557,662 688,532 688,372C688,212 557,81 397,81C237,81 106,212 106,372Z" + "M62,373C62,188 212,39 397,39C582,39 731,188 731,373C731,558 582,708 397,708C212,708 62,558 62,373Z"; + g_assert_cmpmem (str, user_data.consumed, expected, sizeof (expected) - 1); + + user_data.consumed = 0; + g_assert (hb_font_draw_glyph (font, 5, funcs, &user_data)); + /* Fold consequent move-to commands */ + char expected2[] = "M106,372C106,532 237,662 397,662C557,662 688,532 688,372" + "C688,212 557,81 397,81C237,81 106,212 106,372ZM62,373" + "C62,188 212,39 397,39C582,39 731,188 731,373" + "C731,558 582,708 397,708C212,708 62,558 62,373Z"; + g_assert_cmpmem (str, user_data.consumed, expected2, sizeof (expected2) - 1); + hb_font_destroy (font); } }