Repository navigation
[skera] Support naming record overrides - #2411
Conversation
1c9fa72 to
30aa4e5
Compare
|
manual review comments:
below're comments from AI review: Nothing that matters in practice. A name table typically holds tens to a few hundred records, so subsetting it takes microseconds. Still, a few things could be tighter, listed from most 1. retained set is built on every run (worth fixing)In name.rs:30-61, every retained record's key goes into a BTreeSet. That happens on every subset, even when there are no overrides, which is the common case. Only keys that actually The output is the same: a key is "retained" exactly when some record that passed the filters looked it up. The set shrinks from one entry per retained record to at most one per override, 2. Small allocation and loop details• records grows without a capacity hint. Use Vec::with_capacity(self.count() as usize + plan.name_table_overrides.len()). 3. Each record is written as six separate fieldsserialize_name_records calls s.embed(u16) six times per record, and each call does its own bounds check and error mapping. Building the 12-byte record in a [u8; 12] and writing it with 4. override_name_table encoding (negligible)In lib.rs:476-478, encode_utf16().flat_map(u16::to_be_bytes).collect() starts from a low size estimate, so the vector reallocates a couple of times. Vec::with_capacity(text.len() * 2) |
|
Addressed in a02613f:
Output remains deterministic because records are sorted before serialization. |
Remaining nits
non-performance items• The test compares records but not the raw bytes; it could assert byte equality with name.bin. |
|
Addressed the remaining feedback in 92cb532:
Kept the existing record-vector capacity hint, as the review notes that its temporary over-allocation is harmless. Validation passed:
|
|
|
Addressed in c390564:
Validation passed:
The unrestricted Clippy 1.98 run still reports unrelated existing warnings in |
Still open (all small)
|
c390564 to
ac1b977
Compare
|
Addressed in ac1b977, with the PR squashed into a single commit as suggested.
Kept exact UTF-16 sizing rather than the optional short-string shortcut, preserving the earlier fix for over-allocation. Validation passed:
|
Remaining items (minor)
|
Follow HarfBuzz's name override selection and insertion order. Encode Unicode text as UTF-16BE and permit ASCII Macintosh overrides. Reject invalid encoding and length requests up front without replacing previous values; this early validation is an intentional difference from HarfBuzz. Include override text in the initial name-table buffer estimate, another intentional difference from HarfBuzz. This keeps large names usable on tiny source tables even when the serializer's table_len * 256 retry limit would prevent growing the buffer enough. Skip UTF-16 counting when a short UTF-8 input guarantees the encoded name fits, then trim excess capacity before retaining the override. Count longer inputs only up to the encoded length limit before allocating. Compare encoded records with a HarfBuzz reference and cover removals, filter bypass, encoding and length boundaries, large names on tiny source tables, and drop/passthrough precedence.
ac1b977 to
f6812ad
Compare
|
Addressed in f6812ad, keeping the PR as a single commit.
An optimized local encoder-only microbenchmark favored the bound-and-trim approach over exact counting for five representative short names; these are not whole-font timings. Validation passed:
|
|
my agent says: ready to merge as is! |
|
Yoohoo! |
Explicit name overrides can now replace or insert a naming record, or remove it with
Noneor an empty string.Plan::override_name_tablefollows HarfBuzz's override semantics: select source records first, apply removals and replacements, then insert nonempty overrides even when normal name, language, or platform filters exclude them.Macintosh overrides require ASCII; other platforms encode Rust strings as UTF-16BE. Rejected encoding or length requests preserve the previous override. Dropped and passthrough name tables retain precedence, and serializer allocation accounts for inserted text.
This replaces #2292 with a clean commit directly on current
main, without its historical stack-propagation merges.Validation includes a saved naming-table reference from HarfBuzz d659591a6 covering surrogate pairs, embedded NULs, repeated requests, insertion past filters, and removals. Additional checks cover rejected requests, a 65,534-byte encoded name, and dropped/passthrough tables.
Tests:
cargo +1.89 fmt --all --checkcargo +1.89 clippy -p skera --all-features --all-targets -- -D warningscargo +1.89 test -p skera --all-features