Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement #237 add support for svg files in img element #254

Merged
merged 1 commit into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ public ReplacedElement createReplacedElement(LayoutContext context, BlockBox box
return new Java2DSVGReplacedElement(e, _svgImpl, cssWidth, cssHeight, box, context);
} else if (nodeName.equals("object") && _objectDrawerFactory != null) {
FSObjectDrawer drawer = _objectDrawerFactory.createDrawer(e);
if (drawer != null)
if (drawer != null) {
return new Java2DObjectDrawerReplacedElement(e, drawer, cssWidth, cssHeight,
context.getSharedContext().getDotsPerPixel());
}
}
} else if (nodeName.equals("img") && _svgImpl != null) {
String srcAttr = e.getAttribute("src");
if (srcAttr != null && srcAttr.endsWith(".svg")) {
return new Java2DSVGReplacedElement(uac.getXMLResource(srcAttr).getDocument().getDocumentElement(), _svgImpl, cssWidth, cssHeight, box, context);
}
}

/*
* Default: Just let the base class handle everything
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public ReplacedElement createReplacedElement(LayoutContext c, BlockBox box,
} else if (nodeName.equals("img")) {
String srcAttr = e.getAttribute("src");
if (srcAttr != null && srcAttr.length() > 0) {

//handle the case of linked svg from img tag
if (srcAttr.endsWith(".svg") && _svgImpl != null) {
return new PdfBoxSVGReplacedElement(uac.getXMLResource(srcAttr).getDocument().getDocumentElement(), _svgImpl, cssWidth, cssHeight, box, c, c.getSharedContext());
}

FSImage fsImage = uac.getImageResource(srcAttr).getImage();
if (fsImage != null) {
boolean hasMaxHeight = !box.getStyle().isMaxHeightNone();
Expand Down
17 changes: 11 additions & 6 deletions openhtmltopdf-svg-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-transcoder</artifactId>
<version>1.9</version>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-transcoder</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>xmlgraphics-commons</artifactId>
<version>2.1</version>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>xmlgraphics-commons</artifactId>
<version>2.1</version>
</dependency>
</dependencies>

Expand Down