Skip to content

Commit 08ad600

Browse files
committed
Fix for some font rendering problems on linux
1 parent 3928b6a commit 08ad600

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

app/src/cc/arduino/view/SplashScreenHelper.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import java.awt.geom.Rectangle2D;
3636
import java.util.Map;
3737

38+
import processing.app.Theme;
39+
3840
public class SplashScreenHelper {
3941

4042
private static final int X_OFFSET = 0;
@@ -96,7 +98,7 @@ private void eraseLastStatusText() {
9698
private void prepareTextAreaAndGraphics() {
9799
splashTextArea = new Rectangle2D.Double(X_OFFSET, Y_OFFSET, TEXTAREA_WIDTH, TEXTAREA_HEIGHT);
98100

99-
splashGraphics = splash.createGraphics();
101+
splashGraphics = Theme.setupGraphics2D(splash.createGraphics());
100102

101103
if (desktopHints != null) {
102104
splashGraphics.addRenderingHints(desktopHints);

app/src/processing/app/Base.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -1745,13 +1745,10 @@ public void handleAbout() {
17451745
final Image image = Theme.getLibImage("about", activeEditor,
17461746
Theme.scale(475), Theme.scale(300));
17471747
final Window window = new Window(activeEditor) {
1748-
public void paint(Graphics g) {
1748+
public void paint(Graphics graphics) {
1749+
Graphics2D g = Theme.setupGraphics2D(graphics);
17491750
g.drawImage(image, 0, 0, null);
17501751

1751-
Graphics2D g2 = (Graphics2D) g;
1752-
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
1753-
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
1754-
17551752
Font f = new Font("SansSerif", Font.PLAIN, Theme.scale(11));
17561753
g.setFont(f);
17571754
g.setColor(Color.white);

app/src/processing/app/EditorHeader.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,13 @@ public void paintComponent(Graphics screen) {
222222
offscreen = createImage(imageW, imageH);
223223
}
224224

225-
Graphics g = offscreen.getGraphics();
225+
Graphics2D g = Theme.setupGraphics2D(offscreen.getGraphics());
226226
if (font == null) {
227227
font = Theme.getFont("header.text.font");
228228
}
229229
g.setFont(font); // need to set this each time through
230230
metrics = g.getFontMetrics();
231231
fontAscent = metrics.getAscent();
232-
//}
233-
234-
//Graphics2D g2 = (Graphics2D) g;
235-
//g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
236-
// RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
237232

238233
// set the background for the offscreen
239234
g.setColor(backgroundColor);
@@ -255,10 +250,8 @@ public void paintComponent(Graphics screen) {
255250
// if modified, add the li'l glyph next to the name
256251
String text = " " + codeName + (code.isModified() ? " \u00A7" : " ");
257252

258-
Graphics2D g2 = (Graphics2D) g;
259-
260253
int textWidth = (int)
261-
font.getStringBounds(text, g2.getFontRenderContext()).getWidth();
254+
font.getStringBounds(text, g.getFontRenderContext()).getWidth();
262255

263256
int pieceCount = 2 + (textWidth / PIECE_WIDTH);
264257
int pieceWidth = pieceCount * PIECE_WIDTH;

app/src/processing/app/EditorLineStatus.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public void set(int newStart, int newStop) {
8989
repaint();
9090
}
9191

92-
public void paintComponent(Graphics g) {
92+
public void paintComponent(Graphics graphics) {
93+
Graphics2D g = Theme.setupGraphics2D(graphics);
9394
if (name == "" && serialport == "") {
9495
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
9596
if (boardPreferences != null)

app/src/processing/app/EditorStatus.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,15 @@ public void paintComponent(Graphics screen) {
218218
offscreen = createImage(imageW, imageH);
219219
}
220220

221-
Graphics graphics = offscreen.getGraphics();
222-
graphics.setColor(BGCOLOR[mode]);
223-
graphics.fillRect(0, 0, imageW, imageH);
224-
graphics.setColor(FGCOLOR[mode]);
221+
Graphics2D g = Theme.setupGraphics2D(offscreen.getGraphics());
222+
g.setColor(BGCOLOR[mode]);
223+
g.fillRect(0, 0, imageW, imageH);
224+
g.setColor(FGCOLOR[mode]);
225225

226-
graphics.setFont(font); // needs to be set each time on osx
227-
int ascent = graphics.getFontMetrics().getAscent();
226+
g.setFont(font); // needs to be set each time on osx
227+
int ascent = g.getFontMetrics().getAscent();
228228
assert message != null;
229-
graphics.drawString(message, Preferences.GUI_SMALL, (sizeH + ascent) / 2);
229+
g.drawString(message, Preferences.GUI_SMALL, (sizeH + ascent) / 2);
230230

231231
screen.drawImage(offscreen, 0, 0, null);
232232
}

app/src/processing/app/EditorToolbar.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public void paintComponent(Graphics screen) {
197197
x1[SERIAL] = width - BUTTON_WIDTH - 14;
198198
x2[SERIAL] = width - 14;
199199
}
200-
Graphics g = offscreen.getGraphics();
200+
Graphics2D g = Theme.setupGraphics2D(offscreen.getGraphics());
201201
g.setColor(bgcolor); //getBackground());
202202
g.fillRect(0, 0, width, height);
203203

app/src/processing/app/Theme.java

+11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.awt.Color;
2727
import java.awt.Component;
2828
import java.awt.Font;
29+
import java.awt.Graphics;
30+
import java.awt.Graphics2D;
2931
import java.awt.Image;
3032
import java.awt.MediaTracker;
3133
import java.awt.RenderingHints;
@@ -287,4 +289,13 @@ private static Image imageFromSVG(URL url, int width, int height)
287289
return Toolkit.getDefaultToolkit().createImage(imgData);
288290
}
289291

292+
static public Graphics2D setupGraphics2D(Graphics graphics) {
293+
Graphics2D g = (Graphics2D) graphics;
294+
if (PreferencesData.getBoolean("editor.antialias")) {
295+
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
296+
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
297+
}
298+
return g;
299+
}
300+
290301
}

0 commit comments

Comments
 (0)