Java源码示例:org.fit.cssbox.layout.Viewport

示例1
public void renderElementBackground(ElementBox elem)
{
    AffineTransform origAt = null;
    AffineTransform at = Transform.createTransform(elem);
    if (at != null)
    {
        origAt = g.getTransform();
        g.transform(at);
    }
    
    if (elem instanceof Viewport)
        clearViewport((Viewport) elem);
    drawBackground(elem, g);
    
    if (origAt != null)
        g.setTransform(origAt);
}
 
示例2
/**
 * Computes the target position of an image within the background according to its CSS
 * background-position and background-size values. Specifics of the viewport background
 * are considered as well.
 * @param img The image to be positioned
 * @return the target position and size of the image
 */
protected Rectangle computeTargetImagePosition(BackgroundImage img)
{
    final Rectangle pos;
    if (isViewportOwner() && ((Viewport) getOwner()).getRootBox() != null)
    {
        // compute the image position within the root box
        final ElementBox root = ((Viewport) getOwner()).getRootBox();
        pos = img.getComputedPosition(root);
        // position the image within the viewport
        Dimension ofs = ((Viewport) getOwner()).getBackgroundOffset();
        pos.x += ofs.width;
        pos.y += ofs.height;
    }
    else
    {
        pos = img.getComputedPosition();
    }
    return pos;
}
 
示例3
/**
 * Updates the layout. It is designed to do a re-layout only, not to process
 * input data again.
 * 
 * @param root
 *            the root
 * @param newDimension
 *            the new dimension
 * @param cba
 *            the CSSBoxAnalyzer
 * @return the list
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public List<ElementSpec> update(Viewport root, Dimension newDimension, CSSBoxAnalyzer cba) throws IOException
{
    if (cba == null)
        throw new IllegalArgumentException("CSSBoxAnalyzer can not be NULL !!!\nProvide your custom implementation or check instantiation of DefaultAnalyzer object...");

    elements = new LinkedList<ElementSpec>();
    elements.add(new ElementSpec(SimpleAttributeSet.EMPTY, ElementSpec.EndTagType));
    order = 0;

    Viewport vp;
    try
    {
        vp = cba.update(newDimension);
    } catch (Exception e)
    {
        throw new IOException(e);
    }

    vp.draw(this);
    
    return elements;
}
 
示例4
@Override
protected void renderViewport(Viewport viewport)
{
    // adds clearCanvas before rendering
    GraphicsRenderer r = (GraphicsRenderer) getRenderer();
    r.init(viewport);
    r.clearCanvas();
    viewport.draw(r);
    r.close();
}
 
示例5
protected void clearViewport(Viewport vp)
{
    Color bgcolor = convertColor(vp.getConfig().getViewportBackgroundColor());
    if (getViewportBackground() != null && getViewportBackground().getBgcolor() != null)
        bgcolor = convertColor(getViewportBackground().getBgcolor());
    
    Color color = g.getColor();
    g.setColor(bgcolor);
    g.fillRect(0, 0, Math.round(vp.getCanvasWidth()), Math.round(vp.getCanvasHeight()));
    g.setColor(color);
}
 
示例6
public ElementBackground(ElementBox owner)
{
    this.owner = owner;
    this.viewportOwner = (owner instanceof Viewport);
    bounds = owner.getAbsoluteBorderBounds();
    clipped = owner.getClippedBounds();
    if (viewportOwner)
        bounds = clipped;  //for the root box (Viewport), use the whole clipped content (not only the visible part)
    clipped = new Rectangle(clipped.x - bounds.x, clipped.y - bounds.y, clipped.width, clipped.height); //make the clip relative to the background bounds
}
 
示例7
@Override
public Viewport analyze(DocumentSource docSource, Dimension dim)
        throws Exception
{
    DOMSource parser = new DefaultDOMSource(docSource);
    w3cdoc = parser.parse();

    // Create the CSS analyzer
    DOMAnalyzer da = new DOMAnalyzer(w3cdoc, docSource.getURL());
    da.attributesToStyles();
    da.addStyleSheet(null, CSSNorm.stdStyleSheet(), DOMAnalyzer.Origin.AGENT);
    da.addStyleSheet(null, CSSNorm.userStyleSheet(), DOMAnalyzer.Origin.AGENT);
    da.getStyleSheets();
    
    BufferedImage tmpImg = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
    canvas = new BrowserCanvas(da.getRoot(), da, docSource.getURL());
    canvas.setImage(tmpImg);
    canvas.getConfig().setLoadImages(true);
    canvas.getConfig().setLoadBackgroundImages(true);
    canvas.createLayout(dim);

    return canvas.getViewport();
}
 
示例8
@Override
public Viewport update(Dimension dim)
        throws Exception
{
    canvas.createLayout(dim);
    return canvas.getViewport();
}
 
示例9
/**
 * Renders the viewport using an SVGRenderer to the given output writer.
 *
 * @param vp
 * @param out
 * @throws IOException
 */
protected void writeSVG(Viewport vp, Writer out) throws IOException
{

    //obtain the viewport bounds depending on whether we are clipping to viewport size or using the whole page
    float w = vp.getClippedContentBounds().width;
    float h = vp.getClippedContentBounds().height;

    SVGDOMRenderer render = new SVGDOMRenderer(w, h, out);
    vp.draw(render);
    render.close();
}
 
