diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index 100915019..c53d6e353 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -256,6 +256,7 @@ struct KerxSubTableFormat1 * other subtables in kerx. Discovered via testing. */ kernAction (&table->machine + table->kernAction), depth (0), + stack_pos (0), crossStream (table->header.coverage & table->header.CrossStream) {} HB_AAT_TRANSITION_INLINE @@ -265,12 +266,16 @@ struct KerxSubTableFormat1 { unsigned int flags = entry.flags; - if (flags & Format1EntryT::Reset) - depth = 0; - + /* CoreText ignores the kerx Reset flag. */ if (flags & Format1EntryT::Push) { - if (likely (depth < ARRAY_LENGTH (stack))) + if (Types::extended) + { + stack[stack_pos] = buffer->idx; + stack_pos = (stack_pos + 1) % ARRAY_LENGTH (stack); + depth = hb_min (depth + 1, (unsigned) ARRAY_LENGTH (stack)); + } + else if (likely (depth < ARRAY_LENGTH (stack))) stack[depth++] = buffer->idx; else depth = 0; /* Probably not what CoreText does, but better? */ @@ -292,11 +297,20 @@ struct KerxSubTableFormat1 hb_mask_t kern_mask = c->plan->kern_mask; + /* Contrary to the kerx spec's destructive pops, CoreText retains an + * eight-slot circular history and walks it anew for each action list. + * See test/shape/data/in-house/tests/aat-kerx.tests for native cases. */ + unsigned int cursor = stack_pos; bool last = false; while (!last && depth) { if (Types::extended) { + if (unlikely (buffer->max_ops-- <= 0)) + { + buffer->successful = false; + return; + } if (!actions->sanitize (&c->sanitizer)) { depth = 0; @@ -314,7 +328,14 @@ struct KerxSubTableFormat1 hb_barrier (); } - unsigned int idx = stack[--depth]; + unsigned int idx; + if (Types::extended) + { + cursor = (cursor + ARRAY_LENGTH (stack) - 1) % ARRAY_LENGTH (stack); + idx = stack[cursor]; + } + else + idx = stack[--depth]; int v = *actions; actions += tuple_count; if (idx >= buffer->len) continue; @@ -388,8 +409,9 @@ struct KerxSubTableFormat1 const KerxSubTableFormat1 *table; private: const UnsizedArrayOf &kernAction; - unsigned int stack[8]; + unsigned int stack[8] = {}; unsigned int depth; + unsigned int stack_pos; bool crossStream; }; diff --git a/test/shape/data/in-house/fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf b/test/shape/data/in-house/fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf new file mode 100644 index 000000000..44b5ccb41 Binary files /dev/null and b/test/shape/data/in-house/fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf differ diff --git a/test/shape/data/in-house/fonts/33f889c2024c188e23bec1c16a74ebb0c717bd7f.ttf b/test/shape/data/in-house/fonts/33f889c2024c188e23bec1c16a74ebb0c717bd7f.ttf new file mode 100644 index 000000000..5d157fb17 Binary files /dev/null and b/test/shape/data/in-house/fonts/33f889c2024c188e23bec1c16a74ebb0c717bd7f.ttf differ diff --git a/test/shape/data/in-house/fonts/4856acb0edc382fd8044d3d822760fed7b0b500e.ttf b/test/shape/data/in-house/fonts/4856acb0edc382fd8044d3d822760fed7b0b500e.ttf new file mode 100644 index 000000000..edc4feff9 Binary files /dev/null and b/test/shape/data/in-house/fonts/4856acb0edc382fd8044d3d822760fed7b0b500e.ttf differ diff --git a/test/shape/data/in-house/fonts/561bf77de7a26a5519dc384eddebfdff04c46c39.ttf b/test/shape/data/in-house/fonts/561bf77de7a26a5519dc384eddebfdff04c46c39.ttf new file mode 100644 index 000000000..61bf3d863 Binary files /dev/null and b/test/shape/data/in-house/fonts/561bf77de7a26a5519dc384eddebfdff04c46c39.ttf differ diff --git a/test/shape/data/in-house/fonts/59e9061302a5ad5b85f9d7c2f702e194fa1d5fce.ttf b/test/shape/data/in-house/fonts/59e9061302a5ad5b85f9d7c2f702e194fa1d5fce.ttf new file mode 100644 index 000000000..12031a122 Binary files /dev/null and b/test/shape/data/in-house/fonts/59e9061302a5ad5b85f9d7c2f702e194fa1d5fce.ttf differ diff --git a/test/shape/data/in-house/fonts/661373fa372e6925c89d82332b60e5a791c8c9f7.ttf b/test/shape/data/in-house/fonts/661373fa372e6925c89d82332b60e5a791c8c9f7.ttf new file mode 100644 index 000000000..3bb4d172b Binary files /dev/null and b/test/shape/data/in-house/fonts/661373fa372e6925c89d82332b60e5a791c8c9f7.ttf differ diff --git a/test/shape/data/in-house/fonts/6bf9a24264162575b51da4af1eafaac975f0af2d.ttf b/test/shape/data/in-house/fonts/6bf9a24264162575b51da4af1eafaac975f0af2d.ttf new file mode 100644 index 000000000..f83b613fd Binary files /dev/null and b/test/shape/data/in-house/fonts/6bf9a24264162575b51da4af1eafaac975f0af2d.ttf differ diff --git a/test/shape/data/in-house/fonts/7ac4822ace9d0c1ebdb3dd52f15408c1be9582e0.ttf b/test/shape/data/in-house/fonts/7ac4822ace9d0c1ebdb3dd52f15408c1be9582e0.ttf new file mode 100644 index 000000000..9b3613335 Binary files /dev/null and b/test/shape/data/in-house/fonts/7ac4822ace9d0c1ebdb3dd52f15408c1be9582e0.ttf differ diff --git a/test/shape/data/in-house/fonts/9882e955795520416cc62be2e4b29648121fd57f.ttf b/test/shape/data/in-house/fonts/9882e955795520416cc62be2e4b29648121fd57f.ttf new file mode 100644 index 000000000..40866554a Binary files /dev/null and b/test/shape/data/in-house/fonts/9882e955795520416cc62be2e4b29648121fd57f.ttf differ diff --git a/test/shape/data/in-house/fonts/a283202703174fdceb061162cb887ec84da5ec8b.ttf b/test/shape/data/in-house/fonts/a283202703174fdceb061162cb887ec84da5ec8b.ttf new file mode 100644 index 000000000..d48cdd6ed Binary files /dev/null and b/test/shape/data/in-house/fonts/a283202703174fdceb061162cb887ec84da5ec8b.ttf differ diff --git a/test/shape/data/in-house/fonts/b2993b8b29634aa46fc9e7bcb61eb6e87cf62972.ttf b/test/shape/data/in-house/fonts/b2993b8b29634aa46fc9e7bcb61eb6e87cf62972.ttf new file mode 100644 index 000000000..81866d2b9 Binary files /dev/null and b/test/shape/data/in-house/fonts/b2993b8b29634aa46fc9e7bcb61eb6e87cf62972.ttf differ diff --git a/test/shape/data/in-house/fonts/b5cb7b50f2975a3375bf6688eb5211d37b16a90b.ttf b/test/shape/data/in-house/fonts/b5cb7b50f2975a3375bf6688eb5211d37b16a90b.ttf new file mode 100644 index 000000000..de24b31dc Binary files /dev/null and b/test/shape/data/in-house/fonts/b5cb7b50f2975a3375bf6688eb5211d37b16a90b.ttf differ diff --git a/test/shape/data/in-house/fonts/b767b987abb0c618ba75fb65459feff4a73e20be.ttf b/test/shape/data/in-house/fonts/b767b987abb0c618ba75fb65459feff4a73e20be.ttf new file mode 100644 index 000000000..29848341a Binary files /dev/null and b/test/shape/data/in-house/fonts/b767b987abb0c618ba75fb65459feff4a73e20be.ttf differ diff --git a/test/shape/data/in-house/fonts/be58c7e67838c61088189342d65e6e6f9dd62345.ttf b/test/shape/data/in-house/fonts/be58c7e67838c61088189342d65e6e6f9dd62345.ttf new file mode 100644 index 000000000..e834c60c0 Binary files /dev/null and b/test/shape/data/in-house/fonts/be58c7e67838c61088189342d65e6e6f9dd62345.ttf differ diff --git a/test/shape/data/in-house/fonts/d79a66345d13c6c6a15c085da4a4c1640b13c810.ttf b/test/shape/data/in-house/fonts/d79a66345d13c6c6a15c085da4a4c1640b13c810.ttf new file mode 100644 index 000000000..741fe625b Binary files /dev/null and b/test/shape/data/in-house/fonts/d79a66345d13c6c6a15c085da4a4c1640b13c810.ttf differ diff --git a/test/shape/data/in-house/fonts/ed2cc6cbd6f0b7c387a672a66d8e3e0be439fa64.ttf b/test/shape/data/in-house/fonts/ed2cc6cbd6f0b7c387a672a66d8e3e0be439fa64.ttf new file mode 100644 index 000000000..04b228741 Binary files /dev/null and b/test/shape/data/in-house/fonts/ed2cc6cbd6f0b7c387a672a66d8e3e0be439fa64.ttf differ diff --git a/test/shape/data/in-house/fonts/f25a8432cd33bdd82904d99f6040c799ce935473.ttf b/test/shape/data/in-house/fonts/f25a8432cd33bdd82904d99f6040c799ce935473.ttf new file mode 100644 index 000000000..3fc801dfc Binary files /dev/null and b/test/shape/data/in-house/fonts/f25a8432cd33bdd82904d99f6040c799ce935473.ttf differ diff --git a/test/shape/data/in-house/tests/aat-kerx.tests b/test/shape/data/in-house/tests/aat-kerx.tests index 4b77eb748..d4e93899b 100644 --- a/test/shape/data/in-house/tests/aat-kerx.tests +++ b/test/shape/data/in-house/tests/aat-kerx.tests @@ -26,4 +26,81 @@ ../fonts/7125f48c02c32e8f8890bd3db88afa13c7ab8b18.ttf;;U+0061,U+0062;[a=0+561|b=1@30,0+645] ../fonts/7125f48c02c32e8f8890bd3db88afa13c7ab8b18.ttf;;U+0063,U+0062;[c=0+480|b=1@70,0+685] ../fonts/a14f746eb8b392338dcc4aa24f7b7450e48c0d7a.ttf;;U+0061,U+0061,U+0062;[a=0+561|a=1+561|b=2@31,0+646] -../fonts/cc3a5bc0b7af5ea992fa8aa7810973e294d3b381.ttf;;U+0061,U+0061,U+0062;[a=0@17,0+578|a=1@13,0+574|b=2@31,0+646] +../fonts/cc3a5bc0b7af5ea992fa8aa7810973e294d3b381.ttf;;U+0061,U+0061,U+0062;[a=0@42,0+603|a=1@17,0+578|b=2@44,0+659] + +# CoreText format 1 retains circular history instead of destructively popping. +# Apple's written rules specify destructive pops and clearing on Reset: +# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6kerx.html +# Native CoreText instead retains eight circular slots, initially pointing to +# the first glyph of the run. Each action list walks backwards from the latest +# push and wraps every eight values; zero values also advance that cursor. +# The Reset flag is ignored. Legacy kern retains its existing pop rules. +# These 35 cases were measured on macOS 15.8.2 and 26.6.2. +# stack-leftover +../fonts/661373fa372e6925c89d82332b60e5a791c8c9f7.ttf;;U+0061,U+0062,U+0063;[a=0+561|b=1@30,0+645|c=2+480] +# stack-extra-value +../fonts/a283202703174fdceb061162cb887ec84da5ec8b.ttf;;U+0061,U+0062;[a=0@60,0+621|b=1@10,0+625] +# stack-double-push +../fonts/b5cb7b50f2975a3375bf6688eb5211d37b16a90b.ttf;;U+0061,U+0062;[a=0@30,0+591|b=1+615] +# stack-zero-first +../fonts/4856acb0edc382fd8044d3d822760fed7b0b500e.ttf;;U+0061,U+0062;[a=0@30,0+591|b=1+615] +# stack-zero-middle +../fonts/ed2cc6cbd6f0b7c387a672a66d8e3e0be439fa64.ttf;;U+0061,U+0062,U+0063;[a=0@30,0+591|b=1+615|c=2@10,0+490] +# stack-negative-odd +../fonts/d79a66345d13c6c6a15c085da4a4c1640b13c810.ttf;;U+0061,U+0061,U+0062;[a=0@-50,0+511|a=1@-40,0+521|b=2@-31,0+584] +# stack-arabic-shape +../fonts/7ac4822ace9d0c1ebdb3dd52f15408c1be9582e0.ttf;;U+0061,U+0062,U+0063,U+0064;[a=0@50,0+611|b=1+615|c=2@20,0+500|d=3+615] +# stream-20 +../fonts/b767b987abb0c618ba75fb65459feff4a73e20be.ttf;;U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062;[a=0@10,0+571|b=1@10,0+625|a=2@10,0+571|b=3@10,0+625|a=4@10,0+571|b=5@10,0+625|a=6@10,0+571|b=7@10,0+625|a=8@10,0+571|b=9@10,0+625|a=10@10,0+571|b=11@10,0+625|a=12@10,0+571|b=13@10,0+625|a=14@10,0+571|b=15@10,0+625|a=16@10,0+571|b=17@10,0+625|a=18@10,0+571|b=19@10,0+625] +# reset-before-action +../fonts/f25a8432cd33bdd82904d99f6040c799ce935473.ttf;;U+0061,U+0062;[a=0@30,0+591|b=1+615] +# reset-and-push +../fonts/b2993b8b29634aa46fc9e7bcb61eb6e87cf62972.ttf;;U+0061,U+0062;[a=0@20,0+581|b=1@10,0+625] +# long-list-64 +../fonts/6bf9a24264162575b51da4af1eafaac975f0af2d.ttf;;U+0061;[a=0@64,0+625] +# history-20 +../fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf;;U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062;[a=0@10,0+571|b=1@10,0+625|a=2@10,0+571|b=3@10,0+625|a=4@10,0+571|b=5@10,0+625|a=6@10,0+571|b=7@10,0+625|a=8@10,0+571|b=9@10,0+625|a=10@10,0+571|b=11@10,0+625|a=12@34,0+595|b=13@32,0+647|a=14@30,0+591|b=15@49,0+664|a=16@46,0+607|b=17@43,0+658|a=18@40,0+601|b=19@37,0+652] +# history-1 +../fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf;;U+0061;[a=0@241,0+802] +# history-2 +../fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf;;U+0061,U+0062;[a=0@214,0+775|b=1@37,0+652] +# history-3 +../fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf;;U+0061,U+0062,U+0061;[a=0@184,0+745|b=1@40,0+655|a=2@37,0+598] +# history-7 +../fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf;;U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061;[a=0@56,0+617|b=1@30,0+645|a=2@49,0+610|b=3@46,0+661|a=4@43,0+604|b=5@40,0+655|a=6@37,0+598] +# history-8 +../fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf;;U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062;[a=0@34,0+595|b=1@32,0+647|a=2@30,0+591|b=3@49,0+664|a=4@46,0+607|b=5@43,0+658|a=6@40,0+601|b=7@37,0+652] +# history-9 +../fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf;;U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061;[a=0@10,0+571|b=1@34,0+649|a=2@32,0+593|b=3@30,0+645|a=4@49,0+610|b=5@46,0+661|a=6@43,0+604|b=7@40,0+655|a=8@37,0+598] +# history-16 +../fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf;;U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062;[a=0@10,0+571|b=1@10,0+625|a=2@10,0+571|b=3@10,0+625|a=4@10,0+571|b=5@10,0+625|a=6@10,0+571|b=7@10,0+625|a=8@34,0+595|b=9@32,0+647|a=10@30,0+591|b=11@49,0+664|a=12@46,0+607|b=13@43,0+658|a=14@40,0+601|b=15@37,0+652] +# history-17 +../fonts/053b0fbe96e1a6ac02e1febd48dc9f28464f5d33.ttf;;U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061;[a=0@10,0+571|b=1@10,0+625|a=2@10,0+571|b=3@10,0+625|a=4@10,0+571|b=5@10,0+625|a=6@10,0+571|b=7@10,0+625|a=8@10,0+571|b=9@34,0+649|a=10@32,0+593|b=11@30,0+645|a=12@49,0+610|b=13@46,0+661|a=14@43,0+604|b=15@40,0+655|a=16@37,0+598] +# late-first-push +../fonts/6bf9a24264162575b51da4af1eafaac975f0af2d.ttf;;U+0062,U+0061;[b=0@56,0+671|a=1@8,0+569] +# late-first-push-three +../fonts/6bf9a24264162575b51da4af1eafaac975f0af2d.ttf;;U+0062,U+0062,U+0061;[b=0@56,0+671|b=1+615|a=2@8,0+569] +# multiple-long-lists +../fonts/6bf9a24264162575b51da4af1eafaac975f0af2d.ttf;;U+0061,U+0061,U+0061;[a=0@168,0+729|a=1@16,0+577|a=2@8,0+569] +# reset-refill +../fonts/b2993b8b29634aa46fc9e7bcb61eb6e87cf62972.ttf;;U+0061,U+0062,U+0061,U+0062;[a=0@20,0+581|b=1@10,0+625|a=2@20,0+581|b=3@10,0+625] +# reset-empty +../fonts/b2993b8b29634aa46fc9e7bcb61eb6e87cf62972.ttf;;U+0062;[b=0@30,0+645] +# reset-repeat +../fonts/b2993b8b29634aa46fc9e7bcb61eb6e87cf62972.ttf;;U+0061,U+0062,U+0062;[a=0@20,0+581|b=1@30,0+645|b=2@10,0+625] +# reset-refill-late +../fonts/b2993b8b29634aa46fc9e7bcb61eb6e87cf62972.ttf;;U+0061,U+0062,U+0061,U+0061,U+0062,U+0061;[a=0@20,0+581|b=1@10,0+625|a=2+561|a=3@20,0+581|b=4@10,0+625|a=5+561] +# action-before-first-push +../fonts/f25a8432cd33bdd82904d99f6040c799ce935473.ttf;;U+0062,U+0061;[b=0+615|a=1@10,0+571] +# reset-without-push +../fonts/f25a8432cd33bdd82904d99f6040c799ce935473.ttf;;U+0061,U+0062,U+0062;[a=0@50,0+611|b=1+615|b=2+615] +# arabic-original +../fonts/561bf77de7a26a5519dc384eddebfdff04c46c39.ttf;;U+0648,U+064E,U+0644,U+064E,U+062F;[uni062F.fina=4+474|uni064E=2@-61,-28+-51|uni0644.init=2+212|uni064E=0@36,-211+-121|uni0648=0+468] +# arabic-revised +../fonts/33f889c2024c188e23bec1c16a74ebb0c717bd7f.ttf;;U+0648,U+064E,U+0644,U+064E,U+062F;[uni062F.fina=4+474|uni064E=2@-61,-28+-51|uni0644.init=2+212|uni064E=0@36,-211+-121|uni0648=0+468] +# reset-long-list +../fonts/59e9061302a5ad5b85f9d7c2f702e194fa1d5fce.ttf;;U+0061,U+0062,U+0061;[a=0@112,0+673|b=1@8,0+623|a=2@8,0+569] +# reset-without-push-long-list +../fonts/9882e955795520416cc62be2e4b29648121fd57f.ttf;;U+0062,U+0061,U+0062,U+0061;[b=0@104,0+719|a=1@16,0+577|b=2+615|a=3@8,0+569] +# reset-each-push-history +../fonts/be58c7e67838c61088189342d65e6e6f9dd62345.ttf;;U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062,U+0061,U+0062;[a=0@10,0+571|b=1@10,0+625|a=2@10,0+571|b=3@10,0+625|a=4@10,0+571|b=5@10,0+625|a=6@10,0+571|b=7@10,0+625|a=8@10,0+571|b=9@10,0+625|a=10@10,0+571|b=11@10,0+625|a=12@34,0+595|b=13@32,0+647|a=14@30,0+591|b=15@49,0+664|a=16@46,0+607|b=17@43,0+658|a=18@40,0+601|b=19@37,0+652]