Skip to content

Commit

Permalink
swf: Better adjust offsets for has_wide_offsets in writer
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian17 committed Oct 8, 2023
1 parent 9ab50bc commit 3e5482a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions swf/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,7 @@ impl<W: Write> Writer<W> {
};
for glyph in &font.glyphs {
// Store offset for later.
let offset = num_glyphs * 4 + shape_writer.output.len();
let offset = shape_writer.output.len();
offsets.push(offset);
if offset > 0xFFFF {
has_wide_offsets = true;
Expand All @@ -2072,13 +2072,19 @@ impl<W: Write> Writer<W> {

// If there are no glyphs, then the following tables are omitted.
if num_glyphs > 0 {
// OffsetTable size, plus CodeTableOffset size
let init_offset = if has_wide_offsets {
num_glyphs * 4 + 4
} else {
num_glyphs * 2 + 2
};

// OffsetTable
for offset in offsets {
// +4/+2 are an extra correction for code_table_offset
if has_wide_offsets {
writer.write_u32((offset + 4) as u32)?;
writer.write_u32((offset + init_offset) as u32)?;
} else {
writer.write_u16((offset + 2) as u16)?;
writer.write_u16((offset + init_offset) as u16)?;
}
}

Expand Down

0 comments on commit 3e5482a

Please sign in to comment.