Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 480639
Collapse All | Expand All

(-)a/bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/Printer.java (+4 lines)
Lines 613-616 Link Here
613
	handle = 0;
613
	handle = 0;
614
}
614
}
615
615
616
@Override
617
protected int getDeviceZoom() {
618
	return 100; // printers don't zoom
619
}
616
}
620
}
(-)a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java (-55 / +256 lines)
Lines 12-17 Link Here
12
12
13
import org.eclipse.swt.*;
13
import org.eclipse.swt.*;
14
import org.eclipse.swt.graphics.*;
14
import org.eclipse.swt.graphics.*;
15
import org.eclipse.swt.widgets.*;
15
16
16
/**
17
/**
17
 * This class hold common constants and utility functions w.r.t. to SWT high DPI
18
 * This class hold common constants and utility functions w.r.t. to SWT high DPI
Lines 87-100 Link Here
87
 * Auto-scale down ImageData
88
 * Auto-scale down ImageData
88
 */
89
 */
89
public static ImageData autoScaleDown (Device device, final ImageData imageData) {
90
public static ImageData autoScaleDown (Device device, final ImageData imageData) {
90
	if (deviceZoom == 100 || imageData == null || (device != null && !device.isAutoScalable())) return imageData;
91
	if (device.getZoom() == 100 || imageData == null || (device != null && !device.isAutoScalable())) return imageData;
91
	float scaleFactor = 1.0f / getScalingFactor ();
92
	float scaleFactor = 1.0f / getScalingFactor (device);
92
	return autoScaleImageData(device, imageData, scaleFactor);
93
	return autoScaleImageData(device, imageData, scaleFactor);
93
}
94
}
94
95
96
/**
97
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleDown(Device, int[])}.
98
 */
