From a05e958733d401711a850ea77b9dfb3120fe7c8b Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 16 Jan 2005 07:07:50 +0000 Subject: [PATCH] fix bug that prevented scar image from loading darcs-hash:20050116070750-5007d-49ca5aed20c1421b4a60393f51f4604ed9046ca8.gz --- src/org/ibex/core/Box.java | 6 +----- src/org/ibex/core/Ibex.java | 15 ++++++-------- src/org/ibex/core/Main.java | 40 +++++++++++++++++++++++------------- src/org/ibex/graphics/Picture.java | 24 ++++++++++++++-------- 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/org/ibex/core/Box.java b/src/org/ibex/core/Box.java index 0ccd421..5133251 100644 --- a/src/org/ibex/core/Box.java +++ b/src/org/ibex/core/Box.java @@ -60,11 +60,7 @@ public final class Box extends JS.Obj implements Callable { // FIXME memory leak static Basket.Map boxToCursor = new Basket.Hash(500, 3); - static final Font DEFAULT_FONT; - static { - try { DEFAULT_FONT = Font.getFont((JS)Main.builtin.get(JSU.S("fonts/vera/Vera.ttf")), 10); } - catch(JSExn e) { throw new Error("Error loading default font: " + e); } - } + public static final Font DEFAULT_FONT = Font.getFont(Main.vera, 10); // Flags ////////////////////////////////////////////////////////////////////// diff --git a/src/org/ibex/core/Ibex.java b/src/org/ibex/core/Ibex.java index 4110a8d..5efc608 100644 --- a/src/org/ibex/core/Ibex.java +++ b/src/org/ibex/core/Ibex.java @@ -74,9 +74,9 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { case "ui.font.wait": return METHOD; case "ui.font.width": return METHOD; case "ui.font.height": return METHOD; - case "ui.font.sansserif": return Main.builtin.get(JSU.S("fonts/vera/Vera.ttf")); - case "ui.font.monospace": return Main.builtin.get(JSU.S("fonts/vera/VeraMono.ttf")); - case "ui.font.serif": return Main.builtin.get(JSU.S("fonts/vera/VeraSe.ttf")); + case "ui.font.sansserif": return Main.vera; + case "ui.font.monospace": return Main.vera; + case "ui.font.serif": return Main.vera; case "ui.browser": return METHOD; case "ui.mouse": return getSub(name); case "ui.mouse.button": @@ -370,7 +370,7 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { // FEATURE: move this into builtin.xwar public Blessing bless(JS b) throws JSExn { return new Ibex.Blessing(b, this, null, null); } // JS:FIXME: This doesn't properly handle traps - public static class Blessing extends JS.Obj { + public static class Blessing extends JS.Clone { private Ibex ibex; private Template t = null; public JS parentkey = null; @@ -378,16 +378,15 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { public JS clonee; private Basket.Map cache = new Basket.Hash(); public Blessing(JS clonee, Ibex ibex, Blessing parent, JS parentkey) throws JSExn { - this.clonee = clonee; this.ibex = ibex; this.parentkey = parentkey; this.parent = parent; } + super(clonee); this.clonee = clonee; this.ibex = ibex; this.parentkey = parentkey; this.parent = parent; } public JS get(JS key) throws JSExn { if (JSU.isString(key) && JSU.toString(key).equals("")) return getStatic(); if (cache.get(key) != null) return (JS)cache.get(key); - JS ret = new Blessing(clonee.get(key), ibex, this, key); + JS ret = new Blessing(super.get(key), ibex, this, key); cache.put(key, ret); return ret; } public static Blessing getBlessing(JS js) { - // CHECKME: is unclone() good enough or do we need getClonee() in Cloneable? while (js instanceof JS.Clone && !(js instanceof Blessing)) js = js.unclone(); if (!(js instanceof Blessing)) return null; return (Blessing)js; @@ -440,8 +439,6 @@ public final class Ibex extends JS.Obj implements JS.Cloneable { if (t == null) throw new JSExn("No such template " + JSU.str(parentkey)); return t; } - // JS:FIXME: Blessing shouldn't need to roll its own JS.Clone implementation - //public InputStream getInputStream() throws JSExn, IOException { return clonee.getInputStream(); } } } diff --git a/src/org/ibex/core/Main.java b/src/org/ibex/core/Main.java index a9c35df..4fd76f0 100644 --- a/src/org/ibex/core/Main.java +++ b/src/org/ibex/core/Main.java @@ -11,7 +11,6 @@ import org.ibex.js.*; import org.ibex.util.*; import org.ibex.plat.*; import org.ibex.graphics.*; -import org.ibex.core.builtin.*; /** Entry point for the Ibex Engine; handles splash screen, initial xwar loading, and argument processing */ public class Main { @@ -29,7 +28,15 @@ public class Main { public static String origin = null; public static String initialTemplate = null; - public static final Fountain builtin = new Fountain.Zip(new Fountain.FromInputStream(Platform.getBuiltinInputStream())); + //public static final Fountain builtin = new Fountain.Zip(new Fountain.FromInputStream(Platform.getBuiltinInputStream())); + public static final Fountain vera; + static { + Fountain temp = null; + try { + temp = new Fountain.FromInputStream(Encode.JavaSourceCode.decode(Vera.data)); + } catch (Exception e) { Log.error(Main.class, e); } + vera = temp; + } public static void printUsage() { System.err.println("Usage: ibex [-lawp] [ url | file | directory ]"); @@ -99,19 +106,24 @@ public class Main { if (Log.on) Log.info(Main.class, "loading xwar"); final Ibex ibex = new Ibex(rr); - org.ibex.graphics.Surface.scarImage = - Picture.load(new Fountain.FromInputStream(Encode.JavaSourceCode.decode(Scar.data)), - new Callable() { - private final JS[] callargs = new JS[1]; - public Object run(Object o) throws JSExn,UnknownHostException { - if (Log.on) Log.info(Main.class, "invoking initial template"); - try { - callargs[0] = new Box(); - ibex.resolveString(startupTemplate, false).call(null, callargs); - } finally { callargs[0] = null; } - return null; - } }); + try { + JS blessed = ibex.bless(new Fountain.FromInputStream(Encode.JavaSourceCode.decode(org.ibex.core.builtin.Scar.data))); + org.ibex.graphics.Surface.scarImage = Platform.createPicture(blessed); + } catch (Exception e) { + Log.error(Main.class, e); + } + Platform.Scheduler.add(new Callable() { + private final JS[] callargs = new JS[1]; + public Object run(Object o) throws JSExn,UnknownHostException { + if (Log.on) Log.info(Main.class, "invoking initial template"); + try { + callargs[0] = new Box(); + ibex.resolveString(startupTemplate, false).call(null, callargs); + } finally { callargs[0] = null; } + return null; + } }); + Platform.Scheduler.init(); } } diff --git a/src/org/ibex/graphics/Picture.java b/src/org/ibex/graphics/Picture.java index ce7b20b..fb236ea 100644 --- a/src/org/ibex/graphics/Picture.java +++ b/src/org/ibex/graphics/Picture.java @@ -29,6 +29,20 @@ public class Picture { public int[] data = null; ///< argb samples public boolean isLoaded = false; ///< true iff the image is fully loaded + public Picture(InputStream is) throws IOException { load(this, is); } + + public static void load(Picture p, InputStream in) throws IOException { + PushbackInputStream pbis = new PushbackInputStream(in); + int firstByte = pbis.read(); + if (firstByte == -1) throw new IOException("empty stream reading image"); + pbis.unread(firstByte); + if ((firstByte & 0xff) == 'G') GIF.load(pbis, p); + else if ((firstByte & 0xff) == 137) PNG.load(pbis, p); + else if ((firstByte & 0xff) == 0xff) Platform.decodeJPEG(pbis, p); + else throw new IOException("couldn't figure out image type from first byte"); + p.loaded(); + } + /** invoked when an image is fully loaded; subclasses can use this to initialize platform-specific constructs */ protected void loaded() { isLoaded = true; } @@ -52,15 +66,7 @@ public class Picture { } if (in == null) { Log.warn(Picture.class, "couldn't load image for stream " + stream.unclone()); return; } try { - PushbackInputStream pbis = new PushbackInputStream(in); - int firstByte = pbis.read(); - if (firstByte == -1) throw new JSExn("empty stream reading image"); - pbis.unread(firstByte); - if ((firstByte & 0xff) == 'G') GIF.load(pbis, p); - else if ((firstByte & 0xff) == 137) PNG.load(pbis, p); - else if ((firstByte & 0xff) == 0xff) Platform.decodeJPEG(pbis, p); - else throw new JSExn("couldn't figure out image type from first byte"); - p.loaded(); + load(p, in); Platform.Scheduler.add(callback); } catch (Exception e) { Log.info(this, "exception while loading image"); -- 1.7.10.4