From 21bf147054f6b5bd1c430c0e02a8c4058ed229a1 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 5 Sep 2018 18:04:52 -0700 Subject: [PATCH] [subset] Fix hdmx subsetted size calculation. --- src/hb-ot-hdmx-table.hh | 14 ++++++++---- test/api/fonts/Roboto-Regular.multihdmx.a.ttf | Bin 0 -> 2052 bytes .../fonts/Roboto-Regular.multihdmx.abc.ttf | Bin 0 -> 2468 bytes test/api/test-subset-hdmx.c | 20 ++++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 test/api/fonts/Roboto-Regular.multihdmx.a.ttf create mode 100644 test/api/fonts/Roboto-Regular.multihdmx.abc.ttf diff --git a/src/hb-ot-hdmx-table.hh b/src/hb-ot-hdmx-table.hh index c523c420a..87dd6d018 100644 --- a/src/hb-ot-hdmx-table.hh +++ b/src/hb-ot-hdmx-table.hh @@ -88,8 +88,13 @@ struct DeviceRecord { TRACE_SERIALIZE (this); - if (unlikely (!c->allocate_size (get_size (subset_view.len())))) + unsigned int size = get_size (subset_view.len()); + if (unlikely (!c->allocate_size (size))) + { + DEBUG_MSG (SUBSET, nullptr, "Couldn't allocate enough space for DeviceRecord: %d.", + size); return_trace (false); + } this->pixel_size.set (subset_view.source_device_record->pixel_size); this->max_width.set (subset_view.source_device_record->max_width); @@ -160,14 +165,14 @@ struct hdmx return_trace (true); } - static inline size_t get_subsetted_size (hb_subset_plan_t *plan) + static inline size_t get_subsetted_size (const hdmx *source_hdmx, hb_subset_plan_t *plan) { - return min_size + DeviceRecord::get_size (plan->glyphs.len); + return min_size + source_hdmx->num_records * DeviceRecord::get_size (plan->glyphs.len); } inline bool subset (hb_subset_plan_t *plan) const { - size_t dest_size = get_subsetted_size (plan); + size_t dest_size = get_subsetted_size (this, plan); hdmx *dest = (hdmx *) malloc (dest_size); if (unlikely (!dest)) { @@ -180,6 +185,7 @@ struct hdmx if (!hdmx_prime || !hdmx_prime->serialize (&c, this, plan)) { free (dest); + DEBUG_MSG(SUBSET, nullptr, "Failed to serialize write new hdmx."); return false; } c.end_serialize (); diff --git a/test/api/fonts/Roboto-Regular.multihdmx.a.ttf b/test/api/fonts/Roboto-Regular.multihdmx.a.ttf new file mode 100644 index 0000000000000000000000000000000000000000..dd82178fd64fd81da1dd5ad7eb8f7d9c65f1a2c4 GIT binary patch literal 2052 zcmZuxeQZ-z6hH5y-(~AYx3U(tSGtXTv}|sr!d#$WyNyh@u?~1$CR&>r_qrj*`*MHh{LVdJ z@4k00Z~#z&;sbZXsvAR>I`Xa{CpmHAM!+NX!njcicS_Izk%G>8LDeY zj+`_D@RyJe48|h~aBx2X2y2ncgGZ85?FYIG0NUfodxjFj@uPnZe1z*s0PfmwWHJGI zSdICraNRsSdTeOV+;1Ck&5iuQNHjjZ+NignKh^-tNGuYC?#p9XuMN3x1P!Kp{7vL@ z$je9K$!XmWa0~eia{cJ|U<95;4R}9-HXfNy@Fjc)atXOK7Kz9BdE@W6ggIbyVtg{0 zjYAas(bIZjB9?e}=&!E;H1*iiPT(P)y)WDoJD?P*;CRMXT~koFh1o1jx(N(|GPBh= z(l-0nutG#6VquN|5K$kp3o<&tUddDq#cOG&AF_S08Cyt+Fw8ExJ5mVEWSrMx#~%c8G@k%=#-KSdd|$BLh;uw+NoNPm9wAK;)Z1i1cd0e(+_Z$GOK zKwtL0C@DdPTs{z9gQ(aGaf;WCF5!0;Pe308L@8H`g4Mx;AkK2Hg9g9HIZY#$EK{X$ z3x=pYwZ)vb+G&ooc6PRcA0iOZ!V$T;2l~Pn=}lG1OgIDAsRHI#)uPjve8_N zNEt~QQ8v?gK`G)x_DD9XV)kOLZ~9}&Umc1Msu7$V19v+!bjfLsI~`u&vM;lj)};+X z|2_}n+>#VL5MbPZhw*O4)i^y&a7!&rsA%byU12FDrFKSBQj0Vai88T5k+={`h3g~+ zA^8AekL+aruwzAyg~LrACQ=%VK<`u-6CBJXK&hDO{`N49yIo>JWtY55W-|c?^9RBX zr&9{D#V(mG1{}_C*u%6dJz}pX4y;kT)w!9r#>4b#hLFts4hG>=it>eImy^w;QjQe9 z!7^WblrM1bUxWYO2Hb(*0yoozsZh9_4l=l$E+=*v4tSWs-5!#I*rF3#G`d+;(8Ek_ zR*k~!PH*7mq*O@0;>YhbxS)r*9{CDX33n4=2XkSw(%gat_bq3mw_N3B{<#GSdgXLA z1RPhOTDTiPySbJ@Eo3+gU(00*IK=saruqtp1@yHr&$T_V(P>3>o|oG;S1Fp%{iL^| zm~7&{r<-d_NYnV->r3)U(;j}NrNKd(?(EUNCKqY?=Z3qs*hw?=1bvlC7UPkDcHcU( znO=-`sD9=co+ZFX)l z(@*d`L7kmTW;zMR3C<8)Cdd+$*|{l-n4*X&ikQmemr^XjF9ccb=;TmM%G+ak7>(T&N`L{t5oL~~0 zz$%^s3!Yi4b`2D9??Zuh5%RQmR&FC6Z)ZHMq5)4LokCUT@zyd!H;lu6oJpMB5QAZu zf>At`6X>Ok>_NK!|7UP`H|T-KbDocRDVsWqku5)Tdr(C)T4)d&p&qt^7-)H_2ke8# zCPu+NJP|tt_R&ak4D9$n;=rur%N>eMjA0culEXF1$WdKbqj;9$yW!P~R&^{_UY1m^ V0lbgYD_823EA`4(>MdtL`44thxQhS) literal 0 HcmV?d00001 diff --git a/test/api/fonts/Roboto-Regular.multihdmx.abc.ttf b/test/api/fonts/Roboto-Regular.multihdmx.abc.ttf new file mode 100644 index 0000000000000000000000000000000000000000..03dd8b6b70954350e44a42b1baa440a6fdfa0d53 GIT binary patch literal 2468 zcmZuzeQaCR6+idAXXp8YiJYB$MqUp^a~1Sj<%i%Qs>q$sQjNea(VX=ChsL7bSx zDPdZ-j*pU=meNs#R0cy6+PV(WYx9w0?W9NpP1^*64Q*u7CQa%e40VEOA3~dI@0|CX zhN3;|opXNYo^$T++-u)!U;yAoA%WT-?d^jQr~ooYZ*%|9;E2`sw@ZjWM0}=yNs?`qWfRq zr)dD*`qXt3=|8;L9)*L&E0Ss@Xaj*1KA2ZFTX15Xqi_(Sl4?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yB-egV~hIzOT-weLPFacAr1haTAEnt-K6z`|I_y0T$>&hVDeNusSshaszqs{O` z_YnEtV-hFqDf-mv#!Yufv7A775-)uZH2R=Oa@WHA^`~wpUb2y8c z$#9J7F`5^DClnc`T3cKZfAKMS2qiYeY1=kynViDVc^#*EgHyf1ss0+L&sF~)yT&p< literal 0 HcmV?d00001 diff --git a/test/api/test-subset-hdmx.c b/test/api/test-subset-hdmx.c index 22fcb4118..8a1e821a3 100644 --- a/test/api/test-subset-hdmx.c +++ b/test/api/test-subset-hdmx.c @@ -50,6 +50,25 @@ test_subset_hdmx_simple_subset (void) hb_face_destroy (face_ac); } +static void +test_subset_hdmx_multiple_device_records (void) +{ + hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Roboto-Regular.multihdmx.abc.ttf"); + hb_face_t *face_a = hb_subset_test_open_font ("fonts/Roboto-Regular.multihdmx.a.ttf"); + + hb_set_t *codepoints = hb_set_create (); + hb_face_t *face_abc_subset; + hb_set_add (codepoints, 'a'); + face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints)); + hb_set_destroy (codepoints); + + hb_subset_test_check (face_a, face_abc_subset, HB_TAG ('h','d','m','x')); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); + hb_face_destroy (face_a); +} + static void test_subset_hdmx_invalid (void) { @@ -115,6 +134,7 @@ main (int argc, char **argv) hb_test_init (&argc, &argv); hb_test_add (test_subset_hdmx_simple_subset); + hb_test_add (test_subset_hdmx_multiple_device_records); hb_test_add (test_subset_hdmx_invalid); hb_test_add (test_subset_hdmx_fails_sanitize); hb_test_add (test_subset_hdmx_noop);