1 package org.xwt.translators;
5 import java.util.zip.*;
7 import org.bouncycastle.util.encoders.Base64;
9 // FEATURE: use streams, not memoryfont's
10 // FEATURE: kerning pairs
11 public class Freetype {
15 private static byte[] image = null;
17 private int mem_allocated = 0;
18 private org.xwt.mips.Runtime vm = null;
20 private Res loadedStream = null;
22 public void loadFontByteStream(Res res) {
24 Log.log(this, "loading font " + res);
26 InputStream is = res.getInputStream();
27 byte[] fontstream = InputStreamToByteArray.convert(is);
28 if (image == null) image = InputStreamToByteArray.convert(Main.builtin.getInputStream("freetype.mips"));
29 //vm = new org.xwt.mips.Interpreter(image);
30 vm = new FreetypeVM();
31 int baseAddr = vm.sbrk(fontstream.length);
32 vm.copyout(fontstream, baseAddr, fontstream.length);
33 vm.setUserInfo(0, baseAddr);
34 vm.setUserInfo(1, fontstream.length);
35 vm.start(new String[]{ "freetype.mips" });
37 } catch (Exception e) {
42 public synchronized void renderGlyph(Font.Glyph glyph) throws IOException {
48 if (loadedStream != glyph.font.res) loadFontByteStream(glyph.font.res);
49 vm.setUserInfo(2, (int)glyph.c);
50 vm.setUserInfo(3, (int)glyph.c);
51 vm.setUserInfo(4, glyph.font.pointsize);
52 long start = System.currentTimeMillis();
54 glyph.font.max_ascent = vm.getUserInfo(8);
55 glyph.font.max_descent = vm.getUserInfo(9);
56 glyph.baseline = vm.getUserInfo(10);
57 glyph.advance = vm.getUserInfo(11);
59 width = vm.getUserInfo(6);
60 height = vm.getUserInfo(7);
62 data = new byte[width * height];
63 int addr = vm.getUserInfo(5);
64 vm.copyin(addr,data,width*height);
66 if (width == 0 || height == 0) Log.log(Freetype.class, "warning glyph has zero width/height");
67 glyph.p = Platform.createAlphaOnlyPicture(data, width, height);
68 } catch (Exception e) {