Skip to content

Commit

Permalink
Improve simple font missing width behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmuizel committed Feb 15, 2024
1 parent 7a33d21 commit 7331339
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ struct PdfSimpleFont<'a> {
encoding: Option<Vec<u16>>,
unicode_map: Option<HashMap<u32, String>>,
widths: HashMap<CharCode, f64>, // should probably just use i32 here
default_width: Option<f64>, // only used for CID fonts and we should probably brake out the different font types
missing_width: f64,
}

#[derive(Clone)]
Expand Down Expand Up @@ -589,7 +589,8 @@ impl<'a> PdfSimpleFont<'a> {
panic!("no widths");
}

PdfSimpleFont {doc, font, widths: width_map, encoding: encoding_table, default_width: None, unicode_map}
let missing_width = get::<Option<f64>>(doc, font, b"MissingWidth").unwrap_or(0.);
PdfSimpleFont {doc, font, widths: width_map, encoding: encoding_table, missing_width, unicode_map}
}

#[allow(dead_code)]
Expand Down Expand Up @@ -745,8 +746,8 @@ impl<'a> PdfFont for PdfSimpleFont<'a> {
} else {
let mut widths = self.widths.iter().collect::<Vec<_>>();
widths.sort_by_key(|x| x.0);
dlog!("missing width for {} len(widths) = {}, {:?} falling back to default_width {:?}", id, self.widths.len(), widths, self.font);
return self.default_width.unwrap();
dlog!("missing width for {} len(widths) = {}, {:?} falling back to missing_width {:?}", id, self.widths.len(), widths, self.font);
return self.missing_width;
}
}
/*fn decode(&self, chars: &[u8]) -> String {
Expand Down

0 comments on commit 7331339

Please sign in to comment.