本文整理匯總了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);
}