From 71cca0d46925b6fb2b877a786fe8400f5857b0f4 Mon Sep 17 00:00:00 2001 From: gohai Date: Fri, 27 May 2016 07:02:26 +0200 Subject: [PATCH 1/2] 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). --- app/src/processing/app/ui/Toolkit.java | 15 +++++++++++++++ build/build.xml | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/processing/app/ui/Toolkit.java b/app/src/processing/app/ui/Toolkit.java index e30b9f98a5..8bc4d4b9c3 100644 --- a/app/src/processing/app/ui/Toolkit.java +++ b/app/src/processing/app/ui/Toolkit.java @@ -975,10 +975,14 @@ 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); } @@ -986,6 +990,10 @@ static private Font createFont(String filename, int size) throws IOException, Fo // 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 @@ -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); } diff --git a/build/build.xml b/build/build.xml index eaaf4dc94f..30c9b05b55 100644 --- a/build/build.xml +++ b/build/build.xml @@ -756,7 +756,10 @@ - + + + + From edd9ea36bb5551bce55d85350116efc23a987b96 Mon Sep 17 00:00:00 2001 From: gohai Date: Sun, 28 Aug 2016 16:31:15 +0200 Subject: [PATCH 2/2] Use fonts in lib/fonts instead of the JVM location for all OS --- build/build.xml | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/build/build.xml b/build/build.xml index 30c9b05b55..b1140e02a2 100644 --- a/build/build.xml +++ b/build/build.xml @@ -611,17 +611,10 @@ - + - - - - - @@ -756,9 +749,6 @@ - - - @@ -860,11 +850,6 @@ --> - - - - - - + @@ -1122,10 +1107,6 @@ --> - - - -