- b.render(x2, y2, w2, h2, buf);
- }
-
- private void renderBorder(int x, int y, int w, int h, DoubleBuffer buf) {
- int bw = border[4].getWidth();
- int bh = border[4].getHeight();
- buf.setClip(x, y, w + x, h + y);
-
- if ((color & 0xFF000000) != 0xFF000000) {
- // if the color is null, we have to be very careful about drawing the corners
- //if (Log.verbose) Log.log(this, "WARNING: (color == null && border != null) on box with border " + imageToNameMap.get(border[4]));
-
- // upper left corner
- buf.drawPicture(border[4],
- pos(0), pos(1), pos(0) + bw / 2, pos(1) + bh / 2,
- 0, 0, bw / 2, bh / 2);
-
- // upper right corner
- buf.drawPicture(border[4],
- pos(0) + size(0) - bw / 2, pos(1), pos(0) + size(0), pos(1) + bh / 2,
- bw - bw / 2, 0, bw, bh / 2);
-
- // lower left corner
- buf.drawPicture(border[4],
- pos(0), pos(1) + size(1) - bh / 2, pos(0) + bw / 2, pos(1) + size(1),
- 0, bh - bh / 2, bw / 2, bh);
-
- // lower right corner
- buf.drawPicture(border[4],
- pos(0) + size(0) - bw / 2, pos(1) + size(1) - bh / 2, pos(0) + size(0), pos(1) + size(1),
- bw - bw / 2, bh - bh / 2, bw, bh);
-
- } else {
- buf.drawPicture(border[4], pos(0), pos(1)); // upper left corner
- buf.drawPicture(border[4], pos(0) + size(0) - bw, pos(1)); // upper right corner
- buf.drawPicture(border[4], pos(0), pos(1) + size(1) - bh); // lower left corner
- buf.drawPicture(border[4], pos(0) + size(0) - bw, pos(1) + size(1) - bh); // lower right corner
-
- }
-
- // top and bottom edges
- buf.setClip(max(x, pos(0) + bw / 2), y, min(x + w, pos(0) + size(0) - bw / 2), h + y);
- for(int i = max(x, pos(0) + bw / 2); i + 100 < min(x + w, pos(0) + size(0) - bw / 2); i += 100) {
- buf.drawPicture(border[0], i, pos(1));
- buf.drawPicture(border[1], i, pos(1) + size(1) - bh / 2);
- }
- buf.drawPicture(border[0], min(x + w, pos(0) + size(0) - bw / 2) - 100, pos(1));
- buf.drawPicture(border[1], min(x + w, pos(0) + size(0) - bw / 2) - 100, pos(1) + size(1) - bh / 2);
-
- // left and right edges
- buf.setClip(x, max(y, pos(1) + bh / 2), w + x, min(y + h, pos(1) + size(1) - bh / 2));
- for(int i = max(y, pos(1) + bh / 2); i + 100 < min(y + h, pos(1) + size(1) - bh / 2); i += 100) {
- buf.drawPicture(border[2], pos(0), i);
- buf.drawPicture(border[3], pos(0) + size(0) - bw / 2, i);
- }
- buf.drawPicture(border[2], pos(0), min(y + h, pos(1) + size(1) - bh / 2) - 100);
- buf.drawPicture(border[3], pos(0) + size(0) - bw / 2, min(y + h, pos(1) + size(1) - bh / 2) - 100);
-
- buf.setClip(0, 0, buf.getWidth(), buf.getHeight());
- }
-
- void renderStretchedImage(int x, int y, int w, int h, DoubleBuffer buf) {
- buf.setClip(x, y, w + x, h + y);
- int bw = border == null ? 0 : border[4].getHeight();
- int bh = border == null ? 0 : border[4].getWidth();
-
- int width = pos(0) + size(0) - bw / 2 - pos(0) + bw / 2;
- int height = pos(1) + size(1) - bh / 2 - pos(1) + bh / 2;
-
- if (fixedaspect) {
- int hstretch = width / image.getWidth();
- if (hstretch == 0) hstretch = -1 * image.getWidth() / width;
- int vstretch = height / image.getHeight();
- if (vstretch == 0) vstretch = -1 * image.getHeight() / height;
-
- if (hstretch < vstretch) {
- height = image.getHeight() * width / image.getWidth();
- } else {
- width = image.getWidth() * height / image.getHeight();
- }
- }
-
- buf.drawPicture(image,
- pos(0) + bw / 2,
- pos(1) + bh / 2,
- pos(0) + bw / 2 + width,
- pos(1) + bh / 2 + height,
- 0, 0, image.getWidth(), image.getHeight());
- buf.setClip(0, 0, buf.getWidth(), buf.getHeight());
- }
-
- void renderTiledImage(int x, int y, int w, int h, DoubleBuffer buf) {
- int iw = image.getWidth();
- int ih = image.getHeight();
- int bh = border == null ? 0 : border[4].getWidth();
- int bw = border == null ? 0 : border[4].getHeight();
-
- for(int i=(x - pos(0) - bw)/iw; i <= (x + w - pos(0) - bw)/iw; i++) {
- for(int j=(y - pos(1) - bh)/ih; j<= (y + h - pos(1) - bh)/ih; j++) {
-
- int dx1 = max(i * iw + pos(0), x);
- int dy1 = max(j * ih + pos(1), y);
- int dx2 = min((i+1) * iw + pos(0), x + w);
- int dy2 = min((j+1) * ih + pos(1), y + h);
-
- int sx1 = dx1 - (i*iw) - pos(0);
- int sy1 = dy1 - (j*ih) - pos(1);
- int sx2 = dx2 - (i*iw) - pos(0);
- int sy2 = dy2 - (j*ih) - pos(1);
-
- if (dx2 - dx1 > 0 && dy2 - dy1 > 0 && sx2 - sx1 > 0 && sy2 - sy1 > 0)
- buf.drawPicture(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);
- }
- }
-
- }
-
- void renderText(int x, int y, int w, int h, DoubleBuffer buf) {
-
- if ((textcolor & 0xFF000000) == 0x00000000) return;
- buf.setClip(x, y, w + x, h + y);
-
- 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,
- pos(0) + pad(0),
- pos(1) + pad(1) + Platform.getMaxAscent(font()) - 1,
- textcolor);
- }
-
- buf.setClip(0, 0, buf.getWidth(), buf.getHeight());
-
- int i=0; while(i<font().length() && !Character.isDigit(font().charAt(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,
- textcolor);
-
- } 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(0) + pad(0) + textdim(0),
- pos(1) + pad(1) + (xwf == null ? Platform.getMaxAscent(font()) : xwf.getMaxAscent()) + 2 + 1,
- textcolor);
- }
-
- }
-
-
- // Methods to implement org.mozilla.javascript.Scriptable //////////////////////////////////////
-
- /** Returns the i_th child */
- public Object get(int i, Scriptable start) {
- if (redirect == null) return null;
- if (redirect != this) return redirect.get(i, start);
- return i >= numChildren() ? null : getChild(i);
- }
-
- /**
- * Inserts value as child i; calls remove() if necessary.
- * This method handles "reinserting" one of your children properly.
- * INVARIANT: after completion, getChild(min(i, numChildren())) == newnode
- * WARNING: O(n) runtime, unless i == numChildren()
- */
- public void put(int i, Scriptable start, Object value) {
-
- if (value != null && !(value instanceof Box)) {
- if (Log.on) Log.log(this, "attempt to set a numerical property on a box to anything other than a box at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
-
- } else if (redirect == null) {
- if (Log.on) Log.log(this, "attempt to add/remove children to/from a node with a null redirect at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
-
- } else if (redirect != this) {
- Box b = value == null ? (Box)redirect.get(i, null) : (Box)value;
- redirect.put(i, null, value);
- put("0", null, b);
-
- } else if (value == null) {
- if (i >= 0 && i < numChildren()) {
- Box b = getChild(i);
- b.remove();
- put("0", null, b);
- }
-
- } else if (value instanceof RootProxy) {
- if (Log.on) Log.log(this, "attempt to reparent a box via its proxy object at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
-
- } else {
- Box newnode = (Box)value;
-
- // check if box being moved is currently target of a redirect
- for(Box cur = newnode.getParent(); cur != null; cur = cur.getParent())
- if (cur.redirect == newnode) {
- if (Log.on) Log.log(this, "attempt to move a box that is the target of a redirect at "+
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- return;
- }
-
- // check for recursive ancestor violation
- for(Box cur = this; cur != null; cur = cur.getParent())
- if (cur == newnode) {
- if (Log.on) Log.log(this, "attempt to make a node a parent of its own ancestor at " +
- Context.enter().interpreterSourceFile + ":" + Context.enter().interpreterLine);
- return;
- }
-
- if (numKids > 15 && children == null) convert_to_array();
- newnode.remove();
- newnode.parent = this;
-
- if (children == null) {
- if (firstKid == null) {
- firstKid = newnode;
- newnode.prevSibling = newnode;
- newnode.nextSibling = newnode;
- } else if (i >= numKids) {
- newnode.prevSibling = firstKid.prevSibling;
- newnode.nextSibling = firstKid;
- firstKid.prevSibling.nextSibling = newnode;
- firstKid.prevSibling = newnode;
- } else {
- Box cur = firstKid;
- for(int j=0; j<i; j++) cur = cur.nextSibling;
- newnode.prevSibling = cur.prevSibling;
- newnode.nextSibling = cur;
- cur.prevSibling.nextSibling = newnode;
- cur.prevSibling = newnode;
- if (i == 0) firstKid = newnode;
- }
- numKids++;
-
- } else {
- if (i >= children.size()) {
- newnode.indexInParent = children.size();
- children.addElement(newnode);
- } else {
- children.insertElementAt(newnode, i);
- for(int j=i; j<children.size(); j++)
- getChild(j).indexInParent = j;
- }
- }
- newnode.setSurface(surface);
-
- // need both of these in case child was already uncalc'ed
- newnode.mark_for_prerender();
- mark_for_prerender();
-
- newnode.dirty();
- sync_cmin_to_children();
-
- // note that JavaScript box[0] will invoke put(int i), not put(String s)
- put("0", null, newnode);
- }