(this is kind of self-advertising)
I have made this library that will render text using FreeType in native code. The problem is that it only is available on WINDOWS, ANDROID and the .dll files take up a lot of space (9mb for windows alone).
https://www.mediafire.com/?r8uki5mk83uag1i
If you want the source code, or if you want to try to contribute:
Here is some ‘example’ code.
JFreeType jfreetype = JFreeType.createInstance();
jfreetype.initialize(true); // the parameter is whether JFreeType should attempt to load native files itself
// if you pass in false, you need to load native files yourself.
JFreeTypeOptions options = new JFreeTypeOptions();
options.font = "C:/path/to/font.ttf"; // full path to font file on the file system
options.text = "A generic string of text"; // the string of text you want to render
options.size = 20; // the size of the font
options.width = 10000; // the width at which the size of the font will be reduced if the string is bigger than this number
options.height = 10000; // the height at which the size of the font will be reduced if the string is bigger than this number
options.lineSpacing = 0; // when wrapping text, spacing between lines (in pixels)
Bitmap bitmap = jfreetype.render(options);
int format = bitmap.format; // this can be ignored, right now the only format is alpha (1 byte alpha)
int width = bitmap.width; // the width of the texture
int height = bitmap.height; // the height of the texture
ByteBuffer pixels = bitmap.pixels; // a byte buffer of pixels (the format is 1 byte alpha)
TextMetrics metrics = bitmap.textMetrics; // contains some metrics generated from rendering the string
int descender = metrics.descender; // the maximum descender of the string
jfreetype.setInstantLoggingEnabled(false); // if instant logging is enabled, will print errors / info instantly to default output stream
// If instant logging is disabling, will 'buffer' the messages (up to 128)
String error = null;
while ((error = jfreetype.getLog()) != null) {
System.out.println(error); // prints out error messages?
}
jfreetype.destroy(); // cleanup?
On the final note, if you decide to try this lib, and something doesn’t work, you might want to just drop it entirely, as this is not really a production level library yet.