1 package org.xwt.translators;
6 // FEATURE: use streams, not memoryfont's
7 // FEATURE: kerning pairs
12 private static org.xwt.mips.Interpreter vm = null;
14 public static synchronized void renderGlyphs(Res res, int pointsize, int firstGlyph, int lastGlyph, Cache glyphCache) {
17 vm = new org.xwt.mips.Interpreter("freetype.mips");
18 vm.start(new String[]{ "freetype.mips"});
22 int FONT_RESERVED = 256*1024;
23 int baseAddr = vm.sbrk(FONT_RESERVED);
25 byte[] fontstream = Resources.isToByteArray(res.getInputStream());
26 vm.copyout(fontstream, baseAddr, fontstream.length);
27 vm.setUserInfo(0, baseAddr);
28 vm.setUserInfo(1, fontstream.length);
29 vm.setUserInfo(2, firstGlyph);
30 vm.setUserInfo(3, lastGlyph);
31 vm.setUserInfo(4, pointsize);
33 long start = System.currentTimeMillis();
35 for(int g = firstGlyph; g <= lastGlyph; g++) {
38 Glyph glyph = new Glyph();
39 glyph.max_ascent = vm.getUserInfo(8);
40 glyph.max_descent = vm.getUserInfo(9) - glyph.max_ascent;
41 glyph.baseline = vm.getUserInfo(10);
42 glyph.advance = vm.getUserInfo(11);
45 gid.width = vm.getUserInfo(6);
46 gid.height = vm.getUserInfo(7);
47 if (gid.data == null || gid.data.length < gid.width * gid.height)
48 gid.data = new int[gid.width * gid.height];
49 int addr = vm.getUserInfo(5);
51 for(int i=0; i<gid.width * gid.height; i += 4) {
52 int val = vm.memRead(addr + i);
53 for (int k = 3; k >= 0; k--) {
54 if (i + k < gid.width * gid.height)
55 gid.data[i + k] = (val & 0xff) << 24;
60 glyph.p = Platform.createPicture(gid);
61 glyphCache.put(res, new Integer((g << 16) | pointsize), glyph);
63 } catch (Exception e) {
64 Log.log(Font.class, e);
68 private static GlyphImageDecoder gid = new GlyphImageDecoder();
69 private static class GlyphImageDecoder extends ImageDecoder {
72 public int getWidth() { return width; }
73 public int getHeight() { return height; }
74 public int[] getData() { return data; }