Point maxOffset = root.getLayer().getMaxOffset(); root.getLayer().setPositionsFinalized(true); intrinsic_size = new Dimension(maxOffset.x, maxOffset.y);
Dimension intrinsic_size = root.getLayer().getPaintingDimension(c);
    public void doActualLayout(Graphics g) {        //Uu.p("doActualLayout called");        this.removeAll();        if (g == null) {            return;        }        if (doc == null) {            return;        }                LayoutContext c = newLayoutContext(pageInfo, (Graphics2D) g);        synchronized (this) {            if (this.layout_context != null) this.layout_context.stopRendering();            this.layout_context = c;        }        c.setRenderQueue(queue);        setRenderWidth((int) c.getExtents().getWidth());        getSharedContext().getTextRenderer().setupGraphics(c.getGraphics());                long start = System.currentTimeMillis();                BlockBox root = Boxing.preLayout(c, new DomToplevelNode(doc));        setRootBox(root);                Boxing.realLayout(c, root, new DomToplevelNode(doc));                long end = System.currentTimeMillis();                XRLog.layout(Level.INFO, "Layout took " + (end - start) + "ms");                if (!c.isStylesAllPopped()) {            XRLog.layout(Level.SEVERE, "mismatch in style popping and pushing");        }        if (c.shouldStop()) {//interrupted layout            return;        }// if there is a fixed child then we need to set opaque to false// so that the entire viewport will be repainted. this is slower// but that's the hit you get from using fixed layout        if (root.getLayer().containsFixedContent()) {            super.setOpaque(false);        } else {            super.setOpaque(true);        }                XRLog.layout(Level.FINEST, "after layout: " + root);                Point maxOffset = root.getLayer().getMaxOffset();        root.getLayer().setPositionsFinalized(true);        intrinsic_size = new Dimension(maxOffset.x, maxOffset.y);                setPreferredSize(intrinsic_size);        revalidate();                // if doc is shorter than viewport        // then stretch canvas to fill viewport exactly        // then adjust the body element accordingly        if (enclosingScrollPane != null) {            if (intrinsic_size.height < enclosingScrollPane.getViewport().getHeight()) {                //Uu.p("int height is less than viewport height");                // XXX Not threadsafe                if (enclosingScrollPane.getViewport().getHeight() != this.getHeight()) {                    this.setPreferredSize(new Dimension(                            intrinsic_size.width, enclosingScrollPane.getViewport().getHeight()));                    this.revalidate();                }                //Uu.p("need to do the body hack");                if (root != null) {                    root.height = enclosingScrollPane.getViewport().getHeight();                    bodyExpandHack(root, root.height);                    intrinsic_size.height = root.height;                }            }                         // turn on simple scrolling mode if there's any fixed elements            if (root.getLayer().containsFixedContent()) {                // Uu.p("is fixed");                enclosingScrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);            } else {                // Uu.p("is not fixed");                enclosingScrollPane.getViewport().setScrollMode(default_scroll_mode);            }        }         if (isUseThreads()) {            queue.dispatchRepaintEvent(new ReflowEvent(ReflowEvent.LAYOUT_COMPLETE));        }        this.fireDocumentLoaded();    }