Skip to content

Commit b0dad17

Browse files
authored
Merge branch 'eclipse-platform:master' into master
2 parents 91b4743 + 0d3622a commit b0dad17

File tree

13 files changed

+161
-117
lines changed

13 files changed

+161
-117
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,11 +1822,28 @@ public String toString () {
18221822
* @noreference This method is not intended to be referenced by clients.
18231823
*/
18241824
public static void drawScaled(GC gc, Image original, int width, int height, float scaleFactor) {
1825-
gc.drawImage (original, 0, 0, DPIUtil.autoScaleDown (width), DPIUtil.autoScaleDown (height),
1825+
gc.drawImage (original, 0, 0, CocoaDPIUtil.autoScaleDown (width), CocoaDPIUtil.autoScaleDown (height),
18261826
/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
18271827
* Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
18281828
*/
1829-
0, 0, Math.round (DPIUtil.autoScaleDown (width * scaleFactor)), Math.round (DPIUtil.autoScaleDown (height * scaleFactor)));
1829+
0, 0, Math.round (CocoaDPIUtil.autoScaleDown (width * scaleFactor)), Math.round (CocoaDPIUtil.autoScaleDown (height * scaleFactor)));
1830+
}
1831+
1832+
private final class CocoaDPIUtil {
1833+
1834+
/**
1835+
* Auto-scale down int dimensions.
1836+
*/
1837+
public static int autoScaleDown(int size) {
1838+
return DPIUtil.scaleDown(size, DPIUtil.getDeviceZoom());
1839+
}
1840+
1841+
/**
1842+
* Auto-scale down float dimensions.
1843+
*/
1844+
public static float autoScaleDown(float size) {
1845+
return DPIUtil.scaleDown(size, DPIUtil.getDeviceZoom());
1846+
}
18301847
}
18311848

18321849
}

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public static ImageData scaleImageData (Device device, final ElementAtZoom<Image
284284
return scaleImageData(device, elementAtZoom.element(), targetZoom, elementAtZoom.zoom());
285285
}
286286

