@@ -22,6 +22,7 @@ pub enum Graphic {
2222 RasterGPU ( List < Raster < GPU > > ) ,
2323 Color ( List < Color > ) ,
2424 Gradient ( List < GradientStops > ) ,
25+ Text ( List < String > ) ,
2526}
2627
2728impl Default for Graphic {
@@ -103,6 +104,18 @@ impl From<List<GradientStops>> for Graphic {
103104 }
104105}
105106
107+ // String
108+ impl From < String > for Graphic {
109+ fn from ( text : String ) -> Self {
110+ Graphic :: Text ( List :: new_from_element ( text) )
111+ }
112+ }
113+ impl From < List < String > > for Graphic {
114+ fn from ( text : List < String > ) -> Self {
115+ Graphic :: Text ( text)
116+ }
117+ }
118+
106119/// Deeply flattens a `List<Graphic>`, collecting only elements matching a specific variant (extracted by `extract_variant`)
107120/// and discarding all other non-matching content. Recursion through `Graphic::Graphic` sub-`List`s composes transforms and opacity.
108121fn flatten_graphic_list < T > ( content : List < Graphic > , extract_variant : fn ( Graphic ) -> Option < List < T > > ) -> List < T > {
@@ -199,6 +212,12 @@ impl TryFromGraphic for GradientStops {
199212 }
200213}
201214
215+ impl TryFromGraphic for String {
216+ fn try_from_graphic ( graphic : Graphic ) -> Option < List < Self > > {
217+ if let Graphic :: Text ( t) = graphic { Some ( t) } else { None }
218+ }
219+ }
220+
202221// Local trait to convert types to List<Graphic> (avoids orphan rule issues)
203222pub trait IntoGraphicList {
204223 fn into_graphic_list ( self ) -> List < Graphic > ;
@@ -255,6 +274,12 @@ impl IntoGraphicList for List<GradientStops> {
255274 }
256275}
257276
277+ impl IntoGraphicList for List < String > {
278+ fn into_graphic_list ( self ) -> List < Graphic > {
279+ List :: new_from_element ( Graphic :: Text ( self ) )
280+ }
281+ }
282+
258283impl IntoGraphicList for DAffine2 {
259284 fn into_graphic_list ( self ) -> List < Graphic > {
260285 List :: new_from_element ( Graphic :: default ( ) )
@@ -324,6 +349,7 @@ impl Graphic {
324349 Graphic :: RasterGPU ( list) => all_clipped ( list) ,
325350 Graphic :: Color ( list) => all_clipped ( list) ,
326351 Graphic :: Gradient ( list) => all_clipped ( list) ,
352+ Graphic :: Text ( list) => all_clipped ( list) ,
327353 }
328354 }
329355
@@ -348,6 +374,7 @@ impl BoundingBox for Graphic {
348374 Graphic :: Graphic ( list) => list. bounding_box ( transform, include_stroke) ,
349375 Graphic :: Color ( list) => list. bounding_box ( transform, include_stroke) ,
350376 Graphic :: Gradient ( list) => list. bounding_box ( transform, include_stroke) ,
377+ Graphic :: Text ( _) => RenderBoundingBox :: None ,
351378 }
352379 }
353380
@@ -359,6 +386,7 @@ impl BoundingBox for Graphic {
359386 Graphic :: Graphic ( graphic) => graphic. thumbnail_bounding_box ( transform, include_stroke) ,
360387 Graphic :: Color ( color) => color. thumbnail_bounding_box ( transform, include_stroke) ,
361388 Graphic :: Gradient ( gradient) => gradient. thumbnail_bounding_box ( transform, include_stroke) ,
389+ Graphic :: Text ( _) => RenderBoundingBox :: None ,
362390 }
363391 }
364392}
@@ -388,6 +416,7 @@ impl RenderComplexity for Graphic {
388416 Self :: RasterGPU ( list) => list. render_complexity ( ) ,
389417 Self :: Color ( list) => list. render_complexity ( ) ,
390418 Self :: Gradient ( list) => list. render_complexity ( ) ,
419+ Self :: Text ( list) => list. len ( ) ,
391420 }
392421 }
393422}
0 commit comments