Skip to content

Commit 0e23309

Browse files
committed
Correct font size calculation for Terminal in multi-monitor setups
The StyleMap of the Terminal implementation uses a GC to calculate the extents of strings to be rendered. This GC is created on the current Display instance, which does not incorporate the zoom of the current usage context (i.e., the monitor on which the Terminal is displayed). But the monitor zoom has an effect on the effective font size, as font sizes in pixels are always integers such that the logical SWT point value can be rounded differently depending on the zoom. An effect of this are cut-off texts on secondary monitors on Windows, because without taking the zoom of the usage context into account the terminal font is erroneously not identified as a monospace font. This change adapts the implementation of StyleMap and its callers to create a GC for text extent calculations for the actual usage context. It makes the Terminal font being properly identified as a monospace font, such that individual characters are rendered and texts are not cut off. Contributes to #2295 # Conflicts: # terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/textcanvas/StyleMap.java
1 parent ce5c9cc commit 0e23309

4 files changed

Lines changed: 13 additions & 7 deletions

File tree

terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/emulator/VT100TerminalControl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ protected void setupControls(Composite parent) {
762762
snapshot.updateSnapshot(false);
763763
fPollingTextCanvasModel = new PollingTextCanvasModel(snapshot);
764764
fCtlText = new TextCanvas(fWndParent, fPollingTextCanvasModel, SWT.NONE,
765-
new TextLineRenderer(fCtlText, fPollingTextCanvasModel));
765+
new TextLineRenderer(() -> fCtlText, fPollingTextCanvasModel));
766766

767767
fCtlText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
768768
fCtlText.addResizeHandler((lines, columns) -> fTerminalText.setDimensions(lines, columns));

terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/textcanvas/StyleMap.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121

2222
import java.util.EnumMap;
2323
import java.util.Map;
24+
import java.util.function.Supplier;
2425

2526
import org.eclipse.jface.resource.JFaceResources;
2627
import org.eclipse.swt.graphics.Color;
28+
import org.eclipse.swt.graphics.Drawable;
2729
import org.eclipse.swt.graphics.Font;
2830
import org.eclipse.swt.graphics.GC;
2931
import org.eclipse.swt.graphics.Point;
@@ -42,15 +44,17 @@
4244
public class StyleMap {
4345

4446
String fFontName = ITerminalConstants.FONT_DEFINITION;
47+
private final Supplier<Drawable> fUsageContextProvider;
4548
private Point fCharSize;
4649
private final TerminalStyle fDefaultStyle;
4750
private boolean fInvertColors;
4851
private boolean fProportional;
4952
private final int[] fOffsets = new int[256];
5053
private final Map<TerminalColor, Color> fColorMap = new EnumMap<>(TerminalColor.class);
5154

52-
public StyleMap() {
55+
public StyleMap(Supplier<Drawable> usageContextProvider) {
5356
fDefaultStyle = TerminalStyle.getDefaultStyle();
57+
fUsageContextProvider = usageContextProvider;
5458
initFont();
5559
initColors();
5660
}
@@ -172,8 +176,8 @@ public int getFontHeight() {
172176
* @since 3.2
173177
*/
174178
public void updateFont(String fontName) {
175-
Display display = Display.getCurrent();
176-
GC gc = new GC(display);
179+
Drawable usageContext = fUsageContextProvider.get();
180+
GC gc = new GC(usageContext != null ? usageContext : Display.getCurrent());
177181
if (JFaceResources.getFontRegistry().hasValueFor(fontName)) {
178182
fFontName = fontName;
179183
} else {

terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/textcanvas/TextLineRenderer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package org.eclipse.terminal.internal.textcanvas;
1818

1919
import java.util.Map;
20+
import java.util.function.Supplier;
2021

2122
import org.eclipse.swt.graphics.Color;
23+
import org.eclipse.swt.graphics.Drawable;
2224
import org.eclipse.swt.graphics.Font;
2325
import org.eclipse.swt.graphics.GC;
2426
import org.eclipse.swt.graphics.Point;
@@ -37,9 +39,9 @@ public class TextLineRenderer implements ILinelRenderer {
3739
private final ITextCanvasModel fModel;
3840
private final StyleMap fStyleMap;
3941

40-
public TextLineRenderer(TextCanvas c, ITextCanvasModel model) {
42+
public TextLineRenderer(Supplier<Drawable> usageContextProvider, ITextCanvasModel model) {
4143
fModel = model;
42-
fStyleMap = new StyleMap();
44+
fStyleMap = new StyleMap(usageContextProvider);
4345
}
4446

4547
@Override

terminal/tests/org.eclipse.terminal.test/src/org/eclipse/terminal/internal/test/ui/TerminalTextUITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static void main(String[] args) {
8282
// TODO how to get the initial size correctly!
8383
snapshot.updateSnapshot(false);
8484
fgModel = new PollingTextCanvasModel(snapshot);
85-
fgTextCanvas = new TextCanvas(shell, fgModel, SWT.NONE, new TextLineRenderer(fgTextCanvas, fgModel));
85+
fgTextCanvas = new TextCanvas(shell, fgModel, SWT.NONE, new TextLineRenderer(() -> fgTextCanvas, fgModel));
8686
fgTextCanvas.setLayoutData(new GridData(GridData.FILL_BOTH));
8787

8888
composite.setLayout(layout);

0 commit comments

Comments
 (0)