287-
private static ImageData autoScaleImageData (Device device, final ImageData imageData, float scaleFactor) {
287+
public static ImageData autoScaleImageData (Device device, final ImageData imageData, float scaleFactor) {
288288
// Guards are already implemented in callers: if (deviceZoom == 100 || imageData == null || scaleFactor == 1.0f) return imageData;
289289
int width = imageData.width;
290290
int height = imageData.height;

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java

Lines changed: 42 additions & 42 deletions
Large diffs are not rendered by default.

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public final class Image extends Resource implements Drawable {
214214
*/
215215
public Image(Device device, int width, int height) {
216216
super(device);
217-
Point size = DPIUtil.autoScaleUp(new Point(width, height));
217+
Point size = new Point(width, height);
218218
currentDeviceZoom = DPIUtil.getDeviceZoom();
219219
init(size.x, size.y);
220220
init();
@@ -411,8 +411,7 @@ public Image(Device device, Rectangle bounds) {
411411
super(device);
412412
if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
413413
currentDeviceZoom = DPIUtil.getDeviceZoom();
414-
Rectangle bounds1 = DPIUtil.autoScaleUp (bounds);
415-
init(bounds1.width, bounds1.height);
414+
init(bounds.width, bounds.height);
416415
init();
417416
}
418417

@@ -440,7 +439,7 @@ public Image(Device device, Rectangle bounds) {
440439
* @see #dispose()
441440
*/
442441
public Image(Device device, ImageData data) {
443-
this(device, DPIUtil.autoScaleUp(device, data), DPIUtil.getDeviceZoom());
442+
this(device, GtkDPIUtil.autoScaleUp(device, data), DPIUtil.getDeviceZoom());
444443
}
445444

446445
private Image(Device device, ImageData data, int zoom) {
@@ -489,8 +488,8 @@ public Image(Device device, ImageData source, ImageData mask) {
489488
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
490489
}
491490
currentDeviceZoom = DPIUtil.getDeviceZoom();
492-
source = DPIUtil.autoScaleUp (device, source);
493-
mask = DPIUtil.autoScaleUp (device, mask);
491+
source = GtkDPIUtil.autoScaleUp (device, source);
492+
mask = GtkDPIUtil.autoScaleUp (device, mask);
494493
mask = ImageData.convertMask (mask);
495494
ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
496495
image.maskPad = mask.scanlinePad;
@@ -997,7 +996,7 @@ public Color getBackground() {
997996
*/
998997
public Rectangle getBounds() {
999998
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
1000-
return DPIUtil.autoScaleDown(getBoundsInPixels());
999+
return getBoundsInPixels();
10011000
}
10021001

10031002
/**
@@ -1586,11 +1585,24 @@ public String toString () {
15861585
* @noreference This method is not intended to be referenced by clients.
15871586
*/
15881587
public static void drawScaled(GC gc, Image original, int width, int height, float scaleFactor) {
1589-
gc.drawImage (original, 0, 0, DPIUtil.autoScaleDown (width), DPIUtil.autoScaleDown (height),
1588+
gc.drawImage (original, 0, 0, width, height,
15901589
/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
15911590
* Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
15921591
*/
1593-
0, 0, Math.round (DPIUtil.autoScaleDown (width * scaleFactor)), Math.round (DPIUtil.autoScaleDown (height * scaleFactor)));
1592+
0, 0, Math.round (width * scaleFactor), Math.round (height * scaleFactor));
1593+
}
1594+
1595+
private final class GtkDPIUtil {
1596+
1597+
/**
1598+
* Auto-scale up ImageData to device zoom that is at 100%.
1599+
*/
1600+
public static ImageData autoScaleUp (Device device, final ImageData imageData) {
1601+
int imageDataZoomFactor = 100;
1602+
if (DPIUtil.getDeviceZoom() == imageDataZoomFactor || imageData == null || (device != null && !device.isAutoScalable())) return imageData;
1603+
float scaleFactor = (float) DPIUtil.getDeviceZoom() / imageDataZoomFactor;
1604+
return DPIUtil.autoScaleImageData(device, imageData, scaleFactor);
1605+
}
15941606
}
15951607

15961608
}

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ public FontMetrics getFixedLineMetrics(Device device) {
107107
}
108108

109109
FontMetrics result = new FontMetrics();
110-
result.ascentInPoints = DPIUtil.autoScaleDown(device, lineMetricsInPixels.ascentInPoints);
111-
result.descentInPoints = DPIUtil.autoScaleDown(device, lineMetricsInPixels.descentInPoints);
112-
result.averageCharWidthInPoints = DPIUtil.autoScaleDown(device, lineMetricsInPixels.averageCharWidthInPoints);
110+
result.ascentInPoints = lineMetricsInPixels.ascentInPoints;
111+
result.descentInPoints = lineMetricsInPixels.descentInPoints;
112+
result.averageCharWidthInPoints =lineMetricsInPixels.averageCharWidthInPoints;
113113

114114
return result;
115115
}
@@ -121,9 +121,9 @@ public void setFixedLineMetrics(Device device, FontMetrics metrics) {
121121
}
122122

123123
FontMetrics result = new FontMetrics();
124-
result.ascentInPoints = DPIUtil.autoScaleUp(device, metrics.ascentInPoints);
125-
result.descentInPoints = DPIUtil.autoScaleUp(device, metrics.descentInPoints);
126-
result.averageCharWidthInPoints = DPIUtil.autoScaleUp(device, metrics.averageCharWidthInPoints);
124+
result.ascentInPoints = metrics.ascentInPoints;
125+
result.descentInPoints = metrics.descentInPoints;
126+
result.averageCharWidthInPoints = metrics.averageCharWidthInPoints;
127127

128128
lineMetricsInPixels = result;
129129
}
@@ -296,8 +296,8 @@ void computeRuns () {
296296
boolean useMinAscentDescent = !metricsAdapter.isFixedMetrics() && (ascentInPoints != -1 || descentInPoints != -1);
297297
if (useMinAscentDescent && segementsLength > 0) {
298298
PangoRectangle rect = new PangoRectangle();
299-
if (ascentInPoints != -1) rect.y = -(DPIUtil.autoScaleUp(getDevice(), ascentInPoints) * OS.PANGO_SCALE);
300-
rect.height = DPIUtil.autoScaleUp(getDevice(), (Math.max(0, ascentInPoints) + Math.max(0, descentInPoints))) * OS.PANGO_SCALE;
299+
if (ascentInPoints != -1) rect.y = -(ascentInPoints * OS.PANGO_SCALE);
300+
rect.height = (Math.max(0, ascentInPoints) + Math.max(0, descentInPoints)) * OS.PANGO_SCALE;
301301
int lineCount = OS.pango_layout_get_line_count(layout);
302302
chars = new char[segementsLength + lineCount * 2];
303303
lineOffsets = new int [lineCount];
@@ -481,9 +481,9 @@ void computeRuns () {
481481
GlyphMetrics metrics = style.metrics;
482482
if (metrics != null) {
483483
PangoRectangle rect = new PangoRectangle();
484-
rect.y = -(DPIUtil.autoScaleUp(getDevice(), metrics.ascent) * OS.PANGO_SCALE);
485-
rect.height = DPIUtil.autoScaleUp(getDevice(), (metrics.ascent + metrics.descent)) * OS.PANGO_SCALE;
486-
rect.width = DPIUtil.autoScaleUp(getDevice(), metrics.width) * OS.PANGO_SCALE;
484+
rect.y = -(metrics.ascent * OS.PANGO_SCALE);
485+
rect.height = (metrics.ascent + metrics.descent) * OS.PANGO_SCALE;
486+
rect.width = metrics.width * OS.PANGO_SCALE;
487487
long attr = OS.pango_attr_shape_new (rect, rect);
488488
OS.memmove (attribute, attr, PangoAttribute.sizeof);
489489
attribute.start_index = byteStart;
@@ -494,7 +494,7 @@ void computeRuns () {
494494
}
495495
int rise = style.rise;
496496
if (rise != 0) {
497-
long attr = OS.pango_attr_rise_new (DPIUtil.autoScaleUp(getDevice(), rise) * OS.PANGO_SCALE);
497+
long attr = OS.pango_attr_rise_new (rise * OS.PANGO_SCALE);
498498
OS.memmove (attribute, attr, PangoAttribute.sizeof);
499499
attribute.start_index = byteStart;
500500
attribute.end_index = byteEnd;
@@ -559,8 +559,6 @@ void destroy() {
559559
* </ul>
560560
*/
561561
public void draw(GC gc, int x, int y) {
562-
x = DPIUtil.autoScaleUp(getDevice(), x);
563-
y = DPIUtil.autoScaleUp(getDevice(), y);
564562
drawInPixels(gc, x, y);
565563
}
566564

@@ -589,8 +587,6 @@ void drawInPixels(GC gc, int x, int y) {
589587
*/
590588
public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) {
591589
checkLayout ();
592-
x = DPIUtil.autoScaleUp(getDevice(), x);
593-
y = DPIUtil.autoScaleUp(getDevice(), y);
594590
drawInPixels(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground);
595591
}
596592
void drawInPixels(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) {
@@ -626,8 +622,6 @@ void drawInPixels(GC gc, int x, int y, int selectionStart, int selectionEnd, Col
626622
*/
627623
public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) {
628624
checkLayout ();
629-
x = DPIUtil.autoScaleUp(getDevice(), x);
630-
y = DPIUtil.autoScaleUp(getDevice(), y);
631625
drawInPixels(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, flags);
632626
}
633627
void drawInPixels(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) {
@@ -685,7 +679,7 @@ void drawInPixels(GC gc, int x, int y, int selectionStart, int selectionEnd, Col
685679
int lineY = y + OS.PANGO_PIXELS(rect.y);
686680
int height = OS.PANGO_PIXELS(rect.height);
687681
if (ascentInPoints != -1 && descentInPoints != -1) {
688-
height = Math.max (height, DPIUtil.autoScaleUp(getDevice(), ascentInPoints + descentInPoints));
682+
height = Math.max (height, ascentInPoints + descentInPoints);
689683
}
690684
height += getSpacingInPixels();
691685
int width = (flags & SWT.FULL_SELECTION) != 0 ? 0x7fff : height / 3;
@@ -918,7 +912,7 @@ public int getAscent () {
918912
*/
919913
public Rectangle getBounds() {
920914
int spacingInPixels = getSpacingInPixels();
921-
return DPIUtil.autoScaleDown(getDevice(), getBoundsInPixels(spacingInPixels));
915+
return getBoundsInPixels(spacingInPixels);
922916
}
923917

924918
Rectangle getBoundsInPixels(int spacingInPixels) {
@@ -931,7 +925,7 @@ Rectangle getBoundsInPixels(int spacingInPixels) {
931925
int width = OS.PANGO_PIXELS(w[0]);
932926
int height = OS.PANGO_PIXELS(h[0]);
933927
if (ascentInPoints != -1 && descentInPoints != -1) {
934-
height = Math.max (height, DPIUtil.autoScaleUp(getDevice(), ascentInPoints + descentInPoints));
928+
height = Math.max (height, ascentInPoints + descentInPoints);
935929
}
936930
height += spacingInPixels;
937931
return new Rectangle(0, 0, width, height + getScaledVerticalIndent());
@@ -953,7 +947,7 @@ Rectangle getBoundsInPixels(int spacingInPixels) {
953947
*/
954948
public Rectangle getBounds(int start, int end) {
955949
checkLayout();
956-
return DPIUtil.autoScaleDown(getDevice(), getBoundsInPixels(start, end));
950+
return getBoundsInPixels(start, end);
957951
}
958952

959953
Rectangle getBoundsInPixels(int start, int end) {
@@ -1059,7 +1053,7 @@ public Font getFont () {
10591053
*/
10601054
public int getIndent () {
10611055
checkLayout();
1062-
return DPIUtil.autoScaleDown(getDevice(), getIndentInPixels());
1056+
return getIndentInPixels();
10631057
}
10641058

10651059
int getIndentInPixels () {
@@ -1141,7 +1135,7 @@ public int getLevel(int offset) {
11411135
*/
11421136
public Rectangle getLineBounds(int lineIndex) {
11431137
checkLayout();
1144-
return DPIUtil.autoScaleDown(getDevice(), getLineBoundsInPixels(lineIndex));
1138+
return getLineBoundsInPixels(lineIndex);
11451139
}
11461140

11471141
Rectangle getLineBoundsInPixels(int lineIndex) {
@@ -1166,7 +1160,7 @@ private Rectangle getLineBoundsInPixels(int lineIndex, long iter) {
11661160
int width = OS.PANGO_PIXELS(rect.width);
11671161
int height = OS.PANGO_PIXELS(rect.height);
11681162
if (ascentInPoints != -1 && descentInPoints != -1) {
1169-
height = Math.max (height, DPIUtil.autoScaleUp(getDevice(), ascentInPoints + descentInPoints));
1163+
height = Math.max (height, ascentInPoints + descentInPoints);
11701164
}
11711165
x += Math.min (indent, wrapIndent);
11721166
return new Rectangle(x, y, width, height);
@@ -1255,14 +1249,14 @@ public FontMetrics getLineMetrics (int lineIndex) {
12551249
long metrics = OS.pango_context_get_metrics(context, font, lang);
12561250
int ascent = OS.pango_font_metrics_get_ascent(metrics);
12571251
int descent = OS.pango_font_metrics_get_descent(metrics);
1258-
ascentInPoints = DPIUtil.autoScaleDown(getDevice(), OS.PANGO_PIXELS(ascent));
1259-
heightInPoints = DPIUtil.autoScaleDown(getDevice(), OS.PANGO_PIXELS(ascent + descent));
1252+
ascentInPoints = OS.PANGO_PIXELS(ascent);
1253+
heightInPoints = OS.PANGO_PIXELS(ascent + descent);
12601254
OS.pango_font_metrics_unref(metrics);
12611255
} else {
12621256
PangoRectangle rect = new PangoRectangle();
12631257
metricsAdapter.pango_layout_line_get_extents(OS.pango_layout_get_line(layout, lineIndex), null, rect);
1264-
ascentInPoints = DPIUtil.autoScaleDown(getDevice(), OS.PANGO_PIXELS(-rect.y));
1265-
heightInPoints = DPIUtil.autoScaleDown(getDevice(), OS.PANGO_PIXELS(rect.height));
1258+
ascentInPoints = OS.PANGO_PIXELS(-rect.y);
1259+
heightInPoints = OS.PANGO_PIXELS(rect.height);
12661260
}
12671261
heightInPoints = Math.max(this.ascentInPoints + this.descentInPoints, heightInPoints);
12681262
ascentInPoints = Math.max(this.ascentInPoints, ascentInPoints);
@@ -1320,7 +1314,7 @@ public int[] getLineOffsets() {
13201314
*/
13211315
public Point getLocation(int offset, boolean trailing) {
13221316
checkLayout();
1323-
return DPIUtil.autoScaleDown(getDevice(), getLocationInPixels(offset, trailing));
1317+
return getLocationInPixels(offset, trailing);
13241318
}
13251319

13261320
Point getLocationInPixels(int offset, boolean trailing) {
@@ -1459,7 +1453,7 @@ int _getOffset (int offset, int movement, boolean forward) {
14591453
*/
14601454
public int getOffset(Point point, int[] trailing) {
14611455
checkLayout();
1462-
return getOffsetInPixels(DPIUtil.autoScaleUp(getDevice(), point), trailing);
1456+
return getOffsetInPixels(point, trailing);
14631457
}
14641458

14651459
int getOffsetInPixels(Point point, int[] trailing) {
@@ -1685,7 +1679,7 @@ String getSegmentsText() {
16851679
*/
16861680
public int getSpacing () {
16871681
checkLayout();
1688-
return DPIUtil.autoScaleDown(getDevice(), getSpacingInPixels());
1682+
return getSpacingInPixels();
16891683
}
16901684

16911685
int getSpacingInPixels () {
@@ -1717,7 +1711,7 @@ private int getScaledVerticalIndent() {
17171711
if (verticalIndentInPoints == 0) {
17181712
return verticalIndentInPoints;
17191713
}
1720-
return DPIUtil.autoScaleUp(getDevice(), verticalIndentInPoints);
1714+
return verticalIndentInPoints;
17211715
}
17221716

17231717
/**
@@ -1787,7 +1781,7 @@ public TextStyle[] getStyles () {
17871781
*/
17881782
public int[] getTabs() {
17891783
checkLayout();
1790-
return DPIUtil.autoScaleDown (getDevice(), getTabsInPixels ());
1784+
return getTabsInPixels ();
17911785
}
17921786

17931787
int[] getTabsInPixels () {
@@ -1834,7 +1828,7 @@ public int getTextDirection () {
18341828
*/
18351829
public int getWidth () {
18361830
checkLayout ();
1837-
return DPIUtil.autoScaleDown(getDevice(), getWidthInPixels());
1831+
return getWidthInPixels();
18381832
}
18391833

18401834
int getWidthInPixels () {
@@ -1854,7 +1848,7 @@ int getWidthInPixels () {
18541848
*/
18551849
public int getWrapIndent () {
18561850
checkLayout ();
1857-
return DPIUtil.autoScaleDown(getDevice(), getWrapIndentInPixels());
1851+
return getWrapIndentInPixels();
18581852
}
18591853
int getWrapIndentInPixels () {
18601854
return wrapIndent;
@@ -2042,7 +2036,7 @@ public void setFont (Font font) {
20422036
*/
20432037
public void setIndent (int indent) {
20442038
checkLayout ();
2045-
setIndentInPixels(DPIUtil.autoScaleUp(getDevice(), indent));
2039+
setIndentInPixels(indent);
20462040
}
20472041

20482042
void setIndentInPixels (int indent) {
@@ -2115,7 +2109,7 @@ public void setOrientation(int orientation) {
21152109
public void setSpacing (int spacing) {
21162110
checkLayout();
21172111
if (spacing < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
2118-
setSpacingInPixels(DPIUtil.autoScaleUp(getDevice(), spacing));
2112+
setSpacingInPixels(spacing);
21192113
}
21202114

21212115
void setSpacingInPixels (int spacing) {
@@ -2338,7 +2332,7 @@ public void setStyle (TextStyle style, int start, int end) {
23382332
public void setTabs(int[] tabs) {
23392333
checkLayout();
23402334
if (this.tabs == null && tabs == null) return;
2341-
setTabsInPixels (DPIUtil.autoScaleUp (getDevice(), tabs));
2335+
setTabsInPixels (tabs);
23422336
}
23432337

23442338
void setTabsInPixels (int[] tabs) {
@@ -2434,7 +2428,7 @@ public void setTextDirection (int textDirection) {
24342428
public void setWidth (int width) {
24352429
checkLayout ();
24362430
if (width < -1 || width == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
2437-
setWidthInPixels(DPIUtil.autoScaleUp(getDevice(), width));
2431+
setWidthInPixels(width);
24382432
}
24392433

24402434
void setWidthInPixels (int width) {
@@ -2472,7 +2466,7 @@ void setWidth () {
24722466
public void setWrapIndent (int wrapIndent) {
24732467
checkLayout();
24742468
if (wrapIndent < 0) return;
2475-
setWrapIndentInPixels(DPIUtil.autoScaleUp(getDevice(), wrapIndent));
2469+
setWrapIndentInPixels(wrapIndent);
24762470
}
24772471

24782472
void setWrapIndentInPixels (int wrapIndent) {

0 commit comments

Comments
 (0)