mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-01 02:36:02 +01:00
Keep the line's word-gap threshold beside a superscript under the script size floor (#3172)
This commit is contained in:
1 parent
6f9c05d8a1
commit
2d45b068fc
2 files changed
+18
-1
No files matched your search
@@ -215,7 +215,16 @@ pub fn layout(glyphs: Vec<TextGlyph>) -> PageText {
|
||||
fn pair_threshold(p: &TextGlyph, c: &TextGlyph, typical: f32, threshold: f32) -> f32 {
|
||||
let height = |g: &TextGlyph| (g.rect[3] - g.rect[1]).max(0.1);
|
||||
let (hp, hc) = (height(p), height(c));
|
||||
if is_script_on(&p.rect, hp, &c.rect, hc) || is_script_on(&c.rect, hc, &p.rect, hp) {
|
||||
// A glyph under the script test's size floor (a small `²`) is still a script when it sits off its neighbour's
|
||||
// baseline inside its line, unlike body text beside a big digit, which shares the digit's baseline.
|
||||
let off_baseline = |host: &[f32; 4], host_h: f32, s: &[f32; 4], s_h: f32| {
|
||||
s_h < host_h * 0.45 && (host[3] - s[3]).abs() >= host_h * 0.15 && s[3] > host[1] && s[1] < host[3]
|
||||
};
|
||||
if is_script_on(&p.rect, hp, &c.rect, hc)
|
||||
|| is_script_on(&c.rect, hc, &p.rect, hp)
|
||||
|| off_baseline(&p.rect, hp, &c.rect, hc)
|
||||
|| off_baseline(&c.rect, hc, &p.rect, hp)
|
||||
{
|
||||
return threshold;
|
||||
}
|
||||
let h = hp.min(hc);
|
||||
|
||||
@@ -1381,6 +1381,14 @@ fn a_letter_close_after_a_combining_mark_takes_no_space() {
|
||||
assert_eq!(layout(v).plain_text(), "xa\u{301}by");
|
||||
}
|
||||
|
||||
/// #3172: a superscript too small for the sub- and superscript test (under half its host's height) still keeps the
|
||||
/// line's word-gap threshold next to its host: its height says no more about that gap (noted in review).
|
||||
#[test]
|
||||
fn a_tiny_superscript_close_to_its_host_takes_no_space() {
|
||||
let v = vec![g("a", 0.0, 10.0, 6.0), g("b", 6.0, 10.0, 12.0), tall("2", 13.0, 9.5, 15.4, 4.0)];
|
||||
assert_eq!(layout(v).plain_text(), "ab2");
|
||||
}
|
||||
|
||||
/// #3172: only another run's ink drops a blank. A space its own run's letter is kerned over is still that run's word
|
||||
/// break, even on a line where another run overprints elsewhere.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user