private static native long toBitmap(long glyph, int renderMode); /* FT_Glyph bitmap = (FT_Glyph)glyph;
/** Creates a new generator from the given font file. Uses {@link FileHandle#length()} to determine the file size. If the file * length could not be determined (it was 0), an extra copy of the font bytes is performed. Throws a * {@link GdxRuntimeException} if loading did not succeed. */ public FreeTypeFontGenerator (FileHandle fontFile, int faceIndex) { name = fontFile.nameWithoutExtension(); library = FreeType.initFreeType(); face = library.newFace(fontFile, faceIndex); if (checkForBitmapFont()) return; setPixelSizes(0, 15); }
public static Library initFreeType() { new SharedLibraryLoader().load("gdx-freetype"); long address = initFreeTypeJni(); if(address == 0) throw new GdxRuntimeException("Couldn't initialize FreeType library, FreeType error code: " + getLastErrorCode()); else return new Library(address); }
/** 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); }
private static native long toBitmap(long glyph, int renderMode); /* FT_Glyph bitmap = (FT_Glyph)glyph;
public static Library initFreeType() { new SharedLibraryLoader().load("gdx-freetype"); long address = initFreeTypeJni(); if(address == 0) throw new GdxRuntimeException("Couldn't initialize FreeType library, FreeType error code: " + getLastErrorCode()); else return new Library(address); }
/** Creates a new generator from the given font file. Uses {@link FileHandle#length()} to determine the file size. If the file * length could not be determined (it was 0), an extra copy of the font bytes is performed. Throws a * {@link GdxRuntimeException} if loading did not succeed. */ public FreeTypeFontGenerator (FileHandle fontFile, int faceIndex) { name = fontFile.nameWithoutExtension(); library = FreeType.initFreeType(); face = library.newFace(fontFile, faceIndex); if (checkForBitmapFont()) return; setPixelSizes(0, 15); }
/** 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); }
public Stroker createStroker() { long stroker = strokerNew(address); if(stroker == 0) throw new GdxRuntimeException("Couldn't create FreeType stroker, FreeType error code: " + getLastErrorCode()); return new Stroker(stroker); }
public static Library initFreeType() { new SharedLibraryLoader().load("gdx-freetype"); long address = initFreeTypeJni(); if(address == 0) throw new GdxRuntimeException("Couldn't initialize FreeType library, FreeType error code: " + getLastErrorCode()); else return new Library(address); }
int fileSize = (int)fontFile.length(); library = FreeType.initFreeType(); if (library == null) throw new GdxRuntimeException("Couldn't initialize FreeType");
@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; }
public Stroker createStroker() { long stroker = strokerNew(address); if(stroker == 0) throw new GdxRuntimeException("Couldn't create FreeType stroker, FreeType error code: " + getLastErrorCode()); return new Stroker(stroker); }
@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; }
private static native long getGlyph(long glyphSlot); /* FT_Glyph 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));
private static native long getGlyph(long glyphSlot); /* FT_Glyph 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));