Commit Graph

341 Commits

Author SHA1 Message Date
Garret Rieger 3f7a74ff40 [repacker] WIP extension promotion implementation. 2022-07-26 12:22:17 -06:00
Behdad Esfahbod 94de328011 [GSUB/GPOS] Adjust buffer message 2022-07-24 18:51:55 -06:00
Behdad Esfahbod bc80e4b923 [GSUB/GPOS] More buffer message for contextuals
Fixes https://github.com/harfbuzz/harfbuzz/issues/3753
2022-07-24 18:50:14 -06:00
Behdad Esfahbod 5a9c7930ef Add HB_NO_BEYOND_64K 2022-07-22 21:33:31 -06:00
Behdad Esfahbod 00dfbbce1c [Coverage] Rename and templatize intersected_coverage_glyphs 2022-07-21 11:45:05 -06:00
Behdad Esfahbod 6826b2c3fd [gsubgpos/closure] Minor condition use bool operator 2022-07-20 13:25:34 -06:00
Behdad Esfahbod 1665cf6bc4 [>64k:layout] Split GDEFVersion1
https://github.com/be-fonts/boring-expansion-spec/issues/36
2022-07-19 14:21:48 -06:00
Behdad Esfahbod 99f017f41d [>64k:layout:GSUBGPOS] Implement format 2
Implements https://github.com/be-fonts/boring-expansion-spec/issues/58

Subset does NOT lower format.
2022-07-12 13:42:52 -06:00
Behdad Esfahbod 9ef9fc0114 [>64k:layout] Templatize GSUBGPOSFormat1 2022-07-12 13:42:52 -06:00
Behdad Esfahbod 5fd0a3f0b9 [>64k:layout] Templatize GSUBGPOSFormat1 2022-07-12 13:42:52 -06:00
Behdad Esfahbod 6d0e3e677b [>64k:layout] Split GSUBGPOSVersion1 into own struct 2022-07-12 13:42:52 -06:00
Behdad Esfahbod 04c5cd4085 [subset/layout] Move find_duplicate_features to subset from layout 2022-07-12 13:42:52 -06:00
Behdad Esfahbod 1bf8fa2f1f [>64k:layout:(Chain)Context] Implement format 4
Implements rest of https://github.com/be-fonts/boring-expansion-spec/issues/34

Subset does NOT lower format.
2022-07-12 13:42:52 -06:00
Behdad Esfahbod 0f13eb1f5c [>64k:layout] Templatize (Chain)ContextFormat1 2022-07-12 13:42:52 -06:00
Behdad Esfahbod d1f58e5979 [>64k:layout:(Chain)Context] Implement format 5
Implements part of https://github.com/be-fonts/boring-expansion-spec/issues/34

Subset does NOT lower format.
2022-07-12 13:42:52 -06:00
Behdad Esfahbod a90c5af9d2 [>64k:layout] Templatize (Chain)ContextFormat2 2022-07-12 13:42:52 -06:00
Behdad Esfahbod 9d0e9faa43 [>64k:layout] Templatable bunch of GSUBGPOS internal functions 2022-07-12 13:42:52 -06:00
Behdad Esfahbod 429b387a6f [>64k:layout] Support HBUINT24 in skippy_iter 2022-07-12 13:42:52 -06:00
Behdad Esfahbod 1ef67a6d66 [gsubgpos] Remove HBUINT16 from matcher 2022-07-12 13:42:52 -06:00
Behdad Esfahbod 6d051f4018 [layout] Simplify StructAfter<> usage 2022-07-08 14:09:04 -06:00
Behdad Esfahbod 5192294f83 . 2022-07-08 14:09:04 -06:00
Behdad Esfahbod 8b349e1139 [gsubgpos] Remove HBUINT16 from match functions signatures 2022-07-08 12:05:01 -06:00
Behdad Esfahbod f114b18c58 [gsubgpos] Break skippy_iter set_match_func into two 2022-07-08 12:04:14 -06:00
Behdad Esfahbod 4119f73c21 [subset/layout] Rename dispatch_closure_lookups_recurse_func to dispatch_recurse_func<> 2022-06-08 18:42:09 +01:00
Behdad Esfahbod 21346af01d [layout-cache] Adjust cost-function for recent change 2022-06-07 14:41:39 -06:00
Behdad Esfahbod bfee6839b0 [layout-cache] Cache lookahead, not input, classdef in ChainContextFormat2
From the commit:

