2003/04/10 01:41:43
[org.ibex.core.git] / src / org / xwt / Box.java
index 7dd88a5..caa7c8a 100644 (file)
@@ -408,13 +408,14 @@ public final class Box extends JSObject {
 
     /** loads the image described by string str, possibly blocking for a network load */
     static ImageDecoder getImage(String str, final Function callback) {
-        boolean ispng = false;
 
         if (str.indexOf(':') == -1) {
             String s = str;
             byte[] b = Resources.getResource(Resources.resolve(s + ".png", null));
-            if (b == null) return null;
-            return PNG.decode(new ByteArrayInputStream(b), str);
+           if (b != null) return PNG.decode(new ByteArrayInputStream(b), str);
+            b = Resources.getResource(Resources.resolve(s + ".jpeg", null));
+           if (b != null) return Platform.decodeJPEG(new ByteArrayInputStream(b), str);
+           return null;
             
         } else {
             Thread thread = Thread.currentThread();
@@ -427,10 +428,6 @@ public final class Box extends JSObject {
             mythread.setPriority(Thread.MIN_PRIORITY);
             mythread.done.release();
             try {
-                // FIXME use mime types here, not extensions
-                if (str.endsWith(".jpeg") || str.endsWith(".jpg"))
-                    str = "http://xmlrpc.xwt.org/jpeg2png/" + str.substring(str.indexOf("//") + 2);
-
                 HTTP http = new HTTP(str);
                 final HTTP.HTTPInputStream in = http.GET();
                 final int contentLength = in.getContentLength();
@@ -461,9 +458,10 @@ public final class Box extends JSObject {
                             return ret;
                         }
                     };
-                
+
                 if (str.endsWith(".gif")) return GIF.decode(is, str);
-                else return PNG.decode(is, str);
+                else if (str.endsWith(".jpeg") || str.endsWith(".jpg")) return Platform.decodeJPEG(is, str);
+               else return PNG.decode(is, str);
 
             } catch (IOException e) {
                 if (Log.on) Log.log(Box.class, "error while trying to load an image from " + str);
@@ -504,7 +502,7 @@ public final class Box extends JSObject {
                 if (Log.on) Log.log(Box.class, "unable to load image " + s + " at " +
                                     Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
                 return;
-            }
+           }
             if (sizetoimage) syncSizeToImage();
             dirty();
         }
@@ -798,7 +796,7 @@ public final class Box extends JSObject {
             for(Box bt = getChild(0); bt != null; bt = bt.nextSibling()) {
                 if (bt.absolute || bt.invisible) continue;
 
-               int btmax = (o == 0 && bt.hshrink) || (o == 1 && bt.vshrink) ? bt.cmin(o) : bt.dmax(o);
+                int btmax = (o == 0 && bt.hshrink) || (o == 1 && bt.vshrink) ? bt.cmin(o) : bt.dmax(o);
                 bt.set(size, o, bound(bt.cmin(o), factor * bt.flex, btmax));
                 total += bt.size(o);
 
@@ -827,7 +825,7 @@ public final class Box extends JSObject {
         while(goal != total && total != last) {
             last = total;
             for(Box bt = getChild(0); bt != null; bt = bt.nextSibling()) {
-               int btmax = (o == 0 && bt.hshrink) || (o == 1 && bt.vshrink) ? bt.cmin(o) : bt.dmax(o);
+                int btmax = (o == 0 && bt.hshrink) || (o == 1 && bt.vshrink) ? bt.cmin(o) : bt.dmax(o);
                 int newsize = bound(bt.cmin(o), bt.size(o) + (goal > total ? 1 : -1), btmax);
                 total += newsize - bt.size(o);
                 bt.set(size, o, newsize);