1 package org.xwt.translators;
3 import org.ibex.util.*;
6 import org.xwt.mips.Runtime;
8 // FEATURE: use streams, not memoryfont's
9 // FEATURE: kerning pairs
10 public class Freetype {
14 private int mem_allocated = 0;
15 private Runtime vm = null;
17 private Stream loadedStream = null;
19 public void loadFontByteStream(Stream res) {
21 Log.info(this, "loading font " + res);
23 InputStream is = Stream.getInputStream(res);
24 byte[] fontstream = InputStreamToByteArray.convert(is);
25 vm = (Runtime)Class.forName("org.xwt.translators.MIPSApps").newInstance();
26 int baseAddr = vm.sbrk(fontstream.length);
27 vm.copyout(fontstream, baseAddr, fontstream.length);
28 vm.setUserInfo(0, baseAddr);
29 vm.setUserInfo(1, fontstream.length);
30 vm.start(new String[]{ "freetype" });
32 if(vm.getState() == Runtime.DONE) throw new Error("Freetype VM exited: " + vm.exitStatus());
33 } catch (Exception e) {
38 public synchronized void renderGlyph(Font.Glyph glyph) throws IOException {
40 Log.debug(this, "rasterizing glyph " + glyph.c + " of font " + glyph.font);
41 if (loadedStream != glyph.font.stream) loadFontByteStream(glyph.font.stream);
42 vm.setUserInfo(2, (int)glyph.c);
43 vm.setUserInfo(3, (int)glyph.c);
44 vm.setUserInfo(4, glyph.font.pointsize);
45 long start = System.currentTimeMillis();
47 glyph.font.max_ascent = vm.getUserInfo(8);
48 glyph.font.max_descent = vm.getUserInfo(9);
49 glyph.baseline = vm.getUserInfo(10);
50 glyph.advance = vm.getUserInfo(11);
52 glyph.width = vm.getUserInfo(6);
53 glyph.height = vm.getUserInfo(7);
55 glyph.data = new byte[glyph.width * glyph.height];
56 int addr = vm.getUserInfo(5);
57 vm.copyin(addr, glyph.data, glyph.width * glyph.height);
58 glyph.isLoaded = true;
60 } catch (Exception e) {