diff options
author | Thomas Wolf | 2019-09-20 16:11:44 +0000 |
---|---|---|
committer | Thomas Wolf | 2019-09-20 16:11:44 +0000 |
commit | d9ffc72f9cff1ea0ae332ba82e4d59f1ef847624 (patch) | |
tree | a021ed8d507d242965533d34839e1f2f2812b9ee | |
parent | 345f92a3fa9e03c3966d0700552c271ab3b205ae (diff) | |
download | eclipse.platform.text-d9ffc72f9cff1ea0ae332ba82e4d59f1ef847624.tar.gz eclipse.platform.text-d9ffc72f9cff1ea0ae332ba82e4d59f1ef847624.tar.xz eclipse.platform.text-d9ffc72f9cff1ea0ae332ba82e4d59f1ef847624.zip |
Bug 551320 - LineNumberRulerColumn: fix overdrawn line numbersI20190923-1800I20190923-0615I20190922-1800I20190921-1800I20190920-1800
Some subclasses may paint outside the line range given, for instance
the LineNumberChangeRulerColumn. When painting directly into the buffer
this may lead to missing line numbers.
Always use an extra Image to paint if we're not painting the whole line
range, and copy the wanted bits. Draw directly into the buffer only if
we're re-drawing everything anyway.
Change-Id: I287711173441a12d7c393d90b20d0854e1ed5f56
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r-- | org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java index a35bcd88a8e..808fdbcfe17 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java @@ -719,10 +719,7 @@ public class LineNumberRulerColumn implements IVerticalRulerColumn { fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); } GC bufferGC= new GC(fBuffer); - if (fForeground != null) { - bufferGC.setForeground(fForeground); - } - bufferGC.setBackground(getBackground(fCanvas.getDisplay())); + Image newBuffer= null; try { int topPixel= fCachedTextWidget.getTopPixel(); int bufferY= 0; @@ -766,7 +763,7 @@ public class LineNumberRulerColumn implements IVerticalRulerColumn { * For higher zoom levels (200%), we manually scale the font and drawing coordinates, * and then use getImageData(100) to extract the high-resolution image data. */ ILineRange lines= visibleLines; - Image zoomedBuffer= new Image(fCanvas.getDisplay(), (ImageDataProvider) zoom -> { + newBuffer= new Image(fCanvas.getDisplay(), (ImageDataProvider) zoom -> { fZoom= zoom; internalSetZoom(zoom); int width= size.x * zoom / 100; @@ -786,14 +783,8 @@ public class LineNumberRulerColumn implements IVerticalRulerColumn { fLastZoomedFont= font; } } - gc.setFont(font); - if (fForeground != null) { - gc.setForeground(fForeground); - } try { - gc.setBackground(getBackground(fCanvas.getDisplay())); - gc.fillRectangle(0, 0, width, height); - + initializeGC(gc, font, 0, 0, width, height); doPaint(gc, lines); } finally { gc.dispose(); @@ -804,24 +795,42 @@ public class LineNumberRulerColumn implements IVerticalRulerColumn { gcImage.dispose(); return imageData; }); + bufferGC.drawImage(newBuffer, 0, bufferY, size.x, bufferH, 0, bufferY, size.x, bufferH); + } else if (dy != 0) { + // Some rulers may paint outside the line region. Let them paint in a new image, + // the copy the wanted bits. + newBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); + GC localGC= new GC(newBuffer); try { - bufferGC.drawImage(zoomedBuffer, 0, bufferY, size.x, bufferH, 0, bufferY, size.x, bufferH); + initializeGC(localGC, fCanvas.getFont(), 0, bufferY, size.x, bufferH); + doPaint(localGC, visibleLines); } finally { - zoomedBuffer.dispose(); + localGC.dispose(); } + bufferGC.drawImage(newBuffer, 0, bufferY, size.x, bufferH, 0, bufferY, size.x, bufferH); } else { - // Draw directly into the buffer - bufferGC.setFont(fCanvas.getFont()); - bufferGC.fillRectangle(0, bufferY, size.x, bufferH); - + // We redraw everything; paint directly into the buffer + initializeGC(bufferGC, fCanvas.getFont(), 0, 0, size.x, size.y); doPaint(bufferGC, visibleLines); } } finally { bufferGC.dispose(); + if (newBuffer != null) { + newBuffer.dispose(); + } } dest.drawImage(fBuffer, 0, 0); } + private void initializeGC(GC gc, Font font, int x, int y, int width, int height) { + gc.setFont(font); + if (fForeground != null) { + gc.setForeground(fForeground); + } + gc.setBackground(getBackground(fCanvas.getDisplay())); + gc.fillRectangle(x, y, width, height); + } + /** * This method is not API and it is expected to disappear in Eclipse 4.8. * Subclasses that want to take advantage of the unsupported workaround for bug 516258 |