Compare commits
7 Commits
8aa4418ec2
...
9cb92a0241
Author | SHA1 | Date | |
---|---|---|---|
|
9cb92a0241 | ||
|
7278d887cf | ||
|
bef4e20434 | ||
|
811996eb70 | ||
|
02f07e7912 | ||
|
693edb475d | ||
|
606183cd30 |
@ -206,13 +206,11 @@ pub fn layout_multi_block(
|
|||||||
let has_inset = !inset.is_zero();
|
let has_inset = !inset.is_zero();
|
||||||
let is_explicit = matches!(body, None | Some(BlockBody::Content(_)));
|
let is_explicit = matches!(body, None | Some(BlockBody::Content(_)));
|
||||||
|
|
||||||
// Skip filling/stroking the first frame if it is empty and a non-empty
|
// Skip filling, stroking and labeling the first frame if it is empty and
|
||||||
// one follows.
|
// a non-empty one follows.
|
||||||
let mut skip_first = false;
|
let mut skip_first = false;
|
||||||
if let [first, rest @ ..] = fragment.as_slice() {
|
if let [first, rest @ ..] = fragment.as_slice() {
|
||||||
skip_first = has_fill_or_stroke
|
skip_first = first.is_empty() && rest.iter().any(|frame| !frame.is_empty());
|
||||||
&& first.is_empty()
|
|
||||||
&& rest.iter().any(|frame| !frame.is_empty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post-process to apply insets, clipping, fills, and strokes.
|
// Post-process to apply insets, clipping, fills, and strokes.
|
||||||
@ -244,7 +242,8 @@ pub fn layout_multi_block(
|
|||||||
|
|
||||||
// Assign label to each frame in the fragment.
|
// Assign label to each frame in the fragment.
|
||||||
if let Some(label) = elem.label() {
|
if let Some(label) = elem.label() {
|
||||||
for frame in fragment.iter_mut() {
|
// Skip empty orphan frames, as a label would make them non-empty.
|
||||||
|
for frame in fragment.iter_mut().skip(if skip_first { 1 } else { 0 }) {
|
||||||
frame.label(label);
|
frame.label(label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -459,6 +459,7 @@ impl<'a> MultiChild<'a> {
|
|||||||
regions: Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<(Frame, Option<MultiSpill<'a, 'b>>)> {
|
) -> SourceResult<(Frame, Option<MultiSpill<'a, 'b>>)> {
|
||||||
let fragment = self.layout_full(engine, regions)?;
|
let fragment = self.layout_full(engine, regions)?;
|
||||||
|
let exist_non_empty_frame = fragment.iter().any(|f| !f.is_empty());
|
||||||
|
|
||||||
// Extract the first frame.
|
// Extract the first frame.
|
||||||
let mut frames = fragment.into_iter();
|
let mut frames = fragment.into_iter();
|
||||||
@ -468,6 +469,7 @@ impl<'a> MultiChild<'a> {
|
|||||||
let mut spill = None;
|
let mut spill = None;
|
||||||
if frames.next().is_some() {
|
if frames.next().is_some() {
|
||||||
spill = Some(MultiSpill {
|
spill = Some(MultiSpill {
|
||||||
|
exist_non_empty_frame,
|
||||||
multi: self,
|
multi: self,
|
||||||
full: regions.full,
|
full: regions.full,
|
||||||
first: regions.size.y,
|
first: regions.size.y,
|
||||||
@ -539,6 +541,7 @@ fn layout_multi_impl(
|
|||||||
/// The spilled remains of a `MultiChild` that broke across two regions.
|
/// The spilled remains of a `MultiChild` that broke across two regions.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MultiSpill<'a, 'b> {
|
pub struct MultiSpill<'a, 'b> {
|
||||||
|
pub(super) exist_non_empty_frame: bool,
|
||||||
multi: &'b MultiChild<'a>,
|
multi: &'b MultiChild<'a>,
|
||||||
first: Abs,
|
first: Abs,
|
||||||
full: Abs,
|
full: Abs,
|
||||||
|
@ -283,6 +283,13 @@ impl<'a, 'b> Distributor<'a, 'b, '_, '_, '_> {
|
|||||||
|
|
||||||
// Lay out the block.
|
// Lay out the block.
|
||||||
let (frame, spill) = multi.layout(self.composer.engine, self.regions)?;
|
let (frame, spill) = multi.layout(self.composer.engine, self.regions)?;
|
||||||
|
if frame.is_empty() && spill.as_ref().is_some_and(|s| s.exist_non_empty_frame) {
|
||||||
|
// If the first frame is empty, but there are non-empty frames in
|
||||||
|
// the spill, the whole child should be put in the next region to
|
||||||
|
// avoid any invisible orphans at the end of this region.
|
||||||
|
return Err(Stop::Finish(false));
|
||||||
|
}
|
||||||
|
|
||||||
self.frame(frame, multi.align, multi.sticky, true)?;
|
self.frame(frame, multi.align, multi.sticky, true)?;
|
||||||
|
|
||||||
// If the block didn't fully fit into the current region, save it into
|
// If the block didn't fully fit into the current region, save it into
|
||||||
|
@ -476,26 +476,18 @@ impl Curve {
|
|||||||
|
|
||||||
/// Computes the size of the bounding box of this curve.
|
/// Computes the size of the bounding box of this curve.
|
||||||
pub fn bbox_size(&self) -> Size {
|
pub fn bbox_size(&self) -> Size {
|
||||||
let mut min_x = Abs::inf();
|
let mut min = Point::splat(Abs::inf());
|
||||||
let mut min_y = Abs::inf();
|
let mut max = Point::splat(-Abs::inf());
|
||||||
let mut max_x = -Abs::inf();
|
|
||||||
let mut max_y = -Abs::inf();
|
|
||||||
|
|
||||||
let mut cursor = Point::zero();
|
let mut cursor = Point::zero();
|
||||||
for item in self.0.iter() {
|
for item in self.0.iter() {
|
||||||
match item {
|
match item {
|
||||||
CurveItem::Move(to) => {
|
CurveItem::Move(to) => {
|
||||||
min_x = min_x.min(cursor.x);
|
|
||||||
min_y = min_y.min(cursor.y);
|
|
||||||
max_x = max_x.max(cursor.x);
|
|
||||||
max_y = max_y.max(cursor.y);
|
|
||||||
cursor = *to;
|
cursor = *to;
|
||||||
}
|
}
|
||||||
CurveItem::Line(to) => {
|
CurveItem::Line(to) => {
|
||||||
min_x = min_x.min(cursor.x);
|
min = min.min(cursor).min(*to);
|
||||||
min_y = min_y.min(cursor.y);
|
max = max.max(cursor).max(*to);
|
||||||
max_x = max_x.max(cursor.x);
|
|
||||||
max_y = max_y.max(cursor.y);
|
|
||||||
cursor = *to;
|
cursor = *to;
|
||||||
}
|
}
|
||||||
CurveItem::Cubic(c0, c1, end) => {
|
CurveItem::Cubic(c0, c1, end) => {
|
||||||
@ -507,17 +499,17 @@ impl Curve {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let bbox = cubic.bounding_box();
|
let bbox = cubic.bounding_box();
|
||||||
min_x = min_x.min(Abs::pt(bbox.x0)).min(Abs::pt(bbox.x1));
|
min.x = min.x.min(Abs::pt(bbox.x0)).min(Abs::pt(bbox.x1));
|
||||||
min_y = min_y.min(Abs::pt(bbox.y0)).min(Abs::pt(bbox.y1));
|
min.y = min.y.min(Abs::pt(bbox.y0)).min(Abs::pt(bbox.y1));
|
||||||
max_x = max_x.max(Abs::pt(bbox.x0)).max(Abs::pt(bbox.x1));
|
max.x = max.x.max(Abs::pt(bbox.x0)).max(Abs::pt(bbox.x1));
|
||||||
max_y = max_y.max(Abs::pt(bbox.y0)).max(Abs::pt(bbox.y1));
|
max.y = max.y.max(Abs::pt(bbox.y0)).max(Abs::pt(bbox.y1));
|
||||||
cursor = *end;
|
cursor = *end;
|
||||||
}
|
}
|
||||||
CurveItem::Close => (),
|
CurveItem::Close => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Size::new(max_x - min_x, max_y - min_y)
|
Size::new(max.x - min.x, max.y - min.y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
tests/ref/block-multiple-pages-empty.png
Normal file
After Width: | Height: | Size: 263 B |
BIN
tests/ref/curve-stroke-gradient-sharp.png
Normal file
After Width: | Height: | Size: 399 B |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
BIN
tests/ref/issue-2914-block-fill-skip-nested.png
Normal file
After Width: | Height: | Size: 452 B |
BIN
tests/ref/issue-2914-block-height-cut-off.png
Normal file
After Width: | Height: | Size: 411 B |
BIN
tests/ref/issue-6125-block-place-width-limited.png
Normal file
After Width: | Height: | Size: 144 B |
BIN
tests/ref/issue-6304-block-skip-label.png
Normal file
After Width: | Height: | Size: 312 B |
BIN
tests/ref/locate-migrated-breakable.png
Normal file
After Width: | Height: | Size: 243 B |
@ -72,6 +72,18 @@ B
|
|||||||
#pagebreak(weak: true)
|
#pagebreak(weak: true)
|
||||||
#metadata(none) <e>
|
#metadata(none) <e>
|
||||||
|
|
||||||
|
--- locate-migrated-breakable ---
|
||||||
|
// Ensure that when a breakable element fully migrates to the next page without
|
||||||
|
// orphan frames, its position correctly reflects that.
|
||||||
|
#set page(height: 40pt)
|
||||||
|
A
|
||||||
|
#block[B]<a>
|
||||||
|
|
||||||
|
#context test(
|
||||||
|
locate(<a>).position(),
|
||||||
|
(page: 2, x: 10pt, y: 10pt),
|
||||||
|
)
|
||||||
|
|
||||||
--- issue-4029-locate-after-spacing ---
|
--- issue-4029-locate-after-spacing ---
|
||||||
#set page(margin: 10pt)
|
#set page(margin: 10pt)
|
||||||
#show heading: it => v(40pt) + it
|
#show heading: it => v(40pt) + it
|
||||||
|
@ -64,6 +64,12 @@ First!
|
|||||||
is the sun.
|
is the sun.
|
||||||
]
|
]
|
||||||
|
|
||||||
|
--- block-multiple-pages-empty ---
|
||||||
|
#set page(height: 60pt)
|
||||||
|
A
|
||||||
|
#block(height: 30pt)
|
||||||
|
B
|
||||||
|
|
||||||
--- block-box-fill ---
|
--- block-box-fill ---
|
||||||
#set page(height: 100pt)
|
#set page(height: 100pt)
|
||||||
#let words = lorem(18).split()
|
#let words = lorem(18).split()
|
||||||
@ -287,6 +293,37 @@ Paragraph
|
|||||||
#block(width: 100%, fill: red, box("a box"))
|
#block(width: 100%, fill: red, box("a box"))
|
||||||
#block(width: 100%, fill: red, [#box("a box") #box()])
|
#block(width: 100%, fill: red, [#box("a box") #box()])
|
||||||
|
|
||||||
|
--- issue-2914-block-height-cut-off ---
|
||||||
|
// Ensure that breaking a block doesn't shrink its height.
|
||||||
|
#set page(height: 65pt)
|
||||||
|
#set block(fill: aqua, width: 25pt, height: 25pt, inset: 5pt)
|
||||||
|
|
||||||
|
#block[A]
|
||||||
|
#block[B]
|
||||||
|
|
||||||
|
--- issue-2914-block-fill-skip-nested ---
|
||||||
|
// Ensure that fill and stroke are skipped for an empty frame with a nested block.
|
||||||
|
#set page(height: 50pt)
|
||||||
|
A
|
||||||
|
#block(fill: aqua, stroke: blue, inset: 5pt, width: 100%, block[B])
|
||||||
|
|
||||||
|
--- issue-6304-block-skip-label ---
|
||||||
|
// Ensure that labeling is skipped for an empty orphan frame.
|
||||||
|
#set page(height: 60pt)
|
||||||
|
A
|
||||||
|
#block(sticky: true)[B]
|
||||||
|
#block[C] <label>
|
||||||
|
|
||||||
|
--- issue-6125-block-place-width-limited ---
|
||||||
|
// Ensure that the width of a placed block isn't limited by its siblings.
|
||||||
|
#set page(height: 70pt)
|
||||||
|
#let b = block({
|
||||||
|
square(size: 20pt, fill: aqua)
|
||||||
|
place(top, box(height: 10pt, width: 1fr, fill: blue))
|
||||||
|
})
|
||||||
|
#b
|
||||||
|
#b
|
||||||
|
|
||||||
--- issue-5296-block-sticky-in-block-at-top ---
|
--- issue-5296-block-sticky-in-block-at-top ---
|
||||||
#set page(height: 3cm)
|
#set page(height: 3cm)
|
||||||
#v(1.6cm)
|
#v(1.6cm)
|
||||||
|
@ -130,6 +130,16 @@
|
|||||||
down, up, down, up, down,
|
down, up, down, up, down,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
--- curve-stroke-gradient-sharp ---
|
||||||
|
#set page(width: auto)
|
||||||
|
#let down = curve.line((40pt, 40pt), relative: true)
|
||||||
|
#let up = curve.line((40pt, -40pt), relative: true)
|
||||||
|
|
||||||
|
#curve(
|
||||||
|
stroke: 4pt + gradient.linear(red, blue).sharp(3),
|
||||||
|
down, up, down, up, down,
|
||||||
|
)
|
||||||
|
|
||||||
--- curve-fill-rule ---
|
--- curve-fill-rule ---
|
||||||
#stack(
|
#stack(
|
||||||
dir: ltr,
|
dir: ltr,
|
||||||
|