/** Uses max advance, ascender and descender of font to calculate real height that makes any n glyphs to fit in given pixel * width. * @param width the max width to fit (in pixels) * @param numChars max number of characters that to fill width */ public int scaleForPixelWidth (int width, int numChars) { SizeMetrics fontMetrics = face.getSize().getMetrics(); int advance = FreeType.toInt(fontMetrics.getMaxAdvance()); int ascent = FreeType.toInt(fontMetrics.getAscender()); int descent = FreeType.toInt(fontMetrics.getDescender()); int unscaledHeight = ascent - descent; int height = unscaledHeight * width / (advance * numChars); setPixelSizes(0, height); return height; }
/** Uses max advance, ascender and descender of font to calculate real height that makes any n glyphs to fit in given pixel * width. * @param width the max width to fit (in pixels) * @param numChars max number of characters that to fill width */ public int scaleForPixelWidth (int width, int numChars) { SizeMetrics fontMetrics = face.getSize().getMetrics(); int advance = FreeType.toInt(fontMetrics.getMaxAdvance()); int ascent = FreeType.toInt(fontMetrics.getAscender()); int descent = FreeType.toInt(fontMetrics.getDescender()); int unscaledHeight = ascent - descent; int height = unscaledHeight * width / (advance * numChars); setPixelSizes(0, height); return height; }
/** Uses ascender and descender of font to calculate real height that makes all glyphs to fit in given pixel size. Source: * http://nothings.org/stb/stb_truetype.h / stbtt_ScaleForPixelHeight */ public int scaleForPixelHeight (int height) { setPixelSizes(0, height); SizeMetrics fontMetrics = face.getSize().getMetrics(); int ascent = FreeType.toInt(fontMetrics.getAscender()); int descent = FreeType.toInt(fontMetrics.getDescender()); return height * height / (ascent - descent); }
/** Uses ascender and descender of font to calculate real height that makes all glyphs to fit in given pixel size. Source: * http://nothings.org/stb/stb_truetype.h / stbtt_ScaleForPixelHeight */ public int scaleForPixelHeight (int height) { setPixelSizes(0, height); SizeMetrics fontMetrics = face.getSize().getMetrics(); int ascent = FreeType.toInt(fontMetrics.getAscender()); int descent = FreeType.toInt(fontMetrics.getDescender()); return height * height / (ascent - descent); }
@Override public Glyph getGlyph (char ch) { Glyph glyph = super.getGlyph(ch); if (glyph == null && generator != null) { generator.setPixelSizes(0, parameter.size); float baseline = ((flipped ? -ascent : ascent) + capHeight) / scaleY; glyph = generator.createGlyph(ch, this, parameter, stroker, baseline, packer); if (glyph == null) return missingGlyph; setGlyphRegion(glyph, regions.get(glyph.page)); setGlyph(ch, glyph); glyphs.add(glyph); dirty = true; Face face = generator.face; if (parameter.kerning) { int glyphIndex = face.getCharIndex(ch); for (int i = 0, n = glyphs.size; i < n; i++) { Glyph other = glyphs.get(i); int otherIndex = face.getCharIndex(other.id); int kerning = face.getKerning(glyphIndex, otherIndex, 0); if (kerning != 0) glyph.setKerning(other.id, FreeType.toInt(kerning)); kerning = face.getKerning(otherIndex, glyphIndex, 0); if (kerning != 0) other.setKerning(ch, FreeType.toInt(kerning)); } } } return glyph; }
@Override public Glyph getGlyph (char ch) { Glyph glyph = super.getGlyph(ch); if (glyph == null && generator != null) { generator.setPixelSizes(0, parameter.size); float baseline = ((flipped ? -ascent : ascent) + capHeight) / scaleY; glyph = generator.createGlyph(ch, this, parameter, stroker, baseline, packer); if (glyph == null) return missingGlyph; setGlyphRegion(glyph, regions.get(glyph.page)); setGlyph(ch, glyph); glyphs.add(glyph); dirty = true; Face face = generator.face; if (parameter.kerning) { int glyphIndex = face.getCharIndex(ch); for (int i = 0, n = glyphs.size; i < n; i++) { Glyph other = glyphs.get(i); int otherIndex = face.getCharIndex(other.id); int kerning = face.getKerning(glyphIndex, otherIndex, 0); if (kerning != 0) glyph.setKerning(other.id, FreeType.toInt(kerning)); kerning = face.getKerning(otherIndex, glyphIndex, 0); if (kerning != 0) other.setKerning(ch, FreeType.toInt(kerning)); } } } return glyph; }
data.ascent = FreeType.toInt(fontMetrics.getAscender()); data.descent = FreeType.toInt(fontMetrics.getDescender()); data.lineHeight = FreeType.toInt(fontMetrics.getHeight()); float baseLine = data.ascent; for (int c = 32; c < (32 + face.getNumGlyphs()); c++) { if (loadChar(c, flags)) { int lh = FreeType.toInt(face.getGlyph().getMetrics().getHeight()); data.lineHeight = (lh > data.lineHeight) ? lh : data.lineHeight; data.spaceXadvance = FreeType.toInt(face.getGlyph().getMetrics().getHoriAdvance()); } else { data.xHeight = FreeType.toInt(face.getGlyph().getMetrics().getHeight()); break; data.capHeight = FreeType.toInt(face.getGlyph().getMetrics().getHeight()) + Math.abs(parameter.shadowOffsetY); break; char c = characters[i]; int height = loadChar(c, flags) ? FreeType.toInt(face.getGlyph().getMetrics().getHeight()) : 0; heights[i] = height; if (kerning != 0) first.setKerning(secondChar, FreeType.toInt(kerning)); if (kerning != 0) second.setKerning(firstChar, FreeType.toInt(kerning));
data.ascent = FreeType.toInt(fontMetrics.getAscender()); data.descent = FreeType.toInt(fontMetrics.getDescender()); data.lineHeight = FreeType.toInt(fontMetrics.getHeight()); float baseLine = data.ascent; for (int c = 32; c < (32 + face.getNumGlyphs()); c++) { if (loadChar(c, flags)) { int lh = FreeType.toInt(face.getGlyph().getMetrics().getHeight()); data.lineHeight = (lh > data.lineHeight) ? lh : data.lineHeight; data.spaceXadvance = FreeType.toInt(face.getGlyph().getMetrics().getHoriAdvance()); } else { data.xHeight = FreeType.toInt(face.getGlyph().getMetrics().getHeight()); break; data.capHeight = FreeType.toInt(face.getGlyph().getMetrics().getHeight()) + Math.abs(parameter.shadowOffsetY); break; char c = characters[i]; int height = loadChar(c, flags) ? FreeType.toInt(face.getGlyph().getMetrics().getHeight()) : 0; heights[i] = height; if (kerning != 0) first.setKerning(secondChar, FreeType.toInt(kerning)); if (kerning != 0) second.setKerning(firstChar, FreeType.toInt(kerning));
else glyph.yoffset = -(glyph.height - mainGlyph.getTop()) - (int)baseLine; glyph.xadvance = FreeType.toInt(metrics.getHoriAdvance()) + (int)parameter.borderWidth + parameter.spaceX;
else glyph.yoffset = -(glyph.height - mainGlyph.getTop()) - (int)baseLine; glyph.xadvance = FreeType.toInt(metrics.getHoriAdvance()) + (int)parameter.borderWidth + parameter.spaceX;
/** Uses max advance, ascender and descender of font to calculate real height that makes any n glyphs to fit in given pixel * width. * @param width the max width to fit (in pixels) * @param numChars max number of characters that to fill width */ public int scaleForPixelWidth (int width, int numChars) { SizeMetrics fontMetrics = face.getSize().getMetrics(); int advance = FreeType.toInt(fontMetrics.getMaxAdvance()); int ascent = FreeType.toInt(fontMetrics.getAscender()); int descent = FreeType.toInt(fontMetrics.getDescender()); int unscaledHeight = ascent - descent; int height = unscaledHeight * width / (advance * numChars); setPixelSizes(0, height); return height; }
/** Uses ascender and descender of font to calculate real height that makes all glyphs to fit in given pixel size. Source: * http://nothings.org/stb/stb_truetype.h / stbtt_ScaleForPixelHeight */ public int scaleForPixelHeight (int height) { setPixelSizes(0, height); SizeMetrics fontMetrics = face.getSize().getMetrics(); int ascent = FreeType.toInt(fontMetrics.getAscender()); int descent = FreeType.toInt(fontMetrics.getDescender()); return height * height / (ascent - descent); }
data.ascent = FreeType.toInt(fontMetrics.getAscender()); data.descent = FreeType.toInt(fontMetrics.getDescender()); data.lineHeight = FreeType.toInt(fontMetrics.getHeight()); if (!face.loadChar(xChar, FreeType.FT_LOAD_DEFAULT)) continue; data.xHeight = FreeType.toInt(face.getGlyph().getMetrics().getHeight()); break; if (!face.loadChar(capChar, FreeType.FT_LOAD_DEFAULT)) continue; data.capHeight = FreeType.toInt(face.getGlyph().getMetrics().getHeight()); break;
@Override public Glyph getGlyph (char ch) { Glyph glyph = super.getGlyph(ch); if (glyph != null && glyph != missingGlyph) return glyph; for (int i = 0; i < generators.size; i++) { FreeTypeFontGenerator generator = generators.get(i); generator.setPixelSizes(0, parameter.size); float baseline = ((flipped ? -ascent : ascent) + capHeight) / scaleY; glyph = generator.createGlyph(ch, this, parameter, stroker, baseline, packer); if (glyph == null) continue; setGlyphRegion(glyph, regions.get(glyph.page)); setGlyph(ch, glyph); glyphs.add(glyph); dirty = true; Face face = generator.face; if (parameter.kerning) { int glyphIndex = face.getCharIndex(ch); for (int j = 0, n = glyphs.size; j < n; j++) { Glyph other = glyphs.get(j); int otherIndex = face.getCharIndex(other.id); int kerning = face.getKerning(glyphIndex, otherIndex, 0); if (kerning != 0) glyph.setKerning(other.id, FreeType.toInt(kerning)); kerning = face.getKerning(otherIndex, glyphIndex, 0); if (kerning != 0) other.setKerning(ch, FreeType.toInt(kerning)); } } return glyph; } return missingGlyph; }
data.ascent = FreeType.toInt(fontMetrics.getAscender()); data.descent = FreeType.toInt(fontMetrics.getDescender()); data.lineHeight = FreeType.toInt(fontMetrics.getHeight()); float baseLine = data.ascent; for (int c = 32; c < (32 + face.getNumGlyphs()); c++) { if (loadChar(c, flags)) { int lh = FreeType.toInt(face.getGlyph().getMetrics().getHeight()); data.lineHeight = (lh > data.lineHeight) ? lh : data.lineHeight; data.spaceXadvance = FreeType.toInt(face.getGlyph().getMetrics().getHoriAdvance()); } else { data.xHeight = FreeType.toInt(face.getGlyph().getMetrics().getHeight()); break; data.capHeight = FreeType.toInt(face.getGlyph().getMetrics().getHeight()) + Math.abs(parameter.shadowOffsetY); break; char c = characters[i]; int height = loadChar(c, flags) ? FreeType.toInt(face.getGlyph().getMetrics().getHeight()) : 0; heights[i] = height; if (kerning != 0) first.setKerning(secondChar, FreeType.toInt(kerning)); if (kerning != 0) second.setKerning(firstChar, FreeType.toInt(kerning));
else glyph.yoffset = -(glyph.height - mainGlyph.getTop()) - (int)baseLine; glyph.xadvance = FreeType.toInt(metrics.getHoriAdvance()) + (int)parameter.borderWidth + parameter.spaceX;