2003/10/29 00:53:07
[org.ibex.core.git] / src / org / xwt / Box.java.pp
index 81439f7..7cae9dd 100644 (file)
@@ -507,19 +507,27 @@ public final class Box extends JS.Scope {
 
     void renderText(int x, int y, int clipx, int clipy, int clipw, int cliph, PixelBuffer buf) {
         for(int i=0; i<text.length(); i++) {
-            // FIXME: clipping
-            char c = text.charAt(i);
-            Glyph g = Glyph.getGlyph(font, fontsize, c);
-            if (g.p != null)
-                buf.drawPictureAlphaOnly(g.p,
-                                         x,
-                                         y + g.max_ascent - g.baseline + g.max_descent,
-                                         x,
-                                         y + g.max_ascent - g.baseline + g.max_descent,
-                                         x + g.p.getWidth(),
-                                         y + g.max_ascent - g.baseline + g.max_descent + g.p.getHeight(),
-                                         textcolor);
-            x += g.advance;
+            final char c = text.charAt(i);
+           Glyph g = Glyph.getCachedGlyph(font, fontsize, c);
+           if (g != null) {
+               int top = y + g.max_ascent - g.baseline + g.max_descent;
+               if (g.p != null)
+                   buf.drawPictureAlphaOnly(g.p, x, top,
+                                            clipx, clipy, clipx + clipw, clipy + cliph, textcolor);
+               x += g.advance;
+           } else {
+               final int fontsize_final = fontsize;
+               final Res font_final = font;
+                ThreadMessage.newthread(new JS.Callable() {
+                        public Object call(JS.Array args) {
+                           Glyph.renderGlyph(font_final, fontsize_final, c);   
+                           recompute_font();
+                           Box b = Box.this; MARK_FOR_REFLOW_b;
+                           dirty();
+                           return null;
+                       } });
+               return;
+           }
         }
     }
 
@@ -848,9 +856,23 @@ public final class Box extends JS.Scope {
             textheight = 0;
             if (text == null) return;
             for(int i=0; i<text.length(); i++) {
-                Glyph g = Glyph.getGlyph(font, fontsize, text.charAt(i));
-                textwidth += g.advance;
-                textheight = g.max_ascent;
+                Glyph g = Glyph.getCachedGlyph(font, fontsize, text.charAt(i));
+               if (g == null) {
+                   final int fontsize_final = fontsize;
+                   final Res font_final = font;
+                   final char c = text.charAt(i);
+                   ThreadMessage.newthread(new JS.Callable() {
+                           public Object call(JS.Array args) {
+                               Glyph.renderGlyph(font_final, fontsize_final, c);       
+                               recompute_font();
+                               Box b = Box.this; MARK_FOR_REFLOW_b;
+                               dirty();
+                               return null;
+                           } });
+               } else {
+                   textwidth += g.advance;
+                   textheight = g.max_ascent;
+               }
             }
         } catch (Exception e) {
             Log.log(this, e);