From cbe385c7d7648cb544fb45ad4259e71c5f353475 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Thu, 8 Aug 2019 16:13:45 +0200 Subject: [PATCH] Add a way to convert a FillOrStrokeStyle to a raqote Source For now most of it unimplemented but it'll allow for some more testing --- components/canvas/raqote_backend.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs index 20e0416f3ca..8c49d9c7c01 100644 --- a/components/canvas/raqote_backend.rs +++ b/components/canvas/raqote_backend.rs @@ -398,3 +398,25 @@ impl Clone for Pattern<'_> { unimplemented!(); } } + +pub trait ToRaqoteSource<'a> { + fn to_raqote_source(self) -> Option>; +} + +impl<'a> ToRaqoteSource<'a> for FillOrStrokeStyle { + fn to_raqote_source(self) -> Option> { + use canvas_traits::canvas::FillOrStrokeStyle::*; + + match self { + Color(rgba) => Some(raqote::Source::Solid(raqote::SolidSource { + r: rgba.red, + g: rgba.green, + b: rgba.blue, + a: rgba.alpha, + })), + LinearGradient(_) => unimplemented!(), + RadialGradient(_) => unimplemented!(), + Surface(_) => unimplemented!(), + } + } +}