/** * Gets the hash key for a concrete instance of a font. * This incorporates size, weight, etc. */ protected static String getFontInstanceHashName(SharedContext ctx, String name, float size, IdentValue weight, IdentValue style, IdentValue variant) { return name + "-" + (size * ctx.getTextRenderer().getFontScale()) + "-" + weight + "-" + style + "-" + variant; }
/** * Gets the hash key for a concrete instance of a font. * This incorporates size, weight, etc. */ protected static String getFontInstanceHashName(SharedContext ctx, String name, float size, IdentValue weight, IdentValue style, IdentValue variant) { return name + "-" + (size * ctx.getTextRenderer().getFontScale()) + "-" + weight + "-" + style + "-" + variant; }
/** * Creates a concrete instance of a font at specified size, weight, style and variant. */ protected static Font createFont(SharedContext ctx, Font rootFont, float size, IdentValue weight, IdentValue style, IdentValue variant) { //Uu.p("creating font: " + root_font + " size = " + size + // " weight = " + weight + " style = " + style + " variant = " + variant); int fontConst = Font.PLAIN; if (weight != null && (weight == IdentValue.BOLD || weight == IdentValue.FONT_WEIGHT_700 || weight == IdentValue.FONT_WEIGHT_800 || weight == IdentValue.FONT_WEIGHT_900)) { fontConst = fontConst | Font.BOLD; } if (style != null && (style == IdentValue.ITALIC || style == IdentValue.OBLIQUE)) { fontConst = fontConst | Font.ITALIC; } // scale vs font scale value too size *= ctx.getTextRenderer().getFontScale(); Font fnt = rootFont.deriveFont(fontConst, size); if (variant != null) { if (variant == IdentValue.SMALL_CAPS) { fnt = fnt.deriveFont((float) (((float) fnt.getSize()) * 0.6)); } } return fnt; }
/** * Creates a concrete instance of a font at specified size, weight, style and variant. */ protected static Font createFont(SharedContext ctx, Font rootFont, float size, IdentValue weight, IdentValue style, IdentValue variant) { //Uu.p("creating font: " + root_font + " size = " + size + // " weight = " + weight + " style = " + style + " variant = " + variant); int fontConst = Font.PLAIN; if (weight != null && (weight == IdentValue.BOLD || weight == IdentValue.FONT_WEIGHT_700 || weight == IdentValue.FONT_WEIGHT_800 || weight == IdentValue.FONT_WEIGHT_900)) { fontConst = fontConst | Font.BOLD; } if (style != null && (style == IdentValue.ITALIC || style == IdentValue.OBLIQUE)) { fontConst = fontConst | Font.ITALIC; } // scale vs font scale value too size *= ctx.getTextRenderer().getFontScale(); Font fnt = rootFont.deriveFont(fontConst, size); if (variant != null) { if (variant == IdentValue.SMALL_CAPS) { fnt = fnt.deriveFont((float) (((float) fnt.getSize()) * 0.6)); } } return fnt; }
size *= ctx.getTextRenderer().getFontScale();