From c55bf37684acbd6b0c52745e783bcce86a83a16e Mon Sep 17 00:00:00 2001 From: Floris Date: Fri, 3 Aug 2018 12:20:49 +0200 Subject: [PATCH] Add a warning to findFont() when a font isn't found (and the default font is used). --- core/src/processing/core/PFont.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/src/processing/core/PFont.java b/core/src/processing/core/PFont.java index 632cd7ec0..b4b9a0fe6 100644 --- a/core/src/processing/core/PFont.java +++ b/core/src/processing/core/PFont.java @@ -145,6 +145,12 @@ public class PFont implements PConstants { /** True if already tried to find the native AWT version of this font. */ protected boolean fontSearched; + /** + * The name of the font that is used as default when a font isn't found. + * See {@link #findFont(String)} and {@link #loadFonts()} for more info. + */ + static protected String defaultFontName; + /** * Array of the native system fonts. Used to lookup native fonts by their * PostScript name. This is a workaround for a several year old Apple Java @@ -901,6 +907,7 @@ public class PFont implements PConstants { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); fonts = ge.getAllFonts(); + defaultFontName = new Font("",Font.PLAIN,1).getFontName(); if (PApplet.platform == PConstants.MACOSX) { fontDifferent = new HashMap(); for (Font font : fonts) { @@ -917,6 +924,10 @@ public class PFont implements PConstants { * Starting with Java 1.5, Apple broke the ability to specify most fonts. * This bug was filed years ago as #4769141 at bugreporter.apple.com. More: * Bug 407. + *
+ * This function displays a warning when the font isn't found and the default font is + * used. + * See: issue #5481 */ static public Font findFont(String name) { loadFonts(); @@ -931,7 +942,14 @@ public class PFont implements PConstants { // } // } } - return new Font(name, Font.PLAIN, 1); + Font font = new Font(name, Font.PLAIN, 1); + if(!defaultFontName.equals(name) && font.getFontName().equals(defaultFontName)) { + System.err.println("Warning: font \"" + name + + "\" is missing or inaccessible on this system. Default font \"" + + defaultFontName + "\" is used."); + + } + return font; }