Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/org.eclipse.jface.text.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.jface.text.tests
Bundle-Version: 3.13.1100.qualifier
Bundle-Version: 3.13.1200.qualifier
Bundle-Vendor: %Plugin.providerName
Bundle-Localization: plugin
Export-Package:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.internal.DPIUtil;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
Expand Down Expand Up @@ -564,14 +565,16 @@ private static boolean hasCodeMiningPrintedBelowLine(ITextViewer viewer, int lin
starty= lineBounds.y;
}

Image image= new Image(widget.getDisplay(), (gc, width, height) -> {}, widget.getSize().x, widget.getSize().y);
Image image= new Image(widget.getDisplay(), (gc, width, height) -> {
}, (widget.getSize().x), (widget.getSize().y));
try {
GC gc= new GC(widget);
gc.copyArea(image, 0, 0);
gc.dispose();
ImageData imageData= image.getImageData();
for (int x= startx + 1; x < image.getBounds().width && x < imageData.width; x++) {
for (int y= starty; y < imageData.height - 10 /*do not include the border*/; y++) {
ImageData imageData= image.getImageData(DPIUtil.getDeviceZoom());
double zoomFactor= DPIUtil.getDeviceZoom() / 100.0;
for (int x= (int) (zoomFactor * startx + 1); x < image.getBounds().width && x < imageData.width; x++) {
for (int y= (int) (zoomFactor * starty); y < imageData.height - 10 /*do not include the border*/; y++) {
if (!imageData.palette.getRGB(imageData.getPixel(x, y)).equals(widget.getBackground().getRGB())) {
// code mining printed
return true;
Expand Down Expand Up @@ -604,14 +607,19 @@ private static boolean hasCodeMiningPrintedAfterTextOnLine(ITextViewer viewer, i
} else {
secondLineBounds= widget.getTextBounds(lineOffset, lineOffset + lineLength);
}
Image image = new Image(widget.getDisplay(), (gc, width, height) -> {}, widget.getSize().x, widget.getSize().y);

Image image= new Image(widget.getDisplay(), (gc, width, height) -> {
}, (widget.getSize().x), (widget.getSize().y));
GC gc = new GC(widget);
gc.copyArea(image, 0, 0);
gc.dispose();
ImageData imageData = image.getImageData();
ImageData imageData= image.getImageData(DPIUtil.getDeviceZoom());

secondLineBounds.x += secondLineBounds.width; // look only area after text
for (int x = secondLineBounds.x + 1; x < image.getBounds().width && x < imageData.width; x++) {
for (int y = secondLineBounds.y; y < secondLineBounds.y + secondLineBounds.height && y < imageData.height; y++) {

double zoomFactor= DPIUtil.getDeviceZoom() / 100.0;
for (int x= (int) (zoomFactor * (secondLineBounds.x + 1)); x < image.getBounds().width && x < imageData.width; x++) {
for (int y= (int) (zoomFactor * (secondLineBounds.y)); y < zoomFactor * (secondLineBounds.y + secondLineBounds.height) && y < imageData.height; y++) {
if (!imageData.palette.getRGB(imageData.getPixel(x, y)).equals(widget.getBackground().getRGB())) {
// code mining printed
image.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.internal.DPIUtil;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Shell;

Expand Down Expand Up @@ -134,20 +135,23 @@ protected boolean condition() {
}.waitForCondition(textWidget.getDisplay(), 2000));
DisplayHelper.sleep(textWidget.getDisplay(), 1000);
Rectangle textBounds= textWidget.getTextBounds(0, textWidget.getText().length() - 1);
int supposedMostRightPaintedPixel = textBounds.x + textBounds.width - 1;
double zoomFactor= DPIUtil.getDeviceZoom() / 100.0;
int supposedMostRightPaintedPixel= (int) (zoomFactor * (textBounds.x + textBounds.width - 1));
int mostRightPaintedPixel= getMostRightPaintedPixel(textWidget);
Assertions.assertEquals(supposedMostRightPaintedPixel, mostRightPaintedPixel, 1.5); // use double comparison with delta to tolerate variation from a system to the other
}

public int getMostRightPaintedPixel(StyledText widget) {
Image image = new Image(widget.getDisplay(), (gc, width, height) -> {}, widget.getSize().x, widget.getSize().y);
Image image= new Image(widget.getDisplay(), (gc, width, height) -> {
}, (widget.getSize().x), (widget.getSize().y));
GC gc = new GC(widget);
gc.copyArea(image, 0, 0);
gc.dispose();
RGB backgroundRgb = widget.getBackground().getRGB();
ImageData imageData = image.getImageData();
ImageData imageData= image.getImageData(DPIUtil.getDeviceZoom());
double zoomFactor= DPIUtil.getDeviceZoom() / 100.0;
for (int x = imageData.width - 50 /* magic number to avoid rulers and other */; x >= 0; x--) {
for (int y = 3 /* magic number as well to avoid title bar */; y < imageData.height - 3; y++) {
for (int y= (int) (3 * zoomFactor) /* magic number as well to avoid title bar */; y < imageData.height - (3 * zoomFactor); y++) {
if (!imageData.palette.getRGB(imageData.getPixel(x, y)).equals(backgroundRgb)) {
image.dispose();
return x;
Expand Down
Loading