From 03244d623ddb6104dd0c87487e5222d562632149 Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 06:59:36 +0000 Subject: [PATCH] 2003/04/30 07:00:50 darcs-hash:20040130065936-2ba56-5ed47173d965c875d8609a2deafe7117a233c996.gz --- src/org/xwt/Box.java | 52 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/org/xwt/Box.java b/src/org/xwt/Box.java index f0645aa..1e55cb8 100644 --- a/src/org/xwt/Box.java +++ b/src/org/xwt/Box.java @@ -189,8 +189,11 @@ public final class Box extends JSObject { /** If redirect is enabled, this holds the Box redirected to */ Box redirect = this; - /** the Box's font -- you must call textupdate() after changing this */ - String font = Platform.getDefaultFont(); + /** the Box's font, null inherits from parent -- you must call textupdate() after changing this */ + String font = null; + + /** if font == null, this might be a cached copy of the inherited ancestor font */ + String cachedFont = null; /** The surface for us to render on; null if none; INVARIANT: surface == getParent().surface */ Surface surface = null; @@ -373,16 +376,34 @@ public final class Box extends JSObject { set(dmin, 1, (image == null ? 0 : image.getHeight()) + (border == null ? 0 : border[0].getHeight()) * 2); } + /** returns the actual font that should be used to render this box */ + private String font() { + if (font != null) return font; + if (font == null && cachedFont != null) return cachedFont; + if (getParent() != null) return cachedFont = getParent().font(); + return cachedFont = Platform.getDefaultFont(); + } + + /** this must be called when a box's font changes */ + void fontChanged() { + textupdate(); + for(Box b = getChild(0); b != null; b = b.nextSibling()) + if (b.font == null) { + b.cachedFont = font(); + b.fontChanged(); + } + } + /** This must be called when font or text is changed */ void textupdate() { if (text.equals("")) { set(textdim, 0, 0); set(textdim, 1, 0); } else { - XWF xwf = XWF.getXWF(font); + XWF xwf = XWF.getXWF(font()); if (xwf == null) { - set(textdim, 0, Platform.stringWidth(font, text)); - set(textdim, 1, (Platform.getMaxAscent(font) + Platform.getMaxDescent(font))); + set(textdim, 0, Platform.stringWidth(font(), text)); + set(textdim, 1, (Platform.getMaxAscent(font()) + Platform.getMaxDescent(font()))); } else { set(textdim, 0, xwf.stringWidth(text)); set(textdim, 1, (xwf.getMaxAscent() + xwf.getMaxDescent())); @@ -1014,34 +1035,34 @@ public final class Box extends JSObject { if ((textcolor & 0xFF000000) == 0x00000000) return; buf.setClip(x, y, w + x, h + y); - XWF xwf = XWF.getXWF(font); + XWF xwf = XWF.getXWF(font()); if (xwf != null) { xwf.drawString(buf, text, pos(0) + pad(0), pos(1) + pad(1) + xwf.getMaxAscent() - 1, textcolor); } else { - buf.drawString(font, text, + buf.drawString(font(), text, pos(0) + pad(0), - pos(1) + pad(1) + Platform.getMaxAscent(font) - 1, + pos(1) + pad(1) + Platform.getMaxAscent(font()) - 1, textcolor); } buf.setClip(0, 0, buf.getWidth(), buf.getHeight()); - int i=0; while(i i) { + if (font().lastIndexOf('d') > i) { for(int j = pos(0) + pad(0); j < pos(0) + pad(0) + textdim(0); j += 2) - buf.fillRect(j, pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font) : xwf.getMaxAscent()) + 2, - j + 1, pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font) : xwf.getMaxAscent()) + 2 + 1, + buf.fillRect(j, pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2, + j + 1, pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2 + 1, textcolor); - } else if (font.lastIndexOf('u') > i) { + } else if (font().lastIndexOf('u') > i) { buf.fillRect(pos(0) + pad(0), - pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font) : xwf.getMaxAscent()) + 2, + pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2, pos(0) + pad(0) + textdim(0), - pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font) : xwf.getMaxAscent()) + 2 + 1, + pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2 + 1, textcolor); } @@ -1316,6 +1337,7 @@ public final class Box extends JSObject { /** remove this node from its parent; INVARIANT: whenever the parent of a node is changed, remove() gets called. */ public void remove() { + cachedFont = null; if (parent == null) { if (surface != null) surface.dispose(true); return; -- 1.7.10.4