當前位置: 首頁>>代碼示例>>Java>>正文


Java LengthSet類代碼示例

本文整理匯總了Java中org.fit.cssbox.layout.LengthSet的典型用法代碼示例。如果您正苦於以下問題:Java LengthSet類的具體用法?Java LengthSet怎麽用?Java LengthSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LengthSet類屬於org.fit.cssbox.layout包,在下文中一共展示了LengthSet類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: renderElementBackground

import org.fit.cssbox.layout.LengthSet; //導入依賴的package包/類
public void renderElementBackground(ElementBox eb)
{
    Rectangle bb = eb.getAbsoluteBorderBounds();
    if (eb instanceof Viewport)
        bb = eb.getClippedBounds(); //for the root box (Viewport), use the whole clipped content
    Color bg = eb.getBgcolor();

    //background color
    if (bg != null)
    {
        String style = "stroke:none;fill-opacity:1;fill:" + colorString(bg);
        out.println("<rect x=\"" + bb.x + "\" y=\"" + bb.y + "\" width=\"" + bb.width + "\" height=\"" + bb.height + "\" style=\"" + style + "\" />");
    }
    
    //background image
    if (eb.getBackgroundImages() != null && eb.getBackgroundImages().size() > 0)
    {
        for (BackgroundImage bimg : eb.getBackgroundImages())
        {
            BufferedImage img = bimg.getBufferedImage();
            if (img != null)
            {
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                try
                {
                    ImageIO.write(img, "png", os);
                } catch (IOException e) {
                    out.println("<!-- I/O error: " + e.getMessage() + " -->");
                }
                char[] data = Base64Coder.encode(os.toByteArray());
                String imgdata = "data:image/png;base64," + new String(data);
                int ix = bb.x + eb.getBorder().left;
                int iy = bb.y + eb.getBorder().top;
                int iw = bb.width - eb.getBorder().right - eb.getBorder().left;
                int ih = bb.height - eb.getBorder().bottom - eb.getBorder().top;
                out.println("<image x=\"" + ix + "\" y=\"" + iy + "\" width=\"" + iw + "\" height=\"" + ih + "\" xlink:href=\"" + imgdata + "\" />");
            }
        }
        
    }

    //border
    LengthSet borders = eb.getBorder();
    if (borders.top > 0)
        writeBorderSVG(eb, bb.x, bb.y, bb.x + bb.width, bb.y, "top", borders.top, 0, borders.top/2);
    if (borders.right > 0)
        writeBorderSVG(eb, bb.x + bb.width, bb.y, bb.x + bb.width, bb.y + bb.height, "right", borders.right, -borders.right/2, 0);
    if (borders.bottom > 0)
        writeBorderSVG(eb, bb.x, bb.y + bb.height, bb.x + bb.width, bb.y + bb.height, "bottom", borders.bottom, 0, -borders.bottom/2);
    if (borders.left > 0)
        writeBorderSVG(eb, bb.x, bb.y, bb.x, bb.y + bb.height, "left", borders.left, borders.left/2, 0);
}
 
開發者ID:radkovo,項目名稱:CSSBox,代碼行數:53,代碼來源:SVGRenderer.java


注:本文中的org.fit.cssbox.layout.LengthSet類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。