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 synchronized void renderGlyphs(Res res, int pointsize, int firstGlyph, int lastGlyph, Cache glyphCache) {
20 InputStream bis = Platform.getBuiltinInputStream();
21 ZipInputStream zis = new ZipInputStream(bis);
22 for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("freetype.mips"); ze = zis.getNextEntry()) { }
23 byte[] image = InputStreamToByteArray.convert(zis);
24 vm = new org.xwt.mips.Interpreter(image);
25 vm.start(new String[]{ "freetype.mips" });
29 int FONT_RESERVED = 256*1024;
30 int baseAddr = vm.sbrk(FONT_RESERVED);
32 byte[] fontstream = InputStreamToByteArray.convert(res.getInputStream());
33 vm.copyout(fontstream, baseAddr, fontstream.length);
34 vm.setUserInfo(0, baseAddr);
35 vm.setUserInfo(1, fontstream.length);
36 vm.setUserInfo(2, firstGlyph);
37 vm.setUserInfo(3, lastGlyph);
38 vm.setUserInfo(4, pointsize);
40 long start = System.currentTimeMillis();
42 for(int g = firstGlyph; g <= lastGlyph; g++) {
45 Glyph glyph = new Glyph();
46 glyph.max_ascent = vm.getUserInfo(8);
47 glyph.max_descent = vm.getUserInfo(9) - glyph.max_ascent;
48 glyph.baseline = vm.getUserInfo(10);
49 glyph.advance = vm.getUserInfo(11);
52 int width = vm.getUserInfo(6);
53 int height = vm.getUserInfo(7);
54 int[] data = new int[width * height];
55 int addr = vm.getUserInfo(5);
57 for(int i=0; i<width * height; i += 4) {
58 int val = vm.memRead(addr + i);
59 for (int k = 3; k >= 0; k--) {
60 if (i + k < width * height)
61 data[i + k] = (val & 0xff) << 24;
66 glyph.p = Platform.createPicture(data, width, height);
67 glyphCache.put(res, new Integer((g << 16) | pointsize), glyph);
69 } catch (Exception e) {
70 Log.log(Freetype.class, e);