improvements to Doc.java, corresponding fixes to the reference
[org.ibex.core.git] / src / org / ibex / Ibex.java
index 1b55939..d1e3284 100644 (file)
@@ -65,6 +65,8 @@ public final class Ibex extends JS.Cloneable {
         case "ui": return getSub("ui");
         case "ui.font": return getSub("ui.font");
         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("fonts/vera/Vera.ttf");
         case "ui.font.monospace": return Main.builtin.get("fonts/vera/VeraMono.ttf");
         case "ui.font.serif": return Main.builtin.get("fonts/vera/VeraSe.ttf");
@@ -198,7 +200,8 @@ public final class Ibex extends JS.Cloneable {
                     //#end
                 case 3:
                     //#switch(name)
-                    case "font.wait":
+                    case "ui.font.height": return N(Font.getFont((Stream)a, JS.toInt(b)).textheight((String)c));
+                    case "ui.font.wait":
                         try {
                             JS.UnpauseCallback callback = JS.pause();
                             Font font = Font.getFont((Stream)a, JS.toInt(b));
@@ -206,6 +209,8 @@ public final class Ibex extends JS.Cloneable {
                         } catch (JS.NotPauseableException npe) {
                             JS.error("can't wait for a font in a foreground thread");
                         }
+                        return null;
+                    case "ui.font.width": return N(Font.getFont((Stream)a, JS.toInt(b)).textwidth((String)c));
                     //#end
                     break;
             }
@@ -215,7 +220,7 @@ public final class Ibex extends JS.Cloneable {
             throw new JSExn("invalid argument for ibex object method "+name+"()");
         }
 
-        throw new JSExn("invalid number of arguments for ibex object method "+name+"()");
+        throw new JSExn("invalid number of arguments ("+nargs+") for ibex object method "+name+"()");
     }
 
     public Stream url2res(String url) throws JSExn {
@@ -324,10 +329,15 @@ public final class Ibex extends JS.Cloneable {
         private Template t = null;
         public Object parentkey = null;
         public Blessing parent = null;
+        private Hash cache = new Hash();
         public Blessing(JS.Cloneable clonee, Ibex ibex, Blessing parent, Object parentkey) {
             super(clonee); this.ibex = ibex; this.parentkey = parentkey; this.parent = parent; }
         public Object get(Object key) throws JSExn {
-            return key.equals("") ? ((Object)getStatic()) : (new Blessing((JS.Cloneable)clonee.get(key), ibex, this, key));
+            if (key.equals("")) return ((Object)getStatic());
+            if (cache.get(key) != null) return cache.get(key);
+            Object ret = new Blessing((JS.Cloneable)clonee.get(key), ibex, this, key);
+            cache.put(key, ret);
+            return ret;
         }
         public static Blessing getBlessing(Object o) {
             if (!(o instanceof JS)) return null;
@@ -351,9 +361,7 @@ public final class Ibex extends JS.Cloneable {
         }
         public JSScope getStatic() {
             try {
-                // FIXME background?
-                if (t == null)
-                    t = Template.buildTemplate(parentkey + ".t", parent.get(parentkey + ".t"), ibex);
+                if (t == null) t = Template.buildTemplate(parentkey + ".t", parent.get(parentkey + ".t"), ibex);
                 return t.staticScope;
             } catch (Exception e) {
                 Log.error(this, e);