com.openhtmltopdf.pdfboxout.PdfBoxSVGReplacedElement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openhtmltopdf-pdfbox Show documentation
Show all versions of openhtmltopdf-pdfbox Show documentation
Openhtmltopdf is a CSS 2.1 renderer written in Java. This artifact supports PDF output with Apache PDF-BOX 2.
package com.openhtmltopdf.pdfboxout;
import java.awt.Point;
import org.w3c.dom.Element;
import com.openhtmltopdf.extend.SVGDrawer;
import com.openhtmltopdf.layout.LayoutContext;
import com.openhtmltopdf.render.BlockBox;
import com.openhtmltopdf.render.RenderingContext;
public class PdfBoxSVGReplacedElement implements PdfBoxReplacedElement {
private final Element e;
private final SVGDrawer svg;
private Point point = new Point(0, 0);
private final int width;
private final int height;
private final int dotsPerPixel;
public PdfBoxSVGReplacedElement(Element e, SVGDrawer svgImpl, int cssWidth, int cssHeight, int dotsPerPixel) {
this.e = e;
this.svg = svgImpl;
this.width = cssWidth;
this.height = cssHeight;
this.dotsPerPixel = dotsPerPixel;
}
@Override
public int getIntrinsicWidth() {
if (this.width >= 0) {
// CSS takes precedence over width and height defined on element.
return this.width;
}
else {
// Seems to need dots rather than pixels.
return this.svg.getSVGWidth(e) * this.dotsPerPixel;
}
}
@Override
public int getIntrinsicHeight() {
if (this.height >= 0) {
// CSS takes precedence over width and height defined on element.
return this.height;
}
else {
// Seems to need dots rather than pixels.
return this.svg.getSVGHeight(e) * this.dotsPerPixel;
}
}
@Override
public Point getLocation() {
return point;
}
@Override
public void setLocation(int x, int y) {
point.setLocation(x, y);
}
@Override
public void detach(LayoutContext c) {
}
@Override
public boolean isRequiresInteractivePaint() {
return false;
}
@Override
public boolean hasBaseline() {
return false;
}
@Override
public int getBaseline() {
return 0;
}
@Override
public void paint(RenderingContext c, PdfBoxOutputDevice outputDevice, BlockBox box) {
svg.drawSVG(e, outputDevice, c, point.getX(), point.getY(), this.dotsPerPixel * 96f);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy