@@ -108,6 +108,9 @@ static bool MCGContextStateCreate(MCGContextStateRef& r_state)
108108
109109 if (t_success)
110110 {
111+ t_state -> base_transform = MCGAffineTransformMakeIdentity ();
112+ t_state -> transform = MCGAffineTransformMakeIdentity ();
113+
111114 t_state -> opacity = 1 .0f ;
112115 t_state -> blend_mode = kMCGBlendModeSourceOver ;
113116 t_state -> flatness = 0 .0f ;
@@ -127,7 +130,6 @@ static bool MCGContextStateCreate(MCGContextStateRef& r_state)
127130 t_state -> stroke_attr . dashes = NULL ;
128131 t_state -> stroke_style = kMCGPaintStyleOpaque ;
129132
130-
131133 t_state -> is_layer_begin_pt = false ;
132134 t_state -> parent = NULL ;
133135 }
@@ -140,7 +142,6 @@ static bool MCGContextStateCreate(MCGContextStateRef& r_state)
140142 return t_success;
141143}
142144
143-
144145static bool MCGContextStateCopy (MCGContextStateRef p_state, MCGContextStateRef& r_new_state)
145146{
146147 bool t_success;
@@ -153,6 +154,9 @@ static bool MCGContextStateCopy(MCGContextStateRef p_state, MCGContextStateRef&
153154
154155 if (t_success)
155156 {
157+ t_state->base_transform = MCGAffineTransformMakeIdentity ();
158+ t_state->transform = MCGAffineTransformMakeIdentity ();
159+
156160 t_state -> opacity = p_state -> opacity;
157161 t_state -> blend_mode = p_state -> blend_mode;
158162 t_state -> flatness = p_state -> flatness;
@@ -300,6 +304,7 @@ static bool MCGContextPushState(MCGContextRef self)
300304 if (t_success)
301305 {
302306 t_state -> parent = self -> state;
307+ t_state->base_transform = MCGContextGetDeviceTransform (self);
303308 self -> state = t_state;
304309 }
305310
@@ -366,8 +371,6 @@ static bool MCGContextCreateUnbound(MCGContextRef& r_context)
366371
367372 if (t_success)
368373 {
369- // t_context -> width = p_bitmap . width();
370- // t_context -> height = p_bitmap . height();
371374 t_context->references = 1 ;
372375 t_context->path = NULL ;
373376 t_context->is_valid = true ;
@@ -575,7 +578,7 @@ void MCGContextSave(MCGContextRef self)
575578 if (t_success)
576579 {
577580 // we use skia to manage the clip and matrix between states, everything else is held in the state directly
578- self -> layer -> canvas -> save ();
581+ self -> layer -> canvas -> save ();
579582 t_success = MCGContextPushState (self);
580583 }
581584
@@ -1722,22 +1725,30 @@ void MCGContextSetStrokePaintStyle(MCGContextRef self, MCGPaintStyle p_paint_sty
17221725
17231726inline static bool MCGContextSetCTM (MCGContextRef self, MCGAffineTransform p_transform)
17241727{
1728+ self->state ->transform = p_transform;
1729+
17251730 SkMatrix t_matrix;
1726- MCGAffineTransformToSkMatrix (p_transform, t_matrix);
1731+ MCGAffineTransformToSkMatrix (MCGAffineTransformConcat (self-> state -> base_transform , p_transform) , t_matrix);
17271732 self -> layer -> canvas -> setMatrix (t_matrix);
1728-
1733+
17291734 // no need to transform the clip at this point as this is handled internally by skia
17301735 return true ;
17311736}
17321737
1738+ void MCGContextSetTransform (MCGContextRef self, MCGAffineTransform p_transform)
1739+ {
1740+ if (!MCGContextIsValid (self))
1741+ return ;
1742+
1743+ MCGContextSetCTM (self, p_transform);
1744+ }
1745+
17331746void MCGContextConcatCTM (MCGContextRef self, MCGAffineTransform p_transform)
17341747{
17351748 if (!MCGContextIsValid (self))
17361749 return ;
17371750
1738- SkMatrix t_matrix;
1739- MCGAffineTransformToSkMatrix (p_transform, t_matrix);
1740- self -> layer -> canvas -> concat (t_matrix);
1751+ MCGContextSetCTM (self, MCGAffineTransformConcat (self->state ->transform , p_transform));
17411752}
17421753
17431754void MCGContextRotateCTM (MCGContextRef self, MCGFloat p_angle)
0 commit comments