diff options
-rw-r--r-- | docs/examples/svg/embedding.fo | 10 | ||||
-rw-r--r-- | docs/examples/svg/external.fo | 5 | ||||
-rw-r--r-- | docs/examples/svg/view.svg | 11 | ||||
-rw-r--r-- | src/org/apache/fop/layout/inline/ForeignObjectArea.java | 8 | ||||
-rw-r--r-- | src/org/apache/fop/render/pdf/PDFRenderer.java | 12 | ||||
-rw-r--r-- | src/org/apache/fop/svg/SVGElement.java | 41 |
6 files changed, 75 insertions, 12 deletions
diff --git a/docs/examples/svg/embedding.fo b/docs/examples/svg/embedding.fo index f685d5c40..a01e204a0 100644 --- a/docs/examples/svg/embedding.fo +++ b/docs/examples/svg/embedding.fo @@ -939,7 +939,7 @@ Sizing <fo:table-row> <fo:table-cell number-columns-spanned="2"> <fo:block space-before.optimum="5pt"> -Specify the size on the instream-foreign-object element. <fo:inline color="red">Note: currently not functional, bug.</fo:inline> +Specify the size on the instream-foreign-object element. </fo:block> </fo:table-cell> </fo:table-row> @@ -948,7 +948,7 @@ Specify the size on the instream-foreign-object element. <fo:inline color="red"> <fo:table-cell> <fo:block font-size="8pt" white-space-collapse="false" space-before.optimum="5pt"> <![CDATA[ -<fo:instream-foreign-object width="20pt" height="20pt"> +<fo:instream-foreign-object content-width="20pt" content-height="20pt"> <svg:svg> <svg:g style="fill:red; stroke:#000000"> <svg:rect x="0" y="0" width="15" height="15"/> @@ -962,8 +962,8 @@ Specify the size on the instream-foreign-object element. <fo:inline color="red"> </fo:table-cell> <fo:table-cell> <fo:block space-before.optimum="15pt"> -<!-- -<fo:instream-foreign-object width="20pt" height="20pt"> + +<fo:instream-foreign-object content-width="20pt" content-height="20pt"> <svg:svg> <svg:g style="fill:red; stroke:#000000"> <svg:rect x="0" y="0" width="15" height="15"/> @@ -971,7 +971,7 @@ Specify the size on the instream-foreign-object element. <fo:inline color="red"> </svg:g> </svg:svg> </fo:instream-foreign-object> ---> + </fo:block> </fo:table-cell> </fo:table-row> diff --git a/docs/examples/svg/external.fo b/docs/examples/svg/external.fo index abd3d31b6..9d908ea96 100644 --- a/docs/examples/svg/external.fo +++ b/docs/examples/svg/external.fo @@ -120,6 +120,11 @@ and </fo:block> + <fo:block space-before.optimum="10pt"> +This example is an svg from an external image: +<fo:external-graphic src="file:view.svg"/> +it has a viewbox that resizes the contents. + </fo:block> </fo:flow> </fo:page-sequence> diff --git a/docs/examples/svg/view.svg b/docs/examples/svg/view.svg new file mode 100644 index 000000000..4704ec9ec --- /dev/null +++ b/docs/examples/svg/view.svg @@ -0,0 +1,11 @@ +<?xml version="1.0" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN" +"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd"> + +<svg viewBox="0 0 10 10" width="20" height="20" xml:space="preserve"> + <g style="fill:red; stroke:#000000"> + <rect x="0" y="0" width="15" height="15"/> + <rect x="5" y="5" width="15" height="15"/> + </g> +</svg> + diff --git a/src/org/apache/fop/layout/inline/ForeignObjectArea.java b/src/org/apache/fop/layout/inline/ForeignObjectArea.java index 72fb91dc0..535743499 100644 --- a/src/org/apache/fop/layout/inline/ForeignObjectArea.java +++ b/src/org/apache/fop/layout/inline/ForeignObjectArea.java @@ -92,6 +92,14 @@ public class ForeignObjectArea extends InlineArea { chauto = ha; } + public boolean isContentWidthAuto() { + return cwauto; + } + + public boolean isContentHeightAuto() { + return chauto; + } + public void setAlign(int align) { this.align = align; } diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 6cec91dd0..e4ae8f056 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -387,6 +387,7 @@ public class PDFRenderer extends PrintRenderer { SVGSVGElement svg = ((SVGDocument)doc).getRootElement(); int w = (int)(svg.getWidth().getBaseVal().getValue() * 1000); int h = (int)(svg.getHeight().getBaseVal().getValue() * 1000); + float sx = 1, sy = -1; int xOffset = x, yOffset = y; @@ -412,6 +413,17 @@ public class PDFRenderer extends PrintRenderer { currentStream.add(sx + " 0 0 " + sy + " " + xOffset / 1000f + " " + yOffset / 1000f + " cm\n"); + AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg, w / 1000f, h / 1000f); + if(!at.isIdentity()) { + double[] vals = new double[6]; + at.getMatrix(vals); + currentStream.add(PDFNumber.doubleOut(vals[0]) + " " + + PDFNumber.doubleOut(vals[1]) + " " + + PDFNumber.doubleOut(vals[2]) + " " + + PDFNumber.doubleOut(vals[3]) + " " + + PDFNumber.doubleOut(vals[4]) + " " + + PDFNumber.doubleOut(vals[5]) + " cm\n"); + } UserAgent userAgent = new MUserAgent(new AffineTransform()); diff --git a/src/org/apache/fop/svg/SVGElement.java b/src/org/apache/fop/svg/SVGElement.java index 91ef47bb0..b4f3dd811 100644 --- a/src/org/apache/fop/svg/SVGElement.java +++ b/src/org/apache/fop/svg/SVGElement.java @@ -26,6 +26,8 @@ import org.apache.batik.dom.svg.SVGDOMImplementation; import java.io.File; import java.net.URL; +import java.util.List; +import java.util.ArrayList; /** * class representing svg:svg pseudo flow object. @@ -80,7 +82,7 @@ public class SVGElement extends Svg { * * @return the status of the layout */ - public Status layout(Area area) throws FOPException { + public Status layout(final Area area) throws FOPException { if (!(area instanceof ForeignObjectArea)) { // this is an error @@ -100,7 +102,7 @@ public class SVGElement extends Svg { String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; Document doc = impl.createDocument(svgNS, "svg", null); - Element svgRoot = doc.getDocumentElement(); + final Element svgRoot = doc.getDocumentElement(); try { String baseDir = Configuration.getStringValue("baseDir"); @@ -109,18 +111,33 @@ public class SVGElement extends Svg { DefaultSVGContext dc = new DefaultSVGContext() { public float getPixelToMM() { - return 0.264583333333333333333f; // 72 dpi + return 0.35277777777777777778f; } - public float getViewportWidth() { - return 100; + public float getViewportWidth(Element e) throws IllegalStateException { + if(e == svgRoot) { + ForeignObjectArea foa = (ForeignObjectArea)area; + if(!foa.isContentWidthAuto()) { + return foa.getContentWidth(); + } + } + return super.getViewportWidth(e); } - public float getViewportHeight() { - return 100; + public float getViewportHeight(Element e) throws IllegalStateException { + if(e == svgRoot) { + ForeignObjectArea foa = (ForeignObjectArea)area; + if(!foa.isContentHeightAuto()) { + return foa.getContentHeight(); + } + } + return super.getViewportHeight(e); } + public List getDefaultFontFamilyValue() { + return FONT_FAMILY; + } }; ((SVGOMDocument)doc).setSVGContext(dc); buildTopLevel(doc, svgRoot); @@ -145,4 +162,14 @@ public class SVGElement extends Svg { return new Status(Status.OK); } + public final static List FONT_FAMILY; + static { + FONT_FAMILY = new ArrayList(); + FONT_FAMILY.add("Helvetica"); + FONT_FAMILY.add("Times"); + FONT_FAMILY.add("Courier"); + FONT_FAMILY.add("sans-serif"); + FONT_FAMILY.add("serif"); + } + } |