@@ -5,14 +5,15 @@ use core_types::ops::TableConvert;
55use core_types:: render_complexity:: RenderComplexity ;
66use core_types:: table:: { Table , TableRow } ;
77use core_types:: uuid:: NodeId ;
8- use core_types:: { ATTR_CLIPPING_MASK , ATTR_EDITOR_LAYER_PATH , ATTR_OPACITY , ATTR_OPACITY_FILL , ATTR_TRANSFORM , Color } ;
8+ use core_types:: { ATTR_CLIPPING_MASK , ATTR_EDITOR_LAYER_PATH , ATTR_GRADIENT_TYPE , ATTR_OPACITY , ATTR_OPACITY_FILL , ATTR_SPREAD_METHOD , ATTR_TRANSFORM , Color } ;
99use dyn_any:: DynAny ;
1010use glam:: DAffine2 ;
1111use raster_types:: { CPU , GPU , Raster } ;
1212use vector_types:: GradientStops ;
1313// use vector_types::Vector;
1414
1515pub use vector_types:: Vector ;
16+ use vector_types:: vector:: style:: Fill ;
1617
1718/// The possible forms of graphical content that can be rendered by the Render node into either an image or SVG syntax.
1819#[ derive( Clone , Debug , CacheHash , PartialEq , DynAny ) ]
@@ -193,6 +194,24 @@ fn flatten_graphic_table<T>(content: Table<Graphic>, extract_variant: fn(Graphic
193194 output
194195}
195196
197+ /// Converts a `Fill` enum into the `Table<Graphic>` representation used as paint storage.
198+ /// TODO: Remove once all paint sources flow through `Table<Graphic>` directly without going through the `Fill` enum.
199+ pub fn fill_to_paint ( fill : & Fill ) -> Option < Table < Graphic > > {
200+ match fill {
201+ Fill :: None => None ,
202+ Fill :: Solid ( color) => Some ( Table :: new_from_element ( ( * color) . into ( ) ) ) ,
203+ Fill :: Gradient ( gradient) => {
204+ let gradient_row = TableRow :: new_from_element ( gradient. stops . clone ( ) )
205+ . with_attribute ( ATTR_TRANSFORM , gradient. to_transform ( ) )
206+ . with_attribute ( ATTR_GRADIENT_TYPE , gradient. gradient_type )
207+ . with_attribute ( ATTR_SPREAD_METHOD , gradient. spread_method ) ;
208+ let gradient_table = Table :: new_from_row ( gradient_row) ;
209+
210+ Some ( Table :: new_from_element ( Graphic :: Gradient ( gradient_table) ) )
211+ }
212+ }
213+ }
214+
196215/// Maps from a concrete element type to its corresponding `Graphic` enum variant,
197216/// enabling type-directed casting of typed `Table`s from a `Graphic` value.
198217pub trait TryFromGraphic : Clone + Sized {
0 commit comments