Skip to content

Commit

Permalink
Merge pull request #254 from syjer/svg-src-img
Browse files Browse the repository at this point in the history
implement #237 add support for svg files in img element
  • Loading branch information
danfickle authored Jul 16, 2018
2 parents 02c2a66 + d80996a commit 8a3168d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
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

0 comments on commit 8a3168d

Please sign in to comment.