Load a built-in font from the Processing lib/fonts folder and register it with the GraphicsEnvironment so that it's broadly available. (i.e. shows up in getFontList() works, so it appears in the list of fonts in the Preferences window, and can be used by HTMLEditorKit for WebFrame.)
(String filename, int size)
| 1341 | * in the Preferences window, and can be used by HTMLEditorKit for WebFrame.) |
| 1342 | */ |
| 1343 | static private Font initFont(String filename, int size) throws IOException, FontFormatException { |
| 1344 | File fontFile = Platform.getContentFile("lib/fonts/" + filename); |
| 1345 | |
| 1346 | if (fontFile == null || !fontFile.exists()) { |
| 1347 | String msg = "Could not find required fonts. "; |
| 1348 | // This gets the JAVA_HOME for the *local* copy of the JRE installed with |
| 1349 | // Processing. If it's not using the local JRE, it may be because of this |
| 1350 | // launch4j bug: https://github.com/processing/processing/issues/3543 |
| 1351 | if (Util.containsNonASCII(Platform.getJavaHome().getAbsolutePath())) { |
| 1352 | msg += "Trying moving Processing\n" + |
| 1353 | "to a location with only ASCII characters in the path."; |
| 1354 | } else { |
| 1355 | msg += "Please reinstall Processing."; |
| 1356 | } |
| 1357 | Messages.showError("Font Sadness", msg, null); |
| 1358 | } |
| 1359 | |
| 1360 | BufferedInputStream input = new BufferedInputStream(new FileInputStream(fontFile)); |
| 1361 | Font font = Font.createFont(Font.TRUETYPE_FONT, input); |
| 1362 | input.close(); |
| 1363 | |
| 1364 | // Register the font to be available for other function calls |
| 1365 | GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font); |
| 1366 | |
| 1367 | return font.deriveFont((float) size); |
| 1368 | } |
| 1369 | |
| 1370 | |
| 1371 | /** |
no test coverage detected