示例10
@Override
public void init(Viewport vp)
{
    this.vp = vp;
    findViewportBackgroundSource();
}
 
示例11
/**
 * Returns the viewport for which the renderer was initialized.
 * @return The viewport box.
 */
public Viewport getViewport()
{
    return vp;
}
 
示例12
/**
 * Reads input data and converts them to "elements"
 * 
 * @param docSource
 *            the document source
 * @param cba
 *            the instance of {@link CSSBoxAnalyzer}
 * @param dim
 *            the dimension
 * @return the list of elements. Note that, this method returns instance of
 *         LinkedList.
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public List<ElementSpec> read(DocumentSource docSource, CSSBoxAnalyzer cba, Dimension dim)
        throws IOException
{
    // ale ked sa pouzije setText() neviem nic o url, nic sa nenastavuje ,
    // moze byt null
    // (URL) doc.getProperty(Document.StreamDescriptionProperty)

    if (cba == null)
        throw new IllegalArgumentException("CSSBoxAnalyzer can not be NULL !!!\nProvide your custom implementation or check instantiation of DefaultAnalyzer object...");

    elements = new Vector<ElementSpec>();// ArrayList<ElementSpec>(1024);
    elements.add(new ElementSpec(SimpleAttributeSet.EMPTY, ElementSpec.EndTagType));
    order = 0;

    // System.err.print("used Reader and encoding ? " +
    // is.getCharacterStream() + "  ,  ");
    // InputStreamReader r = (InputStreamReader)is.getCharacterStream();
    // System.err.println(r.getEncoding());

    Viewport vp;
    try
    {
        // System.err.println("analyzing...");
        vp = cba.analyze(docSource, dim);
        // System.err.println("analyzing finished...");
    } catch (Exception e)
    {
        throw new IOException(e);
    }

    //Use this for "drawing" the boxes. This constructs the element list.
    vp.draw(this);

    // System.err.println("num. of elements : " + elements.size());
    // System.err.println("Root min width : " + root.getMinimalWidth() +
    // " ,normal width : " + root.getWidth() + " ,maximal width : " +
    // root.getMaximalWidth());

    // TODO po skonceni nacitavania aj nejake info spravit
    // >> Document.TitleProperty - observer, metainfo
    return elements;
}
 
示例13
private SimpleAttributeSet buildElement(ElementBox box)
{
    if (box instanceof InlineBox)
    {
        return buildInlineBox((InlineBox) box);
    }
    else if (box instanceof Viewport)
    { // -- the boxes
        return buildViewport((Viewport) box);
    }
    else if (box instanceof TableBox)
    { // -- tables
        return buildTableBox((TableBox) box);
    }
    else if (box instanceof TableCaptionBox)
    {
        return buildTableCaptionBox((TableCaptionBox) box);
    }
    else if (box instanceof TableBodyBox)
    {
        return buildTableBodyBox((TableBodyBox) box);
    }
    else if (box instanceof TableRowBox)
    {
        return buildTableRowBox((TableRowBox) box);
    }
    else if (box instanceof TableCellBox)
    {
        return buildTableCellBox((TableCellBox) box);
    }
    else if (box instanceof TableColumnGroup)
    {
        return buildTableColumnGroup((TableColumnGroup) box);
    }
    else if (box instanceof TableColumn)
    {
        return buildTableColumn((TableColumn) box);
    }
    else if (box instanceof BlockTableBox)
    {
        return buildBlockTableBox((BlockTableBox) box);
    }
    else if (box instanceof ListItemBox)
    {
        return buildListItemBox((ListItemBox) box);
    }
    else if (box instanceof BlockBox)
    {
        return buildBlockBox((BlockBox) box);
    }
    else
    {
        System.err.println("Unknown BOX : " + box.getClass().getName());
        return null;
    }
}
 
示例14
private SimpleAttributeSet buildViewport(Viewport box)
{
    return commonBuild(box, Constants.VIEWPORT);
}
 
示例15
/**
 * Updates layout, using new dimensions.
 * 
 * @param doc
 *            the document
 * @param root
 *            the root box
 * @param dim
 *            new dimension
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void update(SwingBoxDocument doc, Viewport root, Dimension dim)
        throws IOException
{
    ContentReader rdr = new ContentReader();
    List<ElementSpec> elements = rdr.update(root, dim, getCSSBoxAnalyzer());
    ElementSpec elementsArray[] = elements.toArray(new ElementSpec[0]);
    doc.create(elementsArray);
}
 
示例16
/**
 * 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);
 
示例17
/**
 * Analyzes content from InputSource and constructs a tree of Boxes, which
 * is further processed.
 * 
 * @param docSource
 *            the document source implementation.
 * @param dim
 *            the dimension of rendering area.
 * @return the tree of boxes.
 * @throws Exception
 *             some exception may be thrown during processing.
 */
Viewport analyze(DocumentSource docSource, Dimension dim) throws Exception;
 
示例18
/**
 * Updates the layout according to the new dimension (the tree structure of
 * view objects has to be modified).
 * 
 * @param dim
 *            the new dimension of rendering area.
 * @return the box
 * @throws Exception
 *             some exception may be thrown during processing.
 */
Viewport update(Dimension dim) throws Exception;