// Path: src/main/java/org/fit/cssbox/render/BoxRenderer.java
// public interface BoxRenderer extends Closeable
// {
//     /**
//      * Initializes the renderer for rendering a ready-to-render viewport.
//      * @param vp The viewport that will be rendered. The viewport must be fully initialized
//      * and ready to draw.
//      */
//     public void init(Viewport vp);
//     
//     /**
//      * Initializes the rendering of an element. This is called before any contents of the element
//      * or child boxes are rendered. Note that the {@link BoxRenderer#renderElementBackground} method 
//      * may be called before this method.
//      * @param elem the element
//      */
//     public void startElementContents(ElementBox elem);
//     
//     /**
//      * Finishes the rendering of an element. This is called after all contents of the element
//      * and the child boxes are rendered.
//      * @param elem the element
//      */
//     public void finishElementContents(ElementBox elem);
//     
//     /**
//      * Renders the background and borders of the given element box according to its style.
//      * @param elem
//      */
//     public void renderElementBackground(ElementBox elem);
//     
//     /**
//      * Renders the marker (the bullet or item number) used by the list-item boxes.
//      * @param elem the list-item box
//      */
//     public void renderMarker(ListItemBox elem);
//     
//     /**
//      * Renders the text represented by a text box according to its computed style.
//      * @param text
//      */
//     public void renderTextContent(TextBox text);
//     
//     /**
//      * Renders the contents of a replaced box.
//      * @param box
//      */
//     public void renderReplacedContent(ReplacedBox box);
//     
//     /**
//      * Finishes and the output.
//      */
//     public void close() throws IOException;
//     
// }


import java.util.Vector;
import org.fit.cssbox.render.BoxRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import cz.vutbr.web.css.CSSFactory;
	{
        //first round: position most boxes
        recomputeAbs = false;
        for (int i = 0; i < getSubBoxNumber(); i++)
            getSubBox(i).absolutePositions();
        if (recomputeAbs)
        {
            //second round: some reference boxes used, recompute once again
            if (scontext != null) //clear the stacking context if it exists -- the child contexts will register again
                scontext.clear();
            for (int i = 0; i < getSubBoxNumber(); i++)
                getSubBox(i).absolutePositions();
            recomputeAbs = false;
        }
	}
	
    /**
     * Sets the current renderer and draws the whole subtree using the given renderer.
     * @param renderer The renderer to be used for drawing.
     */
    public void draw(BoxRenderer renderer)
    {
        this.renderer = renderer;
        drawStackingContext(false);
    }
	
    /**
     * Obtains the current renderer used for painting the boxes.
     * @return current renderer.
     */
// Path: src/main/java/org/fit/cssbox/render/BoxRenderer.java
// public interface BoxRenderer extends Closeable
// {
//     /**
//      * Initializes the renderer for rendering a ready-to-render viewport.
//      * @param vp The viewport that will be rendered. The viewport must be fully initialized
//      * and ready to draw.
//      */
//     public void init(Viewport vp);
//     
//     /**
//      * Initializes the rendering of an element. This is called before any contents of the element
//      * or child boxes are rendered. Note that the {@link BoxRenderer#renderElementBackground} method 
//      * may be called before this method.
//      * @param elem the element
//      */
//     public void startElementContents(ElementBox elem);
//     
//     /**
//      * Finishes the rendering of an element. This is called after all contents of the element
//      * and the child boxes are rendered.
//      * @param elem the element
//      */
//     public void finishElementContents(ElementBox elem);
//     
//     /**
//      * Renders the background and borders of the given element box according to its style.
//      * @param elem
//      */
//     public void renderElementBackground(ElementBox elem);
//     
//     /**
//      * Renders the marker (the bullet or item number) used by the list-item boxes.
//      * @param elem the list-item box
//      */
//     public void renderMarker(ListItemBox elem);
//     
//     /**
//      * Renders the text represented by a text box according to its computed style.
//      * @param text
//      */
//     public void renderTextContent(TextBox text);
//     
//     /**
//      * Renders the contents of a replaced box.
//      * @param box
//      */
//     public void renderReplacedContent(ReplacedBox box);
//     
//     /**
//      * Finishes and the output.
//      */
//     public void close() throws IOException;
//     
// }


// Path: src/main/java/org/fit/cssbox/layout/Viewport.java
import java.util.Vector;
import org.fit.cssbox.render.BoxRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import cz.vutbr.web.css.CSSFactory;

	{
        //first round: position most boxes
        recomputeAbs = false;
        for (int i = 0; i < getSubBoxNumber(); i++)
            getSubBox(i).absolutePositions();
        if (recomputeAbs)
        {
            //second round: some reference boxes used, recompute once again
            if (scontext != null) //clear the stacking context if it exists -- the child contexts will register again
                scontext.clear();
            for (int i = 0; i < getSubBoxNumber(); i++)
                getSubBox(i).absolutePositions();
            recomputeAbs = false;
        }
	}
	
    /**
     * Sets the current renderer and draws the whole subtree using the given renderer.
     * @param renderer The renderer to be used for drawing.
     */
    public void draw(BoxRenderer renderer)
    {
        this.renderer = renderer;
        drawStackingContext(false);
    }
	
    /**
     * Obtains the current renderer used for painting the boxes.
     * @return current renderer.
     */
    public BoxRenderer getRenderer()