Skip to content

Commit 8d95917

Browse files
authored
Fix bounding box issue for text (part 2) (#73)
1 parent 241b49d commit 8d95917

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/render/text.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ pub fn write_font(chunk: &mut Chunk, alloc: &mut RefAllocator, font: &mut Font)
107107
flags.insert(FontFlags::SYMBOLIC);
108108
flags.insert(FontFlags::SMALL_CAP);
109109

110-
let convert = |val| {
111-
(val / units_per_em as f32) * 1000.0
112-
};
110+
let convert = |val| (val / units_per_em as f32) * 1000.0;
113111

114112
let global_bbox = ttf.global_bounding_box();
115113
let bbox = pdf_writer::Rect::new(
@@ -121,8 +119,13 @@ pub fn write_font(chunk: &mut Chunk, alloc: &mut RefAllocator, font: &mut Font)
121119

122120
let italic_angle = ttf.italic_angle().unwrap_or(0.0);
123121
let ascender = convert(ttf.typographic_ascender().unwrap_or(ttf.ascender()) as f32);
124-
let descender = convert(ttf.typographic_descender().unwrap_or(ttf.descender()) as f32);
125-
let cap_height = ttf.capital_height().filter(|&h| h > 0).map(|h| convert(h as f32)).unwrap_or(ascender);
122+
let descender =
123+
convert(ttf.typographic_descender().unwrap_or(ttf.descender()) as f32);
124+
let cap_height = ttf
125+
.capital_height()
126+
.filter(|&h| h > 0)
127+
.map(|h| convert(h as f32))
128+
.unwrap_or(ascender);
126129
let stem_v = 10.0 + 0.244 * (f32::from(ttf.weight().to_number()) - 50.0);
127130

128131
// Write the font descriptor (contains metrics about the font).
@@ -132,9 +135,9 @@ pub fn write_font(chunk: &mut Chunk, alloc: &mut RefAllocator, font: &mut Font)
132135
.flags(flags)
133136
.bbox(bbox)
134137
.italic_angle(italic_angle)
135-
.ascent(ascender as f32)
136-
.descent(descender as f32)
137-
.cap_height(cap_height as f32)
138+
.ascent(ascender)
139+
.descent(descender)
140+
.cap_height(cap_height)
138141
.stem_v(stem_v);
139142

140143
if is_cff {

0 commit comments

Comments
 (0)