emergency change for font not working properly across platforms

This commit is contained in:
Ben Fry
2013-06-03 17:19:57 -04:00
parent f5b170cc70
commit 29c4c990b9
+52 -19
View File
@@ -12,6 +12,8 @@ package processing.app.syntax;
import java.awt.*;
import javax.swing.JComponent;
import processing.app.Preferences;
/**
* A simple text style class. It can specify the color, italic flag,
@@ -82,7 +84,7 @@ public class SyntaxStyle
// (bold ? Font.BOLD : 0)
// | (italic ? Font.ITALIC : 0),
// font.getSize());
lastStyledFont =
lastStyledFont =
findFont(font.getFamily(), bold ? Font.BOLD : Font.PLAIN, font.getSize());
return lastStyledFont;
}
@@ -102,35 +104,66 @@ public class SyntaxStyle
// (bold ? Font.BOLD : 0)
// | (italic ? Font.ITALIC : 0),
// font.getSize());
lastStyledFont =
lastStyledFont =
findFont(font.getFamily(), bold ? Font.BOLD : Font.PLAIN, font.getSize());
//fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(lastStyledFont);
fontMetrics = comp.getFontMetrics(lastStyledFont);
return fontMetrics;
}
private String monoFontFamily;
/*
on Windows (and I presume Linux) we get something like this:
mono family Source Code Pro
mono fontname Source Code Pro
mono name Source Code Pro
mono psname SourceCodePro-Regular
mono family Source Code Pro Semibold
mono fontname Source Code Pro Semibold
mono name Source Code Pro Semibold
mono psname SourceCodePro-Semibold
...which means that 'family' is not a usable method.
*/
//private String monoFontFamily;
private Font findFont(String familyName, int style, int size) {
if (monoFontFamily == null) {
// Just get the font family name for comparison
monoFontFamily =
processing.app.Toolkit.getMonoFont(size, style).getFamily();
//processing.app.Toolkit.getMonoFont(size, style).getFamily();
// Font mono = processing.app.Toolkit.getMonoFont(size, style);
// System.out.println("mono family " + mono.getFamily());
// System.out.println("mono fontname " + mono.getFontName());
// System.out.println("mono name " + mono.getName());
// System.out.println("mono psname " + mono.getPSName());
}
if (familyName.equals(monoFontFamily)) {
// System.out.println("getting style bold? " + (style == Font.BOLD));
// getFamily() is too unreliable across platforms
if (Preferences.get("editor.font").startsWith("processing.mono")) {
return processing.app.Toolkit.getMonoFont(size, style);
} else {
// System.out.println("name is " + name + " mono name is " + monoFontName + " " + style);
return new Font(familyName, style, size);
}
/*
if (monoFontFamily == null) {
// This should be more reliable across platforms than the
// family name, which only seems to work correctly on OS X.
// (Or perhaps only when it's installed locally.)
String psName =
processing.app.Toolkit.getMonoFont(size, style).getPSName();
int dash = psName.indexOf('-');
monoFontFamily = psName.substring(0, dash);
// Just get the font family name for comparison
//monoFontFamily =
//processing.app.Toolkit.getMonoFont(size, style).getFamily();
//processing.app.Toolkit.getMonoFont(size, style).getFamily();
Font mono = processing.app.Toolkit.getMonoFont(size, style);
System.out.println("mono family " + mono.getFamily());
System.out.println("mono fontname " + mono.getFontName());
System.out.println("mono name " + mono.getName());
System.out.println("mono psname " + mono.getPSName());
}
if (familyName.equals(monoFontFamily)) {
System.out.println("getting style bold? " + (style == Font.BOLD));
return processing.app.Toolkit.getMonoFont(size, style);
} else {
//System.out.println("name is " + name + " mono name is " + monoFontName + " " + style);
return new Font(familyName, style, size);
}
*/
}
/**