@@ -2,143 +2,18 @@ mod renderer;
22
33use notify:: Watcher ;
44use serde:: { Deserialize , Serialize } ;
5- use strata_core:: { Circle , Line , Point , Rect , Shape } ;
5+ use strata_core:: Point ;
66use tauri:: ipc:: Response ;
77use tauri:: Emitter ;
88use tauri:: Manager ;
99use image:: load_from_memory;
1010
11- use crate :: renderer:: { generate_ir, generate_pixels, ShapeIr } ;
12-
13- #[ derive( Debug , Deserialize ) ]
14- #[ serde( tag = "kind" ) ]
15- enum IpcShape {
16- #[ serde( rename = "rect" ) ]
17- Rect { x : f64 , y : f64 , w : f64 , h : f64 } ,
18- #[ serde( rename = "ellipse" ) ]
19- Ellipse { cx : f64 , cy : f64 , rx : f64 , ry : f64 } ,
20- #[ serde( rename = "circle" ) ]
21- Circle { cx : f64 , cy : f64 , r : f64 } ,
22- #[ serde( rename = "line" ) ]
23- Line { from : [ f64 ; 2 ] , to : [ f64 ; 2 ] , tolerance : f64 } ,
24- #[ serde( rename = "polygon" ) ]
25- Polygon { cx : f64 , cy : f64 , radius : f64 , sides : u32 , rotation : f64 } ,
26- #[ serde( rename = "star" ) ]
27- Star { cx : f64 , cy : f64 , #[ serde( rename = "innerRadius" ) ] inner_radius : f64 , #[ serde( rename = "outerRadius" ) ] outer_radius : f64 , points : u32 , rotation : f64 } ,
28- #[ serde( rename = "text" ) ]
29- Text {
30- text : String ,
31- #[ serde( rename = "fontSize" ) ]
32- font_size : f64 ,
33- #[ serde( rename = "fontFamily" ) ]
34- font_family : String ,
35- #[ serde( rename = "fontWeight" ) ]
36- font_weight : u16 ,
37- #[ serde( rename = "fontStyle" ) ]
38- font_style : String ,
39- #[ serde( rename = "textAlign" ) ]
40- text_align : String ,
41- x : f64 ,
42- y : f64 ,
43- w : f64 ,
44- h : f64 ,
45- #[ serde( default , rename = "letterSpacing" ) ]
46- letter_spacing : Option < f64 > ,
47- #[ serde( default , rename = "lineHeight" ) ]
48- line_height : Option < f64 > ,
49- #[ serde( default , rename = "textCase" ) ]
50- text_case : Option < String > ,
51- #[ serde( default , rename = "textDecoration" ) ]
52- text_decoration : Option < String > ,
53- #[ serde( default , rename = "openTypeFeatures" ) ]
54- open_type_features : Option < serde_json:: Value > ,
55- #[ serde( default , rename = "variableAxes" ) ]
56- variable_axes : Option < serde_json:: Value > ,
57- } ,
58- }
59-
60- impl IpcShape {
61- fn into_shape ( self ) -> Shape {
62- match self {
63- IpcShape :: Rect { x, y, w, h } => Shape :: Rect ( Rect :: new ( x, y, x + w, y + h) ) ,
64- IpcShape :: Ellipse { cx, cy, rx, ry } => Shape :: Ellipse { center : Point :: new ( cx, cy) , rx, ry } ,
65- IpcShape :: Circle { cx, cy, r } => Shape :: Circle ( Circle :: new ( Point :: new ( cx, cy) , r) ) ,
66- IpcShape :: Line { from, to, tolerance } => Shape :: Line { line : Line :: new ( Point :: new ( from[ 0 ] , from[ 1 ] ) , Point :: new ( to[ 0 ] , to[ 1 ] ) ) , tolerance } ,
67- IpcShape :: Polygon { cx, cy, radius, sides, rotation } => Shape :: Polygon { cx, cy, radius, sides, rotation } ,
68- IpcShape :: Star { inner_radius, outer_radius, cx, cy, points, rotation } => Shape :: Star { cx, cy, inner_radius, outer_radius, points, rotation } ,
69- IpcShape :: Text { text, font_size, font_family, font_weight, font_style, text_align, x, y, w, h, letter_spacing, line_height, text_case, text_decoration, open_type_features, variable_axes } => Shape :: Text {
70- text,
71- font_size,
72- font_family,
73- font_weight,
74- font_style,
75- text_align,
76- x,
77- y,
78- w,
79- h,
80- letter_spacing,
81- line_height,
82- text_case,
83- text_decoration,
84- open_type_features,
85- variable_axes,
86- } ,
87- }
88- }
89- }
90-
91- #[ derive( Debug , Deserialize ) ]
92- struct IpcSceneNode {
93- #[ allow( dead_code) ]
94- id : String ,
95- name : String ,
96- #[ serde( with = "affine_serde" ) ]
97- transform : strata_core:: Affine ,
98- shape : IpcShape ,
99- fill : [ u8 ; 4 ] ,
100- #[ serde( default = "default_opacity" ) ]
101- opacity : f64 ,
102- #[ serde( default = "default_blend" ) ]
103- blend_mode : String ,
104- #[ serde( default ) ]
105- rotation : f64 ,
106- #[ serde( default ) ]
107- strokes : Vec < strata_core:: Stroke > ,
108- #[ serde( default ) ]
109- effects : Vec < strata_core:: Effect > ,
110- }
111-
112- fn default_opacity ( ) -> f64 { 1.0 }
113- fn default_blend ( ) -> String { "normal" . into ( ) }
11+ use strata_bridge:: { convert_engine_nodes, IpcSceneNode } ;
11412
115- mod affine_serde {
116- use serde:: { Deserialize , Deserializer } ;
117- use strata_core:: Affine ;
118- pub fn deserialize < ' de , D > ( d : D ) -> Result < Affine , D :: Error > where D : Deserializer < ' de > {
119- let coeffs: [ f64 ; 6 ] = Deserialize :: deserialize ( d) ?;
120- Ok ( Affine :: new ( coeffs) )
121- }
122- }
13+ use crate :: renderer:: { generate_ir, generate_pixels, ShapeIr } ;
12314
12415fn convert_scene ( nodes : Vec < IpcSceneNode > ) -> Vec < strata_core:: SceneNode > {
125- nodes. into_iter ( ) . enumerate ( ) . map ( |( i, n) | strata_core:: SceneNode {
126- id : strata_core:: NodeId ( i as u64 ) ,
127- name : n. name ,
128- transform : n. transform ,
129- shape : n. shape . into_shape ( ) ,
130- fill : n. fill ,
131- children : Vec :: new ( ) ,
132- component_id : None ,
133- slots : None ,
134- opacity : n. opacity ,
135- blend_mode : n. blend_mode ,
136- rotation : n. rotation ,
137- strokes : n. strokes ,
138- effects : n. effects ,
139- corner_radius : None ,
140- fills : None ,
141- } ) . collect ( )
16+ convert_engine_nodes ( nodes)
14217}
14318
14419#[ tauri:: command]
@@ -985,6 +860,40 @@ mod tests {
985860 }
986861 }
987862
863+ #[ test]
864+ fn ipc_parity_fills_filters_corner_radius ( ) {
865+ let json = serde_json:: json!( [ {
866+ "id" : "n0" ,
867+ "name" : "Rounded" ,
868+ "transform" : [ 1.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 ] ,
869+ "shape" : { "kind" : "rect" , "x" : 0.0 , "y" : 0.0 , "w" : 20.0 , "h" : 20.0 , "cornerRadius" : 8 } ,
870+ "fill" : { "space" : "rgb" , "r" : 57 , "g" : 208 , "b" : 198 , "a" : 255 } ,
871+ "fills" : [ {
872+ "type" : "solid" ,
873+ "color" : [ 57 , 208 , 198 , 255 ] ,
874+ "opacity" : 1.0 ,
875+ "blendMode" : "normal" ,
876+ "visible" : true
877+ } ] ,
878+ "filters" : [ { "type" : "exposure" , "exposure" : 0.5 } ]
879+ } ] ) ;
880+ let nodes: Vec < IpcSceneNode > = serde_json:: from_value ( json) . expect ( "deserialize" ) ;
881+ let scene = convert_scene ( nodes) ;
882+ assert ! ( scene[ 0 ] . fills. is_some( ) ) ;
883+ assert ! ( scene[ 0 ] . filters. is_some( ) ) ;
884+ assert ! ( scene[ 0 ] . corner_radius. is_some( ) ) ;
885+ assert_eq ! ( scene[ 0 ] . fill, [ 57 , 208 , 198 , 255 ] ) ;
886+
887+ let ir = strata_engine:: build_render_ir ( & scene) ;
888+ assert ! ( ir[ 0 ] . fills. is_some( ) ) ;
889+ assert ! ( ir[ 0 ] . filters. is_some( ) ) ;
890+ if let strata_engine:: Primitive :: Rect { corner_radius, .. } = & ir[ 0 ] . primitive {
891+ assert ! ( corner_radius. is_some( ) ) ;
892+ } else {
893+ panic ! ( "expected rect" ) ;
894+ }
895+ }
896+
988897 #[ test]
989898 fn round_trip_hit_test ( ) {
990899 let json = ts_wire_json ( ) ;
0 commit comments