public PFont loadFont(String filename) { try { InputStream input = createInput(filename); return new PFont(input); } catch (Exception e) { die("Could not load font " + filename + ". " + "Make sure that the font has been copied " + "to the data folder of your sketch.", e); } return null; }
/** * Create a bitmap font on the fly from either a font name that's * installed on the system, or from a .ttf or .otf that's inside * the data folder of this sketch. * <p/> * Use 'null' for the charset if you want to dynamically create * character bitmaps only as they're needed. */ public PFont createFont(String name, float size, boolean smooth, char[] charset) { String lowerName = name.toLowerCase(); Typeface baseFont = null; if (lowerName.endsWith(".otf") || lowerName.endsWith(".ttf")) { AssetManager assets = activity.getAssets(); baseFont = Typeface.createFromAsset(assets, name); } else { baseFont = (Typeface) PFont.findNative(name); } return new PFont(baseFont, round(size), smooth, charset); }
protected PFont createFont(String name, float size, boolean smooth, char[] charset) { String lowerName = name.toLowerCase(); Font baseFont = null; try { InputStream stream = null; if (lowerName.endsWith(".otf") || lowerName.endsWith(".ttf")) { stream = parent.createInput(name); if (stream == null) { System.err.println("The font \"" + name + "\" " + "is missing or inaccessible, make sure " + "the URL is valid or that the file has been " + "added to your sketch and is readable."); return null; } baseFont = Font.createFont(Font.TRUETYPE_FONT, parent.createInput(name)); } else { baseFont = PFont.findFont(name); } return new PFont(baseFont.deriveFont(size * parent.pixelDensity), smooth, charset, stream != null, parent.pixelDensity); } catch (Exception e) { System.err.println("Problem with createFont(\"" + name + "\")"); e.printStackTrace(); return null; } }
return new PFont(input);