mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-02 06:47:11 -06:00
fix(formats): support relative font size values in HTML font tags (#2130)
* fix(formats): support relative font size values in HTML font tags * Drop the duplicate divyanshu2074 entry in people.toml (already on main) --------- Co-authored-by: Brandon Thomas <echelon@gmail.com>
This commit is contained in:
co-authored by
Brandon Thomas
parent
eedf9c9740
commit
e2d9224996
@@ -1156,8 +1156,18 @@ impl<'r> Builder<'r> {
|
||||
fmt.font = Some(fam);
|
||||
}
|
||||
}
|
||||
if let Some(sz) = attr(attrs, "size").and_then(|s| s.trim().parse::<i32>().ok()) {
|
||||
fmt.size = Some([7.5, 10.0, 12.0, 13.5, 18.0, 24.0, 36.0].get((sz.clamp(1, 7) - 1) as usize).copied().unwrap_or(12.0));
|
||||
if let Some(sz) = attr(attrs, "size") {
|
||||
let s = sz.trim();
|
||||
let val = if let Some(rest) = s.strip_prefix('+') {
|
||||
rest.parse::<i32>().ok().map(|d| 3 + d)
|
||||
} else if let Some(rest) = s.strip_prefix('-') {
|
||||
rest.parse::<i32>().ok().map(|d| 3 - d)
|
||||
} else {
|
||||
s.parse::<i32>().ok()
|
||||
};
|
||||
if let Some(sz) = val {
|
||||
fmt.size = Some([7.5, 10.0, 12.0, 13.5, 18.0, 24.0, 36.0].get((sz.clamp(1, 7) - 1) as usize).copied().unwrap_or(12.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
"a" => {
|
||||
@@ -1941,4 +1951,21 @@ mod tests {
|
||||
assert!(!paras2[0].page_break);
|
||||
assert!(paras2[1].page_break);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn font_size_relative_and_absolute() {
|
||||
let f = parse("<font size=\"+1\">larger</font><font size=\"-1\">smaller</font><font size=\"5\">huge</font>");
|
||||
let inls = match &f.blocks[0] {
|
||||
FBlock::Para(p) => &p.inlines,
|
||||
_ => panic!("expected para"),
|
||||
};
|
||||
let sizes: Vec<Option<f32>> = inls
|
||||
.iter()
|
||||
.map(|i| match i {
|
||||
Inline::Text(_, fmt) => fmt.size,
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(sizes, vec![Some(13.5), Some(10.0), Some(18.0)]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user