]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
handles viewbox and no svg size better
authorKeiron Liddle <keiron@apache.org>
Thu, 30 Aug 2001 10:09:03 +0000 (10:09 +0000)
committerKeiron Liddle <keiron@apache.org>
Thu, 30 Aug 2001 10:09:03 +0000 (10:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194446 13f79535-47bb-0310-9956-ffa450edef68

docs/examples/svg/embedding.fo
docs/examples/svg/external.fo
docs/examples/svg/view.svg [new file with mode: 0644]
src/org/apache/fop/layout/inline/ForeignObjectArea.java
src/org/apache/fop/render/pdf/PDFRenderer.java
src/org/apache/fop/svg/SVGElement.java

index f685d5c40bef30c91e0c538fcbf1b15263dc3361..a01e204a06047c5c2bcfe91c6f8a4776d94fc120 100644 (file)
@@ -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>
index abd3d31b61c7572c44f7dd6bf1d273a02e5c94e9..9d908ea961f8574fb3449e1d593a9b0f6012c92e 100644 (file)
@@ -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 (file)
index 0000000..4704ec9
--- /dev/null
@@ -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>
+
index 72fb91dc0f4e47fcfc1eac7c06feab0f057cfeb3..5357434998ed9b5e52931ca3839e4c9bfe3a4699 100644 (file)
@@ -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;
     }
index 6cec91dd0aaacf0c7942d452142b8175142a29ba..e4ae8f0569e068d3ec8f5864924051125c42e5a1 100644 (file)
@@ -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());
 
index 91ef47bb0f4329949ef65a35d0f20819d3783b15..b4f3dd811dc326f4a6d2d506a31c08e0cbc19f36 100644 (file)
@@ -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");
+    }
+
 }