99
100
@Deprecated
95
public static int[] autoScaleDown(int[] pointArray) {
101
public static int[] autoScaleDown(int[] pointArray) {
96
	if (deviceZoom == 100 || pointArray == null) return pointArray;
102
	return autoScaleDown(Display.getDefault(),pointArray);
97
	float scaleFactor = getScalingFactor ();
103
}
104
105
public static int[] autoScaleDown(Device device,int[] pointArray) {
106
	if (device.getZoom() == 100 || pointArray == null) return pointArray;
107
	float scaleFactor = getScalingFactor (device);
98
	int [] returnArray = new int[pointArray.length];
108
	int [] returnArray = new int[pointArray.length];
99
	for (int i = 0; i < pointArray.length; i++) {
109
	for (int i = 0; i < pointArray.length; i++) {
100
		returnArray [i] =  Math.round (pointArray [i] / scaleFactor);
110
		returnArray [i] =  Math.round (pointArray [i] / scaleFactor);
Lines 102-118 Link Here
102
	return returnArray;
112
	return returnArray;
103
}
113
}
104
114
115
/**
116
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleDown(Device, Drawable, int[])}.
117
 */
118
119
@Deprecated
105
public static int[] autoScaleDown(Drawable drawable, int[] pointArray) {
120
public static int[] autoScaleDown(Drawable drawable, int[] pointArray) {
121
	return autoScaleDown (Display.getDefault(), drawable, pointArray);
122
}
123
124
public static int[] autoScaleDown(Device device, Drawable drawable, int[] pointArray) {
106
	if (drawable != null && !drawable.isAutoScalable ()) return pointArray;
125
	if (drawable != null && !drawable.isAutoScalable ()) return pointArray;
107
	return autoScaleDown (pointArray);
126
	return autoScaleDown (device, pointArray);
108
}
127
}
109
128
110
/**
129
/**
111
 * Auto-scale up float array dimensions.
130
 * Auto-scale up float array dimensions.
131
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleDown(Device, float[])}.
112
 */
132
 */
133
@Deprecated
113
public static float[] autoScaleDown (float size[]) {
134
public static float[] autoScaleDown (float size[]) {
114
	if (deviceZoom == 100 || size == null) return size;
135
	return autoScaleDown(Display.getDefault(), size);
115
	float scaleFactor = getScalingFactor ();
136
}
137
/**
138
 * Auto-scale up float array dimensions.
139
 */
140
public static float[] autoScaleDown (Device device, float size[]) {
141
	if (device.getZoom() == 100 || size == null) return size;
142
	float scaleFactor = getScalingFactor (device);
116
	float scaledSize[] = new float[size.length];
143
	float scaledSize[] = new float[size.length];
117
	for (int i = 0; i < scaledSize.length; i++) {
144
	for (int i = 0; i < scaledSize.length; i++) {
118
		scaledSize[i] = size[i] / scaleFactor;
145
		scaledSize[i] = size[i] / scaleFactor;
Lines 122-172 Link Here
122
149
123
/**
150
/**
124
 * Auto-scale up float array dimensions if enabled for Drawable class.
151
 * Auto-scale up float array dimensions if enabled for Drawable class.
152
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleDown(Device, Drawable,  float[])}.
125
 */
153
 */
154
@Deprecated
126
public static float[] autoScaleDown (Drawable drawable, float size[]) {
155
public static float[] autoScaleDown (Drawable drawable, float size[]) {
156
	return autoScaleDown(Display.getDefault(), drawable, size);
157
}
158
/**
159
 * Auto-scale up float array dimensions if enabled for Drawable class.
160
 */
161
public static float[] autoScaleDown (Device device,Drawable drawable, float size[]) {
127
	if (drawable != null && !drawable.isAutoScalable ()) return size;
162
	if (drawable != null && !drawable.isAutoScalable ()) return size;
128
	return autoScaleDown (size);
163
	return autoScaleDown (device, size);
129
}
164
}
130
165
131
/**
166
/**
132
 * Auto-scale down int dimensions.
167
 * Auto-scale down int dimensions.
168
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleDown(Device, int)}.
133
 */
169
 */
170
@Deprecated
134
public static int autoScaleDown (int size) {
171
public static int autoScaleDown (int size) {
135
	if (deviceZoom == 100 || size == SWT.DEFAULT) return size;
172
	return autoScaleDown(Display.getDefault(), size);
136
	float scaleFactor = getScalingFactor ();
173
}
174
/**
175
 * Auto-scale down int dimensions.
176
 */
177
public static int autoScaleDown (Device device, int size) {
178
	if (device.getZoom() == 100 || size == SWT.DEFAULT) return size;
179
	float scaleFactor = getScalingFactor (device);
137
	return Math.round (size / scaleFactor);
180
	return Math.round (size / scaleFactor);
138
}
181
}
139
/**
182
/**
140
 * Auto-scale down int dimensions if enabled for Drawable class.
183
 * Auto-scale down int dimensions if enabled for Drawable class.
141
 */
184
 */
142
public static int autoScaleDown (Drawable drawable, int size) {
185
public static int autoScaleDown (Drawable drawable, int size) {
186
	return autoScaleDown (Display.getDefault(), drawable, size);
187
}
188
189
/**
190
 * Auto-scale down int dimensions if enabled for Drawable class.
191
 */
192
public static int autoScaleDown (Device device, Drawable drawable, int size) {
143
	if (drawable != null && !drawable.isAutoScalable ()) return size;
193
	if (drawable != null && !drawable.isAutoScalable ()) return size;
144
	return autoScaleDown (size);
194
	return autoScaleDown (device, size);
145
}
195
}
146
196
147
/**
197
/**
148
 * Auto-scale down float dimensions.
198
 * Auto-scale down float dimensions.
199
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleDown(Device, float)}.
149
 */
200
 */
201
@Deprecated
150
public static float autoScaleDown (float size) {
202
public static float autoScaleDown (float size) {
151
	if (deviceZoom == 100 || size == SWT.DEFAULT) return size;
203
	return autoScaleDown(Display.getDefault(), size);
152
	float scaleFactor = getScalingFactor ();
204
}
205
/**
206
 * Auto-scale down float dimensions.
207
 */
208
public static float autoScaleDown (Device device,float size) {
209
	if (device.getZoom() == 100 || size == SWT.DEFAULT) return size;
210
	float scaleFactor = getScalingFactor (device);
153
	return (size / scaleFactor);
211
	return (size / scaleFactor);
154
}
212
}
155
213
156
/**
214
/**
157
 * Auto-scale down float dimensions if enabled for Drawable class.
215
 * Auto-scale down float dimensions if enabled for Drawable class.
216
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleDown(Device, Drawable, float)}.
158
 */
217
 */
218
@Deprecated
159
public static float autoScaleDown (Drawable drawable, float size) {
219
public static float autoScaleDown (Drawable drawable, float size) {
220
	return autoScaleDown(Display.getDefault(),drawable, size);
221
}
222
/**
223
 * Auto-scale down float dimensions if enabled for Drawable class.
224
 */
225
public static float autoScaleDown (Device device, Drawable drawable, float size) {
160
	if (drawable != null && !drawable.isAutoScalable ()) return size;
226
	if (drawable != null && !drawable.isAutoScalable ()) return size;
161
	return autoScaleDown (size);
227
	return autoScaleDown (device, size);
162
}
228
}
163
229
164
/**
230
/**
165
 * Returns a new scaled down Point.
231
 * Returns a new scaled down Point.
232
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleDown(Device, Point)}.
166
 */
233
 */
234
@Deprecated
167
public static Point autoScaleDown (Point point) {
235
public static Point autoScaleDown (Point point) {
168
	if (deviceZoom == 100 || point == null) return point;
236
	return autoScaleDown(Display.getDefault(), point);
169
	float scaleFactor = getScalingFactor ();
237
}
238
/**
239
 * Returns a new scaled down Point.
240
 */
241
public static Point autoScaleDown (Device device, Point point) {
242
	if (device.getZoom() == 100 || point == null) return point;
243
	float scaleFactor = getScalingFactor (device);
170
	Point scaledPoint = new Point (0,0);
244
	Point scaledPoint = new Point (0,0);
171
	scaledPoint.x = Math.round (point.x / scaleFactor);
245
	scaledPoint.x = Math.round (point.x / scaleFactor);
172
	scaledPoint.y = Math.round (point.y / scaleFactor);
246
	scaledPoint.y = Math.round (point.y / scaleFactor);
Lines 175-194 Link Here
175
249
176
/**
250
/**
177
 * Returns a new scaled down Point if enabled for Drawable class.
251
 * Returns a new scaled down Point if enabled for Drawable class.
252
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleDown(Device, Drawable, Point)}.
178
 */
253
 */
254
@Deprecated
179
public static Point autoScaleDown (Drawable drawable, Point point) {
255
public static Point autoScaleDown (Drawable drawable, Point point) {
256
	return autoScaleDown (Display.getDefault(),  drawable, point);
257
}
258
259
/**
260
 * Returns a new scaled down Point if enabled for Drawable class.
261
 */
262
public static Point autoScaleDown (Device device, Drawable drawable, Point point) {
180
	if (drawable != null && !drawable.isAutoScalable ()) return point;
263
	if (drawable != null && !drawable.isAutoScalable ()) return point;
181
	return autoScaleDown (point);
264
	return autoScaleDown (device, point);
182
}
265
}
183
266
184
/**
267
/**
185
 * Returns a new scaled down Rectangle.
268
 * Returns a new scaled down Rectangle.
269
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleDown(Device, Rectangle)}.
186
 */
270
 */
271
@Deprecated
187
public static Rectangle autoScaleDown (Rectangle rect) {
272
public static Rectangle autoScaleDown (Rectangle rect) {
188
	if (deviceZoom == 100 || rect == null) return rect;
273
	return autoScaleDown(Display.getDefault(), rect);
274
}
275
/**
276
 * Returns a new scaled down Rectangle.
277
 */
278
public static Rectangle autoScaleDown (Device device, Rectangle rect) {
279
	if (device.getZoom()  == 100 || rect == null) return rect;
189
	Rectangle scaledRect = new Rectangle (0,0,0,0);
280
	Rectangle scaledRect = new Rectangle (0,0,0,0);
190
	Point scaledTopLeft = DPIUtil.autoScaleDown (new Point (rect.x, rect.y));
281
	Point scaledTopLeft = DPIUtil.autoScaleDown (device, new Point (rect.x, rect.y));
191
	Point scaledBottomRight = DPIUtil.autoScaleDown (new Point (rect.x + rect.width, rect.y + rect.height));
282
	Point scaledBottomRight = DPIUtil.autoScaleDown (device, new Point (rect.x + rect.width, rect.y + rect.height));
192
283
193
	scaledRect.x = scaledTopLeft.x;
284
	scaledRect.x = scaledTopLeft.x;
194
	scaledRect.y = scaledTopLeft.y;
285
	scaledRect.y = scaledTopLeft.y;
Lines 198-205 Link Here
198
}
289
}
199
/**
290
/**
200
 * Returns a new scaled down Rectangle if enabled for Drawable class.
291
 * Returns a new scaled down Rectangle if enabled for Drawable class.
292
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleDown(Device, Drawable, Rectangle)}.
201
 */
293
 */
294
@Deprecated
202
public static Rectangle autoScaleDown (Drawable drawable, Rectangle rect) {
295
public static Rectangle autoScaleDown (Drawable drawable, Rectangle rect) {
296
	return autoScaleDown(Display.getDefault(), drawable, rect);
297
}
298
/**
299
 * Returns a new scaled down Rectangle if enabled for Drawable class.
300
 */
301
public static Rectangle autoScaleDown (Device device, Drawable drawable, Rectangle rect) {
203
	if (drawable != null && !drawable.isAutoScalable ()) return rect;
302
	if (drawable != null && !drawable.isAutoScalable ()) return rect;
204
	return autoScaleDown (rect);
303
	return autoScaleDown (rect);
205
}
304
}
Lines 230-243 Link Here
230
		Image resultImage = new Image (device, (ImageDataProvider) zoom -> resultData);
329
		Image resultImage = new Image (device, (ImageDataProvider) zoom -> resultData);
231
		GC gc = new GC (resultImage);
330
		GC gc = new GC (resultImage);
232
		gc.setAntialias (SWT.ON);
331
		gc.setAntialias (SWT.ON);
233
		gc.drawImage (original, 0, 0, DPIUtil.autoScaleDown (width), DPIUtil.autoScaleDown (height),
332
		gc.drawImage (original, 0, 0, DPIUtil.autoScaleDown (device, width), DPIUtil.autoScaleDown (height),
234
				/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
333
				/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
235
				 * Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
334
				 * Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
236
				 */
335
				 */
237
				0, 0, Math.round (DPIUtil.autoScaleDown ((float) width * scaleFactor)), Math.round (DPIUtil.autoScaleDown ((float) height * scaleFactor)));
336
				0, 0, Math.round (DPIUtil.autoScaleDown (device, (float) width * scaleFactor)), Math.round (DPIUtil.autoScaleDown ((float) height * scaleFactor)));
238
		gc.dispose ();
337
		gc.dispose ();
239
		original.dispose ();
338
		original.dispose ();
240
		ImageData result = resultImage.getImageData (DPIUtil.getDeviceZoom ());
339
		ImageData result = resultImage.getImageData (device.getZoom ());
241
		resultImage.dispose ();
340
		resultImage.dispose ();
242
		return result;
341
		return result;
243
	case NEAREST:
342
	case NEAREST:
Lines 248-256 Link Here
248
347
249
/**
348
/**
250
 * Returns a new rectangle as per the scaleFactor.
349
 * Returns a new rectangle as per the scaleFactor.
350
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleBounds(Device, Rectangle, int, int)}.
251
 */
351
 */
352
@Deprecated
252
public static Rectangle autoScaleBounds (Rectangle rect, int targetZoom, int currentZoom) {
353
public static Rectangle autoScaleBounds (Rectangle rect, int targetZoom, int currentZoom) {
253
	if (deviceZoom == 100 || rect == null || targetZoom == currentZoom) return rect;
354
	return autoScaleBounds(Display.getDefault(), rect, targetZoom, currentZoom);
355
}
356
/**
357
 * Returns a new rectangle as per the scaleFactor.
358
 */
359
public static Rectangle autoScaleBounds (Device device, Rectangle rect, int targetZoom, int currentZoom) {
360
	if (device.getZoom() == 100 || rect == null || targetZoom == currentZoom) return rect;
254
	float scaleFactor = ((float)targetZoom) / (float)currentZoom;
361
	float scaleFactor = ((float)targetZoom) / (float)currentZoom;
255
	Rectangle returnRect = new Rectangle (0,0,0,0);
362
	Rectangle returnRect = new Rectangle (0,0,0,0);
256
	returnRect.x = Math.round (rect.x * scaleFactor);
363
	returnRect.x = Math.round (rect.x * scaleFactor);
Lines 264-277 Link Here
264
 * Auto-scale up ImageData
371
 * Auto-scale up ImageData
265
 */
372
 */
266
public static ImageData autoScaleUp (Device device, final ImageData imageData) {
373
public static ImageData autoScaleUp (Device device, final ImageData imageData) {
267
	if (deviceZoom == 100 || imageData == null || (device != null && !device.isAutoScalable())) return imageData;
374
	if (device.getZoom() == 100 || imageData == null || (device != null && !device.isAutoScalable())) return imageData;
268
	float scaleFactor = getScalingFactor ();
375
	float scaleFactor = getScalingFactor (device);
269
	return autoScaleImageData(device, imageData, scaleFactor);
376
	return autoScaleImageData(device, imageData, scaleFactor);
270
}
377
}
271
378
379
/**
380
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleUp(Device, int[])}.
381
 */
382
383
@Deprecated
272
public static int[] autoScaleUp(int[] pointArray) {
384
public static int[] autoScaleUp(int[] pointArray) {
273
	if (deviceZoom == 100 || pointArray == null) return pointArray;
385
	return autoScaleUp(Display.getDefault(), pointArray);
274
	float scaleFactor = getScalingFactor ();
386
}
387
public static int[] autoScaleUp(Device device, int[] pointArray) {
388
	if (device.getZoom() == 100 || pointArray == null) return pointArray;
389
	float scaleFactor = getScalingFactor (device);
275
	int [] returnArray = new int[pointArray.length];
390
	int [] returnArray = new int[pointArray.length];
276
	for (int i = 0; i < pointArray.length; i++) {
391
	for (int i = 0; i < pointArray.length; i++) {
277
		returnArray [i] =  Math.round (pointArray [i] * scaleFactor);
392
		returnArray [i] =  Math.round (pointArray [i] * scaleFactor);
Lines 279-295 Link Here
279
	return returnArray;
394
	return returnArray;
280
}
395
}
281
396
397
398
/**
399
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleUp(Device, Drawable, int[])}.
400
 */
401
402
@Deprecated
282
public static int[] autoScaleUp(Drawable drawable, int[] pointArray) {
403
public static int[] autoScaleUp(Drawable drawable, int[] pointArray) {
404
	return autoScaleUp(Display.getDefault(), drawable, pointArray);
405
}
406
407
public static int[] autoScaleUp(Device device, Drawable drawable, int[] pointArray) {
283
	if (drawable != null && !drawable.isAutoScalable ()) return pointArray;
408
	if (drawable != null && !drawable.isAutoScalable ()) return pointArray;
284
	return autoScaleUp (pointArray);
409
	return autoScaleUp (device, pointArray);
285
}
410
}
286
411
287
/**
412
/**
288
 * Auto-scale up int dimensions.
413
 * Auto-scale up int dimensions.
414
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleUp(Device, int)}.
289
 */
415
 */
416
@Deprecated
290
public static int autoScaleUp (int size) {
417
public static int autoScaleUp (int size) {
291
	if (deviceZoom == 100 || size == SWT.DEFAULT) return size;
418
	return autoScaleUp(Display.getDefault(), size);
292
	float scaleFactor = getScalingFactor ();
419
}
420
/**
421
 * Auto-scale up int dimensions.
422
 */
423
public static int autoScaleUp (Device device, int size) {
424
	if (device.getZoom() == 100 || size == SWT.DEFAULT) return size;
425
	float scaleFactor = getScalingFactor (device);
293
	return Math.round (size * scaleFactor);
426
	return Math.round (size * scaleFactor);
294
}
427
}
295
428
Lines 304-332 Link Here
304
437
305
/**
438
/**
306
 * Auto-scale up int dimensions if enabled for Drawable class.
439
 * Auto-scale up int dimensions if enabled for Drawable class.
440
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleUp(Device, Drawable, int)}.
307
 */
441
 */
442
@Deprecated
308
public static int autoScaleUp (Drawable drawable, int size) {
443
public static int autoScaleUp (Drawable drawable, int size) {
444
	return autoScaleUp(Display.getDefault(),drawable, size);
445
}
446
/**
447
 * Auto-scale up int dimensions if enabled for Drawable class.
448
 */
449
public static int autoScaleUp (Device device, Drawable drawable, int size) {
309
	if (drawable != null && !drawable.isAutoScalable ()) return size;
450
	if (drawable != null && !drawable.isAutoScalable ()) return size;
310
	return autoScaleUp (size);
451
	return autoScaleUp (device, size);
311
}
452
}
312
453
454
/**
455
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleUp(Device, float)}.
456
 */
457
@Deprecated
313
public static float autoScaleUp(float size) {
458
public static float autoScaleUp(float size) {
314
	if (deviceZoom == 100 || size == SWT.DEFAULT) return size;
459
	return autoScaleUp(Display.getDefault(), size);
315
	float scaleFactor = getScalingFactor ();
460
}
461
public static float autoScaleUp(Device device, float size) {
462
	if (device.getZoom() == 100 || size == SWT.DEFAULT) return size;
463
	float scaleFactor = getScalingFactor (device);
316
	return (size * scaleFactor);
464
	return (size * scaleFactor);
317
}
465
}
318
466
467
/**
468
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleUp(Device, Drawable, float)}.
469
 */
470
471
@Deprecated
319
public static float autoScaleUp(Drawable drawable, float size) {
472
public static float autoScaleUp(Drawable drawable, float size) {
473
	return autoScaleUp(Display.getDefault(), drawable, size);
474
}
475
public static float autoScaleUp(Device device, Drawable drawable, float size) {
320
	if (drawable != null && !drawable.isAutoScalable ()) return size;
476
	if (drawable != null && !drawable.isAutoScalable ()) return size;
321
	return autoScaleUp (size);
477
	return autoScaleUp (device, size);
322
}
478
}
323
479
324
/**
480
/**
325
 * Returns a new scaled up Point.
481
 * Returns a new scaled up Point.
482
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleUp(Device, Point)}.
326
 */
483
 */
484
@Deprecated
327
public static Point autoScaleUp (Point point) {
485
public static Point autoScaleUp (Point point) {
328
	if (deviceZoom == 100 || point == null) return point;
486
	return autoScaleUp(Display.getDefault(), point);
329
	float scaleFactor = getScalingFactor ();
487
}
488
/**
489
 * Returns a new scaled up Point.
490
 */
491
public static Point autoScaleUp (Device device, Point point) {
492
	if (device.getZoom() == 100 || point == null) return point;
493
	float scaleFactor = getScalingFactor (device);
330
	Point scaledPoint = new Point (0,0);
494
	Point scaledPoint = new Point (0,0);
331
	scaledPoint.x = Math.round (point.x * scaleFactor);
495
	scaledPoint.x = Math.round (point.x * scaleFactor);
332
	scaledPoint.y = Math.round (point.y * scaleFactor);
496
	scaledPoint.y = Math.round (point.y * scaleFactor);
Lines 335-354 Link Here
335
499
336
/**
500
/**
337
 * Returns a new scaled up Point if enabled for Drawable class.
501
 * Returns a new scaled up Point if enabled for Drawable class.
502
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleUp(Device, Drawable, Point)}.
338
 */
503
 */
504
@Deprecated
339
public static Point autoScaleUp (Drawable drawable, Point point) {
505
public static Point autoScaleUp (Drawable drawable, Point point) {
506
	return autoScaleUp(Display.getDefault(), drawable, point);
507
}
508
/**
509
 * Returns a new scaled up Point if enabled for Drawable class.
510
 */
511
public static Point autoScaleUp (Device device, Drawable drawable, Point point) {
340
	if (drawable != null && !drawable.isAutoScalable ()) return point;
512
	if (drawable != null && !drawable.isAutoScalable ()) return point;
341
	return autoScaleUp (point);
513
	return autoScaleUp (device, point);
342
}
514
}
343
515
344
/**
516
/**
345
 * Returns a new scaled up Rectangle.
517
 * Returns a new scaled up Rectangle.
518
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleUp(Device, Rectangle)}.
346
 */
519
 */
520
@Deprecated
347
public static Rectangle autoScaleUp (Rectangle rect) {
521
public static Rectangle autoScaleUp (Rectangle rect) {
348
	if (deviceZoom == 100 || rect == null) return rect;
522
	return autoScaleUp(Display.getDefault(), rect);
523
}
524
/**
525
 * Returns a new scaled up Rectangle.
526
 */
527
public static Rectangle autoScaleUp (Device device, Rectangle rect) {
528
	if (device.getZoom() == 100 || rect == null) return rect;
349
	Rectangle scaledRect = new Rectangle (0,0,0,0);
529
	Rectangle scaledRect = new Rectangle (0,0,0,0);
350
	Point scaledTopLeft = DPIUtil.autoScaleUp (new Point (rect.x, rect.y));
530
	Point scaledTopLeft = DPIUtil.autoScaleUp (device, new Point (rect.x, rect.y));
351
	Point scaledBottomRight = DPIUtil.autoScaleUp (new Point (rect.x + rect.width, rect.y + rect.height));
531
	Point scaledBottomRight = DPIUtil.autoScaleUp (device, new Point (rect.x + rect.width, rect.y + rect.height));
352
532
353
	scaledRect.x = scaledTopLeft.x;
533
	scaledRect.x = scaledTopLeft.x;
354
	scaledRect.y = scaledTopLeft.y;
534
	scaledRect.y = scaledTopLeft.y;
Lines 359-376 Link Here
359
539
360
/**
540
/**
361
 * Returns a new scaled up Rectangle if enabled for Drawable class.
541
 * Returns a new scaled up Rectangle if enabled for Drawable class.
542
 * @deprecated the device zoom depends on the {@link Device}, so use {@link #autoScaleUp(Device, Drawable, Rectangle)}.
362
 */
543
 */
544
@Deprecated
363
public static Rectangle autoScaleUp (Drawable drawable, Rectangle rect) {
545
public static Rectangle autoScaleUp (Drawable drawable, Rectangle rect) {
546
	return autoScaleUp(Display.getDefault(), drawable,rect);
547
}
548
/**
549
 * Returns a new scaled up Rectangle if enabled for Drawable class.
550
 */
551
public static Rectangle autoScaleUp (Device device, Drawable drawable, Rectangle rect) {
364
	if (drawable != null && !drawable.isAutoScalable ()) return rect;
552
	if (drawable != null && !drawable.isAutoScalable ()) return rect;
365
	return autoScaleUp (rect);
553
	return autoScaleUp (device, rect);
366
}
554
}
367
555
368
/**
556
/**
369
 * Returns Scaling factor from the display
557
 * Returns Scaling factor from the display
370
 * @return float scaling factor
558
 * @return float scaling factor
371
 */
559
 */
372
private static float getScalingFactor () {
560
private static float getScalingFactor (Device device) {
373
	return deviceZoom / 100f;
561
	return device.getZoom() / 100f;
374
}
562
}
375
563
376
/**
564
/**
Lines 413-424 Link Here
413
	return filename;
601
	return filename;
414
}
602
}
415
603
604
/**
605
 * @deprecated the device zoom depends on the {@link Device}, so use {@link Device#getZoom()}.
606
 */
607
608
609
@Deprecated
416
public static int getDeviceZoom() {
610
public static int getDeviceZoom() {
417
	return deviceZoom;
611
	return deviceZoom;
418
}
612
}
419
613
614
/**
615
 * @deprecated the device zoom depends on the {@link Device}, so use {@link Device#setZoom(int)}.
616
 */
617
618
@Deprecated
420
public static void setDeviceZoom (int nativeDeviceZoom) {
619
public static void setDeviceZoom (int nativeDeviceZoom) {
421
	DPIUtil.nativeDeviceZoom = nativeDeviceZoom;
620
	deviceZoom = calculateDeviceZoom(nativeDeviceZoom);
621
	System.setProperty("org.eclipse.swt.internal.deviceZoom", Integer.toString(deviceZoom));
622
	if (deviceZoom != 100 && autoScaleMethodSetting == AutoScaleMethod.AUTO) {
623
		if (deviceZoom / 100 * 100 == deviceZoom || !"gtk".equals(SWT.getPlatform())) {
624
			autoScaleMethod = AutoScaleMethod.NEAREST;
625
		} else {
626
			autoScaleMethod = AutoScaleMethod.SMOOTH;
627
		}
628
	}
629
}
630
631
public static int calculateDeviceZoom (int nativeDeviceZoom) {
422
	int deviceZoom = 0;
632
	int deviceZoom = 0;
423
	String value = System.getProperty (SWT_AUTOSCALE);
633
	String value = System.getProperty (SWT_AUTOSCALE);
424
 	if (value != null) {
634
 	if (value != null) {
Lines 444-459 Link Here
444
			deviceZoom = Math.min (deviceZoom, 200);
654
			deviceZoom = Math.min (deviceZoom, 200);
445
		}
655
		}
446
	}
656
	}
447
657
	return deviceZoom;
448
	DPIUtil.deviceZoom = deviceZoom;
449
	System.setProperty("org.eclipse.swt.internal.deviceZoom", Integer.toString(deviceZoom));
450
	if (deviceZoom != 100 && autoScaleMethodSetting == AutoScaleMethod.AUTO) {
451
		if (deviceZoom / 100 * 100 == deviceZoom || !"gtk".equals(SWT.getPlatform())) {
452
			autoScaleMethod = AutoScaleMethod.NEAREST;
453
		} else {
454
			autoScaleMethod = AutoScaleMethod.SMOOTH;
455
		}
456
	}
457
}
658
}
458
659
459
/**
660
/**
(-)a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java (+12 lines)
Lines 70-75 Link Here
70
70
71
	/* Auto-Scaling*/
71
	/* Auto-Scaling*/
72
	boolean enableAutoScaling = true;
72
	boolean enableAutoScaling = true;
73
	int zoom;
73
74
74
	/*
75
	/*
75
	* TEMPORARY CODE. When a graphics object is
76
	* TEMPORARY CODE. When a graphics object is
Lines 709-714 Link Here
709
	/* Initialize the system font slot */
710
	/* Initialize the system font slot */
710
	systemFont = getSystemFont();
711
	systemFont = getSystemFont();
711
712
713
	zoom = DPIUtil.calculateDeviceZoom(getDeviceZoom());
714
712
	/* Initialize scripts list */
715
	/* Initialize scripts list */
713
	if (!OS.IsWinCE) {
716
	if (!OS.IsWinCE) {
714
		long /*int*/ [] ppSp = new long /*int*/ [1];
717
		long /*int*/ [] ppSp = new long /*int*/ [1];
Lines 1018-1021 Link Here
1018
	return DPIUtil.mapDPIToZoom ( _getDPIx ());
1021
	return DPIUtil.mapDPIToZoom ( _getDPIx ());
1019
}
1022
}
1020
1023
1024
1025
void setZoom(int zoom) {
1026
	this.zoom = zoom;
1027
}
1028
1029
public int getZoom() {
1030
	return zoom;
1031
}
1032
1021
}
1033
}
(-)a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java (-7 / +9 lines)
Lines 39-49 Link Here
39
	 * @noreference This field is not intended to be referenced by clients.
39
	 * @noreference This field is not intended to be referenced by clients.
40
	 */
40
	 */
41
	public TEXTMETRIC handle;
41
	public TEXTMETRIC handle;
42
	private Device device;
42
43
43
/**
44
/**
44
 * Prevents instances from being created outside the package.
45
 * Prevents instances from being created outside the package.
45
 */
46
 */
46
FontMetrics() {
47
FontMetrics(Device device) {
48
	this.device=device;
47
}
49
}
48
50
49
/**
51
/**
Lines 92-98 Link Here
92
 * @return the ascent of the font
94
 * @return the ascent of the font
93
 */
95
 */
94
public int getAscent() {
96
public int getAscent() {
95
	return DPIUtil.autoScaleDown(handle.tmAscent - handle.tmInternalLeading);
97
	return DPIUtil.autoScaleDown(device, handle.tmAscent - handle.tmInternalLeading);
96
}
98
}
97
99
98
/**
100
/**
Lines 102-108 Link Here
102
 * @return the average character width of the font
104
 * @return the average character width of the font
103
 */
105
 */
104
public int getAverageCharWidth() {
106
public int getAverageCharWidth() {
105
	return DPIUtil.autoScaleDown(handle.tmAveCharWidth);
107
	return DPIUtil.autoScaleDown(device,handle.tmAveCharWidth);
106
}
108
}
107
109
108
/**
110
/**
Lines 114-120 Link Here
114
 * @return the descent of the font
116
 * @return the descent of the font
115
 */
117
 */
116
public int getDescent() {
118
public int getDescent() {
117
	return DPIUtil.autoScaleDown(handle.tmDescent);
119
	return DPIUtil.autoScaleDown(device,handle.tmDescent);
118
}
120
}
119
121
120
/**
122
/**
Lines 129-135 Link Here
129
 * @see #getLeading
131
 * @see #getLeading
130
 */
132
 */
131
public int getHeight() {
133
public int getHeight() {
132
	return DPIUtil.autoScaleDown(handle.tmHeight);
134
	return DPIUtil.autoScaleDown(device,handle.tmHeight);
133
}
135
}
134
136
135
/**
137
/**
Lines 192-199 Link Here
192
 *
194
 *
193
 * @noreference This method is not intended to be referenced by clients.
195
 * @noreference This method is not intended to be referenced by clients.
194
 */
196
 */
195
public static FontMetrics win32_new(TEXTMETRIC handle) {
197
public static FontMetrics win32_new(Device device, TEXTMETRIC handle) {
196
	FontMetrics fontMetrics = new FontMetrics();
198
	FontMetrics fontMetrics = new FontMetrics(device);
197
	fontMetrics.handle = handle;
199
	fontMetrics.handle = handle;
198
	return fontMetrics;
200
	return fontMetrics;
199
}
201
}
(-)a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java (-92 / +92 lines)
Lines 446-453 Link Here
446
 * </ul>
446
 * </ul>
447
 */
447
 */
448
public void copyArea (Image image, int x, int y) {
448
public void copyArea (Image image, int x, int y) {
449
	x = DPIUtil.autoScaleUp(drawable, x);
449
	x = DPIUtil.autoScaleUp(this.device, drawable, x);
450
	y = DPIUtil.autoScaleUp(drawable, y);
450
	y = DPIUtil.autoScaleUp(this.device, drawable, y);
451
	copyAreaInPixels(image, x, y);
451
	copyAreaInPixels(image, x, y);
452
}
452
}
453
453
Lines 502-513 Link Here
502
 * @since 3.1
502
 * @since 3.1
503
 */
503
 */
504
public void copyArea (int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
504
public void copyArea (int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
505
	srcX = DPIUtil.autoScaleUp(drawable, srcX);
505
	srcX = DPIUtil.autoScaleUp(this.device, drawable, srcX);
506
	srcY = DPIUtil.autoScaleUp(drawable, srcY);
506
	srcY = DPIUtil.autoScaleUp(this.device, drawable, srcY);
507
	width = DPIUtil.autoScaleUp(drawable, width);
507
	width = DPIUtil.autoScaleUp(this.device, drawable, width);
508
	height = DPIUtil.autoScaleUp(drawable, height);
508
	height = DPIUtil.autoScaleUp(this.device, drawable, height);
509
	destX = DPIUtil.autoScaleUp(drawable, destX);
509
	destX = DPIUtil.autoScaleUp(this.device, drawable, destX);
510
	destY = DPIUtil.autoScaleUp(drawable, destY);
510
	destY = DPIUtil.autoScaleUp(this.device, drawable, destY);
511
	copyAreaInPixels(srcX, srcY, width, height, destX, destY, paint);
511
	copyAreaInPixels(srcX, srcY, width, height, destX, destY, paint);
512
}
512
}
513
513
Lines 743-752 Link Here
743
 * </ul>
743
 * </ul>
744
 */
744
 */
745
public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
745
public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
746
	x = DPIUtil.autoScaleUp(drawable, x);
746
	x = DPIUtil.autoScaleUp(this.device, drawable, x);
747
	y = DPIUtil.autoScaleUp(drawable, y);
747
	y = DPIUtil.autoScaleUp(this.device, drawable, y);
748
	width = DPIUtil.autoScaleUp(drawable, width);
748
	width = DPIUtil.autoScaleUp(this.device, drawable, width);
749
	height = DPIUtil.autoScaleUp(drawable, height);
749
	height = DPIUtil.autoScaleUp(this.device, drawable, height);
750
	drawArcInPixels(x, y, width, height, startAngle, arcAngle);
750
	drawArcInPixels(x, y, width, height, startAngle, arcAngle);
751
}
751
}
752
752
Lines 849-858 Link Here
849
 * @see #drawRectangle(int, int, int, int)
849
 * @see #drawRectangle(int, int, int, int)
850
 */
850
 */
851
public void drawFocus (int x, int y, int width, int height) {
851
public void drawFocus (int x, int y, int width, int height) {
852
	x = DPIUtil.autoScaleUp (drawable, x);
852
	x = DPIUtil.autoScaleUp (device, drawable, x);
853
	y = DPIUtil.autoScaleUp (drawable, y);
853
	y = DPIUtil.autoScaleUp (device, drawable, y);
854
	width = DPIUtil.autoScaleUp (drawable, width);
854
	width = DPIUtil.autoScaleUp (device, drawable, width);
855
	height = DPIUtil.autoScaleUp (drawable, height);
855
	height = DPIUtil.autoScaleUp (device, drawable, height);
856
	drawFocusInPixels(x, y, width, height);
856
	drawFocusInPixels(x, y, width, height);
857
}
857
}
858
858
Lines 927-934 Link Here
927
 * </ul>
927
 * </ul>
928
 */
928
 */
929
public void drawImage (Image image, int x, int y) {
929
public void drawImage (Image image, int x, int y) {
930
	x = DPIUtil.autoScaleUp(drawable, x);
930
	x = DPIUtil.autoScaleUp(this.device, drawable, x);
931
	y = DPIUtil.autoScaleUp(drawable, y);
931
	y = DPIUtil.autoScaleUp(this.device, drawable, y);
932
	drawImageInPixels(image, x, y);
932
	drawImageInPixels(image, x, y);
933
}
933
}
934
934
Lines 980-988 Link Here
980
	if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
980
	if (image == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
981
	if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
981
	if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
982
982
983
	Rectangle src = DPIUtil.autoScaleUp(drawable, new Rectangle(srcX, srcY, srcWidth, srcHeight));
983
	Rectangle src = DPIUtil.autoScaleUp(this.device, drawable, new Rectangle(srcX, srcY, srcWidth, srcHeight));
984
	Rectangle dest = DPIUtil.autoScaleUp(drawable, new Rectangle(destX, destY, destWidth, destHeight));
984
	Rectangle dest = DPIUtil.autoScaleUp(this.device, drawable, new Rectangle(destX, destY, destWidth, destHeight));
985
	int deviceZoom = DPIUtil.getDeviceZoom();
985
	int deviceZoom = device.getZoom();
986
	if (deviceZoom != 100) {
986
	if (deviceZoom != 100) {
987
		/*
987
		/*
988
		 * This is a HACK! Due to rounding errors at fractional scale factors,
988
		 * This is a HACK! Due to rounding errors at fractional scale factors,
Lines 1735-1744 Link Here
1735
 * </ul>
1735
 * </ul>
1736
 */
1736
 */
1737
public void drawLine (int x1, int y1, int x2, int y2) {
1737
public void drawLine (int x1, int y1, int x2, int y2) {
1738
	x1 = DPIUtil.autoScaleUp (drawable, x1);
1738
	x1 = DPIUtil.autoScaleUp (device, drawable, x1);
1739
	x2 = DPIUtil.autoScaleUp (drawable, x2);
1739
	x2 = DPIUtil.autoScaleUp (device, drawable, x2);
1740
	y1 = DPIUtil.autoScaleUp (drawable, y1);
1740
	y1 = DPIUtil.autoScaleUp (device, drawable, y1);
1741
	y2 = DPIUtil.autoScaleUp (drawable, y2);
1741
	y2 = DPIUtil.autoScaleUp (device, drawable, y2);
1742
	drawLineInPixels(x1, y1, x2, y2);
1742
	drawLineInPixels(x1, y1, x2, y2);
1743
}
1743
}
1744
1744
Lines 1792-1801 Link Here
1792
 * </ul>
1792
 * </ul>
1793
 */
1793
 */
1794
public void drawOval (int x, int y, int width, int height) {
1794
public void drawOval (int x, int y, int width, int height) {
1795
	x = DPIUtil.autoScaleUp (drawable, x);
1795
	x = DPIUtil.autoScaleUp (device, drawable, x);
1796
	y = DPIUtil.autoScaleUp (drawable, y);
1796
	y = DPIUtil.autoScaleUp (device, drawable, y);
1797
	width = DPIUtil.autoScaleUp (drawable, width);
1797
	width = DPIUtil.autoScaleUp (device, drawable, width);
1798
	height = DPIUtil.autoScaleUp (drawable, height);
1798
	height = DPIUtil.autoScaleUp (device, drawable, height);
1799
	drawOvalInPixels(x, y, width, height);
1799
	drawOvalInPixels(x, y, width, height);
1800
}
1800
}
1801
1801
Lines 1868-1875 Link Here
1868
 * @since 3.0
1868
 * @since 3.0
1869
 */
1869
 */
1870
public void drawPoint (int x, int y) {
1870
public void drawPoint (int x, int y) {
1871
	x = DPIUtil.autoScaleUp (drawable, x);
1871
	x = DPIUtil.autoScaleUp (device, drawable, x);
1872
	y = DPIUtil.autoScaleUp (drawable, y);
1872
	y = DPIUtil.autoScaleUp (device, drawable, y);
1873
	drawPointInPixels(x, y);
1873
	drawPointInPixels(x, y);
1874
}
1874
}
1875
1875
Lines 1902-1908 Link Here
1902
 */
1902
 */
1903
public void drawPolygon (int[] pointArray) {
1903
public void drawPolygon (int[] pointArray) {
1904
	if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
1904
	if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
1905
	drawPolygonInPixels(DPIUtil.autoScaleUp(drawable, pointArray));
1905
	drawPolygonInPixels(DPIUtil.autoScaleUp(this.device, drawable, pointArray));
1906
}
1906
}
1907
1907
1908
void drawPolygonInPixels(int[] pointArray) {
1908
void drawPolygonInPixels(int[] pointArray) {
Lines 1950-1956 Link Here
1950
 * </ul>
1950
 * </ul>
1951
 */
1951
 */
1952
public void drawPolyline (int[] pointArray) {
1952
public void drawPolyline (int[] pointArray) {
1953
	drawPolylineInPixels(DPIUtil.autoScaleUp(drawable, pointArray));
1953
	drawPolylineInPixels(DPIUtil.autoScaleUp(this.device, drawable, pointArray));
1954
}
1954
}
1955
1955
1956
void drawPolylineInPixels(int[] pointArray) {
1956
void drawPolylineInPixels(int[] pointArray) {
Lines 2003-2012 Link Here
2003
 * </ul>
2003
 * </ul>
2004
 */
2004
 */
2005
public void drawRectangle (int x, int y, int width, int height) {
2005
public void drawRectangle (int x, int y, int width, int height) {
2006
	x = DPIUtil.autoScaleUp (drawable, x);
2006
	x = DPIUtil.autoScaleUp (device, drawable, x);
2007
	y = DPIUtil.autoScaleUp (drawable, y);
2007
	y = DPIUtil.autoScaleUp (device, drawable, y);
2008
	width = DPIUtil.autoScaleUp (drawable, width);
2008
	width = DPIUtil.autoScaleUp (device, drawable, width);
2009
	height = DPIUtil.autoScaleUp (drawable, height);
2009
	height = DPIUtil.autoScaleUp (device, drawable, height);
2010
	drawRectangleInPixels(x, y, width, height);
2010
	drawRectangleInPixels(x, y, width, height);
2011
}
2011
}
2012
2012
Lines 2062-2068 Link Here
2062
 */
2062
 */
2063
public void drawRectangle (Rectangle rect) {
2063
public void drawRectangle (Rectangle rect) {
2064
	if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
2064
	if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
2065
	rect = DPIUtil.autoScaleUp(drawable, rect);
2065
	rect = DPIUtil.autoScaleUp(this.device, drawable, rect);
2066
	drawRectangleInPixels(rect.x, rect.y, rect.width, rect.height);
2066
	drawRectangleInPixels(rect.x, rect.y, rect.width, rect.height);
2067
}
2067
}
2068
2068
Lines 2088-2099 Link Here
2088
 * </ul>
2088
 * </ul>
2089
 */
2089
 */
2090
public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
2090
public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
2091
	x = DPIUtil.autoScaleUp (drawable, x);
2091
	x = DPIUtil.autoScaleUp (device, drawable, x);
2092
	y = DPIUtil.autoScaleUp (drawable, y);
2092
	y = DPIUtil.autoScaleUp (device, drawable, y);
2093
	width = DPIUtil.autoScaleUp (drawable, width);
2093
	width = DPIUtil.autoScaleUp (device, drawable, width);
2094
	height = DPIUtil.autoScaleUp (drawable, height);
2094
	height = DPIUtil.autoScaleUp (device, drawable, height);
2095
	arcWidth = DPIUtil.autoScaleUp (drawable, arcWidth);
2095
	arcWidth = DPIUtil.autoScaleUp (device, drawable, arcWidth);
2096
	arcHeight = DPIUtil.autoScaleUp (drawable, arcHeight);
2096
	arcHeight = DPIUtil.autoScaleUp (device, drawable, arcHeight);
2097
	drawRoundRectangleInPixels(x, y, width, height, arcWidth, arcHeight);
2097
	drawRoundRectangleInPixels(x, y, width, height, arcWidth, arcHeight);
2098
}
2098
}
2099
2099
Lines 2221-2228 Link Here
2221
 * </ul>
2221
 * </ul>
2222
 */
2222
 */
2223
public void drawString (String string, int x, int y) {
2223
public void drawString (String string, int x, int y) {
2224
	x = DPIUtil.autoScaleUp(drawable, x);
2224
	x = DPIUtil.autoScaleUp(this.device, drawable, x);
2225
	y = DPIUtil.autoScaleUp(drawable, y);
2225
	y = DPIUtil.autoScaleUp(this.device, drawable, y);
2226
	drawStringInPixels(string, x, y, false);
2226
	drawStringInPixels(string, x, y, false);
2227
}
2227
}
2228
2228
Lines 2247-2254 Link Here
2247
 * </ul>
2247
 * </ul>
2248
 */
2248
 */
2249
public void drawString (String string, int x, int y, boolean isTransparent) {
2249
public void drawString (String string, int x, int y, boolean isTransparent) {
2250
	x = DPIUtil.autoScaleUp(drawable, x);
2250
	x = DPIUtil.autoScaleUp(this.device, drawable, x);
2251
	y = DPIUtil.autoScaleUp(drawable, y);
2251
	y = DPIUtil.autoScaleUp(this.device, drawable, y);
2252
	drawStringInPixels(string, x, y, isTransparent);
2252
	drawStringInPixels(string, x, y, isTransparent);
2253
}
2253
}
2254
2254
Lines 2343-2350 Link Here
2343
 * </ul>
2343
 * </ul>
2344
 */
2344
 */
2345
public void drawText (String string, int x, int y) {
2345
public void drawText (String string, int x, int y) {
2346
	x = DPIUtil.autoScaleUp(drawable, x);
2346
	x = DPIUtil.autoScaleUp(this.device, drawable, x);
2347
	y = DPIUtil.autoScaleUp(drawable, y);
2347
	y = DPIUtil.autoScaleUp(this.device, drawable, y);
2348
	drawTextInPixels(string, x, y);
2348
	drawTextInPixels(string, x, y);
2349
}
2349
}
2350
2350
Lines 2373-2380 Link Here
2373
 * </ul>
2373
 * </ul>
2374
 */
2374
 */
2375
public void drawText (String string, int x, int y, boolean isTransparent) {
2375
public void drawText (String string, int x, int y, boolean isTransparent) {
2376
	x = DPIUtil.autoScaleUp(drawable, x);
2376
	x = DPIUtil.autoScaleUp(this.device, drawable, x);
2377
	y = DPIUtil.autoScaleUp(drawable, y);
2377
	y = DPIUtil.autoScaleUp(this.device, drawable, y);
2378
	drawTextInPixels(string, x, y, isTransparent);
2378
	drawTextInPixels(string, x, y, isTransparent);
2379
}
2379
}
2380
2380
Lines 2419-2426 Link Here
2419
 * </ul>
2419
 * </ul>
2420
 */
2420
 */
2421
public void drawText (String string, int x, int y, int flags) {
2421
public void drawText (String string, int x, int y, int flags) {
2422
	x = DPIUtil.autoScaleUp(drawable, x);
2422
	x = DPIUtil.autoScaleUp(this.device, drawable, x);
2423
	y = DPIUtil.autoScaleUp(drawable, y);
2423
	y = DPIUtil.autoScaleUp(this.device, drawable, y);
2424
	drawTextInPixels(string, x, y, flags);
2424
	drawTextInPixels(string, x, y, flags);
2425
}
2425
}
2426
2426
Lines 2820-2829 Link Here
2820
 * @see #drawArc
2820
 * @see #drawArc
2821
 */
2821
 */
2822
public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
2822
public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
2823
	x = DPIUtil.autoScaleUp (drawable, x);
2823
	x = DPIUtil.autoScaleUp (device, drawable, x);
2824
	y = DPIUtil.autoScaleUp (drawable, y);
2824
	y = DPIUtil.autoScaleUp (device, drawable, y);
2825
	width = DPIUtil.autoScaleUp (drawable, width);
2825
	width = DPIUtil.autoScaleUp (device, drawable, width);
2826
	height = DPIUtil.autoScaleUp (drawable, height);
2826
	height = DPIUtil.autoScaleUp (device, drawable, height);
2827
	fillArcInPixels(x, y, width, height, startAngle, arcAngle);
2827
	fillArcInPixels(x, y, width, height, startAngle, arcAngle);
2828
}
2828
}
2829
2829
Lines 2929-2938 Link Here
2929
 * @see #drawRectangle(int, int, int, int)
2929
 * @see #drawRectangle(int, int, int, int)
2930
 */
2930
 */
2931
public void fillGradientRectangle (int x, int y, int width, int height, boolean vertical) {
2931
public void fillGradientRectangle (int x, int y, int width, int height, boolean vertical) {
2932
	x = DPIUtil.autoScaleUp (drawable, x);
2932
	x = DPIUtil.autoScaleUp (device, drawable, x);
2933
	y = DPIUtil.autoScaleUp (drawable, y);
2933
	y = DPIUtil.autoScaleUp (device, drawable, y);
2934
	width = DPIUtil.autoScaleUp (drawable, width);
2934
	width = DPIUtil.autoScaleUp (device, drawable, width);
2935
	height = DPIUtil.autoScaleUp (drawable, height);
2935
	height = DPIUtil.autoScaleUp (device, drawable, height);
2936
	fillGradientRectangleInPixels(x, y, width, height, vertical);
2936
	fillGradientRectangleInPixels(x, y, width, height, vertical);
2937
}
2937
}
2938
2938
Lines 3063-3072 Link Here
3063
 * @see #drawOval
3063
 * @see #drawOval
3064
 */
3064
 */
3065
public void fillOval (int x, int y, int width, int height) {
3065
public void fillOval (int x, int y, int width, int height) {
3066
	x = DPIUtil.autoScaleUp (drawable, x);
3066
	x = DPIUtil.autoScaleUp (device, drawable, x);
3067
	y = DPIUtil.autoScaleUp (drawable, y);
3067
	y = DPIUtil.autoScaleUp (device, drawable, y);
3068
	width = DPIUtil.autoScaleUp (drawable, width);
3068
	width = DPIUtil.autoScaleUp (device, drawable, width);
3069
	height = DPIUtil.autoScaleUp (drawable, height);
3069
	height = DPIUtil.autoScaleUp (device, drawable, height);
3070
	fillOvalInPixels(x, y, width, height);
3070
	fillOvalInPixels(x, y, width, height);
3071
}
3071
}
3072
3072
Lines 3136-3142 Link Here
3136
 */
3136
 */
3137
public void fillPolygon (int[] pointArray) {
3137
public void fillPolygon (int[] pointArray) {
3138
	if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
3138
	if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
3139
	fillPolygonInPixels(DPIUtil.autoScaleUp(drawable, pointArray));
3139
	fillPolygonInPixels(DPIUtil.autoScaleUp(this.device, drawable, pointArray));
3140
}
3140
}
3141
3141
3142
void fillPolygonInPixels (int[] pointArray) {
3142
void fillPolygonInPixels (int[] pointArray) {
Lines 3176-3185 Link Here
3176
 * @see #drawRectangle(int, int, int, int)
3176
 * @see #drawRectangle(int, int, int, int)
3177
 */
3177
 */
3178
public void fillRectangle (int x, int y, int width, int height) {
3178
public void fillRectangle (int x, int y, int width, int height) {
3179
	x = DPIUtil.autoScaleUp (drawable, x);
3179
	x = DPIUtil.autoScaleUp (device, drawable, x);
3180
	y = DPIUtil.autoScaleUp (drawable, y);
3180
	y = DPIUtil.autoScaleUp (device, drawable, y);
3181
	width = DPIUtil.autoScaleUp (drawable, width);
3181
	width = DPIUtil.autoScaleUp (device, drawable, width);
3182
	height = DPIUtil.autoScaleUp (drawable, height);
3182
	height = DPIUtil.autoScaleUp (device, drawable, height);
3183
	fillRectangleInPixels(x, y, width, height);
3183
	fillRectangleInPixels(x, y, width, height);
3184
}
3184
}
3185
3185
Lines 3226-3232 Link Here
3226
 */
3226
 */
3227
public void fillRectangle (Rectangle rect) {
3227
public void fillRectangle (Rectangle rect) {
3228
	if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
3228
	if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
3229
	rect = DPIUtil.autoScaleUp(drawable, rect);
3229
	rect = DPIUtil.autoScaleUp(this.device, drawable, rect);
3230
	fillRectangleInPixels(rect.x, rect.y, rect.width, rect.height);
3230
	fillRectangleInPixels(rect.x, rect.y, rect.width, rect.height);
3231
}
3231
}
3232
3232
Lines 3248-3259 Link Here
3248
 * @see #drawRoundRectangle
3248
 * @see #drawRoundRectangle
3249
 */
3249
 */
3250
public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
3250
public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
3251
	x = DPIUtil.autoScaleUp (drawable, x);
3251
	x = DPIUtil.autoScaleUp (device, drawable, x);
3252
	y = DPIUtil.autoScaleUp (drawable, y);
3252
	y = DPIUtil.autoScaleUp (device, drawable, y);
3253
	width = DPIUtil.autoScaleUp (drawable, width);
3253
	width = DPIUtil.autoScaleUp (device, drawable, width);
3254
	height = DPIUtil.autoScaleUp (drawable, height);
3254
	height = DPIUtil.autoScaleUp (device, drawable, height);
3255
	arcWidth = DPIUtil.autoScaleUp (drawable, arcWidth);
3255
	arcWidth = DPIUtil.autoScaleUp (device, drawable, arcWidth);
3256
	arcHeight = DPIUtil.autoScaleUp (drawable, arcHeight);
3256
	arcHeight = DPIUtil.autoScaleUp (device, drawable, arcHeight);
3257
	fillRoundRectangleInPixels(x, y, width, height, arcWidth, arcHeight);
3257
	fillRoundRectangleInPixels(x, y, width, height, arcWidth, arcHeight);
3258
}
3258
}
3259
3259
Lines 3529-3535 Link Here
3529
 * </ul>
3529
 * </ul>
3530
 */
3530
 */
3531
public Rectangle getClipping () {
3531
public Rectangle getClipping () {
3532
	return DPIUtil.autoScaleDown(drawable, getClippingInPixels());
3532
	return DPIUtil.autoScaleDown(this.device, drawable, getClippingInPixels());
3533
}
3533
}
3534
3534
3535
Rectangle getClippingInPixels() {
3535
Rectangle getClippingInPixels() {
Lines 3698-3704 Link Here
3698
	checkGC(FONT);
3698
	checkGC(FONT);
3699
	TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
3699
	TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA();
3700
	OS.GetTextMetrics(handle, lptm);
3700
	OS.GetTextMetrics(handle, lptm);
3701
	return FontMetrics.win32_new(lptm);
3701
	return FontMetrics.win32_new(device, lptm);
3702
}
3702
}
3703
3703
3704
/**
3704
/**
Lines 3804-3810 Link Here
3804
 */
3804
 */
3805
public LineAttributes getLineAttributes () {
3805
public LineAttributes getLineAttributes () {
3806
	LineAttributes attributes = getLineAttributesInPixels();
3806
	LineAttributes attributes = getLineAttributesInPixels();
3807
	attributes.width = DPIUtil.autoScaleDown(drawable, attributes.width);
3807
	attributes.width = DPIUtil.autoScaleDown(this.device, drawable, attributes.width);
3808
	return attributes;
3808
	return attributes;
3809
}
3809
}
3810
3810
Lines 3906-3912 Link Here
3906
 * </ul>
3906
 * </ul>
3907
 */
3907
 */
3908
public int getLineWidth () {
3908
public int getLineWidth () {
3909
	return DPIUtil.autoScaleDown(drawable, getLineWidthInPixels());
3909
	return DPIUtil.autoScaleDown(this.device, drawable, getLineWidthInPixels());
3910
}
3910
}
3911
3911
3912
int getLineWidthInPixels() {
3912
int getLineWidthInPixels() {
Lines 4470-4479 Link Here
4470
 * </ul>
4470
 * </ul>
4471
 */
4471
 */
4472
public void setClipping (int x, int y, int width, int height) {
4472
public void setClipping (int x, int y, int width, int height) {
4473
	x = DPIUtil.autoScaleUp(drawable, x);
4473
	x = DPIUtil.autoScaleUp(this.device, drawable, x);
4474
	y = DPIUtil.autoScaleUp(drawable, y);
4474
	y = DPIUtil.autoScaleUp(this.device, drawable, y);
4475
	width = DPIUtil.autoScaleUp(drawable, width);
4475
	width = DPIUtil.autoScaleUp(this.device, drawable, width);
4476
	height = DPIUtil.autoScaleUp(drawable, height);
4476
	height = DPIUtil.autoScaleUp(this.device, drawable, height);
4477
	setClippingInPixels(x, y, width, height);
4477
	setClippingInPixels(x, y, width, height);
4478
}
4478
}
4479
4479
Lines 4541-4547 Link Here
4541
		setClipping(0);
4541
		setClipping(0);
4542
	}
4542
	}
4543
	else {
4543
	else {
4544
		rect = DPIUtil.autoScaleUp(drawable, rect);
4544
		rect = DPIUtil.autoScaleUp(this.device, drawable, rect);
4545
		setClippingInPixels(rect.x, rect.y, rect.width, rect.height);
4545
		setClippingInPixels(rect.x, rect.y, rect.width, rect.height);
4546
	}
4546
	}
4547
}
4547
}
Lines 4744-4750 Link Here
4744
 */
4744
 */
4745
public void setLineAttributes (LineAttributes attributes) {
4745
public void setLineAttributes (LineAttributes attributes) {
4746
	if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
4746
	if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
4747
	attributes.width = DPIUtil.autoScaleUp(drawable, attributes.width);
4747
	attributes.width = DPIUtil.autoScaleUp(this.device, drawable, attributes.width);
4748
	setLineAttributesInPixels(attributes);
4748
	setLineAttributesInPixels(attributes);
4749
}
4749
}
4750
4750
Lines 4997-5003 Link Here
4997
 * </ul>
4997
 * </ul>
4998
 */
4998
 */
4999
public void setLineWidth(int lineWidth) {
4999
public void setLineWidth(int lineWidth) {
5000
	lineWidth = DPIUtil.autoScaleUp (drawable, lineWidth);
5000
	lineWidth = DPIUtil.autoScaleUp (device, drawable, lineWidth);
5001
	setLineWidthInPixels(lineWidth);
5001
	setLineWidthInPixels(lineWidth);
5002
}
5002
}
5003
5003
Lines 5151-5157 Link Here
5151
 */
5151
 */
5152
public Point stringExtent (String string) {
5152
public Point stringExtent (String string) {
5153
	if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
5153
	if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
5154
	return DPIUtil.autoScaleDown(drawable, stringExtentInPixels(string));
5154
	return DPIUtil.autoScaleDown(this.device, drawable, stringExtentInPixels(string));
5155
}
5155
}
5156
5156
5157
Point stringExtentInPixels (String string) {
5157
Point stringExtentInPixels (String string) {
Lines 5198-5204 Link Here
5198
 * </ul>
5198
 * </ul>
5199
 */
5199
 */
5200
public Point textExtent (String string) {
5200
public Point textExtent (String string) {
5201
	return DPIUtil.autoScaleDown(drawable, textExtentInPixels(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB));
5201
	return DPIUtil.autoScaleDown(this.device, drawable, textExtentInPixels(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB));
5202
}
5202
}
5203
5203
5204
/**
5204
/**
Lines 5233-5239 Link Here
5233
 * </ul>
5233
 * </ul>
5234
 */
5234
 */
5235
public Point textExtent (String string, int flags) {
5235
public Point textExtent (String string, int flags) {
5236
	return DPIUtil.autoScaleDown(drawable, textExtentInPixels(string, flags));
5236
	return DPIUtil.autoScaleDown(this.device, drawable, textExtentInPixels(string, flags));
5237
}
5237
}
5238
5238
5239
Point textExtentInPixels(String string, int flags) {
5239
Point textExtentInPixels(String string, int flags) {
(-)a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/TextLayout.java (-1 / +1 lines)
Lines 1999-2005 Link Here
1999
	lptm.tmHeight = DPIUtil.autoScaleUp(getDevice(), ascentInPoints + descentInPoints);
1999
	lptm.tmHeight = DPIUtil.autoScaleUp(getDevice(), ascentInPoints + descentInPoints);
2000
	lptm.tmInternalLeading = DPIUtil.autoScaleUp(getDevice(), leadingInPoints);
2000
	lptm.tmInternalLeading = DPIUtil.autoScaleUp(getDevice(), leadingInPoints);
2001
	lptm.tmAveCharWidth = 0;
2001
	lptm.tmAveCharWidth = 0;
2002
	return FontMetrics.win32_new(lptm);
2002
	return FontMetrics.win32_new(device, lptm);
2003
}
2003
}
2004
2004
2005
/**
2005
/**
(-)a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java (-7 / +7 lines)
Lines 144-150 Link Here
144
public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) {
144
public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) {
145
	super(device);
145
	super(device);
146
	this.device.checkGDIP();
146
	this.device.checkGDIP();
147
	handle = Gdip.Matrix_new(m11, m12, m21, m22, DPIUtil.autoScaleUp(dx), DPIUtil.autoScaleUp(dy));
147
	handle = Gdip.Matrix_new(m11, m12, m21, m22, DPIUtil.autoScaleUp(device, dx), DPIUtil.autoScaleUp(device, dy));
148
	if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
148
	if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
149
	init();
149
	init();
150
}
150
}
Lines 180-187 Link Here
180
	if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
180
	if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
181
	if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
181
	if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
182
	Gdip.Matrix_GetElements(handle, elements);
182
	Gdip.Matrix_GetElements(handle, elements);
183
	elements[4] = DPIUtil.autoScaleDown(elements[4]);
183
	elements[4] = DPIUtil.autoScaleDown(device, elements[4]);
184
	elements[5] = DPIUtil.autoScaleDown(elements[5]);
184
	elements[5] = DPIUtil.autoScaleDown(device, elements[5]);
185
}
185
}
186
186
187
/**
187
/**
Lines 312-318 Link Here
312
 */
312
 */
313
public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
313
public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
314
	if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
314
	if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
315
	Gdip.Matrix_SetElements(handle, m11, m12, m21, m22, DPIUtil.autoScaleUp(dx), DPIUtil.autoScaleUp(dy));
315
	Gdip.Matrix_SetElements(handle, m11, m12, m21, m22, DPIUtil.autoScaleUp(device, dx), DPIUtil.autoScaleUp(device, dy));
316
}
316
}
317
317
318
/**
318
/**
Lines 352-362 Link Here
352
	if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
352
	if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
353
	int length = pointArray.length;
353
	int length = pointArray.length;
354
	for (int i = 0; i < length; i++) {
354
	for (int i = 0; i < length; i++) {
355
		pointArray[i] = DPIUtil.autoScaleUp(pointArray[i]);
355
		pointArray[i] = DPIUtil.autoScaleUp(device, pointArray[i]);
356
	}
356
	}
357
	Gdip.Matrix_TransformPoints(handle, pointArray, length / 2);
357
	Gdip.Matrix_TransformPoints(handle, pointArray, length / 2);
358
	for (int i = 0; i < length; i++) {
358
	for (int i = 0; i < length; i++) {
359
		pointArray[i] = DPIUtil.autoScaleDown(pointArray[i]);
359
		pointArray[i] = DPIUtil.autoScaleDown(device, pointArray[i]);
360
	}
360
	}
361
}
361
}
362
362
Lines 373-379 Link Here
373
 */
373
 */
374
public void translate(float offsetX, float offsetY) {
374
public void translate(float offsetX, float offsetY) {
375
	if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
375
	if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
376
	Gdip.Matrix_Translate(handle, DPIUtil.autoScaleUp(offsetX), DPIUtil.autoScaleUp(offsetY), Gdip.MatrixOrderPrepend);
376
	Gdip.Matrix_Translate(handle, DPIUtil.autoScaleUp(device, offsetX), DPIUtil.autoScaleUp(device, offsetY), Gdip.MatrixOrderPrepend);
377
}
377
}
378
378
379
/**
379
/**

Return to bug 480639