[librsvg: 7/9] shared_surface::Operator - new enum, to replace cairo::Operator




commit 762ca64bea99c92099b0614ad87c25c9b5db8590
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri May 28 18:33:50 2021 -0500

    shared_surface::Operator - new enum, to replace cairo::Operator

 src/surface_utils/shared_surface.rs | 54 +++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
---
diff --git a/src/surface_utils/shared_surface.rs b/src/surface_utils/shared_surface.rs
index 98abf4b0..480e06f2 100644
--- a/src/surface_utils/shared_surface.rs
+++ b/src/surface_utils/shared_surface.rs
@@ -51,6 +51,30 @@ impl SurfaceType {
     }
 }
 
+/// Operators supported by `ImageSurface<Shared>::compose`.
+pub enum Operator {
+    Over,
+    In,
+    Out,
+    Atop,
+    Xor,
+    Multiply,
+    Screen,
+    Darken,
+    Lighten,
+    Overlay,
+    ColorDodge,
+    ColorBurn,
+    HardLight,
+    SoftLight,
+    Difference,
+    Exclusion,
+    HslHue,
+    HslSaturation,
+    HslColor,
+    HslLuminosity,
+}
+
 /// Wrapper for a Cairo image surface that enforces exclusive access when modifying it.
 ///
 /// Shared access to `cairo::ImageSurface` is tricky since a read-only borrowed reference
@@ -1347,6 +1371,36 @@ impl ImageSurface<Exclusive> {
     }
 }
 
+impl From<Operator> for cairo::Operator {
+    fn from(op: Operator) -> cairo::Operator {
+        use cairo::Operator as Cairo;
+        use Operator::*;
+
+        match op {
+            Over => Cairo::Over,
+            In => Cairo::In,
+            Out => Cairo::Out,
+            Atop => Cairo::Atop,
+            Xor => Cairo::Xor,
+            Multiply => Cairo::Multiply,
+            Screen => Cairo::Screen,
+            Darken => Cairo::Darken,
+            Lighten => Cairo::Lighten,
+            Overlay => Cairo::Overlay,
+            ColorDodge => Cairo::ColorDodge,
+            ColorBurn => Cairo::ColorBurn,
+            HardLight => Cairo::HardLight,
+            SoftLight => Cairo::SoftLight,
+            Difference => Cairo::Difference,
+            Exclusion => Cairo::Exclusion,
+            HslHue => Cairo::HslHue,
+            HslSaturation => Cairo::HslSaturation,
+            HslColor => Cairo::HslColor,
+            HslLuminosity => Cairo::HslLuminosity,
+        }
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;


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