mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Fix path in sized container (#3954)
This commit is contained in:
parent
4c8a8f122a
commit
02285e8b1f
@ -6,8 +6,7 @@ use crate::foundations::{
|
|||||||
array, cast, elem, Array, Packed, Reflect, Resolve, Smart, StyleChain,
|
array, cast, elem, Array, Packed, Reflect, Resolve, Smart, StyleChain,
|
||||||
};
|
};
|
||||||
use crate::layout::{
|
use crate::layout::{
|
||||||
Abs, Axes, Fragment, Frame, FrameItem, LayoutMultiple, Length, Point, Regions, Rel,
|
Abs, Axes, Frame, FrameItem, LayoutSingle, Length, Point, Regions, Rel, Size,
|
||||||
Size,
|
|
||||||
};
|
};
|
||||||
use crate::visualize::{FixedStroke, Geometry, Paint, Shape, Stroke};
|
use crate::visualize::{FixedStroke, Geometry, Paint, Shape, Stroke};
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ use PathVertex::{AllControlPoints, MirroredControlPoint, Vertex};
|
|||||||
/// ((50%, 0pt), (40pt, 0pt)),
|
/// ((50%, 0pt), (40pt, 0pt)),
|
||||||
/// )
|
/// )
|
||||||
/// ```
|
/// ```
|
||||||
#[elem(LayoutMultiple)]
|
#[elem(LayoutSingle)]
|
||||||
pub struct PathElem {
|
pub struct PathElem {
|
||||||
/// How to fill the path.
|
/// How to fill the path.
|
||||||
///
|
///
|
||||||
@ -70,14 +69,14 @@ pub struct PathElem {
|
|||||||
pub vertices: Vec<PathVertex>,
|
pub vertices: Vec<PathVertex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutMultiple for Packed<PathElem> {
|
impl LayoutSingle for Packed<PathElem> {
|
||||||
#[typst_macros::time(name = "path", span = self.span())]
|
#[typst_macros::time(name = "path", span = self.span())]
|
||||||
fn layout(
|
fn layout(
|
||||||
&self,
|
&self,
|
||||||
_: &mut Engine,
|
_: &mut Engine,
|
||||||
styles: StyleChain,
|
styles: StyleChain,
|
||||||
regions: Regions,
|
regions: Regions,
|
||||||
) -> SourceResult<Fragment> {
|
) -> SourceResult<Frame> {
|
||||||
let resolve = |axes: Axes<Rel<Length>>| {
|
let resolve = |axes: Axes<Rel<Length>>| {
|
||||||
axes.resolve(styles)
|
axes.resolve(styles)
|
||||||
.zip_map(regions.base(), Rel::relative_to)
|
.zip_map(regions.base(), Rel::relative_to)
|
||||||
@ -89,7 +88,7 @@ impl LayoutMultiple for Packed<PathElem> {
|
|||||||
|
|
||||||
let mut size = Size::zero();
|
let mut size = Size::zero();
|
||||||
if points.is_empty() {
|
if points.is_empty() {
|
||||||
return Ok(Fragment::frame(Frame::soft(size)));
|
return Ok(Frame::soft(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only create a path if there are more than zero points.
|
// Only create a path if there are more than zero points.
|
||||||
@ -148,8 +147,7 @@ impl LayoutMultiple for Packed<PathElem> {
|
|||||||
let mut frame = Frame::soft(size);
|
let mut frame = Frame::soft(size);
|
||||||
let shape = Shape { geometry: Geometry::Path(path), stroke, fill };
|
let shape = Shape { geometry: Geometry::Path(path), stroke, fill };
|
||||||
frame.push(Point::zero(), FrameItem::Shape(shape, self.span()));
|
frame.push(Point::zero(), FrameItem::Shape(shape, self.span()));
|
||||||
|
Ok(frame)
|
||||||
Ok(Fragment::frame(frame))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
tests/ref/issue-path-in-sized-container.png
Normal file
BIN
tests/ref/issue-path-in-sized-container.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 152 B |
@ -50,3 +50,16 @@
|
|||||||
--- path-bad-point-array ---
|
--- path-bad-point-array ---
|
||||||
// Error: 7-31 point array must contain exactly two entries
|
// Error: 7-31 point array must contain exactly two entries
|
||||||
#path(((0%, 0%), (0%, 0%, 0%)))
|
#path(((0%, 0%), (0%, 0%, 0%)))
|
||||||
|
|
||||||
|
--- issue-path-in-sized-container ---
|
||||||
|
// Paths used to implement `LayoutMultiple` rather than `LayoutSingle` without
|
||||||
|
// fulfilling the necessary contract of respecting region expansion.
|
||||||
|
#block(
|
||||||
|
fill: aqua,
|
||||||
|
width: 20pt,
|
||||||
|
height: 15pt,
|
||||||
|
path(
|
||||||
|
(0pt, 0pt),
|
||||||
|
(10pt, 10pt),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user