From 64cf53d6197a0e6c56aef744ceff2f8a0ff85654 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Fri, 2 Mar 2018 17:33:49 -0800 Subject: [PATCH 1/6] [subset] Subset vmtx if present. --- src/hb-ot-hmtx-table.hh | 2 +- src/hb-subset.cc | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 3cd48a62e..bff792a60 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -264,7 +264,7 @@ struct hmtxvmtx { advance += (font->num_coords ? var_table->get_advance_var (glyph, font->coords, font->num_coords) : 0); // TODO Optimize?! } - return advance; + return advance; } public: diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 9ebe5d31d..e2d9a89d6 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -252,6 +252,9 @@ _subset_table (hb_subset_plan_t *plan, case HB_OT_TAG_hmtx: result = _subset (plan); break; + case HB_OT_TAG_vmtx: + result = _subset (plan); + break; case HB_OT_TAG_maxp: result = _subset (plan); break; From 0e8f9430c83c076993a0c7a320713bb484051343 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Tue, 6 Mar 2018 13:08:20 -0800 Subject: [PATCH 2/6] [subset] Skip subsetting vhea. --- src/hb-subset.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hb-subset.cc b/src/hb-subset.cc index e2d9a89d6..0f4648547 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -252,6 +252,9 @@ _subset_table (hb_subset_plan_t *plan, case HB_OT_TAG_hmtx: result = _subset (plan); break; + case HB_OT_TAG_vhea: + DEBUG_MSG(SUBSET, nullptr, "skip vhea handled by hmtx"); + return true; case HB_OT_TAG_vmtx: result = _subset (plan); break; From d9263f0230693d108249be0904bc5a3280560cb3 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Tue, 6 Mar 2018 15:40:35 -0800 Subject: [PATCH 3/6] [subset] add unit tests for vmtx subsetting. --- test/api/Makefile.am | 2 + ...-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf | Bin 0 -> 3572 bytes test/api/fonts/Mplus1p-Regular.660E.ttf | Bin 0 -> 2356 bytes test/api/test-subset-vmtx.c | 100 ++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 test/api/fonts/Mplus1p-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf create mode 100644 test/api/fonts/Mplus1p-Regular.660E.ttf create mode 100644 test/api/test-subset-vmtx.c diff --git a/test/api/Makefile.am b/test/api/Makefile.am index a6ebc57a2..3c5a5ccfc 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -36,6 +36,7 @@ TEST_PROGS = \ test-subset-hdmx \ test-subset-hmtx \ test-subset-os2 \ + test-subset-vmtx \ test-unicode \ test-version \ $(NULL) @@ -46,6 +47,7 @@ test_subset_glyf_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_subset_hdmx_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_subset_hmtx_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_subset_os2_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la +test_subset_vmtx_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_unicode_CPPFLAGS = \ $(AM_CPPFLAGS) \ diff --git a/test/api/fonts/Mplus1p-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf b/test/api/fonts/Mplus1p-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf new file mode 100644 index 0000000000000000000000000000000000000000..89c7a1accde325ab37f39472069986cb4d753ee3 GIT binary patch literal 3572 zcmbVPdu&_P8UN0`e&prEuH&TOw%psB#8BIL)V0&3X<|EW9!=ARqz^kpEpFbelbF0l zDX4|=^jeBU*%BCAQF(5R-4r&8w28tVOlXyOR7K(;DzQoM$0jX^QEkoje&^aP1)=@1 zYn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bT(weN^}53Od0OW;CkgRdJmS`{%Xi4QEzQ?K}W`lhts@G|zY IZ|!IQ1)D=4tN;K2 literal 0 HcmV?d00001 diff --git a/test/api/fonts/Mplus1p-Regular.660E.ttf b/test/api/fonts/Mplus1p-Regular.660E.ttf new file mode 100644 index 0000000000000000000000000000000000000000..3e32c8917a45fff26bfd1d9ba858b13d6101acfe GIT binary patch literal 2356 zcmbVOTWl0n82-=9URrwF-mth}&M?KQJKJ_!+6V>R7Hrd7s9V69W)oSq+il6VyLL+j z2@$W5QP2k-L_^|>QDUN}KmsNvpfT!$JfH*<5+V;i@S=$(Y7=SK@62v%A;bsIX3qI9 z-}(RV|IeAt5F;WVCKu6;;ii_;&(#$XDF&>&he}1MbUa3VQe>Agc_w2AGHfdY7xq4MJ{6lxR9`E88GNEd z>Pwk)b|&{awP5Ql>Ca3jGUE3@4g71NH_jrT_Y2?7<85efZ-cMKqx8D& z%+Jp+M*G>oV(v2x0T z)xF(a5%~1Ni=kcLe9Ynt#xo5h&qtxFw3?1kDI|txH8`OjOwvnEkEFyZPOtj;k+Nqi zw)~+4)Z5baL(3*vJ6)>|&*zRWo^c;?wL+EkI)kN119C)0a)z!crHmgBH2#B&>E(UG9=7<22{F=Xe*qEWvfgz*}4^^PgLY$`IU zD*2|SpeQ!@VVUGB#OFfY(5rLddbm%}kZC9E7?;B1eoeFdwxdPznoPJV&(7!fX-HCH z@b8^+N)6s5yn(36d5_*5+s92lx;Gy};>u)Zq~)h-g_G^M!rj3GnbzA3ludT-< z6IqU&B_E$WhAJFGr7S=SRreGCqI$O;+qY+BC30)Efg0V5)y4WR`Y2A$EWx|LoZAso-wXD7mmdq$yU_V?#5_x!w#B>7GS09F9v5p8YaOPD zSZfGa(HBg3?dc-Ry(ZXk>K8>r<{V=uthsJ^SA-82ttJBDh_wy}8#OIa6Cldf=l)cR zlpD&gq$vmG^(7yDU3ia}^FrVrV<_Z>mX}ppkAIrH>{@|wQyGN{b`KCw;LTtz`Nujy zg9Vu({;7hjP&u6`$SQ583kBJ=0^_C!>F{QV6gQVO;#up!71 zAd}Ej6ayjzL^Gm>VC$eB>`FsQ0n-g>3X!s~{~JR_2;LK8H_$TIgtJ3tS&I4J`(#}+ zh_{)V@S9xb8Kkl0+>Ma3Gzun-s4?TzKH=1|#E;W3Fk^`Hyi<|vOdgTK8V9#2;1h_! zQS}s7$(943@8U4^;<9ksf#?#;mn-M6uZ&>8cfVR?z4=qQU*07)F`5Ox38(LSoepy_ zo^W_@cx2vAdKzmCw#``Y?oSrA$or6iSDvfvcM7XK=Op^K1N#U5*B-nr_!^NT_lo>3 lxbI;2W>M7J_zoC`pZQ2Vx^Rj{)Z4j7b8W73(stKA_76=@>wf?M literal 0 HcmV?d00001 diff --git a/test/api/test-subset-vmtx.c b/test/api/test-subset-vmtx.c new file mode 100644 index 000000000..0abab8ca8 --- /dev/null +++ b/test/api/test-subset-vmtx.c @@ -0,0 +1,100 @@ +/* + * Copyright © 2018 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Roderick Sheeter + */ + +#include + +#include "hb-test.h" +#include "hb-subset-test.h" + +/* Unit tests for hmtx subsetting */ + +static void check_num_vmetrics(hb_face_t *face, uint16_t expected_num_hmetrics) +{ + hb_blob_t *vhea_blob = hb_face_reference_table (face, HB_TAG ('v','h','e','a')); + hb_blob_t *vmtx_blob = hb_face_reference_table (face, HB_TAG ('v','m','t','x')); + + // TODO I sure wish I could just use the hmtx table struct! + unsigned int vhea_len; + uint8_t *raw_vhea = (uint8_t *) hb_blob_get_data(vhea_blob, &vhea_len); + uint16_t num_hmetrics = (raw_vhea[vhea_len - 2] << 8) + raw_vhea[vhea_len - 1]; + g_assert_cmpuint(expected_num_hmetrics, ==, num_hmetrics); + + hb_blob_destroy (vhea_blob); + hb_blob_destroy (vmtx_blob); +} + +static void +test_subset_vmtx_simple_subset (void) +{ + hb_face_t *face_full = hb_subset_test_open_font ("fonts/Mplus1p-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf"); + hb_face_t *face_subset = hb_subset_test_open_font ("fonts/Mplus1p-Regular.660E.ttf"); + + hb_set_t *codepoints = hb_set_create (); + hb_set_add (codepoints, 0x660E); + + hb_face_t *face_full_subset = hb_subset_test_create_subset (face_full, hb_subset_test_create_input (codepoints)); + hb_set_destroy (codepoints); + + check_num_vmetrics(face_full_subset, 1); /* nothing has same width */ + hb_subset_test_check (face_subset, face_full_subset, HB_TAG ('v','m','t','x')); + + hb_face_destroy (face_full_subset); + hb_face_destroy (face_full); + hb_face_destroy (face_subset); +} + +static void +test_subset_vmtx_noop (void) +{ + hb_face_t *face_full = hb_subset_test_open_font ("fonts/Mplus1p-Regular.660E,6975,73E0,5EA6,8F38,6E05.ttf"); + + hb_set_t *codepoints = hb_set_create(); + hb_set_add (codepoints, 0x660E); + hb_set_add (codepoints, 0x6975); + hb_set_add (codepoints, 0x73E0); + hb_set_add (codepoints, 0x5EA6); + hb_set_add (codepoints, 0x8F38); + hb_set_add (codepoints, 0x6E05); + hb_face_t *face_full_subset = hb_subset_test_create_subset (face_full, hb_subset_test_create_input (codepoints)); + hb_set_destroy (codepoints); + + check_num_vmetrics(face_full_subset, 1); /* all have the same width */ + hb_subset_test_check (face_full, face_full_subset, HB_TAG ('v','m','t','x')); + + hb_face_destroy (face_full_subset); + hb_face_destroy (face_full); +} + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + + hb_test_add (test_subset_vmtx_simple_subset); + hb_test_add (test_subset_vmtx_noop); + + return hb_test_run(); +} From 91867cda6ae5ae063482b28b0a52ebc30718cb40 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 7 Mar 2018 10:17:06 -0800 Subject: [PATCH 4/6] [subset] cleanup. --- src/hb-subset.cc | 2 +- test/api/test-subset-vmtx.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 0f4648547..541987bf5 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -253,7 +253,7 @@ _subset_table (hb_subset_plan_t *plan, result = _subset (plan); break; case HB_OT_TAG_vhea: - DEBUG_MSG(SUBSET, nullptr, "skip vhea handled by hmtx"); + DEBUG_MSG(SUBSET, nullptr, "skip vhea handled by vmtx"); return true; case HB_OT_TAG_vmtx: result = _subset (plan); diff --git a/test/api/test-subset-vmtx.c b/test/api/test-subset-vmtx.c index 0abab8ca8..f1d94f3a0 100644 --- a/test/api/test-subset-vmtx.c +++ b/test/api/test-subset-vmtx.c @@ -31,12 +31,11 @@ /* Unit tests for hmtx subsetting */ -static void check_num_vmetrics(hb_face_t *face, uint16_t expected_num_hmetrics) +static void check_num_vmetrics(hb_face_t *face, uint16_t expected_num_vmetrics) { hb_blob_t *vhea_blob = hb_face_reference_table (face, HB_TAG ('v','h','e','a')); hb_blob_t *vmtx_blob = hb_face_reference_table (face, HB_TAG ('v','m','t','x')); - // TODO I sure wish I could just use the hmtx table struct! unsigned int vhea_len; uint8_t *raw_vhea = (uint8_t *) hb_blob_get_data(vhea_blob, &vhea_len); uint16_t num_hmetrics = (raw_vhea[vhea_len - 2] << 8) + raw_vhea[vhea_len - 1]; From 89465cb1c7b8ab61c0ef4887f51572ba91039f3e Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 7 Mar 2018 10:29:15 -0800 Subject: [PATCH 5/6] [subset] s/hmetrics/vmetrics. --- test/api/test-subset-vmtx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/api/test-subset-vmtx.c b/test/api/test-subset-vmtx.c index f1d94f3a0..79d41df66 100644 --- a/test/api/test-subset-vmtx.c +++ b/test/api/test-subset-vmtx.c @@ -38,8 +38,8 @@ static void check_num_vmetrics(hb_face_t *face, uint16_t expected_num_vmetrics) unsigned int vhea_len; uint8_t *raw_vhea = (uint8_t *) hb_blob_get_data(vhea_blob, &vhea_len); - uint16_t num_hmetrics = (raw_vhea[vhea_len - 2] << 8) + raw_vhea[vhea_len - 1]; - g_assert_cmpuint(expected_num_hmetrics, ==, num_hmetrics); + uint16_t num_vmetrics = (raw_vhea[vhea_len - 2] << 8) + raw_vhea[vhea_len - 1]; + g_assert_cmpuint(expected_num_vmetrics, ==, num_vmetrics); hb_blob_destroy (vhea_blob); hb_blob_destroy (vmtx_blob); From 362f28240683fde395ff52f4fc1216fbc7131452 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 7 Mar 2018 11:08:55 -0800 Subject: [PATCH 6/6] [subset] fix author. --- test/api/test-subset-vmtx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/api/test-subset-vmtx.c b/test/api/test-subset-vmtx.c index 79d41df66..ce2b02dc7 100644 --- a/test/api/test-subset-vmtx.c +++ b/test/api/test-subset-vmtx.c @@ -21,7 +21,7 @@ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * - * Google Author(s): Roderick Sheeter + * Google Author(s): Garret Rieger */ #include