Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 102 additions & 2 deletions crates/usvg/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,46 @@ impl Stroke {
self.linejoin
}

/// Sets the stroke paint.
pub fn set_paint(&mut self, paint: Paint) {
self.paint = paint;
}

/// Sets the stroke opacity.
pub fn set_opacity(&mut self, opacity: Opacity) {
self.opacity = opacity;
}

/// Sets the stroke width.
pub fn set_width(&mut self, width: StrokeWidth) {
self.width = width;
}

/// Sets the stroke linecap.
pub fn set_linecap(&mut self, linecap: LineCap) {
self.linecap = linecap;
}

/// Sets the stroke linejoin.
pub fn set_linejoin(&mut self, linejoin: LineJoin) {
self.linejoin = linejoin;
}

/// Sets the stroke miterlimit.
pub fn set_miterlimit(&mut self, miterlimit: StrokeMiterlimit) {
self.miterlimit = miterlimit;
}

/// Sets the stroke dash array.
pub fn set_dasharray(&mut self, dasharray: Option<Vec<f32>>) {
self.dasharray = dasharray;
}

/// Sets the stroke dash offset.
pub fn set_dashoffset(&mut self, dashoffset: f32) {
self.dashoffset = dashoffset;
}

/// Converts into a `tiny_skia_path::Stroke` type.
pub fn to_tiny_skia(&self) -> tiny_skia_path::Stroke {
let mut stroke = tiny_skia_path::Stroke {
Expand Down Expand Up @@ -663,6 +703,22 @@ impl Stroke {
}
}

impl Default for Stroke {
fn default() -> Self {
Stroke {
paint: Paint::Color(Color::black()),
dasharray: None,
dashoffset: 0.0,
miterlimit: StrokeMiterlimit::default(),
opacity: Opacity::ONE,
width: StrokeWidth::new(1.0).unwrap(),
linecap: LineCap::default(),
linejoin: LineJoin::default(),
context_element: None,
}
}
}

/// A fill rule.
///
/// `fill-rule` attribute in the SVG.
Expand Down Expand Up @@ -719,6 +775,21 @@ impl Fill {
pub fn rule(&self) -> FillRule {
self.rule
}

/// Sets the fill paint.
pub fn set_paint(&mut self, paint: Paint) {
self.paint = paint;
}

/// Sets the fill opacity.
pub fn set_opacity(&mut self, opacity: Opacity) {
self.opacity = opacity;
}

/// Sets the fill rule.
pub fn set_rule(&mut self, rule: FillRule) {
self.rule = rule;
}
}

impl Default for Fill {
Expand Down Expand Up @@ -1054,7 +1125,7 @@ pub struct Group {
}

impl Group {
pub(crate) fn empty() -> Self {
pub fn empty() -> Self {
let dummy = Rect::from_xywh(0.0, 0.0, 0.0, 0.0).unwrap();
Group {
id: String::new(),
Expand Down Expand Up @@ -1111,6 +1182,16 @@ impl Group {
self.opacity
}

/// Sets the group id.
pub fn set_id(&mut self, id: String) {
self.id = id;
}

/// Sets the group opacity.
pub fn set_opacity(&mut self, opacity: Opacity) {
self.opacity = opacity;
}

/// Group blend mode.
///
/// `mix-blend-mode` in SVG.
Expand Down Expand Up @@ -1197,6 +1278,10 @@ impl Group {
&self.children
}

pub fn push_child(&mut self, child: Node) {
self.children.push(child);
}

/// Checks if this group should be isolated during rendering.
pub fn should_isolate(&self) -> bool {
self.isolate
Expand Down Expand Up @@ -1308,7 +1393,7 @@ impl Path {
)
}

pub(crate) fn new(
pub fn new(
id: String,
visible: bool,
fill: Option<Fill>,
Expand Down Expand Up @@ -1604,6 +1689,21 @@ pub struct Tree {
}

impl Tree {
pub fn new(size: Size, root: Group) -> Self {
Tree {
size,
root,
linear_gradients: Vec::new(),
radial_gradients: Vec::new(),
patterns: Vec::new(),
clip_paths: Vec::new(),
masks: Vec::new(),
filters: Vec::new(),
#[cfg(feature = "text")]
fontdb: Arc::new(fontdb::Database::new()),
}
}

/// Image size.
///
/// Size of an image that should be created to fit the SVG.
Expand Down
Loading