mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
36 lines
954 B
Rust
36 lines
954 B
Rust
use super::*;
|
|
|
|
/// A geometric shape with optional fill and stroke.
|
|
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
|
pub struct Shape {
|
|
/// The shape's geometry.
|
|
pub geometry: Geometry,
|
|
/// The shape's background fill.
|
|
pub fill: Option<Paint>,
|
|
/// The shape's border stroke.
|
|
pub stroke: Option<Stroke>,
|
|
}
|
|
|
|
/// A shape's geometry.
|
|
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
|
pub enum Geometry {
|
|
/// A line to a point (relative to its position).
|
|
Line(Point),
|
|
/// A rectangle with its origin in the topleft corner.
|
|
Rect(Size),
|
|
/// A bezier path.
|
|
Path(Path),
|
|
}
|
|
|
|
impl Geometry {
|
|
/// Fill the geometry without a stroke.
|
|
pub fn filled(self, fill: Paint) -> Shape {
|
|
Shape { geometry: self, fill: Some(fill), stroke: None }
|
|
}
|
|
|
|
/// Stroke the geometry without a fill.
|
|
pub fn stroked(self, stroke: Stroke) -> Shape {
|
|
Shape { geometry: self, fill: None, stroke: Some(stroke) }
|
|
}
|
|
}
|