Skip to content

Commit 76b46d7

Browse files
Tweaks to table keyed patches based on experience implementing it. (#220)
* Tweaks to table keyed patches based on experience implementing it. - Make TablePatch/length into TablePatch/maxUncompressedLength and actually enforce it in the application algorithm. - Clarify what happens when both bit 1 and 0 of flags are set, table removal takes priority. - Make it an error for a non-replacement patch to be missing the base table in the source font. - Make it an error to have leftover unused data in the brotliStream. * Suggestion from @skef --------- Co-authored-by: Chris Lilley <[email protected]>
1 parent f088d8a commit 76b46d7

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

Overview.bs

+18-16
Original file line numberDiff line numberDiff line change
@@ -1687,8 +1687,8 @@ or remove tables in a [=font subset=].
16871687
</tr>
16881688
<tr>
16891689
<td>Tag</td>
1690-
<td><dfn for="Table keyed patch">format</dfn></td>
1691-
<td>Identifies the encoding as table keyed, set to 'iftk'</td>
1690+
<td>format</td>
1691+
<td>Identifies the encoding as table keyed, must be set to 'iftk'</td>
16921692
</tr>
16931693
<tr>
16941694
<td>uint32</td>
@@ -1732,8 +1732,8 @@ of that [=TablePatch=].
17321732
</tr>
17331733
<tr>
17341734
<td>uint32</td>
1735-
<td>length</td>
1736-
<td>The uncompressed length of [=TablePatch/brotliStream=].</td>
1735+
<td><dfn for="TablePatch">maxUncompressedLength</dfn></td>
1736+
<td>The maximum uncompressed length of [=TablePatch/brotliStream=].</td>
17371737
</tr>
17381738
<tr>
17391739
<td>uint8</td>
@@ -1765,9 +1765,8 @@ The algorithm:
17651765

17661766
1. Initialize <var>extended font subset</var> to be an empty font with no tables.
17671767

1768-
2. Check that the [=Table keyed patch/format=] field in <var>patch</var> is equal to 'iftk', if it is
1769-
not equal then <var>patch</var> is not correctly formatted. Patch application has failed, return
1770-
an error.
1768+
2. Check that the <var>patch</var> is valid according to the requirements in [[#table-keyed]] (requirements are marked with a
1769+
"must") and all [=TablePatch=]'s are contained within <var>patch</var>. Otherwise, return an error
17711770

17721771
3. Check that the [=Table keyed patch/compatibilityId=] field in <var>patch</var> is equal to <var>compatibility id</var>.
17731772
If there is no match, or <var>base font subset</var> does not have either an 'IFT ' or 'IFTX' table, then patch application
@@ -1790,23 +1789,26 @@ The algorithm:
17901789
are listed in the [=Table keyed patch/patches=] array.
17911790

17921791

1793-
* If bit 0 (least significant bit) of [=TablePatch/flags=] is set, then decode [=TablePatch/brotliStream=] following
1794-
[[RFC7932#section-10]]. No shared dictionary is used. Add a [[open-type/otff#table-directory|table]] to
1795-
<var>extended font subset</var> identified by [=TablePatch/tag=] with it's contents set to the decoded [=TablePatch/brotliStream=].
1796-
17971792
* If bit 1 of [=TablePatch/flags=] is set, then do not copy or add a [[open-type/otff#table-directory|table]] to
1798-
<var>extended font subset</var> identified by [=TablePatch/tag=].
1793+
<var>extended font subset</var> identified by [=TablePatch/tag=]. Continue to the next entry.
1794+
1795+
* If bit 0 (least significant bit) of [=TablePatch/flags=] is set, then decode [=TablePatch/brotliStream=] following
1796+
[[RFC7932#section-10]]. No shared dictionary is used. If the decoded data is larger than [=TablePatch/maxUncompressedLength=]
1797+
return an error. If there is any data in [=TablePatch/brotliStream=] which was not used by the decoding process return an error.
1798+
Add a [[open-type/otff#table-directory|table]] to <var>extended font subset</var> identified by
1799+
[=TablePatch/tag=] with it's contents set to the decoded [=TablePatch/brotliStream=]. Continue to the next entry.
17991800

18001801
* Otherwise, decode [=TablePatch/brotliStream=] following [[RFC7932#section-10]] and using the
18011802
[[open-type/otff#table-directory|table]] identified by [=TablePatch/tag=] in <var>base font subset</var>
1802-
as a [[Shared-Brotli#section-3.2|shared LZ77 dictionary]]. Add a [[open-type/otff#table-directory|table]] to
1803-
<var>extended font subset</var> identified by [=TablePatch/tag=] with it's contents set to the decoded [=TablePatch/brotliStream=].
1803+
as a [[Shared-Brotli#section-3.2|shared LZ77 dictionary]]. If no such table exists return an error. If the decoded data is
1804+
larger than [=TablePatch/maxUncompressedLength=] return an error. If there is any data in [=TablePatch/brotliStream=] which was
1805+
not used by the decoding process return an error. Add a [[open-type/otff#table-directory|table]] to
1806+
<var>extended font subset</var> identified by [=TablePatch/tag=] with it's contents set to the decoded
1807+
[=TablePatch/brotliStream=].
18041808

18051809
6. For each [[open-type/otff#table-directory|table]] in <var>base font subset</var> which has a tag that was not found in any of
18061810
the entries processed in step 5, add a copy of that table to <var>extended font subset</var>.
18071811

1808-
1809-
18101812
Glyph Keyed {#glyph-keyed}
18111813
--------------------------
18121814

0 commit comments

Comments
 (0)