MCPcopy Index your code
hub / github.com/processing/processing / createFont

Method createFont

app/src/processing/app/ui/Toolkit.java:1105–1142  ·  view source on GitHub ↗

Get a font from the lib/fonts folder. Our default fonts are also installed there so that the monospace (and others) can be used by other font listing calls (i.e. it appears in the list of monospace fonts in the Preferences window, and can be used by HTMLEditorKit for WebFrame).

(String filename, int size)

Source from the content-addressed store, hash-verified

1103 * the Preferences window, and can be used by HTMLEditorKit for WebFrame).
1104 */
1105 static private Font createFont(String filename, int size) throws IOException, FontFormatException {
1106 boolean registerFont = false;
1107
1108 // try the JRE font directory first
1109 File fontFile = new File(System.getProperty("java.home"), "lib/fonts/" + filename);
1110
1111 // else fall back to our own content dir
1112 if (!fontFile.exists()) {
1113 fontFile = Platform.getContentFile("lib/fonts/" + filename);
1114 registerFont = true;
1115 }
1116
1117 if (!fontFile.exists()) {
1118 String msg = "Could not find required fonts. ";
1119 // This gets the JAVA_HOME for the *local* copy of the JRE installed with
1120 // Processing. If it's not using the local JRE, it may be because of this
1121 // launch4j bug: https://github.com/processing/processing/issues/3543
1122 if (Util.containsNonASCII(Platform.getJavaHome().getAbsolutePath())) {
1123 msg += "Trying moving Processing\n" +
1124 "to a location with only ASCII characters in the path.";
1125 } else {
1126 msg += "Please reinstall Processing.";
1127 }
1128 Messages.showError("Font Sadness", msg, null);
1129 }
1130
1131
1132 BufferedInputStream input = new BufferedInputStream(new FileInputStream(fontFile));
1133 Font font = Font.createFont(Font.TRUETYPE_FONT, input);
1134 input.close();
1135
1136 if (registerFont) {
1137 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
1138 ge.registerFont(font);
1139 }
1140
1141 return font.deriveFont((float) size);
1142 }
1143
1144
1145 /**

Callers 2

getMonoFontMethod · 0.95
getSansFontMethod · 0.95

Calls 5

getContentFileMethod · 0.95
containsNonASCIIMethod · 0.95
getJavaHomeMethod · 0.95
showErrorMethod · 0.95
closeMethod · 0.45

Tested by

no test coverage detected