[librsvg: 1/4] Add mix-blend-mode CSS property definitions




commit 76724d1c2e6a8246d3596da37223a40b2d60cadf
Author: John Ledbetter <john ledbetter gmail com>
Date:   Sat Aug 22 13:36:29 2020 -0400

    Add mix-blend-mode CSS property definitions
    
    We simply parse the property value and provide the ability to convert
    it into an equivalent cairo::Operator.

 rsvg_internals/src/drawing_ctx.rs   | 29 +++++++++++++++++++++++++++--
 rsvg_internals/src/properties.rs    |  2 ++
 rsvg_internals/src/property_defs.rs | 26 ++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 2 deletions(-)
---
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index db08b7ad..b96cad89 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -24,8 +24,8 @@ use crate::paint_server::{PaintServer, PaintSource};
 use crate::path_builder::*;
 use crate::properties::ComputedValues;
 use crate::property_defs::{
-    ClipRule, FillRule, Opacity, Overflow, ShapeRendering, StrokeDasharray, StrokeLinecap,
-    StrokeLinejoin,
+    ClipRule, FillRule, MixBlendMode, Opacity, Overflow, ShapeRendering, StrokeDasharray,
+    StrokeLinecap, StrokeLinejoin,
 };
 use crate::rect::Rect;
 use crate::shapes::Markers;
@@ -1391,6 +1391,31 @@ impl From<StrokeLinecap> for cairo::LineCap {
     }
 }
 
+impl From<MixBlendMode> for cairo::Operator {
+    fn from(m: MixBlendMode) -> cairo::Operator {
+        use cairo::Operator;
+
+        match m {
+            MixBlendMode::Normal => Operator::Over,
+            MixBlendMode::Multiply => Operator::Multiply,
+            MixBlendMode::Screen => Operator::Screen,
+            MixBlendMode::Overlay => Operator::Overlay,
+            MixBlendMode::Darken => Operator::Darken,
+            MixBlendMode::Lighten => Operator::Lighten,
+            MixBlendMode::ColorDodge => Operator::ColorDodge,
+            MixBlendMode::ColorBurn => Operator::ColorBurn,
+            MixBlendMode::HardLight => Operator::HardLight,
+            MixBlendMode::SoftLight => Operator::SoftLight,
+            MixBlendMode::Difference => Operator::Difference,
+            MixBlendMode::Exclusion => Operator::Exclusion,
+            MixBlendMode::Hue => Operator::HslHue,
+            MixBlendMode::Saturation => Operator::HslSaturation,
+            MixBlendMode::Color => Operator::HslColor,
+            MixBlendMode::Luminosity => Operator::HslLuminosity,
+        }
+    }
+}
+
 impl From<ClipRule> for cairo::FillRule {
     fn from(c: ClipRule) -> cairo::FillRule {
         match c {
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index 3ed61438..d6552e47 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -415,6 +415,7 @@ make_properties! {
 
     longhands_not_supported_by_markup5ever: {
         "line-height"                 => line_height                 : LineHeight,
+        "mix-blend-mode"              => mix_blend_mode              : MixBlendMode,
     }
 
     // These are not properties, but presentation attributes.  However,
@@ -590,6 +591,7 @@ impl SpecifiedValues {
         compute!(MarkerMid, marker_mid);
         compute!(MarkerStart, marker_start);
         compute!(Mask, mask);
+        compute!(MixBlendMode, mix_blend_mode);
         compute!(Opacity, opacity);
         compute!(Overflow, overflow);
         compute!(ShapeRendering, shape_rendering);
diff --git a/rsvg_internals/src/property_defs.rs b/rsvg_internals/src/property_defs.rs
index 67a96657..e19462b5 100644
--- a/rsvg_internals/src/property_defs.rs
+++ b/rsvg_internals/src/property_defs.rs
@@ -449,6 +449,32 @@ make_property!(
     newtype_parse: IRI,
 );
 
+// https://www.w3.org/TR/compositing/#mix-blend-mode
+make_property!(
+    ComputedValues,
+    MixBlendMode,
+    default: Normal,
+    inherits_automatically: false,
+
+    identifiers:
+    "normal" => Normal,
+    "multiply" => Multiply,
+    "screen" => Screen,
+    "overlay" => Overlay,
+    "darken" => Darken,
+    "lighten" => Lighten,
+    "color-dodge" => ColorDodge,
+    "color-burn" => ColorBurn,
+    "hard-light" => HardLight,
+    "soft-light" => SoftLight,
+    "difference" => Difference,
+    "exclusion" => Exclusion,
+    "hue" => Hue,
+    "saturation" => Saturation,
+    "color" => Color,
+    "luminosity" => Luminosity,
+);
+
 // https://www.w3.org/TR/SVG/masking.html#OpacityProperty
 make_property!(
     ComputedValues,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]