Skip to content

Commit

Permalink
Fix SOF shift bug in SequenceContext definition
Browse files Browse the repository at this point in the history
  • Loading branch information
archaephyrryx committed Nov 28, 2024
1 parent dd4ae42 commit 81e885d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 55 deletions.
28 changes: 13 additions & 15 deletions doodle-formats/src/format/opentype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2465,54 +2465,51 @@ pub fn main(module: &mut FormatModule, base: &BaseModule) -> FormatRef {
),
])
};
let sequence_context_format1 = {
let sequence_context_format1 = |table_start: Expr| {
record([
("table_start", pos32()),
(
"coverage",
offset16(var("table_start"), coverage_table.call(), base),
offset16(table_start.clone(), coverage_table.call(), base),
),
("seq_rule_set_count", base.u16be()),
(
"seq_rule_sets",
repeat_count(
var("seq_rule_set_count"),
offset16(var("table_start"), rule_set.clone(), base),
offset16(table_start, rule_set.clone(), base),
),
),
])
};
let sequence_context_format2 = {
let sequence_context_format2 = |table_start: Expr| {
record([
("table_start", pos32()),
(
"coverage",
offset16(var("table_start"), coverage_table.call(), base),
offset16(table_start.clone(), coverage_table.call(), base),
),
(
"class_def",
offset16(var("table_start"), class_def.call(), base),
offset16(table_start.clone(), class_def.call(), base),
),
("class_seq_rule_set_count", base.u16be()),
(
"class_seq_rule_sets",
repeat_count(
var("class_seq_rule_set_count"),
offset16(var("table_start"), rule_set, base),
offset16(table_start, rule_set.clone(), base),
),
),
])
};
let sequence_context_format3 = {
let sequence_context_format3 = |table_start: Expr| {
record([
("table_start", pos32()),
("glyph_count", base.u16be()),
("seq_lookup_count", base.u16be()),
(
"coverage_tables",
repeat_count(
var("glyph_count"),
offset16(var("table_start"), coverage_table.call(), base),
offset16(table_start, coverage_table.call(), base),
),
),
(
Expand All @@ -2524,15 +2521,16 @@ pub fn main(module: &mut FormatModule, base: &BaseModule) -> FormatRef {
module.define_format(
"opentype.common.sequence_context",
record([
("table_start", pos32()),
("format", base.u16be()),
(
"subst",
match_variant(
var("format"),
[
(Pattern::U16(1), "Format1", sequence_context_format1),
(Pattern::U16(2), "Format2", sequence_context_format2),
(Pattern::U16(3), "Format3", sequence_context_format3),
(Pattern::U16(1), "Format1", sequence_context_format1(var("table_start"))),
(Pattern::U16(2), "Format2", sequence_context_format2(var("table_start"))),
(Pattern::U16(3), "Format3", sequence_context_format3(var("table_start"))),
(Pattern::Wildcard, "BadFormat", Format::Fail),
],
),
Expand Down
70 changes: 30 additions & 40 deletions generated/sample_codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ distance: u16
}

#[derive(Debug, Clone)]
pub enum deflate_main_codes__dupX1 { literal(u8), reference(deflate_main_codes_reference) }
pub enum deflate_main_codes { literal(u8), reference(deflate_main_codes_reference) }

#[derive(Debug, Clone)]
pub struct deflate_dynamic_huffman {
Expand All @@ -340,7 +340,7 @@ literal_length_distance_alphabet_code_lengths_value: Vec<u8>,
literal_length_alphabet_code_lengths_value: Vec<u8>,
distance_alphabet_code_lengths_value: Vec<u8>,
codes: Vec<deflate_dynamic_huffman_codes>,
codes_values: Vec<deflate_main_codes__dupX1>
codes_values: Vec<deflate_main_codes>
}

#[derive(Debug, Clone)]
Expand All @@ -360,7 +360,7 @@ extra: Option<deflate_fixed_huffman_codes_values>
#[derive(Debug, Clone)]
pub struct deflate_fixed_huffman {
codes: Vec<deflate_fixed_huffman_codes>,
codes_values: Vec<deflate_main_codes__dupX1>
codes_values: Vec<deflate_main_codes>
}

#[derive(Debug, Clone)]
Expand All @@ -369,23 +369,23 @@ align: (),
len: u16,
nlen: u16,
bytes: Vec<u8>,
codes_values: Vec<deflate_main_codes__dupX1>
codes_values: Vec<deflate_main_codes>
}

#[derive(Debug, Clone)]
pub enum deflate_main_codes { dynamic_huffman(deflate_dynamic_huffman), fixed_huffman(deflate_fixed_huffman), uncompressed(deflate_uncompressed) }
pub enum deflate_main_codes__dupX1 { dynamic_huffman(deflate_dynamic_huffman), fixed_huffman(deflate_fixed_huffman), uncompressed(deflate_uncompressed) }

#[derive(Debug, Clone)]
pub struct deflate_block {
r#final: u8,
r#type: u8,
data: deflate_main_codes
data: deflate_main_codes__dupX1
}

#[derive(Debug, Clone)]
pub struct deflate_main {
blocks: Vec<deflate_block>,
codes: Vec<deflate_main_codes__dupX1>,
codes: Vec<deflate_main_codes>,
inflate: Vec<u8>
}

Expand Down Expand Up @@ -2285,15 +2285,13 @@ link: Option<opentype_common_sequence_context_subst_Format1_seq_rule_sets_link>

#[derive(Debug, Clone)]
pub struct opentype_common_sequence_context_subst_Format1 {
table_start: u32,
coverage: opentype_common_sequence_context_subst_Format1_coverage,
seq_rule_set_count: u16,
seq_rule_sets: Vec<opentype_common_sequence_context_subst_Format1_seq_rule_sets>
}

#[derive(Debug, Clone)]
pub struct opentype_common_sequence_context_subst_Format2 {
table_start: u32,
coverage: opentype_common_sequence_context_subst_Format1_coverage,
class_def: opentype_gdef_table_glyph_class_def,
class_seq_rule_set_count: u16,
Expand All @@ -2302,7 +2300,6 @@ class_seq_rule_sets: Vec<opentype_common_sequence_context_subst_Format1_seq_rule

#[derive(Debug, Clone)]
pub struct opentype_common_sequence_context_subst_Format3 {
table_start: u32,
glyph_count: u16,
seq_lookup_count: u16,
coverage_tables: Vec<opentype_common_sequence_context_subst_Format1_coverage>,
Expand All @@ -2314,6 +2311,7 @@ pub enum opentype_common_sequence_context_subst { Format1(opentype_common_sequen

#[derive(Debug, Clone)]
pub struct opentype_common_sequence_context {
table_start: u32,
format: u16,
subst: opentype_common_sequence_context_subst
}
Expand Down Expand Up @@ -7653,14 +7651,14 @@ PResult::Ok(opentype_common_feature_list { table_start, feature_count, feature_r
}

fn Decoder_opentype_common_sequence_context<'input>(_input: &mut Parser<'input>) -> Result<opentype_common_sequence_context, ParseError> {
let format = ((|| PResult::Ok((Decoder24(_input))?))())?;
let subst = ((|| PResult::Ok(match format {
1u16 => {
let inner = {
let table_start = ((|| PResult::Ok({
let inner = _input.get_offset_u64();
((|x: u64| PResult::Ok(x as u32))(inner))?
}))())?;
let format = ((|| PResult::Ok((Decoder24(_input))?))())?;
let subst = ((|| PResult::Ok(match format {
1u16 => {
let inner = {
let coverage = ((|| PResult::Ok({
let offset = ((|| PResult::Ok((Decoder24(_input))?))())?;
let link = ((|| PResult::Ok(match offset != 0u16 {
Expand Down Expand Up @@ -7778,17 +7776,13 @@ opentype_common_sequence_context_subst_Format1_seq_rule_sets { offset, link }
}
accum
}))())?;
opentype_common_sequence_context_subst_Format1 { table_start, coverage, seq_rule_set_count, seq_rule_sets }
opentype_common_sequence_context_subst_Format1 { coverage, seq_rule_set_count, seq_rule_sets }
};
opentype_common_sequence_context_subst::Format1(inner)
},

2u16 => {
let inner = {
let table_start = ((|| PResult::Ok({
let inner = _input.get_offset_u64();
((|x: u64| PResult::Ok(x as u32))(inner))?
}))())?;
let coverage = ((|| PResult::Ok({
let offset = ((|| PResult::Ok((Decoder24(_input))?))())?;
let link = ((|| PResult::Ok(match offset != 0u16 {
Expand Down Expand Up @@ -7930,17 +7924,13 @@ opentype_common_sequence_context_subst_Format1_seq_rule_sets { offset, link }
}
accum
}))())?;
opentype_common_sequence_context_subst_Format2 { table_start, coverage, class_def, class_seq_rule_set_count, class_seq_rule_sets }
opentype_common_sequence_context_subst_Format2 { coverage, class_def, class_seq_rule_set_count, class_seq_rule_sets }
};
opentype_common_sequence_context_subst::Format2(inner)
},

3u16 => {
let inner = {
let table_start = ((|| PResult::Ok({
let inner = _input.get_offset_u64();
((|x: u64| PResult::Ok(x as u32))(inner))?
}))())?;
let glyph_count = ((|| PResult::Ok((Decoder24(_input))?))())?;
let seq_lookup_count = ((|| PResult::Ok((Decoder24(_input))?))())?;
let coverage_tables = ((|| PResult::Ok({
Expand Down Expand Up @@ -7980,7 +7970,7 @@ accum.push((Decoder_opentype_common_sequence_lookup(_input))?);
}
accum
}))())?;
opentype_common_sequence_context_subst_Format3 { table_start, glyph_count, seq_lookup_count, coverage_tables, seq_lookup_records }
opentype_common_sequence_context_subst_Format3 { glyph_count, seq_lookup_count, coverage_tables, seq_lookup_records }
};
opentype_common_sequence_context_subst::Format3(inner)
},
Expand All @@ -7989,7 +7979,7 @@ _ => {
return Err(ParseError::FailToken);
}
}))())?;
PResult::Ok(opentype_common_sequence_context { format, subst })
PResult::Ok(opentype_common_sequence_context { table_start, format, subst })
}

fn Decoder46<'input>(_input: &mut Parser<'input>) -> Result<(), ParseError> {
Expand Down Expand Up @@ -12111,26 +12101,26 @@ accum.push(elem);
accum
}))())?;
let codes = ((|| PResult::Ok((try_flat_map_vec(blocks.iter().cloned(), |x: deflate_block| PResult::Ok(match x.data.clone() {
deflate_main_codes::uncompressed(y) => {
deflate_main_codes__dupX1::uncompressed(y) => {
y.codes_values.clone()
},

deflate_main_codes::fixed_huffman(y) => {
deflate_main_codes__dupX1::fixed_huffman(y) => {
y.codes_values.clone()
},

deflate_main_codes::dynamic_huffman(y) => {
deflate_main_codes__dupX1::dynamic_huffman(y) => {
y.codes_values.clone()
}
})))?))())?;
let inflate = ((|| PResult::Ok((try_flat_map_append_vec(codes.iter().cloned(), |tuple_var: (&Vec<u8>, deflate_main_codes__dupX1)| PResult::Ok(match tuple_var {
let inflate = ((|| PResult::Ok((try_flat_map_append_vec(codes.iter().cloned(), |tuple_var: (&Vec<u8>, deflate_main_codes)| PResult::Ok(match tuple_var {
(buffer, symbol) => {
match symbol {
deflate_main_codes__dupX1::literal(b) => {
deflate_main_codes::literal(b) => {
[b].to_vec()
},

deflate_main_codes__dupX1::reference(r) => {
deflate_main_codes::reference(r) => {
{
let ix = (try_sub!((buffer.len()) as u32, (r.distance.clone()) as u32)) as usize;
(slice_ext(&buffer, ix..ix + (((r.length.clone()) as u32) as usize))).to_vec()
Expand All @@ -12155,17 +12145,17 @@ let field1 = ((|| PResult::Ok((Decoder136(_input))?))())?;
let data = ((|| PResult::Ok(match r#type {
0u8 => {
let inner = (Decoder_deflate_uncompressed(_input))?;
deflate_main_codes::uncompressed(inner)
deflate_main_codes__dupX1::uncompressed(inner)
},

1u8 => {
let inner = (Decoder_deflate_fixed_huffman(_input))?;
deflate_main_codes::fixed_huffman(inner)
deflate_main_codes__dupX1::fixed_huffman(inner)
},

2u8 => {
let inner = (Decoder_deflate_dynamic_huffman(_input))?;
deflate_main_codes::dynamic_huffman(inner)
deflate_main_codes__dupX1::dynamic_huffman(inner)
},

_other => {
Expand Down Expand Up @@ -12246,7 +12236,7 @@ let field7 = ((|| PResult::Ok((Decoder136(_input))?))())?;
}
accum
}))())?;
let codes_values = ((|| PResult::Ok((try_flat_map_vec(bytes.iter().cloned(), |x: u8| PResult::Ok([deflate_main_codes__dupX1::literal(x)].to_vec())))?))())?;
let codes_values = ((|| PResult::Ok((try_flat_map_vec(bytes.iter().cloned(), |x: u8| PResult::Ok([deflate_main_codes::literal(x)].to_vec())))?))())?;
PResult::Ok(deflate_uncompressed { align, len, nlen, bytes, codes_values })
}

Expand Down Expand Up @@ -13025,7 +13015,7 @@ let codes_values = ((|| PResult::Ok((try_flat_map_vec(codes.iter().cloned(), |x:
257u16..=285u16 => {
match x.extra.clone() {
Some(ref rec) => {
[deflate_main_codes__dupX1::reference(deflate_main_codes_reference { length: rec.length.clone(), distance: rec.distance_record.distance.clone() })].to_vec()
[deflate_main_codes::reference(deflate_main_codes_reference { length: rec.length.clone(), distance: rec.distance_record.distance.clone() })].to_vec()
},

_ => {
Expand All @@ -13039,7 +13029,7 @@ return Err(ParseError::ExcludedBranch(4350808036978594792u64));
},

_ => {
[deflate_main_codes__dupX1::literal((x.code.clone()) as u8)].to_vec()
[deflate_main_codes::literal((x.code.clone()) as u8)].to_vec()
}
})))?))())?;
PResult::Ok(deflate_fixed_huffman { codes, codes_values })
Expand Down Expand Up @@ -13725,7 +13715,7 @@ let codes_values = ((|| PResult::Ok((try_flat_map_vec(codes.iter().cloned(), |x:
257u16..=285u16 => {
match x.extra.clone() {
Some(ref rec) => {
[deflate_main_codes__dupX1::reference(deflate_main_codes_reference { length: rec.length.clone(), distance: rec.distance_record.distance.clone() })].to_vec()
[deflate_main_codes::reference(deflate_main_codes_reference { length: rec.length.clone(), distance: rec.distance_record.distance.clone() })].to_vec()
},

_ => {
Expand All @@ -13739,7 +13729,7 @@ return Err(ParseError::ExcludedBranch(4350808036978594792u64));
},

_ => {
[deflate_main_codes__dupX1::literal((x.code.clone()) as u8)].to_vec()
[deflate_main_codes::literal((x.code.clone()) as u8)].to_vec()
}
})))?))())?;
PResult::Ok(deflate_dynamic_huffman { hlit, hdist, hclen, code_length_alphabet_code_lengths, literal_length_distance_alphabet_code_lengths, literal_length_distance_alphabet_code_lengths_value, literal_length_alphabet_code_lengths_value, distance_alphabet_code_lengths_value, codes, codes_values })
Expand Down
Binary file added test-fonts/NotoSansGujarati-Regular.ttf
Binary file not shown.

0 comments on commit 81e885d

Please sign in to comment.