#![cfg(feature = "html")]
use std::collections::BTreeMap;
use printpdf::*;
const PAGE: &str = r#"
<html>
<body>
<p style="font-size: 16px; line-height: 40px;">Cock<sup>a</sup> and x<sub>2</sub></p>
</body>
</html>
"#;
fn text_baselines(doc: &PdfDocument) -> Vec<i64> {
let mut ys: Vec<i64> = doc
.pages
.iter()
.flat_map(|page| page.ops.iter())
.filter_map(|op| match op {
Op::SetTextMatrix { matrix } => Some((matrix.as_array()[5] * 10.0).round() as i64),
_ => None,
})
.collect();
ys.sort_unstable();
ys.dedup();
ys
}
#[test]
fn a_superscript_and_a_subscript_are_drawn_off_the_line_in_the_pdf() {
let mut warnings = Vec::new();
let doc = PdfDocument::from_html(
PAGE,
&BTreeMap::new(),
&BTreeMap::new(),
&GeneratePdfOptions::default(),
&mut warnings,
)
.expect("the page renders");
let baselines = text_baselines(&doc);
assert!(
baselines.len() >= 3,
"the line's text, the raised \"a\" and the lowered \"2\" sit on three different \
baselines, got {baselines:?} (in tenths of a point)"
);
}