本文整理汇总了Java中org.fit.cssbox.layout.BackgroundImage类的典型用法代码示例。如果您正苦于以下问题:Java BackgroundImage类的具体用法?Java BackgroundImage怎么用?Java BackgroundImage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BackgroundImage类属于org.fit.cssbox.layout包,在下文中一共展示了BackgroundImage类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertBgImg
import org.fit.cssbox.layout.BackgroundImage; //导入依赖的package包/类
/**
* Draws element background image to OUTPUT
*/
private void insertBgImg (ElementBox elem, int i, float plusOffset, float plusHeight) {
for (BackgroundImage bimg : elem.getBackgroundImages()) {
BufferedImage img = bimg.getBufferedImage();
float pageStart = i*pageFormat.getHeight();
float pageEnd = (i+1)*pageFormat.getHeight();
if (img != null && elem.getAbsoluteContentY()*resCoef+plusOffset < pageEnd && (elem.getAbsoluteContentY()+img.getHeight())*resCoef+plusOffset+plusHeight > pageStart) {
// calculates resized coordinates in CSSBox form
float startX = (elem.getAbsoluteContentX()-elem.getPadding().left)*resCoef;
float startY = (elem.getAbsoluteContentY()-elem.getPadding().top)*resCoef+plusOffset-i*pageFormat.getHeight();
float width = img.getWidth()*resCoef;
float height = img.getHeight()*resCoef;
// correction of long backgrounds
if (height > 5*plusHeight) height += plusHeight;
// inserts image
insertImagePDFBox(img, startX, startY, width, height);
}
}
}
示例2: renderElementBackground
import org.fit.cssbox.layout.BackgroundImage; //导入依赖的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);
}