Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IFT] major rework to the IFT API around patch intersection and application. #1239

Merged
merged 19 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
07916af
[IFT] begin to define the patch group API.
garretrieger Nov 4, 2024
70c1f3a
[IFT] Implement patch uri -> patch info conversion.
garretrieger Nov 4, 2024
f4522dc
[IFT] implement uri template substitution for patch uri's.
garretrieger Nov 4, 2024
54eb9a3
[IFT] begin to add tests for PatchApplicationGroup.
garretrieger Nov 4, 2024
677e229
[IFT] add tests for mixed compatibility groups.
garretrieger Nov 5, 2024
769e2bd
[IFT] add tests for uri deduplication in patch selection.
garretrieger Nov 5, 2024
035d17c
[IFT] implement PatchApplicationGroup::pending_uris().
garretrieger Nov 5, 2024
b7eadc4
[IFT] begin implementing PatchApplicationGroup::add_patch_data().
garretrieger Nov 6, 2024
defde06
[IFT] Begin reworking the patch application api.
garretrieger Nov 6, 2024
ca9b1af
[IFT] Simplify application patch group.
garretrieger Nov 7, 2024
b6f2d6f
[IFT] fix clippy.
garretrieger Nov 7, 2024
c28617e
[IFT] make apply_patches() it's own public method.
garretrieger Nov 8, 2024
2ecc911
[IFT] rework PatchGroup api to have a distinct type when ready for pa…
garretrieger Nov 8, 2024
777bf8b
[IFT] add remaining rests for patch_group.rs.
garretrieger Nov 8, 2024
388e1c8
[IFT] make patch application apply only one scope of patches at a time.
garretrieger Nov 13, 2024
d9859c9
[IFT] add tests to font_patch.rs.
garretrieger Nov 13, 2024
dc19a69
[IFT] fix typo.
garretrieger Nov 13, 2024
7f00f54
[IFT] address review comments.
garretrieger Nov 15, 2024
f62f973
[IFT] Add module comment for table_keyed.rs.
garretrieger Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions font-test-data/src/ift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! Used for incremental font transfer. Specification:
//! <https://w3c.github.io/IFT/Overview.html>

use std::collections::HashMap;

use read_fonts::types::Tag;
use read_fonts::{be_buffer, be_buffer_add, test_helpers::BeBuffer, types::Int24, types::Uint24};
use write_fonts::{
Expand Down Expand Up @@ -183,7 +185,10 @@ pub fn codepoints_only_format2() -> BeBuffer {

0u32, // reserved

[1, 2, 3, 4u32], // compat id
{1u32: "compat_id[0]"},
{2u32: "compat_id[1]"},
{3u32: "compat_id[2]"},
{4u32: "compat_id[3]"},

3u8, // default patch encoding
(Uint24::new(4)), // entry count
Expand Down Expand Up @@ -480,12 +485,46 @@ pub fn string_ids_format2() -> BeBuffer {
buffer
}

// Format specification: https://w3c.github.io/IFT/Overview.html#patch-map-format-2
pub fn table_keyed_format2() -> BeBuffer {
let mut buffer = be_buffer! {
2u8, // format

0u32, // reserved

{1u32: "compat_id[0]"},
{2u32: "compat_id[1]"},
{3u32: "compat_id[2]"},
{4u32: "compat_id[3]"},

{1u8: "encoding"}, // default patch encoding
(Uint24::new(1)), // entry count
{0u32: "entries_offset"},
0u32, // entry string data offset

8u16, // uriTemplateLength
[b'f', b'o', b'o', b'/', b'{', b'i', b'd', b'}'], // uriTemplate[8]

/* ### Entries Array ### */
// Entry id = 1
{0b00010100u8: "entries"}, // format = CODEPOINT_BIT_1
{(Int24::new(0)): "id_delta"},
[0b00001101, 0b00000011, 0b00110001u8] // codepoints = [0..17]
};

let offset = buffer.offset_for("entries") as u32;
buffer.write_at("entries_offset", offset);

buffer
}

// Format specification: https://w3c.github.io/IFT/Overview.html#table-keyed
pub fn table_keyed_patch() -> BeBuffer {
let mut buffer = be_buffer! {
{(Tag::new(b"iftk")): "tag"},
0u32, // reserved
[1, 2, 3, 4u32], // compat id
{1u32: "compat_id"},
[2, 3, 4u32], // compat id
3u16, // patch count

// patch_offsets[3]
Expand Down Expand Up @@ -544,12 +583,19 @@ pub fn noop_table_keyed_patch() -> BeBuffer {
}
}

pub fn test_font_for_patching_with_loca_mod<F>(loca_mod: F) -> Vec<u8>
pub fn test_font_for_patching_with_loca_mod<F>(
loca_mod: F,
additional_tables: HashMap<Tag, &[u8]>,
) -> Vec<u8>
where
F: Fn(&mut Vec<u32>),
{
let mut font_builder = FontBuilder::new();

for (tag, data) in additional_tables {
font_builder.add_raw(tag, data);
}

let maxp = Maxp {
num_glyphs: 15,
..Default::default()
Expand Down Expand Up @@ -608,7 +654,7 @@ where
}

pub fn test_font_for_patching() -> Vec<u8> {
test_font_for_patching_with_loca_mod(|_| {})
test_font_for_patching_with_loca_mod(|_| {}, Default::default())
}

// Format specification: https://w3c.github.io/IFT/Overview.html#glyph-keyed
Expand Down
3 changes: 3 additions & 0 deletions incremental-font-transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ write-fonts = { workspace = true }
font-types = { workspace = true }
skrifa = { workspace = true }
shared-brotli-patch-decoder = { workspace = true }
uritemplate = "0.1.2"
data-encoding = "2.6.0"
data-encoding-macro = "0.1.15"

[dev-dependencies]
font-test-data = { workspace = true }
Expand Down
Loading