From d92bf596035be1647bdd06d7fa496eac7eb4028c Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Thu, 27 Jan 2022 22:04:41 -0500 Subject: [PATCH] possible fix for #194 on macOS, need to check Windows --- app/src/processing/app/syntax/JEditTextArea.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java index 7fa871552..c4abe95d4 100644 --- a/app/src/processing/app/syntax/JEditTextArea.java +++ b/app/src/processing/app/syntax/JEditTextArea.java @@ -1380,8 +1380,22 @@ public class JEditTextArea extends JComponent float additionalOffset = getPartialPixelWidth(metrics, x, expander, startOffset) * s.length(); + if (Platform.isWindows()) { + // When the OS is using 125% or 250% or other fractional scaling, + // the layout gets hosed. This is fixed (in 4.0 beta 4) by + // subtracting this additionalOffset: + // https://github.com/processing/processing4/issues/226 + // However, on macOS, changing the font size makes this show up + // as well, only in the opposite direction: + // https://github.com/processing/processing4/issues/194 + // Bottom line, it's related to fractional metrics, + // and is especially bad with Source Code Pro. + // https://github.com/sampottinger/processing/issues/103 + additionalOffset = -additionalOffset; + } + return Math.round( - Utilities.getTabbedTextWidth(s, metrics, x, expander, startOffset) - additionalOffset + Utilities.getTabbedTextWidth(s, metrics, x, expander, startOffset) + additionalOffset ); }