public static Map<String, Typeface> loadFontsFromAssets(AssetManager assetManager) { return loadFontsFromAssets(assetManager, "fonts"); }
public static Typeface getTypeface(String fontFamily, String fontStyle, String fontVariant, int fontWeight) { return getTypeface(fontFamily, getTypefaceStyle(fontStyle, fontVariant, fontWeight)); }
int version = readDword(header, 0); int numTables = readWord(header, 4); return null; position += tableDescr.length; int tag = readDword(tableDescr, 0); int offset = readDword(tableDescr, 8); int length = readDword(tableDescr, 12); int count = readWord(table, 2); int stringOffset = readWord(table, 4); int platformID = readWord(table, nameIdOffset); int nameIdValue = readWord(table, nameIdOffset + 6); int nameLength = readWord(table, nameIdOffset + 8); int nameOffset = readWord(table, nameIdOffset + 10);
@Override public final void setFontProperties(@NonNull String fontFamily, float fontLineHeight, float fontSize, String fontStyle, @NonNull String fontVariant, int fontWeight) { Typeface typeface = typefaceMap == null ? FontUtils.getTypeface(fontFamily, fontStyle, fontVariant, fontWeight) : FontUtils.getTypeface(typefaceMap, fontFamily, fontStyle, fontVariant, fontWeight); // scale font size to the canvas transform scale, to ensure best font rendering // (text size is expressed in pixels, while fontSize is in mm) textPaint.setTypeface(typeface); textPaint.setTextSize(Math.round((fontSize / 25.4f) * displayMetrics.ydpi)); }
public static Map<String, Typeface> loadFontsFromAssets(AssetManager assetManager, String assetsDir) { Map<String, Typeface> typefaceMap = new HashMap<>(); try { String[] files = assetManager.list(assetsDir); for (String filename : files) { String fontPath = assetsDir + File.separatorChar + filename; String fontFamily = FontUtils.getFontFamily(assetManager, fontPath); final Typeface typeface = Typeface.createFromAsset(assetManager, fontPath); if (fontFamily != null && typeface != null) { typefaceMap.put(fontFamily, typeface); } } } catch (IOException e) { Log.e("FontUtils", "Failed to list fonts from assets", e); return null; } return typefaceMap; }
public static int getTypefaceStyle(Style style) { return getTypefaceStyle(style.getFontStyle(), style.getFontVariant(), style.getFontWeight()); }
Map<String, Typeface> typefaceMap = FontUtils.loadFontsFromAssets(assetManager); editorView.setTypefaces(typefaceMap);
public static Typeface getTypeface(Map<String, Typeface> typefaceMap, String fontFamily, String fontStyle, String fontVariant, int fontWeight) { Typeface ref = typefaceMap.get(fontFamily); if (ref == null) return getTypeface(fontFamily, getTypefaceStyle(fontStyle, fontVariant, fontWeight)); return Typeface.create(ref, FontUtils.getTypefaceStyle(fontStyle, fontVariant, fontWeight)); }
Map<String, Typeface> typefaceMap = FontUtils.loadFontsFromAssets(assetManager); editorView.setTypefaces(typefaceMap);
public static Typeface getTypeface(Style style) { return getTypeface(style.getFontFamily(), getTypefaceStyle(style)); }
int typefaceStyle = FontUtils.getTypefaceStyle(style); String fontFamily = style.getFontFamily(); int fontSize = Math.round(y_mm2px(style.getFontSize())); Typeface typeface = FontUtils.getTypeface(typefaceMap, fontFamily, style.getFontStyle(), style.getFontVariant(), style.getFontWeight()); if (typeface == null) span = new TextAppearanceSpan(fontFamily, typefaceStyle, fontSize, fontColor, fontLinkColor);