summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-04-13 15:52:20 +0200
committerLaurenz <laurmaedje@gmail.com>2023-04-13 15:52:20 +0200
commit46ce9c94e3f615751989d3cba5aa1599e0ba5913 (patch)
tree4f954ffdb9bd3ac95ac51e1a8ff6b5fbca487fd9
parent9025ecb2ee3ed19865ee2078eb6c01f4660351e9 (diff)
Fix linebreak after inline objects with metadata
-rw-r--r--library/src/layout/par.rs13
-rw-r--r--tests/ref/meta/query-figure.pngbin0 -> 289118 bytes
-rw-r--r--tests/ref/meta/query-header.pngbin0 -> 121102 bytes
-rw-r--r--tests/ref/meta/query.pngbin554447 -> 0 bytes
-rw-r--r--tests/ref/text/linebreak-obj.pngbin0 -> 41719 bytes
-rw-r--r--tests/typ/meta/query-figure.typ (renamed from tests/typ/meta/query.typ)33
-rw-r--r--tests/typ/meta/query-header.typ32
-rw-r--r--tests/typ/text/linebreak-obj.typ18
8 files changed, 59 insertions, 37 deletions
diff --git a/library/src/layout/par.rs b/library/src/layout/par.rs
index 17e07cd0..3385e0e7 100644
--- a/library/src/layout/par.rs
+++ b/library/src/layout/par.rs
@@ -318,7 +318,8 @@ impl Segment<'_> {
Self::Text(len) => len,
Self::Spacing(_) => SPACING_REPLACE.len_utf8(),
Self::Box(_, true) => SPACING_REPLACE.len_utf8(),
- Self::Equation(_) | Self::Box(_, _) | Self::Meta => OBJ_REPLACE.len_utf8(),
+ Self::Equation(_) | Self::Box(_, _) => OBJ_REPLACE.len_utf8(),
+ Self::Meta => 0,
}
}
}
@@ -334,6 +335,8 @@ enum Item<'a> {
Fractional(Fr, Option<(&'a BoxElem, StyleChain<'a>)>),
/// Layouted inline-level content.
Frame(Frame),
+ /// Metadata.
+ Meta(Frame),
}
impl<'a> Item<'a> {
@@ -351,6 +354,7 @@ impl<'a> Item<'a> {
Self::Text(shaped) => shaped.text.len(),
Self::Absolute(_) | Self::Fractional(_, _) => SPACING_REPLACE.len_utf8(),
Self::Frame(_) => OBJ_REPLACE.len_utf8(),
+ Self::Meta(_) => 0,
}
}
@@ -360,7 +364,7 @@ impl<'a> Item<'a> {
Self::Text(shaped) => shaped.width,
Self::Absolute(v) => *v,
Self::Frame(frame) => frame.width(),
- Self::Fractional(_, _) => Abs::zero(),
+ Self::Fractional(_, _) | Self::Meta(_) => Abs::zero(),
}
}
}
@@ -585,7 +589,6 @@ fn collect<'a>(
full.push(if frac { SPACING_REPLACE } else { OBJ_REPLACE });
Segment::Box(elem, frac)
} else if child.is::<MetaElem>() {
- full.push(OBJ_REPLACE);
Segment::Meta
} else {
bail!(child.span(), "unexpected paragraph child");
@@ -670,7 +673,7 @@ fn prepare<'a>(
Segment::Meta => {
let mut frame = Frame::new(Size::zero());
frame.meta(styles, true);
- items.push(Item::Frame(frame));
+ items.push(Item::Meta(frame));
}
}
@@ -1336,7 +1339,7 @@ fn commit(
let frame = shaped.build(vt, justification_ratio, extra_justification);
push(&mut offset, frame);
}
- Item::Frame(frame) => {
+ Item::Frame(frame) | Item::Meta(frame) => {
push(&mut offset, frame.clone());
}
}
diff --git a/tests/ref/meta/query-figure.png b/tests/ref/meta/query-figure.png
new file mode 100644
index 00000000..3b8d3398
--- /dev/null
+++ b/tests/ref/meta/query-figure.png
Binary files differ
diff --git a/tests/ref/meta/query-header.png b/tests/ref/meta/query-header.png
new file mode 100644
index 00000000..80981202
--- /dev/null
+++ b/tests/ref/meta/query-header.png
Binary files differ
diff --git a/tests/ref/meta/query.png b/tests/ref/meta/query.png
deleted file mode 100644
index 7801d22b..00000000
--- a/tests/ref/meta/query.png
+++ /dev/null
Binary files differ
diff --git a/tests/ref/text/linebreak-obj.png b/tests/ref/text/linebreak-obj.png
new file mode 100644
index 00000000..5fa25001
--- /dev/null
+++ b/tests/ref/text/linebreak-obj.png
Binary files differ
diff --git a/tests/typ/meta/query.typ b/tests/typ/meta/query-figure.typ
index 91325b61..4b730770 100644
--- a/tests/typ/meta/query.typ
+++ b/tests/typ/meta/query-figure.typ
@@ -1,35 +1,4 @@
-// Test the query function.
-
----
-#set page(
- paper: "a7",
- margin: (y: 1cm, x: 0.5cm),
- header: {
- smallcaps[Typst Academy]
- h(1fr)
- locate(it => {
- let after = query(selector(heading).after(it), it)
- let before = query(selector(heading).before(it), it)
- let elem = if before.len() != 0 {
- before.last()
- } else if after.len() != 0 {
- after.first()
- }
- emph(elem.body)
- })
- }
-)
-
-#outline()
-
-= Introduction
-#lorem(35)
-
-= Background
-#lorem(35)
-
-= Approach
-#lorem(60)
+// Test a list of figures.
---
#set page(
diff --git a/tests/typ/meta/query-header.typ b/tests/typ/meta/query-header.typ
new file mode 100644
index 00000000..dd83c128
--- /dev/null
+++ b/tests/typ/meta/query-header.typ
@@ -0,0 +1,32 @@
+// Test creating a header with the query function.
+
+---
+#set page(
+ paper: "a7",
+ margin: (y: 1cm, x: 0.5cm),
+ header: {
+ smallcaps[Typst Academy]
+ h(1fr)
+ locate(it => {
+ let after = query(selector(heading).after(it), it)
+ let before = query(selector(heading).before(it), it)
+ let elem = if before.len() != 0 {
+ before.last()
+ } else if after.len() != 0 {
+ after.first()
+ }
+ emph(elem.body)
+ })
+ }
+)
+
+#outline()
+
+= Introduction
+#lorem(35)
+
+= Background
+#lorem(35)
+
+= Approach
+#lorem(60)
diff --git a/tests/typ/text/linebreak-obj.typ b/tests/typ/text/linebreak-obj.typ
new file mode 100644
index 00000000..bd3b69ae
--- /dev/null
+++ b/tests/typ/text/linebreak-obj.typ
@@ -0,0 +1,18 @@
+// Test linebreaks with after inline elements.
+
+---
+// Test punctuation after citations.
+#set page(width: 162pt)
+
+They can look for the details in @netwok,
+which is the authorative source.
+
+#bibliography("/works.bib")
+
+---
+// Test punctuation after math equations.
+#set page(width: 85pt)
+
+We prove $1 < 2$. \
+We prove $1 < 2$! \
+We prove $1 < 2$– \