From 4f91e7a65f7bbbc0328e2e5e5c39492ccab869f0 Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Tue, 12 Dec 2017 16:08:51 +0300 Subject: [PATCH] IDEA-183638 [fps] moving caret up/down leaves artifacts in the editor --- .../editor/impl/EditorComponentImpl.java | 2 +- .../util/src/com/intellij/util/ui/JBUI.java | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java index a66ddb66b872..1e4068ac0912 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorComponentImpl.java @@ -230,7 +230,7 @@ public class EditorComponentImpl extends JTextComponent implements Scrollable, D UISettings.setupAntialiasing(gg); } gg.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, myEditor.myFractionalMetricsHintValue); - AffineTransform origTx = JBUI.alignToIntGrid(gg); + AffineTransform origTx = JBUI.alignToIntGrid(gg, true, false); myEditor.paint(gg); if (origTx != null) gg.setTransform(origTx); } diff --git a/platform/util/src/com/intellij/util/ui/JBUI.java b/platform/util/src/com/intellij/util/ui/JBUI.java index 032bfd6a4a74..25f840cefa9b 100644 --- a/platform/util/src/com/intellij/util/ui/JBUI.java +++ b/platform/util/src/com/intellij/util/ui/JBUI.java @@ -556,21 +556,24 @@ public class JBUI { } /** - * If the graphics has floating point scale transform, aligns the graphics to the integer coordinate grid, + * Aligns the x or/and y translate of the graphics to the integer coordinate grid if the graphics has fractional scale transform, * otherwise does nothing. This is used to avoid the rounding problem, see JRE-502. * * @param g the graphics to align + * @param alignX should the x-translate be aligned + * @param alignY should the y-translate be aligned * @return the original graphics transform when aligned, otherwise null */ - public static AffineTransform alignToIntGrid(@NotNull Graphics2D g) { + public static AffineTransform alignToIntGrid(@NotNull Graphics2D g, boolean alignX, boolean alignY) { try { AffineTransform tx = g.getTransform(); - double scaleX = tx.getScaleX(); - double scaleY = tx.getScaleY(); - boolean fpsTx = scaleX != (int)scaleX || scaleY != (int)scaleY; - if (fpsTx) { + if (isFractionalScale(tx)) { + double scaleX = tx.getScaleX(); + double scaleY = tx.getScaleY(); AffineTransform alignedTx = new AffineTransform(); - alignedTx.translate((int)Math.ceil(tx.getTranslateX() - 0.5), (int)Math.ceil(tx.getTranslateY() - 0.5)); + double trX = alignX ? (int)Math.ceil(tx.getTranslateX() - 0.5) : tx.getTranslateX(); + double trY = alignY ? (int)Math.ceil(tx.getTranslateY() - 0.5) : tx.getTranslateY(); + alignedTx.translate(trX, trY); alignedTx.scale(scaleX, scaleY); assert tx.getShearX() == 0 && tx.getShearY() == 0; // the shear is ignored g.setTransform(alignedTx); @@ -583,6 +586,15 @@ public class JBUI { return null; } + /** + * Returns true if the transform matrix contains fractional scale element. + */ + public static boolean isFractionalScale(AffineTransform tx) { + double scaleX = tx.getScaleX(); + double scaleY = tx.getScaleY(); + return scaleX != (int)scaleX || scaleY != (int)scaleY; + } + public static class Fonts { @NotNull public static JBFont label() {