From 10ae0a2c2b54ee1dc1119de528fd209eea5284b4 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 8 Jun 2023 10:20:24 +0200 Subject: [PATCH] Fix line alignment Fixes #1398. How this works for the other shapes is a hack, but the line was missing from that hack. --- library/src/layout/flow.rs | 6 ++++-- library/src/layout/mod.rs | 4 +++- tests/ref/bugs/line-align.png | Bin 0 -> 137 bytes tests/typ/bugs/line-align.typ | 5 +++++ 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 tests/ref/bugs/line-align.png create mode 100644 tests/typ/bugs/line-align.typ diff --git a/library/src/layout/flow.rs b/library/src/layout/flow.rs index cd713c681..627ea9886 100644 --- a/library/src/layout/flow.rs +++ b/library/src/layout/flow.rs @@ -6,7 +6,8 @@ use super::{ use crate::meta::{FootnoteElem, FootnoteEntry}; use crate::prelude::*; use crate::visualize::{ - CircleElem, EllipseElem, ImageElem, PathElem, PolygonElem, RectElem, SquareElem, + CircleElem, EllipseElem, ImageElem, LineElem, PathElem, PolygonElem, RectElem, + SquareElem, }; /// Arrange spacing, paragraphs and block-level elements into a flow. @@ -45,7 +46,8 @@ impl Layout for FlowElem { layouter.layout_spacing(vt, elem, styles)?; } else if let Some(elem) = child.to::() { layouter.layout_par(vt, elem, styles)?; - } else if child.is::() + } else if child.is::() + || child.is::() || child.is::() || child.is::() || child.is::() diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index 9b6ba2049..de7915251 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -58,7 +58,8 @@ use crate::prelude::*; use crate::shared::BehavedBuilder; use crate::text::{LinebreakElem, SmartQuoteElem, SpaceElem, TextElem}; use crate::visualize::{ - CircleElem, EllipseElem, ImageElem, PathElem, PolygonElem, RectElem, SquareElem, + CircleElem, EllipseElem, ImageElem, LineElem, PathElem, PolygonElem, RectElem, + SquareElem, }; /// Hook up all layout definitions. @@ -248,6 +249,7 @@ fn realize_block<'a>( styles: StyleChain<'a>, ) -> SourceResult<(Content, StyleChain<'a>)> { if content.can::() + && !content.is::() && !content.is::() && !content.is::() && !content.is::() diff --git a/tests/ref/bugs/line-align.png b/tests/ref/bugs/line-align.png new file mode 100644 index 0000000000000000000000000000000000000000..1117ed6bf423919ffbe3c11a9287931a9ea6f6bb GIT binary patch literal 137 zcmeAS@N?(olHy`uVBq!ia0y~yU}OQZColpDhGU;K+<;Vor;B4q#jUs34EY!YcpNTv zHSetIPby{;ZeBRMk*)Lpa=v^aO{FLCS(`-~cc_%aT-c#(5qyMS>9!O9>P0sq1UXok m8Xfj%+uW=D7u4~&Y0vAxc@`&Ie(yLBvcuEW&t;ucLK6V~`Y=fV literal 0 HcmV?d00001 diff --git a/tests/typ/bugs/line-align.typ b/tests/typ/bugs/line-align.typ new file mode 100644 index 000000000..0518eaaa9 --- /dev/null +++ b/tests/typ/bugs/line-align.typ @@ -0,0 +1,5 @@ +// Test right-aligning a line and a rectangle. + +--- +#align(right, line(length: 30%)) +#align(right, rect())