Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Decouple Editor fonts from JVM
This makes it easier to run Processing with a custom or globally installed copy of the the VM, where before Processing wouldn't start because of missing fonts (font sadness).

This proposal would add a second copy of the fonts to the Linux tar-ball, and fall back to this one as a last resort. I have only tested registerFont() on Linux, where it seems to be working (Font in TextAreaPainter.updateAppearance does not fall back to monospaced).

On OS X this does not seem to work currently (UnsatisfiedLinkError: sun.font.FreetypeFontScaler.initIDs).
  • Loading branch information
gohai committed Aug 27, 2016
commit 71cca0d46925b6fb2b877a786fe8400f5857b0f4
15 changes: 15 additions & 0 deletions app/src/processing/app/ui/Toolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -975,17 +975,25 @@ static public Font getSansFont(int size, int style) {
* the Preferences window, and can be used by HTMLEditorKit for WebFrame).
*/
static private Font createFont(String filename, int size) throws IOException, FontFormatException {
boolean registerFont = false;

// Can't use Base.getJavaHome(), because if we're not using our local JRE,
// we likely have bigger problems with how things are running.
File fontFile = new File(System.getProperty("java.home"), "lib/fonts/" + filename);
if (!fontFile.exists()) {
// any of the fallbacks below is a custom location, so try to register the font as well
registerFont = true;
// if we're debugging from Eclipse, grab it from the work folder (user.dir is /app)
fontFile = new File(System.getProperty("user.dir"), "../build/shared/lib/fonts/" + filename);
}
if (!fontFile.exists()) {
// if we're debugging the new Java Mode from Eclipse, paths are different
fontFile = new File(System.getProperty("user.dir"), "../../shared/lib/fonts/" + filename);
}
if (!fontFile.exists()) {
// this if for Linux, where we're shipping a second copy of the fonts outside of java
fontFile = Platform.getContentFile("lib/fonts/" + filename);
}
if (!fontFile.exists()) {
String msg = "Could not find required fonts. ";
// This gets the JAVA_HOME for the *local* copy of the JRE installed with
Expand All @@ -1003,6 +1011,13 @@ static private Font createFont(String filename, int size) throws IOException, Fo
BufferedInputStream input = new BufferedInputStream(new FileInputStream(fontFile));
Font font = Font.createFont(Font.TRUETYPE_FONT, input);
input.close();

// this makes Font() work for font files in custom locations
if (registerFont) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
}

return font.deriveFont((float) size);
}

Expand Down
5 changes: 4 additions & 1 deletion build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,10 @@
<copy todir="linux/work">
<fileset dir=".." includes="core/library/**" />
<fileset dir="shared" includes="launch4j/**" />
<fileset dir="shared" includes="lib/**" excludes="lib/fonts/**" />
<!-- this used to excludes="lib/fonts/**", but instead, ship a second -->
<!-- copy of the font files on Linux, so that users can experiment with -->
<!-- drop-in or globally installed JVM versions -->
<fileset dir="shared" includes="lib/**" />
<fileset dir="shared" includes="modes/**" />
<fileset file="shared/revisions.txt" />
</copy>
Expand Down