2003/09/23 08:25:00
[org.ibex.core.git] / src / org / xwt / translators / Font.java
index 8026108..de71002 100644 (file)
@@ -19,8 +19,8 @@ public class Font {
 
                 InputStream bis = Platform.getBuiltinInputStream();
                 ZipInputStream zis = new ZipInputStream(bis);
-                for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("freetype.mips"); ze = zis.getNextEntry());
-                byte[] image = Resources.isToByteArray(zis);
+                for(ZipEntry ze = zis.getNextEntry(); ze != null && !ze.getName().equals("freetype.mips"); ze = zis.getNextEntry()) { }
+                byte[] image = InputStreamToByteArray.convert(zis);
                 vm = new org.xwt.mips.Interpreter(image);
                 vm.start(new String[]{ "freetype.mips" });
                 vm.execute();
@@ -29,7 +29,7 @@ public class Font {
             int FONT_RESERVED = 256*1024;
             int baseAddr = vm.sbrk(FONT_RESERVED);
             
-            byte[] fontstream = Resources.isToByteArray(res.getInputStream());
+            byte[] fontstream = InputStreamToByteArray.convert(res.getInputStream());
             vm.copyout(fontstream, baseAddr, fontstream.length);
             vm.setUserInfo(0, baseAddr);
             vm.setUserInfo(1, fontstream.length);
@@ -49,35 +49,25 @@ public class Font {
                 glyph.advance = vm.getUserInfo(11);
                 glyph.c = (char)g;
                 
-                gid.width = vm.getUserInfo(6);
-                gid.height = vm.getUserInfo(7);
-                if (gid.data == null || gid.data.length < gid.width * gid.height)
-                    gid.data = new int[gid.width * gid.height];
+                int width = vm.getUserInfo(6);
+                int height = vm.getUserInfo(7);
+                int[] data = new int[width * height];
                 int addr = vm.getUserInfo(5);
 
-                for(int i=0; i<gid.width * gid.height; i += 4) {
+                for(int i=0; i<width * height; i += 4) {
                     int val = vm.memRead(addr + i);
                     for (int k = 3; k >= 0; k--) {
-                        if (i + k < gid.width * gid.height)
-                            gid.data[i + k] = (val & 0xff) << 24;
+                        if (i + k < width * height)
+                            data[i + k] = (val & 0xff) << 24;
                         val >>>= 8;
                     }
                 }
                 
-                glyph.p = Platform.createPicture(gid);
+                glyph.p = Platform.createPicture(data, width, height);
                 glyphCache.put(res, new Integer((g << 16) | pointsize), glyph);
             }
         } catch (Exception e) {
             Log.log(Font.class, e);
         }
     }
-
-    private static GlyphImageDecoder gid = new GlyphImageDecoder();
-    private static class GlyphImageDecoder extends ImageDecoder {
-       int[] data = null;
-       int width, height;
-       public int getWidth() { return width; }
-       public int getHeight() { return height; }
-       public int[] getData() { return data; }
-    }
 }