summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-04-13 11:24:42 +0200
committerLaurenz <laurmaedje@gmail.com>2022-04-13 11:24:42 +0200
commit002b6c5b3e32b6d7ad51a1a77a80a51252495959 (patch)
treea5f4f91c837f8902f1827249b7003028c2a7e67e
parent072543fc59582eacfd9446055639c4427e707941 (diff)
Don't hang quotes
-rw-r--r--src/library/text/par.rs43
-rw-r--r--tests/ref/code/repr.pngbin32209 -> 32238 bytes
-rw-r--r--tests/ref/graphics/shape-aspect.pngbin4663 -> 4501 bytes
-rw-r--r--tests/ref/structure/enum.pngbin25685 -> 25686 bytes
-rw-r--r--tests/ref/text/microtype.pngbin14346 -> 10904 bytes
-rw-r--r--tests/typ/text/microtype.typ39
6 files changed, 29 insertions, 53 deletions
diff --git a/src/library/text/par.rs b/src/library/text/par.rs
index 65bc5224..d740df03 100644
--- a/src/library/text/par.rs
+++ b/src/library/text/par.rs
@@ -497,16 +497,6 @@ fn prepare<'a>(
}
},
Segment::Node(node) => {
- // Prevent margin overhang in the inline node except if there's
- // just this one.
- let local;
- let styles = if par.0.len() != 1 {
- local = StyleMap::with(TextNode::OVERHANG, false);
- local.chain(&styles)
- } else {
- styles
- };
-
let size = Size::new(regions.first.x, regions.base.y);
let pod = Regions::one(size, regions.base, Spec::splat(false));
let frame = node.layout(ctx, &pod, styles)?.remove(0);
@@ -994,9 +984,11 @@ fn commit(
// Handle hanging punctuation to the left.
if let Some(Item::Text(text)) = reordered.first() {
if let Some(glyph) = text.glyphs.first() {
- if text.styles.get(TextNode::OVERHANG) {
- let start = text.dir.is_positive();
- let amount = overhang(glyph.c, start) * glyph.x_advance.at(text.size);
+ if !text.dir.is_positive()
+ && text.styles.get(TextNode::OVERHANG)
+ && (reordered.len() > 1 || text.glyphs.len() > 1)
+ {
+ let amount = overhang(glyph.c) * glyph.x_advance.at(text.size);
offset -= amount;
remaining += amount;
}
@@ -1006,11 +998,11 @@ fn commit(
// Handle hanging punctuation to the right.
if let Some(Item::Text(text)) = reordered.last() {
if let Some(glyph) = text.glyphs.last() {
- if text.styles.get(TextNode::OVERHANG)
+ if text.dir.is_positive()
+ && text.styles.get(TextNode::OVERHANG)
&& (reordered.len() > 1 || text.glyphs.len() > 1)
{
- let start = !text.dir.is_positive();
- let amount = overhang(glyph.c, start) * glyph.x_advance.at(text.size);
+ let amount = overhang(glyph.c) * glyph.x_advance.at(text.size);
remaining += amount;
}
}
@@ -1110,24 +1102,19 @@ fn reorder<'a>(line: &'a Line<'a>) -> Vec<&'a Item<'a>> {
reordered
}
-/// How much a character should hang into the margin.
+/// How much a character should hang into the end margin.
///
-/// For selection of overhang characters, see also:
+/// For more discussion, see:
/// https://recoveringphysicist.com/21/
-fn overhang(c: char, start: bool) -> f64 {
+fn overhang(c: char) -> f64 {
match c {
- '“' | '”' | '„' | '‟' | '"' if start => 1.0,
- '‘' | '’' | '‚' | '‛' | '\'' if start => 1.0,
-
- '“' | '”' | '„' | '‟' | '"' if !start => 0.6,
- '‘' | '’' | '‚' | '‛' | '\'' if !start => 0.6,
- '–' | '—' if !start => 0.2,
- '-' if !start => 0.55,
+ // Dashes.
+ '–' | '—' => 0.2,
+ '-' => 0.55,
+ // Punctuation.
'.' | ',' => 0.8,
':' | ';' => 0.3,
- '«' | '»' => 0.2,
- '‹' | '›' => 0.4,
// Arabic and Ideographic
'\u{60C}' | '\u{6D4}' => 0.4,
diff --git a/tests/ref/code/repr.png b/tests/ref/code/repr.png
index 4474149a..b6427518 100644
--- a/tests/ref/code/repr.png
+++ b/tests/ref/code/repr.png
Binary files differ
diff --git a/tests/ref/graphics/shape-aspect.png b/tests/ref/graphics/shape-aspect.png
index 719c1e6e..a8e458fb 100644
--- a/tests/ref/graphics/shape-aspect.png
+++ b/tests/ref/graphics/shape-aspect.png
Binary files differ
diff --git a/tests/ref/structure/enum.png b/tests/ref/structure/enum.png
index 9aec9213..a9111f57 100644
--- a/tests/ref/structure/enum.png
+++ b/tests/ref/structure/enum.png
Binary files differ
diff --git a/tests/ref/text/microtype.png b/tests/ref/text/microtype.png
index a76ef293..7edc61cc 100644
--- a/tests/ref/text/microtype.png
+++ b/tests/ref/text/microtype.png
Binary files differ
diff --git a/tests/typ/text/microtype.typ b/tests/typ/text/microtype.typ
index 7e85bd3f..d3b47f6d 100644
--- a/tests/typ/text/microtype.typ
+++ b/tests/typ/text/microtype.typ
@@ -1,34 +1,23 @@
// Test micro-typographical shenanigans.
---
-// Test that overhang is off by default in boxes.
-A#box["]B
+// Test hanging punctuation.
+#set page(width: 130pt, margins: 15pt)
+#set par(justify: true, linebreaks: "simple")
+#set text(lang: "en", size: 9pt)
+#rect(fill: rgb(repr(teal) + "00"), width: 100%)[
+ This is a little bit of text that builds up to
+ hang-ing hyphens and dash---es and then, you know,
+ some punctuation in the margin.
+]
----
-// Test justified quotes.
-#set par(justify: true)
-“A quote that hangs a bit into the margin.” \
- --- somebody
-
----
-// Test fancy quotes in the left margin.
-#set par(align: right)
-»Book quotes are even smarter.« \
-›Book quotes are even smarter.‹ \
-
----
-// Test fancy quotes in the right margin.
-#set par(align: left)
-«Book quotes are even smarter.» \
-‹Book quotes are even smarter.› \
-
----
-#set text(lang: "ar", "Noto Sans Arabic", "IBM Plex Sans")
-"المطر هو الحياة" \
-المطر هو الحياة
+// Test hanging punctuation with RTL.
+#set text(lang: "he")
+בנייה נכונה של משפטים ארוכים דורשת ידע בשפה. אז בואו נדבר על מזג האוויר.
---
// Test that lone punctuation doesn't overhang into the margin.
#set page(margins: 0pt)
-#set par(align: right)
+#set par(align: end)
+#set text(dir: rtl)
: