Scale inline math proportionally
Inline math in a 12pt paragraph kept 10pt glyphs because paint_math advances with 10pt metrics. Paint the math atom into a temporary display list at the 10pt baseline and scale that list as a unit (text sizes and positions, rule widths/heights, line endpoints) to the paragraph size before translating it to the baseline. The box no longer pins its size, so a scaled math glyph now reports font-size 12.000 in a 12pt paragraph. The twelve-point test now also asserts that an italic math glyph is rendered at the paragraph size; the sized-paragraph test still expects a math box and no literal dollars.
This commit is contained in:
1 parent
b3fbbc8dda
commit
88a03ec1a1
5 files changed
+62
-17
No files matched your search
@@ -2055,7 +2055,7 @@ pub fn layout_paragraph_segments(segments: &[InlineSegment], style: &ParagraphSt
|
||||
italic: 0,
|
||||
font: None,
|
||||
math: Some(Box::new(atom.clone())),
|
||||
size: Some(655_360),
|
||||
size: None,
|
||||
raise: 0,
|
||||
color: None,
|
||||
background: None,
|
||||
|
||||
@@ -747,16 +747,58 @@ impl Page {
|
||||
}
|
||||
let glyph_size = box_.size.unwrap_or(size);
|
||||
let glyph_y = baseline - box_.raise;
|
||||
let x0_math = |value: i64, positioned: &dyn Fn(i64) -> i64| {
|
||||
x + positioned(value)
|
||||
};
|
||||
if let Some(math) = &box_.math {
|
||||
let math_font = Cmr10Metrics::default();
|
||||
Self::paint_math(
|
||||
math,
|
||||
&math_font,
|
||||
x,
|
||||
glyph_y,
|
||||
glyph_size,
|
||||
&mut list.items,
|
||||
);
|
||||
let mut raw = Vec::new();
|
||||
Self::paint_math(math, &math_font, 0, 0, 655_360, &mut raw);
|
||||
let ratio = glyph_size as f64 / 655_360.0;
|
||||
let positioned = |value: i64| (value as f64 * ratio) as i64;
|
||||
for item in raw {
|
||||
let item = match item {
|
||||
DisplayItem::Text {
|
||||
x,
|
||||
y,
|
||||
size,
|
||||
text,
|
||||
font,
|
||||
} => DisplayItem::Text {
|
||||
x: x0_math(x, &positioned),
|
||||
y: glyph_y + positioned(y),
|
||||
size: positioned(size).max(1),
|
||||
text,
|
||||
font,
|
||||
},
|
||||
DisplayItem::Rule {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
} => DisplayItem::Rule {
|
||||
x: x0_math(x, &positioned),
|
||||
y: glyph_y + positioned(y),
|
||||
width: positioned(width),
|
||||
height: positioned(height).max(1),
|
||||
},
|
||||
DisplayItem::Line {
|
||||
x1,
|
||||
y1,
|
||||
x2,
|
||||
y2,
|
||||
width,
|
||||
} => DisplayItem::Line {
|
||||
x1: x0_math(x1, &positioned),
|
||||
y1: glyph_y + positioned(y1),
|
||||
x2: x0_math(x2, &positioned),
|
||||
y2: glyph_y + positioned(y2),
|
||||
width: positioned(width).max(1),
|
||||
},
|
||||
other => other,
|
||||
};
|
||||
list.items.push(item);
|
||||
}
|
||||
}
|
||||
if let Some(character) = box_.character {
|
||||
list.push(DisplayItem::Text {
|
||||
|
||||
Reference in new issue
Block a user