Commit 35a7cb5
committed
Fix GC#drawImage + ImageGcDrawer for Cropping and Scaling
The GC#drawImage method takes
(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight)
as arguments and crops and scales from the source region to the destination
region.
Passing an image drawn via ImageGCDrawer led to the following issue:
The image handle from the subcall is resolved using the monitor zoom
(data.nativeZoom) and the calculated scaledImageZoom (gcZoom * scaleFactor).
This handle corresponds to an ImageData initialized at scaledImageZoom,
whereas the drawings of the second GC are performed using the monitor zoom,
subject to the auto-scale property.
This mismatch results in unaligned sizing of drawings. For example, a 200%
monitor zoom combined with a scale factor of 0.5 produces a scaledImageZoom of
100%. As a result, the ImageData is initialized at 100%, while drawing occurs
at 200%. This exact case is demonstrated in
vi-eclipse/Eclipse-Platform#554
.
Furthermore, the calculation of scaledImageZoom uses fallback logic that only
allows 100% and 200% as possible outcomes, which is clearly unintended in this
context.
The fix delegates resolving the correct handle to the Image class by passing
the width/height of the full image scaled by the scaledImageZoom. This
is a space on where scaled src coordinates/width/height lie. A callback
then creates a new handle for the height/width and respects the auto-scale property.
If the returned handle matches the full image scaled to the requested
scaledImageZoom in width and height, the source region
coordinates/width/height are passed directly in pixels at that zoom. Otherwise,
the internal zoom factor is derived from the returned handle’s width relative to
the full image, and the source region coordinates are converted to pixel values
using this internal zoom.
Additionally, if a transform is applied via the GC, then both drawImage
APIs consider now the best fitting handle by requesting it through the
width/height of the full image scaled by the scaleFactor (relating
destination width/height to source width/height) times the width/height scaling induced by
the transformation.1 parent f005865 commit 35a7cb5
1 file changed
Lines changed: 48 additions & 27 deletions
Lines changed: 48 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
20 | | - | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
27 | | - | |
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
| |||
1183 | 1180 | | |
1184 | 1181 | | |
1185 | 1182 | | |
1186 | | - | |
1187 | | - | |
1188 | | - | |
1189 | | - | |
1190 | | - | |
1191 | | - | |
1192 | | - | |
1193 | | - | |
1194 | | - | |
1195 | 1183 | | |
1196 | 1184 | | |
1197 | 1185 | | |
| |||
1207 | 1195 | | |
1208 | 1196 | | |
1209 | 1197 | | |
1210 | | - | |
1211 | | - | |
1212 | | - | |
1213 | | - | |
1214 | | - | |
1215 | | - | |
1216 | | - | |
| 1198 | + | |
1217 | 1199 | | |
1218 | 1200 | | |
1219 | 1201 | | |
| |||
1232 | 1214 | | |
1233 | 1215 | | |
1234 | 1216 | | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
1235 | 1227 | | |
1236 | | - | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
1237 | 1233 | | |
1238 | 1234 | | |
1239 | 1235 | | |
1240 | 1236 | | |
1241 | | - | |
| 1237 | + | |
1242 | 1238 | | |
1243 | 1239 | | |
1244 | 1240 | | |
1245 | 1241 | | |
1246 | 1242 | | |
1247 | 1243 | | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
1248 | 1250 | | |
1249 | 1251 | | |
1250 | 1252 | | |
1251 | 1253 | | |
1252 | 1254 | | |
1253 | 1255 | | |
1254 | | - | |
1255 | | - | |
1256 | | - | |
| 1256 | + | |
| 1257 | + | |
1257 | 1258 | | |
1258 | 1259 | | |
1259 | | - | |
| 1260 | + | |
1260 | 1261 | | |
1261 | 1262 | | |
1262 | 1263 | | |
1263 | 1264 | | |
1264 | 1265 | | |
1265 | | - | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
1266 | 1287 | | |
1267 | 1288 | | |
1268 | 1289 | | |
| |||
5810 | 5831 | | |
5811 | 5832 | | |
5812 | 5833 | | |
5813 | | - | |
| 5834 | + | |
5814 | 5835 | | |
5815 | 5836 | | |
5816 | 5837 | | |
| |||
0 commit comments