Skip to content

Commit 9700bd3

Browse files
tobias-melchertobiasmelcher
authored andcommitted
Fix code mining tests on windows if native zoom has value not equal 100
1 parent d1713be commit 9700bd3

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.eclipse.swt.graphics.ImageData;
4141
import org.eclipse.swt.graphics.Point;
4242
import org.eclipse.swt.graphics.Rectangle;
43+
import org.eclipse.swt.internal.DPIUtil;
4344
import org.eclipse.swt.layout.FillLayout;
4445
import org.eclipse.swt.widgets.Display;
4546
import org.eclipse.swt.widgets.Shell;
@@ -564,14 +565,17 @@ private static boolean hasCodeMiningPrintedBelowLine(ITextViewer viewer, int lin
564565
starty= lineBounds.y;
565566
}
566567

567-
Image image= new Image(widget.getDisplay(), (gc, width, height) -> {}, widget.getSize().x, widget.getSize().y);
568+
Image image= new Image(widget.getDisplay(), (gc, width, height) -> {
569+
}, (widget.getSize().x), (widget.getSize().y));
568570
try {
569571
GC gc= new GC(widget);
570572
gc.copyArea(image, 0, 0);
571573
gc.dispose();
572-
ImageData imageData= image.getImageData();
573-
for (int x= startx + 1; x < image.getBounds().width && x < imageData.width; x++) {
574-
for (int y= starty; y < imageData.height - 10 /*do not include the border*/; y++) {
574+
int zoom= DPIUtil.getDeviceZoom();
575+
ImageData imageData= image.getImageData(zoom);
576+
double zoomFactor= zoom / 100.0;
577+
for (int x= (int) (zoomFactor * startx + 1); x < image.getBounds().width && x < imageData.width; x++) {
578+
for (int y= (int) (zoomFactor * starty); y < imageData.height - 10 /*do not include the border*/; y++) {
575579
if (!imageData.palette.getRGB(imageData.getPixel(x, y)).equals(widget.getBackground().getRGB())) {
576580
// code mining printed
577581
return true;
@@ -604,14 +608,20 @@ private static boolean hasCodeMiningPrintedAfterTextOnLine(ITextViewer viewer, i
604608
} else {
605609
secondLineBounds= widget.getTextBounds(lineOffset, lineOffset + lineLength);
606610
}
607-
Image image = new Image(widget.getDisplay(), (gc, width, height) -> {}, widget.getSize().x, widget.getSize().y);
611+
612+
Image image= new Image(widget.getDisplay(), (gc, width, height) -> {
613+
}, (widget.getSize().x), (widget.getSize().y));
608614
GC gc = new GC(widget);
609615
gc.copyArea(image, 0, 0);
610616
gc.dispose();
611-
ImageData imageData = image.getImageData();
617+
int zoom= DPIUtil.getDeviceZoom();
618+
ImageData imageData= image.getImageData(zoom);
619+
612620
secondLineBounds.x += secondLineBounds.width; // look only area after text
613-
for (int x = secondLineBounds.x + 1; x < image.getBounds().width && x < imageData.width; x++) {
614-
for (int y = secondLineBounds.y; y < secondLineBounds.y + secondLineBounds.height && y < imageData.height; y++) {
621+
622+
double zoomFactor= zoom / 100.0;
623+
for (int x= (int) (zoomFactor * (secondLineBounds.x + 1)); x < image.getBounds().width && x < imageData.width; x++) {
624+
for (int y= (int) (zoomFactor * (secondLineBounds.y)); y < zoomFactor * (secondLineBounds.y + secondLineBounds.height) && y < imageData.height; y++) {
615625
if (!imageData.palette.getRGB(imageData.getPixel(x, y)).equals(widget.getBackground().getRGB())) {
616626
// code mining printed
617627
image.dispose();

tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/source/inlined/LineContentBoundsDrawingTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.eclipse.swt.graphics.ImageData;
2626
import org.eclipse.swt.graphics.RGB;
2727
import org.eclipse.swt.graphics.Rectangle;
28+
import org.eclipse.swt.internal.DPIUtil;
2829
import org.eclipse.swt.layout.FillLayout;
2930
import org.eclipse.swt.widgets.Shell;
3031

@@ -134,20 +135,25 @@ protected boolean condition() {
134135
}.waitForCondition(textWidget.getDisplay(), 2000));
135136
DisplayHelper.sleep(textWidget.getDisplay(), 1000);
136137
Rectangle textBounds= textWidget.getTextBounds(0, textWidget.getText().length() - 1);
137-
int supposedMostRightPaintedPixel = textBounds.x + textBounds.width - 1;
138+
int zoom= DPIUtil.getDeviceZoom();
139+
double zoomFactor= zoom / 100.0;
140+
int supposedMostRightPaintedPixel= (int) (zoomFactor * (textBounds.x + textBounds.width - 1));
138141
int mostRightPaintedPixel= getMostRightPaintedPixel(textWidget);
139142
Assertions.assertEquals(supposedMostRightPaintedPixel, mostRightPaintedPixel, 1.5); // use double comparison with delta to tolerate variation from a system to the other
140143
}
141144

142145
public int getMostRightPaintedPixel(StyledText widget) {
143-
Image image = new Image(widget.getDisplay(), (gc, width, height) -> {}, widget.getSize().x, widget.getSize().y);
146+
Image image= new Image(widget.getDisplay(), (gc, width, height) -> {
147+
}, (widget.getSize().x), (widget.getSize().y));
144148
GC gc = new GC(widget);
145149
gc.copyArea(image, 0, 0);
146150
gc.dispose();
147151
RGB backgroundRgb = widget.getBackground().getRGB();
148-
ImageData imageData = image.getImageData();
152+
int zoom= DPIUtil.getDeviceZoom();
153+
ImageData imageData= image.getImageData(zoom);
154+
double zoomFactor= zoom / 100.0;
149155
for (int x = imageData.width - 50 /* magic number to avoid rulers and other */; x >= 0; x--) {
150-
for (int y = 3 /* magic number as well to avoid title bar */; y < imageData.height - 3; y++) {
156+
for (int y= (int) (3 * zoomFactor) /* magic number as well to avoid title bar */; y < imageData.height - (3 * zoomFactor); y++) {
151157
if (!imageData.palette.getRGB(imageData.getPixel(x, y)).equals(backgroundRgb)) {
152158
image.dispose();
153159
return x;

0 commit comments

Comments
 (0)