short charcode;
FT_Check(FT_Init_FreeType(&library));
- emu_pause();
+ FT_Check(FT_New_Memory_Face(library, _user_info[0], (int)_user_info[1], 0, &face));
for(;;) {
- FT_Check(FT_New_Memory_Face(library, _user_info[0], (int)_user_info[1], 0, &face));
- FT_Check(FT_Set_Char_Size(face, 0, ((int)_user_info[4]) * 64, 72, 72));
-
+
+ emu_pause();
+ FT_Check(FT_Set_Char_Size(face, 0, ((int)_user_info[4]) * 64, 72, 72));
for(charcode = (int)_user_info[2]; charcode <= (int)_user_info[3]; charcode++) {
glyph_index = FT_Get_Char_Index(face, charcode);
_user_info[6] = (char*)face->glyph->bitmap.width;
_user_info[7] = (char*)face->glyph->bitmap.rows;
_user_info[8] = (char*)(face->size->metrics.ascender >> 6);
- _user_info[9] = (char*)(face->size->metrics.descender >> 6);
+ _user_info[9] = (char*)((-1 * face->size->metrics.descender) >> 6);
_user_info[10] = (char*)(face->glyph->metrics.horiBearingY >> 6);
_user_info[11] = (char*)(face->glyph->advance.x >> 6);
- emu_pause();
}
}
}
import org.xwt.util.*;
import java.io.*;
import java.util.zip.*;
+import java.util.*;
// FEATURE: use streams, not memoryfont's
// FEATURE: kerning pairs
public class Freetype {
- Freetype() { }
+ public Freetype() { }
- private static org.xwt.mips.Interpreter vm = null;
+ private static byte[] image = null;
+ private static final int FONT_RESERVED = 256*1024;
- public static void renderGlyphs(Res res, int pointsize, int firstGlyph, int lastGlyph, Cache glyphCache) {
+ private org.xwt.mips.Interpreter vm = null;
+ private Res loadedStream = null;
+
+ public void loadFontByteStream(Res res) {
try {
+ Log.log(this, "loading font " + res.getDescriptiveName());
+ loadedStream = res;
InputStream is = res.getInputStream();
byte[] fontstream = InputStreamToByteArray.convert(is);
+ if (image == null) image = InputStreamToByteArray.convert(Main.builtin.getInputStream("freetype.mips"));
+ vm = new org.xwt.mips.Interpreter(image);
+ int baseAddr = vm.sbrk(FONT_RESERVED);
+ vm.copyout(fontstream, baseAddr, fontstream.length);
+ vm.setUserInfo(0, baseAddr);
+ vm.setUserInfo(1, fontstream.length);
+ vm.start(new String[]{ "freetype.mips" });
+ vm.execute();
+ } catch (Exception e) {
+ Log.log(this, e);
+ }
+ }
- synchronized(Freetype.class) {
- if (vm == null) {
- InputStream bis = Platform.getBuiltinInputStream();
- ZipInputStream zis = new ZipInputStream(bis);
- for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("freetype.mips"); ze = zis.getNextEntry()) { }
- byte[] image = InputStreamToByteArray.convert(zis);
- vm = new org.xwt.mips.Interpreter(image);
- vm.start(new String[]{ "freetype.mips" });
- vm.execute();
- }
-
- int FONT_RESERVED = 256*1024;
- int baseAddr = vm.sbrk(FONT_RESERVED);
-
- vm.copyout(fontstream, baseAddr, fontstream.length);
- vm.setUserInfo(0, baseAddr);
- vm.setUserInfo(1, fontstream.length);
- vm.setUserInfo(2, firstGlyph);
- vm.setUserInfo(3, lastGlyph);
- vm.setUserInfo(4, pointsize);
-
- long start = System.currentTimeMillis();
+ public synchronized void renderGlyph(Res res, Glyph glyph) {
+ try {
+ if (loadedStream != res) loadFontByteStream(res);
+ vm.setUserInfo(2, (int)glyph.c);
+ vm.setUserInfo(3, (int)glyph.c);
+ vm.setUserInfo(4, glyph.pointsize);
+ long start = System.currentTimeMillis();
+ vm.execute();
+ glyph.max_ascent = vm.getUserInfo(8);
+ glyph.max_descent = vm.getUserInfo(9);
+ glyph.baseline = vm.getUserInfo(10);
+ glyph.advance = vm.getUserInfo(11);
+
+ int width = vm.getUserInfo(6);
+ int height = vm.getUserInfo(7);
+ if (width == 0 || height == 0) {
+ Log.log(Freetype.class, "warning glyph has zero width/height");
- for(int g = firstGlyph; g <= lastGlyph; g++) {
- vm.execute();
-
- Glyph glyph = new Glyph();
- glyph.max_ascent = vm.getUserInfo(8);
- glyph.max_descent = vm.getUserInfo(9);
- glyph.baseline = vm.getUserInfo(10);
- glyph.advance = vm.getUserInfo(11);
- glyph.c = (char)g;
-
- int width = vm.getUserInfo(6);
- int height = vm.getUserInfo(7);
-
- if (width == 0 || height == 0) {
- Log.log(Freetype.class, "warning glyph " + g + " has zero width/height");
-
- } else {
- byte[] data = new byte[width * height];
- int addr = vm.getUserInfo(5);
- vm.copyin(addr,data,width*height);
- glyph.p = Platform.createAlphaOnlyPicture(data, width, height);
- }
-
- glyphCache.put(res, new Integer((g << 16) | pointsize), glyph);
- }
+ } else {
+ byte[] data = new byte[width * height];
+ int addr = vm.getUserInfo(5);
+ vm.copyin(addr,data,width*height);
+ glyph.p = Platform.createAlphaOnlyPicture(data, width, height);
}
} catch (Exception e) {
- Log.log(Freetype.class, e);
+ Log.log(this, e);
}
}
}