@@ -80,15 +80,71 @@ bool MCImage::get_rep_and_transform(MCImageRep *&r_rep, bool &r_has_transform, M
8080
8181void MCImage::drawme (MCDC *dc, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, int2 dy, uint2 dw, uint2 dh)
8282{
83- MCRectangle drect, crect;
84-
8583 if (m_rep != nil)
8684 {
85+ /* Printer output generally requires special-casing */
86+ bool t_printer = dc->gettype () == CONTEXT_TYPE_PRINTER;
87+
88+ /* Update the transform - as necessary */
89+ bool t_update = !((state & CS_SIZE) && (state & CS_EDITED));
90+
91+ if (t_update)
92+ apply_transform ();
93+
8794 if (m_rep->GetType () == kMCImageRepVector )
8895 {
89- MCU_set_rect (drect, dx - sx, dy - sy, rect.width , rect.height );
90- MCU_set_rect (crect, dx, dy, dw, dh);
91- static_cast <MCVectorImageRep*>(m_rep)->Render (dc, false , drect, crect);
96+ MCGAffineTransform t_transform;
97+ if (m_has_transform)
98+ {
99+ t_transform = m_transform;
100+ }
101+ else
102+ {
103+ t_transform = MCGAffineTransformMakeIdentity ();
104+ }
105+
106+ uindex_t t_rep_width, t_rep_height;
107+ m_rep->GetGeometry (t_rep_width, t_rep_height);
108+
109+ // MW-2014-06-19: [[ IconGravity ]] Scale the image appropriately.
110+ if (dw != sw || dh != sh)
111+ {
112+ t_transform = MCGAffineTransformPreScale (t_transform, dw / (float )sw, dh / (float )sh);
113+ }
114+
115+ // MW-2014-06-19: [[ IconGravity ]] Only clip if we are drawing a partial image (we need to double-check, but I don't think sx/sy are ever non-zero).
116+ MCRectangle t_old_clip;
117+ t_old_clip = dc->getclip ();
118+ if (sx != 0 && sy != 0 )
119+ {
120+ dc->setclip (MCRectangleMake (dx, dy, sw, sh));
121+ }
122+
123+ t_transform = MCGAffineTransformConcat (t_transform,
124+ MCGAffineTransformMakeTranslation (-(dx - sx), -(dy - sy)));
125+ t_transform = MCGAffineTransformPreTranslate (t_transform, (dx - sx), (dy - sy));
126+
127+ MCGContextRef t_gcontext;
128+ if (dc->lockgcontext (t_gcontext))
129+ {
130+ MCGContextSave (t_gcontext);
131+
132+ MCGContextConcatCTM (t_gcontext, t_transform);
133+
134+ auto t_vector_rep = static_cast <MCVectorImageRep *>(m_rep);
135+
136+ void * t_data;
137+ uindex_t t_data_size;
138+ t_vector_rep->GetData (t_data, t_data_size);
139+
140+ MCGContextPlaybackRectOfDrawing (t_gcontext, MCMakeSpan ((const byte_t *)t_data, t_data_size), MCGRectangleMake (0 , 0 , t_rep_width, t_rep_height), MCGRectangleMake (dx - sx, dy - sy, t_rep_width, t_rep_height));
141+
142+ MCGContextRestore (t_gcontext);
143+
144+ dc->unlockgcontext (t_gcontext);
145+ }
146+
147+ dc->setclip (t_old_clip);
92148 }
93149 else
94150 {
@@ -99,12 +155,6 @@ void MCImage::drawme(MCDC *dc, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, in
99155 bool t_success = true ;
100156
101157 MCGImageFrame t_frame;
102-
103- bool t_printer = dc->gettype () == CONTEXT_TYPE_PRINTER;
104- bool t_update = !((state & CS_SIZE) && (state & CS_EDITED));
105-
106- if (t_update)
107- apply_transform ();
108158
109159 // IM-2013-11-06: [[ RefactorGraphics ]] Use common method to get image rep & transform
110160 // so imagedata & rendered image have the same appearance
@@ -201,7 +251,7 @@ void MCImage::drawme(MCDC *dc, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, in
201251 else
202252 {
203253 // can't get image data from rep
204- drawnodata (dc, drect, sw, sh, dx, dy, dw, dh);
254+ drawnodata (dc, sw, sh, dx, dy, dw, dh);
205255 }
206256
207257 if (t_success)
@@ -233,12 +283,13 @@ void MCImage::drawme(MCDC *dc, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, in
233283 else if (!MCStringIsEmpty (filename))
234284 {
235285 // AL-2014-01-15: [[ Bug 11570 ]] Draw stippled background when referenced image file not found
236- drawnodata (dc, rect, sw, sh, dx, dy, dw, dh);
286+ drawnodata (dc, sw, sh, dx, dy, dw, dh);
237287 }
238288}
239289
240- void MCImage::drawnodata (MCDC *dc, MCRectangle drect, uint2 sw, uint2 sh, int2 dx, int2 dy, uint2 dw, uint2 dh)
290+ void MCImage::drawnodata (MCDC *dc, uint2 sw, uint2 sh, int2 dx, int2 dy, uint2 dw, uint2 dh)
241291{
292+ MCRectangle drect;
242293 MCU_set_rect (drect, dx, dy, dw, dh);
243294 setforeground (dc, DI_BACK, False);
244295 dc->setbackground (MCscreen->getwhite ());
0 commit comments