From bbb9ed07ffe8a2a0ea0a232f6cfc52f82f7f7afe Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 10 Mar 2021 10:20:01 +0100 Subject: =?UTF-8?q?Better=20line=20spacing=20calculations=20=E2=86=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Only add line spacing between lines. Previously, line spacing was added below every line, making `#box[word]` higher than just `word`. - Compute box height of text as `ascender - descender` so that the full word is contained in the box. --- tests/ref/comment.png | Bin 716 -> 746 bytes tests/ref/control/for.png | Bin 2762 -> 2787 bytes tests/ref/control/if.png | Bin 1689 -> 1727 bytes tests/ref/control/invalid.png | Bin 3700 -> 3772 bytes tests/ref/control/let.png | Bin 2050 -> 2089 bytes tests/ref/control/while.png | Bin 886 -> 929 bytes tests/ref/expr/array.png | Bin 3448 -> 3317 bytes tests/ref/expr/block-invalid.png | Bin 506 -> 522 bytes tests/ref/expr/block.png | Bin 1423 -> 1453 bytes tests/ref/expr/call-invalid.png | Bin 2944 -> 2789 bytes tests/ref/expr/call.png | Bin 6143 -> 5863 bytes tests/ref/expr/dict.png | Bin 1651 -> 1627 bytes tests/ref/expr/ops.png | Bin 807 -> 827 bytes tests/ref/full/coma.png | Bin 59535 -> 59486 bytes tests/ref/library/box.png | Bin 2663 -> 2510 bytes tests/ref/library/font.png | Bin 4484 -> 4554 bytes tests/ref/library/hv.png | Bin 3898 -> 3960 bytes tests/ref/library/image.png | Bin 220343 -> 219392 bytes tests/ref/library/page.png | Bin 8276 -> 8417 bytes tests/ref/library/pagebreak.png | Bin 814 -> 840 bytes tests/ref/markup/emph.png | Bin 3060 -> 3079 bytes tests/ref/markup/escape.png | Bin 4190 -> 4197 bytes tests/ref/markup/heading.png | Bin 4623 -> 4656 bytes tests/ref/markup/linebreak.png | Bin 3765 -> 3864 bytes tests/ref/markup/nbsp.png | Bin 1745 -> 1818 bytes tests/ref/markup/raw.png | Bin 7334 -> 7282 bytes tests/ref/markup/strong.png | Bin 2799 -> 2847 bytes tests/ref/repr.png | Bin 10420 -> 10208 bytes tests/ref/spacing.png | Bin 5455 -> 5494 bytes tests/ref/text.png | Bin 1853 -> 1880 bytes tests/typ/full/coma.typ | 2 +- tests/typ/library/box.typ | 12 ++++++------ tests/typ/repr.typ | 3 +-- tests/typeset.rs | 2 +- 34 files changed, 9 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/ref/comment.png b/tests/ref/comment.png index 9cee51b6..1fad97fe 100644 Binary files a/tests/ref/comment.png and b/tests/ref/comment.png differ diff --git a/tests/ref/control/for.png b/tests/ref/control/for.png index f0d4a5cd..d04ea62c 100644 Binary files a/tests/ref/control/for.png and b/tests/ref/control/for.png differ diff --git a/tests/ref/control/if.png b/tests/ref/control/if.png index 04724e1f..99bde49e 100644 Binary files a/tests/ref/control/if.png and b/tests/ref/control/if.png differ diff --git a/tests/ref/control/invalid.png b/tests/ref/control/invalid.png index c9822eeb..ff4c6987 100644 Binary files a/tests/ref/control/invalid.png and b/tests/ref/control/invalid.png differ diff --git a/tests/ref/control/let.png b/tests/ref/control/let.png index 693a8d4f..5fb1c992 100644 Binary files a/tests/ref/control/let.png and b/tests/ref/control/let.png differ diff --git a/tests/ref/control/while.png b/tests/ref/control/while.png index 55a6ed80..890131f1 100644 Binary files a/tests/ref/control/while.png and b/tests/ref/control/while.png differ diff --git a/tests/ref/expr/array.png b/tests/ref/expr/array.png index 44331d9f..784553b3 100644 Binary files a/tests/ref/expr/array.png and b/tests/ref/expr/array.png differ diff --git a/tests/ref/expr/block-invalid.png b/tests/ref/expr/block-invalid.png index 11899d86..b380defc 100644 Binary files a/tests/ref/expr/block-invalid.png and b/tests/ref/expr/block-invalid.png differ diff --git a/tests/ref/expr/block.png b/tests/ref/expr/block.png index ffa59568..d5ad52ae 100644 Binary files a/tests/ref/expr/block.png and b/tests/ref/expr/block.png differ diff --git a/tests/ref/expr/call-invalid.png b/tests/ref/expr/call-invalid.png index 0d3783a8..88f13780 100644 Binary files a/tests/ref/expr/call-invalid.png and b/tests/ref/expr/call-invalid.png differ diff --git a/tests/ref/expr/call.png b/tests/ref/expr/call.png index 39941778..7197bb90 100644 Binary files a/tests/ref/expr/call.png and b/tests/ref/expr/call.png differ diff --git a/tests/ref/expr/dict.png b/tests/ref/expr/dict.png index 351e0498..28a7cb3b 100644 Binary files a/tests/ref/expr/dict.png and b/tests/ref/expr/dict.png differ diff --git a/tests/ref/expr/ops.png b/tests/ref/expr/ops.png index fb717dd0..95a24c0e 100644 Binary files a/tests/ref/expr/ops.png and b/tests/ref/expr/ops.png differ diff --git a/tests/ref/full/coma.png b/tests/ref/full/coma.png index ed849404..f5db682d 100644 Binary files a/tests/ref/full/coma.png and b/tests/ref/full/coma.png differ diff --git a/tests/ref/library/box.png b/tests/ref/library/box.png index e8513d70..2804f8e9 100644 Binary files a/tests/ref/library/box.png and b/tests/ref/library/box.png differ diff --git a/tests/ref/library/font.png b/tests/ref/library/font.png index 92b5b7fc..8e611b16 100644 Binary files a/tests/ref/library/font.png and b/tests/ref/library/font.png differ diff --git a/tests/ref/library/hv.png b/tests/ref/library/hv.png index 13a352a4..0842d409 100644 Binary files a/tests/ref/library/hv.png and b/tests/ref/library/hv.png differ diff --git a/tests/ref/library/image.png b/tests/ref/library/image.png index 70f263e6..af497c8d 100644 Binary files a/tests/ref/library/image.png and b/tests/ref/library/image.png differ diff --git a/tests/ref/library/page.png b/tests/ref/library/page.png index 1ddeeb3d..1537fad4 100644 Binary files a/tests/ref/library/page.png and b/tests/ref/library/page.png differ diff --git a/tests/ref/library/pagebreak.png b/tests/ref/library/pagebreak.png index dfb9dcaa..b1ee0eef 100644 Binary files a/tests/ref/library/pagebreak.png and b/tests/ref/library/pagebreak.png differ diff --git a/tests/ref/markup/emph.png b/tests/ref/markup/emph.png index aec7fefb..f002610e 100644 Binary files a/tests/ref/markup/emph.png and b/tests/ref/markup/emph.png differ diff --git a/tests/ref/markup/escape.png b/tests/ref/markup/escape.png index 54e61201..3fa44c6d 100644 Binary files a/tests/ref/markup/escape.png and b/tests/ref/markup/escape.png differ diff --git a/tests/ref/markup/heading.png b/tests/ref/markup/heading.png index b4aa1bbd..9f2ce6ec 100644 Binary files a/tests/ref/markup/heading.png and b/tests/ref/markup/heading.png differ diff --git a/tests/ref/markup/linebreak.png b/tests/ref/markup/linebreak.png index dda5efa6..fec65248 100644 Binary files a/tests/ref/markup/linebreak.png and b/tests/ref/markup/linebreak.png differ diff --git a/tests/ref/markup/nbsp.png b/tests/ref/markup/nbsp.png index ad7591ac..3e1f0ee7 100644 Binary files a/tests/ref/markup/nbsp.png and b/tests/ref/markup/nbsp.png differ diff --git a/tests/ref/markup/raw.png b/tests/ref/markup/raw.png index c0bf0160..ce833428 100644 Binary files a/tests/ref/markup/raw.png and b/tests/ref/markup/raw.png differ diff --git a/tests/ref/markup/strong.png b/tests/ref/markup/strong.png index cd6d670d..ac38c436 100644 Binary files a/tests/ref/markup/strong.png and b/tests/ref/markup/strong.png differ diff --git a/tests/ref/repr.png b/tests/ref/repr.png index 54a1d240..21d7af27 100644 Binary files a/tests/ref/repr.png and b/tests/ref/repr.png differ diff --git a/tests/ref/spacing.png b/tests/ref/spacing.png index a8086177..8bdc9885 100644 Binary files a/tests/ref/spacing.png and b/tests/ref/spacing.png differ diff --git a/tests/ref/text.png b/tests/ref/text.png index 31d0b45e..38ae364d 100644 Binary files a/tests/ref/text.png and b/tests/ref/text.png differ diff --git a/tests/typ/full/coma.typ b/tests/typ/full/coma.typ index 39404a35..d324627f 100644 --- a/tests/typ/full/coma.typ +++ b/tests/typ/full/coma.typ @@ -1,5 +1,5 @@ // Configuration with `page` and `font` functions. -#page(width: 450pt, height: 380pt, margins: 1cm) +#page(width: 450pt, margins: 1cm) // There are variables and they can take normal values like strings, ... #let city = "Berlin" diff --git a/tests/typ/library/box.typ b/tests/typ/library/box.typ index 10e2c93e..7ce56859 100644 --- a/tests/typ/library/box.typ +++ b/tests/typ/library/box.typ @@ -1,15 +1,15 @@ // Test the box function. --- -#page("a7", flip: true) +#page("a8", flip: true) // Box with fixed width, should have text height. -#box(width: 2cm, color: #9650D6)[A] +#box(width: 2cm, color: #9650D6)[Legal] Sometimes there is no box. // Box with fixed height, should span line. -#box(height: 2cm, width: 100%, color: #734CED)[B] +#box(height: 1cm, width: 100%, color: #734CED)[B] // Empty box with fixed width and height. #box(width: 6cm, height: 12pt, color: #CB4CED) @@ -18,6 +18,6 @@ Sometimes there is no box. #box(width: 2in, color: #ff0000) // These are in a row! -#box(width: 1in, height: 10pt, color: #D6CD67) -#box(width: 1in, height: 10pt, color: #EDD466) -#box(width: 1in, height: 10pt, color: #E3BE62) +#box(width: 0.5in, height: 10pt, color: #D6CD67) +#box(width: 0.5in, height: 10pt, color: #EDD466) +#box(width: 0.5in, height: 10pt, color: #E3BE62) diff --git a/tests/typ/repr.typ b/tests/typ/repr.typ index 6eead75e..96eb710e 100644 --- a/tests/typ/repr.typ +++ b/tests/typ/repr.typ @@ -32,9 +32,8 @@ {12e1pt} \ {2.5rad} \ {45deg} \ - // Not in monospace via repr. -#repr(45deg) +#repr(45deg) \ --- // Colors. diff --git a/tests/typeset.rs b/tests/typeset.rs index c56655f5..232dfa5c 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -393,7 +393,7 @@ fn draw_text(env: &Env, canvas: &mut Canvas, pos: Point, shaped: &Shaped) { let units_per_em = face.units_per_em().unwrap_or(1000); let x = (pos.x + offset).to_pt() as f32; - let y = (pos.y + shaped.font_size).to_pt() as f32; + let y = pos.y.to_pt() as f32; let scale = (shaped.font_size / units_per_em as f64).to_pt() as f32; let mut builder = WrappedPathBuilder(PathBuilder::new()); -- cgit v1.2.3