diff --git a/doodle-formats/src/format/opentype.rs b/doodle-formats/src/format/opentype.rs index f6f5bc21..0d02b95f 100644 --- a/doodle-formats/src/format/opentype.rs +++ b/doodle-formats/src/format/opentype.rs @@ -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), ), ), ( @@ -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), ], ), diff --git a/generated/sample_codegen.rs b/generated/sample_codegen.rs index 3429214a..8e529f45 100644 --- a/generated/sample_codegen.rs +++ b/generated/sample_codegen.rs @@ -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 { @@ -340,7 +340,7 @@ literal_length_distance_alphabet_code_lengths_value: Vec, literal_length_alphabet_code_lengths_value: Vec, distance_alphabet_code_lengths_value: Vec, codes: Vec, -codes_values: Vec +codes_values: Vec } #[derive(Debug, Clone)] @@ -360,7 +360,7 @@ extra: Option #[derive(Debug, Clone)] pub struct deflate_fixed_huffman { codes: Vec, -codes_values: Vec +codes_values: Vec } #[derive(Debug, Clone)] @@ -369,23 +369,23 @@ align: (), len: u16, nlen: u16, bytes: Vec, -codes_values: Vec +codes_values: Vec } #[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, -codes: Vec, +codes: Vec, inflate: Vec } @@ -2285,7 +2285,6 @@ link: Option #[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 @@ -2293,7 +2292,6 @@ seq_rule_sets: Vec #[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, @@ -2302,7 +2300,6 @@ class_seq_rule_sets: Vec, @@ -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 } @@ -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 { -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 { @@ -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 { @@ -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({ @@ -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) }, @@ -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> { @@ -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, deflate_main_codes__dupX1)| PResult::Ok(match tuple_var { +let inflate = ((|| PResult::Ok((try_flat_map_append_vec(codes.iter().cloned(), |tuple_var: (&Vec, 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() @@ -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 => { @@ -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 }) } @@ -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() }, _ => { @@ -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 }) @@ -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() }, _ => { @@ -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 }) diff --git a/test-fonts/NotoSansGujarati-Regular.ttf b/test-fonts/NotoSansGujarati-Regular.ttf new file mode 100644 index 00000000..11fe8c7f Binary files /dev/null and b/test-fonts/NotoSansGujarati-Regular.ttf differ