Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: v image v clip conflict #23

Merged
merged 7 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
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
35 changes: 34 additions & 1 deletion soft-skia-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ impl SoftSkiaWASM {

Self::recursive_rasterization_node_to_pixmap(item, pixmap);
}
if let Some(context) = context {
if let Some(mask) = &context.mask {
pixmap.apply_mask(mask)
}
}
}

#[wasm_bindgen(js_name = setAttrBySerde)]
Expand Down Expand Up @@ -339,7 +344,13 @@ impl SoftSkiaWASM {
}) => {
let color = parse_color(color);
let style = parse_style(style);
let mut clip = GroupClip::default();
let provider = self.0.get_tree_node_by_id(id).unwrap().provider.as_ref();
// reuse original clip
let mut clip = if let Some(Providers::G(group)) = provider {
group.clip.clone().unwrap_or_default()
} else {
GroupClip::default()
};
clip.invert = invert_clip;

self.0.set_provider_to_child(
Expand Down Expand Up @@ -406,6 +417,28 @@ impl SoftSkiaWASM {
}),
)
}
WASMShapesAttr::T(WASMTextAttr {
x,
y,
text,
font_size,
color,
max_width,
}) => {
let color = parse_color(color);
let font_size = font_size.unwrap_or(16.0);
self.0.set_shape_to_child(
id,
Shapes::T(Text {
text,
x,
y,
font_size,
color,
max_width,
}),
)
}
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion soft-skia/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Providers {
}
}

#[derive(Debug)]
#[derive(Debug, Default, Clone)]
pub struct GroupClip {
pub id: Option<usize>,
pub invert: Option<bool>,
Expand Down
33 changes: 10 additions & 23 deletions soft-skia/src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ use std::collections::HashMap;

use fontdue::{
layout::{CoordinateSystem, Layout, LayoutSettings, TextStyle},
Font, Metrics,
Font,
};
use std::iter::zip;
pub use tiny_skia::{ColorU8, FillRule, Mask, Paint, PathBuilder, Pixmap, Stroke, Transform};
use tiny_skia::{LineCap, LineJoin, Path, PixmapPaint};

use crate::log;

#[derive(Debug)]
pub enum Shapes {
R(Rect),
Expand Down Expand Up @@ -169,7 +167,6 @@ impl Shape for Rect {
color,
style,
stroke_width,
mask,
..
} = context;

Expand All @@ -180,7 +177,6 @@ impl Shape for Rect {
.color
.unwrap_or(color.unwrap_or(ColorU8::from_rgba(0, 0, 0, 255)));
let style = self.style.unwrap_or(style.unwrap_or(PaintStyle::Fill));
let mask = mask.as_ref();

paint.set_color_rgba8(color.red(), color.green(), color.blue(), color.alpha());

Expand All @@ -192,7 +188,7 @@ impl Shape for Rect {
stroke.width = w as f32
}

pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), mask);
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), None);
}
PaintStyle::Fill => {
paint.anti_alias = true;
Expand All @@ -201,7 +197,7 @@ impl Shape for Rect {
&paint,
FillRule::Winding,
Transform::identity(),
mask,
None,
);
}
_ => {}
Expand Down Expand Up @@ -239,7 +235,6 @@ impl Shape for Circle {
color,
style,
stroke_width,
mask,
..
} = context;

Expand All @@ -250,7 +245,6 @@ impl Shape for Circle {
.color
.unwrap_or(color.unwrap_or(ColorU8::from_rgba(0, 0, 0, 255)));
let style = self.style.unwrap_or(style.unwrap_or(PaintStyle::Fill));
let mask = mask.as_ref();

paint.set_color_rgba8(color.red(), color.green(), color.blue(), color.alpha());
paint.anti_alias = true;
Expand All @@ -263,7 +257,7 @@ impl Shape for Circle {
stroke.width = w as f32
}

pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), mask);
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), None);
}
PaintStyle::Fill => {
paint.anti_alias = true;
Expand All @@ -272,7 +266,7 @@ impl Shape for Circle {
&paint,
FillRule::Winding,
Transform::identity(),
mask,
None,
);
}
_ => {}
Expand Down Expand Up @@ -306,7 +300,6 @@ impl Shape for RoundRect {
color,
style,
stroke_width,
mask,
..
} = context;

Expand All @@ -317,7 +310,6 @@ impl Shape for RoundRect {
.color
.unwrap_or(color.unwrap_or(ColorU8::from_rgba(0, 0, 0, 255)));
let style = self.style.unwrap_or(style.unwrap_or(PaintStyle::Fill));
let mask = mask.as_ref();

paint.set_color_rgba8(color.red(), color.green(), color.blue(), color.alpha());
paint.anti_alias = true;
Expand All @@ -330,7 +322,7 @@ impl Shape for RoundRect {
stroke.width = w as f32
}

pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), mask);
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), None);
}
PaintStyle::Fill => {
paint.anti_alias = true;
Expand All @@ -339,7 +331,7 @@ impl Shape for RoundRect {
&paint,
FillRule::Winding,
Transform::identity(),
mask,
None,
);
}
_ => {}
Expand Down Expand Up @@ -395,7 +387,6 @@ impl Shape for Line {
let DrawContext {
color,
stroke_width,
mask,
..
} = context;

Expand All @@ -406,7 +397,6 @@ impl Shape for Line {
.color
.unwrap_or(color.unwrap_or(ColorU8::from_rgba(0, 0, 0, 255)));
let stroke_width = self.stroke_width.unwrap_or(stroke_width.unwrap_or(1));
let mask = mask.as_ref();

let stroke = Stroke {
width: stroke_width as f32,
Expand All @@ -417,7 +407,7 @@ impl Shape for Line {
};

paint.set_color_rgba8(color.red(), color.green(), color.blue(), color.alpha());
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), mask);
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), None);
}

fn get_path(
Expand Down Expand Up @@ -448,7 +438,6 @@ impl Shape for Points {
color,
style,
stroke_width,
mask,
..
} = context;

Expand All @@ -460,7 +449,6 @@ impl Shape for Points {
.unwrap_or(color.unwrap_or(ColorU8::from_rgba(0, 0, 0, 255)));
let style = self.style.unwrap_or(style.unwrap_or(PaintStyle::Fill));
let stroke_width = self.stroke_width.unwrap_or(stroke_width.unwrap_or(1));
let mask = mask.as_ref();

paint.set_color_rgba8(color.red(), color.green(), color.blue(), color.alpha());

Expand All @@ -473,7 +461,7 @@ impl Shape for Points {
line_join: LineJoin::Miter,
dash: None,
};
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), mask);
pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), None);
}
PaintStyle::Fill => {
paint.anti_alias = true;
Expand All @@ -482,7 +470,7 @@ impl Shape for Points {
&paint,
FillRule::Winding,
Transform::identity(),
mask,
None,
);
}
_ => {}
Expand Down Expand Up @@ -587,7 +575,6 @@ impl Shape for Text {
rgba_bitmap.extend([0, 0, 0, bitmap[i]].iter());
}
}

let p = Pixmap::from_vec(
rgba_bitmap,
tiny_skia::IntSize::from_wh(dim.0 as u32, dim.1 as u32).unwrap(),
Expand Down
Loading