mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-04 00:08:11 +08:00
add: mask to raster data
This commit is contained in:
@@ -1021,6 +1021,8 @@ impl GraphicElementRendered for RasterDataTable<CPU> {
|
|||||||
base64::engine::general_purpose::STANDARD.encode_string(output, &mut base64_string);
|
base64::engine::general_purpose::STANDARD.encode_string(output, &mut base64_string);
|
||||||
base64_string
|
base64_string
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let render_image = |render: &mut SvgRender| {
|
||||||
render.leaf_tag("image", |attributes| {
|
render.leaf_tag("image", |attributes| {
|
||||||
attributes.push("width", 1.to_string());
|
attributes.push("width", 1.to_string());
|
||||||
attributes.push("height", 1.to_string());
|
attributes.push("height", 1.to_string());
|
||||||
@@ -1038,8 +1040,15 @@ impl GraphicElementRendered for RasterDataTable<CPU> {
|
|||||||
if instance.alpha_blending.blend_mode != BlendMode::default() {
|
if instance.alpha_blending.blend_mode != BlendMode::default() {
|
||||||
attributes.push("style", instance.alpha_blending.blend_mode.render());
|
attributes.push("style", instance.alpha_blending.blend_mode.render());
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
// Unlike path and g elements, the mask attribute of image element is broken and
|
||||||
|
// behaves differently across different browsers. And so we use g to have it work correctly.
|
||||||
if let Some(mask) = instance.mask {
|
if let Some(mask) = instance.mask {
|
||||||
|
render.parent_tag(
|
||||||
|
"g",
|
||||||
|
|attributes| {
|
||||||
let uuid = generate_uuid();
|
let uuid = generate_uuid();
|
||||||
let mask_type = if mask.can_reduce_to_clip_path() { MaskType::Clip } else { MaskType::Mask };
|
let mask_type = if mask.can_reduce_to_clip_path() { MaskType::Clip } else { MaskType::Mask };
|
||||||
let mut svg = SvgRender::new();
|
let mut svg = SvgRender::new();
|
||||||
@@ -1051,8 +1060,12 @@ impl GraphicElementRendered for RasterDataTable<CPU> {
|
|||||||
let selector = format!("url(#{id})");
|
let selector = format!("url(#{id})");
|
||||||
|
|
||||||
attributes.push(mask_type.to_attribute(), selector);
|
attributes.push(mask_type.to_attribute(), selector);
|
||||||
|
},
|
||||||
|
render_image,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
render_image(render)
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user