Auto-scale editor and console fonts as well

This commit is contained in:
Cristian Maglie 2016-01-17 11:36:42 +02:00
parent 59ec660c9b
commit 4659c6f985
3 changed files with 14 additions and 5 deletions

View File

@ -503,10 +503,9 @@ public class Editor extends JFrame implements RunnerListener {
}
// apply changes to the font size for the editor
//TextAreaPainter painter = textarea.getPainter();
textarea.setFont(PreferencesData.getFont("editor.font"));
//Font font = painter.getFont();
//textarea.getPainter().setFont(new Font("Courier", Font.PLAIN, 36));
Font editorFont = scale(PreferencesData.getFont("editor.font"));
textarea.setFont(editorFont);
scrollPane.getGutter().setLineNumberFont(editorFont);
// in case tab expansion stuff has changed
// listener.applyPreferences();

View File

@ -28,6 +28,8 @@ import javax.swing.text.*;
import java.awt.*;
import java.io.PrintStream;
import static processing.app.Theme.scale;
/**
* Message console that sits below the editing area.
*/
@ -70,7 +72,7 @@ public class EditorConsole extends JScrollPane {
Font consoleFont = Theme.getFont("console.font");
Font editorFont = PreferencesData.getFont("editor.font");
Font actualFont = new Font(consoleFont.getName(), consoleFont.getStyle(), editorFont.getSize());
Font actualFont = new Font(consoleFont.getName(), consoleFont.getStyle(), scale(editorFont.getSize()));
SimpleAttributeSet stdOutStyle = new SimpleAttributeSet();
StyleConstants.setForeground(stdOutStyle, Theme.getColor("console.output.color"));

View File

@ -133,6 +133,14 @@ public class Theme {
return new Dimension(scale(dim.width), scale(dim.height));
}
static public Font scale(Font font) {
float size = scale(font.getSize());
// size must be float to call the correct Font.deriveFont(float)
// method that is different from Font.deriveFont(int)!
Font scaled = font.deriveFont(size);
return scaled;
}
static public Rectangle scale(Rectangle rect) {
Rectangle res = new Rectangle(rect);
res.x = scale(res.x);