+    /* For ChainContextFormat2 we cache the LookaheadClassDef instead of InputClassDef.
+     * The reason is that most heavy fonts want to identify a glyph in context and apply
+     * a lookup to it. In this scenario, the length of the input sequence is one, whereas
+     * the lookahead / backtrack are typically longer.  The one glyph in input sequence is
+     * looked-up below and no input glyph is looked up in individual rules, whereas the
+     * lookahead and backtrack glyphs are tried.  Since we match lookahead before backtrack,
+     * we should cache lookahead.  This decisions showed a 20% improvement in shaping of
+     * the Gulzar font.

https://github.com/harfbuzz/harfbuzz/pull/3636
2022-06-07 11:41:05 -06:00
Behdad Esfahbod 39820af72f [layout] Add HB_NO_OT_LAYOUT_LOOKUP_CACHE to disable caching lookups
Enabled when optimize-size profile is enabled.
2022-06-07 10:27:55 -06:00
Behdad Esfahbod c8fb048f79 [gsubgpos] Document caching 2022-06-07 09:20:27 -06:00
Behdad Esfahbod 5963cf4469 [gsubgpos] Merge cache_enter and cache_leave entry points
Saves a pointer per subtable
2022-06-07 09:17:14 -06:00
Behdad Esfahbod d4c09e9a87 [gsubgpos] Remove apply_cached() entry point
Just use a bool to apply()
2022-06-07 09:17:14 -06:00
Behdad Esfahbod b96622d15c [layout] Use a cache for main input ClassDef of (Chain)ContextLookupFormat2
This commit adds a per-lookup caching infrastructure to GSUB/GPOS, and
uses it to cache input ClassDef.get_class value for (Chain)ContextLookupFormat2.

For fonts heavy on use of heave class-based2 context matching, this shows
a good speedup. For NotoNastaliqUrdu for example, I observe 17% speedup.

Unfortunately not many other lookups can use a cache like this :(.

https://github.com/harfbuzz/harfbuzz/pull/3636
2022-06-07 09:14:38 -06:00
Behdad Esfahbod e6409d3905 Revert "[layout] Use a cache for main input ClassDef of (Chain)ContextLookups"
This reverts commit 57d1c08739.

Err. This was an accident.
2022-06-05 06:57:37 -06:00
Behdad Esfahbod 57d1c08739 [layout] Use a cache for main input ClassDef of (Chain)ContextLookups 2022-06-05 06:54:19 -06:00
Behdad Esfahbod f9b643f6b2 [layout] s/hb_get_subtables_context_t/hb_accelerate_subtables_context_t/g 2022-06-04 09:27:31 -06:00
Behdad Esfahbod a42c624fca Convert one final use of hashmap to unique_ptr 2022-06-03 01:22:34 -06:00
Behdad Esfahbod f13a79548f [subset] Convert another use of hashmap to unique_ptr 2022-06-03 01:17:20 -06:00
Behdad Esfahbod 997d9cc466 [map] Make unique_ptr hashable 2022-06-02 18:47:42 -06:00
Behdad Esfahbod bca710e8ad [gsubgpos] Use map has() instead of get() when appropriate 2022-06-02 12:06:25 -06:00
Behdad Esfahbod e9407a2bd2 Use shared_ptr<hb_set_t> in one place
See if valgrind is happy...
2022-06-02 12:00:43 -06:00
Behdad Esfahbod 9a2a857043 [ot-shape] Don't verify buffer if shaping failed
Fixes all of fuzzing verify failures, which were result of buffer failure
on super-long results, which fails unsafe-to-break because shorter strings
don't fail shaping.
2022-05-31 06:35:42 -06:00
Behdad Esfahbod f4a8b70016 More member initialization 2022-05-30 05:30:37 -06:00
Behdad Esfahbod 97aa1ce6ba [gsubgpos] Move some member initialization 2022-05-29 10:56:41 -06:00
Behdad Esfahbod 3eb7eff487 Remove varstore cache use if HB_NO_VAR 2022-05-21 15:25:53 -06:00
Behdad Esfahbod 880f50f7e4 Refactor varstore cache 2022-05-21 15:12:14 -06:00
Behdad Esfahbod f2a2fb91a3 [GPOS] Cache VarStore region scalars 2022-05-21 15:12:14 -06:00
Behdad Esfahbod 202e6c4699 [subset] Remove unnecessary test 2022-05-18 17:12:43 -06:00
Behdad Esfahbod 4cfc2d668e [subset] Use a std::move on set_t when feasible 2022-05-18 15:32:19 -06:00
Behdad Esfahbod 6695bf0560 [gsubgpos] Remove wrong condition in Context application
Fixes https://github.com/harfbuzz/harfbuzz/issues/3545
2022-04-22 13:48:41 -06:00
Behdad Esfahbod a85461b9b6 Add link to Context LookupFlag discussion
https://github.com/harfbuzz/harfbuzz/discussions/3538
2022-04-20 12:13:40 -06:00
Behdad Esfahbod 044d7a06db [indic-like] Add per-lookup per-syllable flag
This allows mix-and-matching per-syllable and other lookups.
In fact, removes the clear-syllables call completely.

Fixes https://github.com/harfbuzz/harfbuzz/issues/3513
2022-03-28 17:39:54 -06:00
Behdad Esfahbod e8f3397f4e [matcher] Simplify syllable initialization 2022-03-28 13:23:37 -06:00
Behdad Esfahbod ccd9161bfd [apply-lookup] Try to fix the logic for contextual lookups
Fixes https://github.com/harfbuzz/harfbuzz/issues/1611

Notably, this fixes Myles's AdditionFont:
https://litherum.blogspot.com/2019/03/addition-font.html

Test with AdditionFont, eg.:
$ util/hb-view AdditionFont.otf =1112112+1113134=
2022-03-25 15:14:40 -06:00
Behdad Esfahbod bf2a845a17 [ot-layout] Comment 2022-03-24 13:09:53 -06:00
Garret Rieger 4e2f409bce [subset] Don't hold references to members of the active_glyph_stack.
These references may get invalidated after the vector for the stack is resized. Fixes: https://oss-fuzz.com/testcase-detail/5422577634377728
2022-01-31 22:58:53 +02:00
Garret Rieger bc899650c7 [subset] Fix for issue #3397.
cur_intersected_glyphs gets modified during recursion leading to incorrect filtering of sub tables in some cases. So don't use cur_intersected_glyphs. Instead just add an additional entry onto the parent_active_glyphs () stack.

Additionaly expands NotoNastaliqUrdu tests to include coverage of the issue from #3397.
2022-01-28 14:20:33 -08:00
Garret Rieger f3c1f4f0da [subset] convert active_glyphs_stack to be a vector of hb_set_t instead of hb_set_t*. 2022-01-28 14:20:33 -08:00
Behdad Esfahbod 60006d3687 [gsubgpos] Adjust chaining unsafe-to-concat application
Fixes three tests.
2022-01-22 11:53:18 -07:00
Behdad Esfahbod 78481b32c0 [gsubgpos] Combine input/backtrack/lookahead unsafe-to-concat
I feel like this is correct logic. Still have to prove.

Errors unchanged at 10.
2022-01-22 11:53:18 -07:00
Behdad Esfahbod 3122c2cdc4 [buffer] Add HB_GLYPH_FLAG_UNSAFE_TO_CONCAT
Fixes https://github.com/harfbuzz/harfbuzz/issues/1463
2022-01-22 11:53:18 -07:00
Behdad Esfahbod ac1bb3e39e [machinery] Move accelerators to constructor/destructor 2022-01-20 12:10:05 -07:00
Behdad Esfahbod e062376ef1 [machinery] Make accelerator lazy-loader call Xinit/Xfini
Instead of init/fini. To isolate those functions. To be turned into
constructor/destructors, ideally one per commit (after some SFINAE
foo.)
2022-01-19 17:09:34 -07:00
Behdad Esfahbod c8195dbc01
Merge pull request #3365 from harfbuzz/gdef-fix
GDEF fix
2022-01-19 06:56:05 -08:00
Behdad Esfahbod 5a91db1135 [map] Remove constexpr invalid items
These were non-workable in the general case, eg std::string.
2022-01-13 12:44:48 -07:00
Behdad Esfahbod fa12f1ae25 Rename method 2022-01-12 15:08:34 -07:00
Behdad Esfahbod 9408e0d6d1 Rename variable 2022-01-12 15:07:34 -07:00
Behdad Esfahbod 96c969c820 Preserve glyph props 2022-01-12 15:06:40 -07:00
Garret Rieger 77507a1d8d [subset] Don't double count visit lookups in closure_lookups
Each recursed lookup was getting counted once in closure_lookups() and then again in hb_closure_lookups_context_t::recurse.
2021-12-10 15:13:49 -07:00
Garret Rieger d67025705f [subset] reset the visited lookup count before each closure iteration. 2021-12-10 15:13:49 -07:00
Qunxin Liu 706014f69d [subset] (Chain)ContextSubst glyph_closure fix
- When pos_glyphs is empty, use current full glyphs set as input for
subsequent recursive closure process
- Also increase max_lookup_visit_count to 35000 cause a real font file hit
previous limit 20000 and some lookups are dropped unexpectedly
2021-12-10 11:08:36 -07:00
Behdad Esfahbod 98fefd5ded
Merge pull request #3301 from harfbuzz/hashmap-classes
Hashmap classes
2021-11-19 13:34:53 -07:00
Qunxin Liu ca418cac74 [subset] keep features that have FeatureParams and the tag is "size" 2021-11-19 13:31:25 -07:00
Qunxin Liu e88fc41ef3 [subset] inputSequence could be empty, change the sanity check 2021-11-19 12:57:43 -07:00
Behdad Esfahbod 394f772937 [map] Allow storing classes in the hashmap
Fixes https://github.com/harfbuzz/harfbuzz/issues/3293

The trick was to change the type of the invalid key/value to be non-class.
2021-11-19 11:49:23 -07:00
Garret Rieger f51b48c8e7 [subset] Fix fuzzer found memory leak.
Happens because an insert into a map with an invalid key reports successful, but this causes the set being inserted to be lost.
2021-11-02 17:00:07 -07:00
Qunxin Liu 540f19b6fe [subset] fix bug in (Chain)ContextFormat2
Only keep rulesets for glyphs class numbers that survived in coverage
2021-11-02 16:05:55 -07:00
Qunxin Liu 364b6b3989 [subset] Don't assume FeatureList is sorted
Though the spec said FeatureRecords are sorted alphabetically by feature
tag, there're font files with unsorted FeatureList. And harfbuzz is not
able to subset these files correctly because we use binary search in
finding featureRecords when collecting lookups. Also
find_duplicate_features needs to be updated to handle this.
2021-11-02 15:15:02 -07:00
Behdad Esfahbod 6d555ce82e [meta] Use std::forward instead of hb_forward() 2021-11-02 00:18:22 -06:00
Qunxin Liu 36ed56b6e8 [subset] code cleanup
- rename copy() method if it takes extra parameter
- get rid of same code blocks
2021-10-09 13:37:20 -06:00
Garret Rieger c2cc566c9d [subset] Fix subset_offset_array adding unused space to serializer.
ArrayOf.serialize_append allocates space for the new item, but ArrayOf.pop() does not recover the allocated space. So in the case where the revert path was entered the extra space added by serialize_append gets left in the serialization buffer. This moves the snapshot to before ArrayOf.serialize_append is called so that revert cleans up the buffer extend.
2021-09-22 16:07:18 -06:00
Qunxin Liu 8c5c81746d [subset] fix find_duplicate_features
We should check each feature against all other features with the same
tag for duplicates.
2021-09-22 15:35:38 -06:00
Qunxin Liu 37379f8f7d [subset] fox for (Chain)ContextFormat3: subset lookupRecord
skip copying a lookupRecord if lookup referenced in the lookupRecord is
not retained after subset
2021-09-08 13:55:21 -06:00
Behdad Esfahbod fad452bffb [set] Move main functionality into hb_bit_set_t
To add inversion on top in hb_invertible_set_t and use that as hb_set_t.
2021-08-17 10:47:18 -06:00
Behdad Esfahbod 30579f5a37 [set] Document & use open-ended del_range() 2021-07-29 11:19:13 -06:00
Behdad Esfahbod 2337f0d047 Internally use hb_malloc/.../hb_free instead of malloc/.../free
Redefining those stock names as macros was conflicting with gcc 10
headers.

Fixes https://github.com/harfbuzz/harfbuzz/issues/3044
2021-07-08 10:54:09 -07:00
Garret Rieger 085aa65e09 [subset] Convert offset serialization in gsubgpos and gdef to serialize_serialize(). 2021-06-14 16:47:45 -07:00
Behdad Esfahbod bc33b87f5e [set] Use references, not pointers, in internal C++ API 2021-06-09 11:54:12 -06:00
Garret Rieger 8b686afeb5 [subset] add unlikely(). 2021-04-06 12:34:44 -06:00
Garret Rieger 64122b5a44 [subset] don't visit lookup if covered glyph set has failed.
If covered glyph set is in error then the same lookup can be recursed into repeatedly potentially causing a fuzzer timeout. Fixes: https://oss-fuzz.com/testcase-detail/5416421032067072.
2021-04-06 12:34:44 -06:00
Garret Rieger c35d786397 [subset] never drop the 'pref' feature.
Never ever drop feature 'pref', even if it's empty. Harfbuzz uses it to choose the shaper for Khmer.
2021-04-01 16:27:35 -06:00
Garret Rieger b10741ca7f [subset] when closing glyphs in context lookups don't use a current glyph set if a lookup is already applied. 2021-03-31 21:03:33 -06:00
Behdad Esfahbod 5639e253f9 Add Array16Of<> 2021-03-31 16:04:43 -06:00
Behdad Esfahbod 5efe360986 Rename (Unsized)OffsetListOf 2021-03-31 15:33:22 -06:00
Behdad Esfahbod 6c4e0491d7 s/OffsetArrayOf/Array16OfOffset16To/g 2021-03-31 15:31:32 -06:00
Behdad Esfahbod 9b4b58493b Fixup for recent OffsetTo<> changes 2021-03-31 13:27:21 -06:00
Behdad Esfahbod ad28f973f3 Rename offset types to be explicit about their size
Add Offset16To<>, Offset24To<>, and Offset32To<> for most use-cases.
2021-03-31 13:00:07 -06:00
Garret Rieger adca4ce071 [subset] fixes https://oss-fuzz.com/testcase-detail/6173520787800064.
Caused by incorrect bounds check in glyph closure for context lookups.
2021-03-30 15:44:41 -06:00
Garret Rieger 9f77a0c1ff [subset] use hb_set_clear to avoid calling clear() on null pool set. 2021-03-30 15:12:52 -06:00
Garret Rieger 752e393ad2 [subset] avoid calling clear on null pool set. 2021-03-30 15:12:52 -06:00
Behdad Esfahbod 9ed5f04a70 [subset] Simplify recent out-of-memory fixes
By checking return status of map->set().
2021-03-29 18:14:30 -06:00
Garret Rieger 52df6b9fd8 [subset] check for set insertion success. 2021-03-29 17:41:07 -06:00