Skip to content

Commit 6cdb3c5

Browse files
Fix code mining tests on windows if native zoom has value 200
1 parent 71f4d11 commit 6cdb3c5

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,17 @@ private static boolean hasCodeMiningPrintedBelowLine(ITextViewer viewer, int lin
564564
starty= lineBounds.y;
565565
}
566566

567-
Image image= new Image(widget.getDisplay(), (gc, width, height) -> {}, widget.getSize().x, widget.getSize().y);
567+
double zoomFactor= widget.nativeZoom / 100.0;
568+
Image image= new Image(widget.getDisplay(), (gc, width, height) -> {
569+
}, (int) (widget.getSize().x * zoomFactor), (int) (widget.getSize().y * zoomFactor));
568570
try {
569571
GC gc= new GC(widget);
572+
gc.getGCData().nativeZoom= 100;
570573
gc.copyArea(image, 0, 0);
571574
gc.dispose();
572575
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++) {
576+
for (int x= (int) (zoomFactor * startx + 1); x < image.getBounds().width && x < imageData.width; x++) {
577+
for (int y= (int) (zoomFactor * starty); y < imageData.height - 10 /*do not include the border*/; y++) {
575578
if (!imageData.palette.getRGB(imageData.getPixel(x, y)).equals(widget.getBackground().getRGB())) {
576579
// code mining printed
577580
return true;
@@ -604,14 +607,18 @@ private static boolean hasCodeMiningPrintedAfterTextOnLine(ITextViewer viewer, i
604607
} else {
605608
secondLineBounds= widget.getTextBounds(lineOffset, lineOffset + lineLength);
606609
}
607-
Image image = new Image(widget.getDisplay(), (gc, width, height) -> {}, widget.getSize().x, widget.getSize().y);
610+
double zoomFactor= widget.nativeZoom / 100.0;
611+
Image image= new Image(widget.getDisplay(), (gc, width, height) -> {
612+
}, (int) (widget.getSize().x * zoomFactor), (int) (widget.getSize().y * zoomFactor));
608613
GC gc = new GC(widget);
614+
gc.getGCData().nativeZoom= 100;
609615
gc.copyArea(image, 0, 0);
610616
gc.dispose();
611617
ImageData imageData = image.getImageData();
612618
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++) {
619+
620+
for (int x= (int) (zoomFactor * (secondLineBounds.x + 1)); x < image.getBounds().width && x < imageData.width; x++) {
621+
for (int y= (int) (zoomFactor * (secondLineBounds.y)); y < zoomFactor * (secondLineBounds.y + secondLineBounds.height) && y < imageData.height; y++) {
615622
if (!imageData.palette.getRGB(imageData.getPixel(x, y)).equals(widget.getBackground().getRGB())) {
616623
// code mining printed
617624
image.dispose();

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,24 @@ protected boolean condition() {
134134
}.waitForCondition(textWidget.getDisplay(), 2000));
135135
DisplayHelper.sleep(textWidget.getDisplay(), 1000);
136136
Rectangle textBounds= textWidget.getTextBounds(0, textWidget.getText().length() - 1);
137-
int supposedMostRightPaintedPixel = textBounds.x + textBounds.width - 1;
137+
double zoomFactor= textWidget.nativeZoom / 100.0;
138+
int supposedMostRightPaintedPixel= (int) (zoomFactor * (textBounds.x + textBounds.width - 1));
138139
int mostRightPaintedPixel= getMostRightPaintedPixel(textWidget);
139140
Assertions.assertEquals(supposedMostRightPaintedPixel, mostRightPaintedPixel, 1.5); // use double comparison with delta to tolerate variation from a system to the other
140141
}
141142

142143
public int getMostRightPaintedPixel(StyledText widget) {
143-
Image image = new Image(widget.getDisplay(), (gc, width, height) -> {}, widget.getSize().x, widget.getSize().y);
144+
double zoomFactor= widget.nativeZoom / 100.0;
145+
Image image= new Image(widget.getDisplay(), (gc, width, height) -> {
146+
}, (int) (zoomFactor * widget.getSize().x), (int) (zoomFactor * widget.getSize().y));
144147
GC gc = new GC(widget);
148+
gc.getGCData().nativeZoom= 100;
145149
gc.copyArea(image, 0, 0);
146150
gc.dispose();
147151
RGB backgroundRgb = widget.getBackground().getRGB();
148152
ImageData imageData = image.getImageData();
149153
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++) {
154+
for (int y= (int) (3 * zoomFactor) /* magic number as well to avoid title bar */; y < imageData.height - (3 * zoomFactor); y++) {
151155
if (!imageData.palette.getRGB(imageData.getPixel(x, y)).equals(backgroundRgb)) {
152156
image.dispose();
153157
return x;

0 commit comments

Comments
 (0)