Fix color transforms on web

The color matrix filter was not being applied to the vector art.
This commit is contained in:
Mike Welsh 2019-08-08 13:14:58 -07:00
parent e64e306137
commit a2b95eb12a
1 changed files with 14 additions and 20 deletions

View File

@ -55,11 +55,18 @@ impl WebCanvasRenderBackend {
) )
.map_err(|_| "Couldn't make SVG")?; .map_err(|_| "Couldn't make SVG")?;
// Ensure a previous instance of the color matrix filter node doesn't exist.
// TODO: Remove it in player.destroy()? This is dangerous if the client page has something with this id...
if let Some(element) = document.get_element_by_id("_cm") {
element.remove();
}
// Create a color matrix filter to handle Flash color effects.
let filter = document let filter = document
.create_element_ns(Some("http://www.w3.org/2000/svg"), "filter") .create_element_ns(Some("http://www.w3.org/2000/svg"), "filter")
.map_err(|_| "Couldn't make SVG filter")?; .map_err(|_| "Couldn't make SVG filter")?;
filter filter
.set_attribute("id", "cm") .set_attribute("id", "_cm")
.map_err(|_| "Couldn't make SVG filter")?; .map_err(|_| "Couldn't make SVG filter")?;
let color_matrix = document let color_matrix = document
@ -71,28 +78,15 @@ impl WebCanvasRenderBackend {
color_matrix color_matrix
.set_attribute("values", "1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0") .set_attribute("values", "1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0")
.map_err(|_| "Couldn't make SVG feColorMatrix element")?; .map_err(|_| "Couldn't make SVG feColorMatrix element")?;
// canvas
// .set_attribute(
// "style",
// "color-interpolation-filters:linearRGB;color-interpolation:linearRGB",
// )
// .unwrap();
// color_matrix
// .set_attribute(
// "style",
// "color-interpolation-filters:linearRGB;color-interpolation:linearRGB",
// )
// .unwrap();
// filter
// .set_attribute(
// "style",
// "color-interpolation-filters:linearRGB;color-interpolation:linearRGB",
// )
// .unwrap();
filter filter
.append_child(&color_matrix.clone()) .append_child(&color_matrix.clone())
.map_err(|_| "append_child failed")?; .map_err(|_| "append_child failed")?;
canvas
.append_child(&filter)
.map_err(|_| "append_child failed")?;
Ok(Self { Ok(Self {
canvas: canvas.clone(), canvas: canvas.clone(),
color_matrix, color_matrix,
@ -368,7 +362,7 @@ impl RenderBackend for WebCanvasRenderBackend {
.set_attribute("values", &matrix_str) .set_attribute("values", &matrix_str)
.unwrap(); .unwrap();
self.context.set_filter("url('#cm')"); self.context.set_filter("url('#_cm')");
} }
self.context self.context