Get the Font object of the default (built-in) monospaced font. As of 4.x, this is Source Code Pro and ships in lib/fonts because it looks like JDK 11+ no longer supports a "fonts" subfolder (or at least
(int size, int style)
| 1248 | * its cross-platform implementation is inconsistent). |
| 1249 | */ |
| 1250 | static public Font getMonoFont(int size, int style) { |
| 1251 | // Prior to 4.0 beta 9, we had a manual override for |
| 1252 | // individual languages to use SansSerif instead. |
| 1253 | // In beta 9, that was moved to the language translation file. |
| 1254 | // https://github.com/processing/processing/issues/2886 |
| 1255 | // https://github.com/processing/processing/issues/4944 |
| 1256 | String fontFamilyMono = Language.text("font.family.mono"); |
| 1257 | |
| 1258 | if (monoFont == null || monoBoldFont == null) { |
| 1259 | try { |
| 1260 | if ("Source Code Pro".equals(fontFamilyMono)) { |
| 1261 | monoFont = initFont("SourceCodePro-Regular.ttf", size); |
| 1262 | monoBoldFont = initFont("SourceCodePro-Bold.ttf", size); |
| 1263 | } |
| 1264 | } catch (Exception e) { |
| 1265 | Messages.err("Could not load mono font", e); |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | // If not using Source Code Pro above, or an Exception was thrown |
| 1270 | if (monoFont == null || monoBoldFont == null) { |
| 1271 | monoFont = new Font(fontFamilyMono, Font.PLAIN, size); |
| 1272 | monoBoldFont = new Font(fontFamilyMono, Font.BOLD, size); |
| 1273 | } |
| 1274 | |
| 1275 | if (style == Font.BOLD) { |
| 1276 | if (size == monoBoldFont.getSize()) { |
| 1277 | return monoBoldFont; |
| 1278 | } else { |
| 1279 | return monoBoldFont.deriveFont((float) size); |
| 1280 | } |
| 1281 | } else { |
| 1282 | if (size == monoFont.getSize()) { |
| 1283 | return monoFont; |
| 1284 | } else { |
| 1285 | return monoFont.deriveFont((float) size); |
| 1286 | } |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | |
| 1291 | static public String getSansFontName() { |