1 package org.xwt.translators;
5 import java.util.zip.*;
7 // FEATURE: use streams, not memoryfont's
8 // FEATURE: kerning pairs
9 public class Freetype {
13 private static org.xwt.mips.Interpreter vm = null;
15 public static void renderGlyphs(Res res, int pointsize, int firstGlyph, int lastGlyph, Cache glyphCache) {
18 InputStream is = res.getInputStream();
19 byte[] fontstream = InputStreamToByteArray.convert(is);
21 synchronized(Freetype.class) {
23 InputStream bis = Platform.getBuiltinInputStream();
24 ZipInputStream zis = new ZipInputStream(bis);
25 for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("freetype.mips"); ze = zis.getNextEntry()) { }
26 byte[] image = InputStreamToByteArray.convert(zis);
27 vm = new org.xwt.mips.Interpreter(image);
28 vm.start(new String[]{ "freetype.mips" });
32 int FONT_RESERVED = 256*1024;
33 int baseAddr = vm.sbrk(FONT_RESERVED);
35 vm.copyout(fontstream, baseAddr, fontstream.length);
36 vm.setUserInfo(0, baseAddr);
37 vm.setUserInfo(1, fontstream.length);
38 vm.setUserInfo(2, firstGlyph);
39 vm.setUserInfo(3, lastGlyph);
40 vm.setUserInfo(4, pointsize);
42 long start = System.currentTimeMillis();
44 for(int g = firstGlyph; g <= lastGlyph; g++) {
47 Glyph glyph = new Glyph();
48 glyph.max_ascent = vm.getUserInfo(8);
49 glyph.max_descent = vm.getUserInfo(9);
50 glyph.baseline = vm.getUserInfo(10);
51 glyph.advance = vm.getUserInfo(11);
54 int width = vm.getUserInfo(6);
55 int height = vm.getUserInfo(7);
57 if (width == 0 || height == 0) {
58 Log.log(Freetype.class, "warning glyph " + g + " has zero width/height");
61 byte[] data = new byte[width * height];
62 int addr = vm.getUserInfo(5);
63 vm.copyin(addr,data,width*height);
64 glyph.p = Platform.createAlphaOnlyPicture(data, width, height);
67 glyphCache.put(res, new Integer((g << 16) | pointsize), glyph);
70 } catch (Exception e) {
71 Log.log(Freetype.class, e);