@@ -156,6 +156,54 @@ pub trait IntoGraphicTable {
156156 flatten_table ( & mut output, content) ;
157157 output
158158 }
159+
160+ /// Deeply flattens any raster content within a graphic table, discarding non-raster content, and returning a table of only raster elements.
161+ fn into_flattened_raster_table ( self ) -> Table < Raster < CPU > >
162+ where
163+ Self : std:: marker:: Sized ,
164+ {
165+ let content = self . into_graphic_table ( ) ;
166+
167+ fn flatten_table ( output_raster_table : & mut Table < Raster < CPU > > , current_graphic_table : Table < Graphic > ) {
168+ for current_graphic_row in current_graphic_table. iter ( ) {
169+ let current_graphic = current_graphic_row. element . clone ( ) ;
170+ let source_node_id = * current_graphic_row. source_node_id ;
171+
172+ match current_graphic {
173+ // If we're allowed to recurse, flatten any tables we encounter
174+ Graphic :: Graphic ( mut current_graphic_table) => {
175+ // Apply the parent graphic's transform to all child elements
176+ for graphic in current_graphic_table. iter_mut ( ) {
177+ * graphic. transform = * current_graphic_row. transform * * graphic. transform ;
178+ }
179+
180+ flatten_table ( output_raster_table, current_graphic_table) ;
181+ }
182+ // Push any leaf RasterCPU elements we encounter
183+ Graphic :: RasterCPU ( raster_table) => {
184+ for current_raster_row in raster_table. iter ( ) {
185+ output_raster_table. push ( TableRow {
186+ element : current_raster_row. element . clone ( ) ,
187+ transform : * current_graphic_row. transform * * current_raster_row. transform ,
188+ alpha_blending : AlphaBlending {
189+ blend_mode : current_raster_row. alpha_blending . blend_mode ,
190+ opacity : current_graphic_row. alpha_blending . opacity * current_raster_row. alpha_blending . opacity ,
191+ fill : current_raster_row. alpha_blending . fill ,
192+ clip : current_raster_row. alpha_blending . clip ,
193+ } ,
194+ source_node_id,
195+ } ) ;
196+ }
197+ }
198+ _ => { }
199+ }
200+ }
201+ }
202+
203+ let mut output = Table :: new ( ) ;
204+ flatten_table ( & mut output, content) ;
205+ output
206+ }
159207}
160208
161209impl IntoGraphicTable for Table < Graphic > {
0 commit comments