You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ke...@apache.org on 2001/08/30 12:09:03 UTC
cvs commit: xml-fop/src/org/apache/fop/layout/inline ForeignObjectArea.java
keiron 01/08/30 03:09:03
Modified: docs/examples/svg embedding.fo external.fo
src/org/apache/fop/svg SVGElement.java
src/org/apache/fop/render/pdf PDFRenderer.java
src/org/apache/fop/layout/inline ForeignObjectArea.java
Added: docs/examples/svg view.svg
Log:
handles viewbox and no svg size better
Revision Changes Path
1.4 +5 -5 xml-fop/docs/examples/svg/embedding.fo
Index: embedding.fo
===================================================================
RCS file: /home/cvs/xml-fop/docs/examples/svg/embedding.fo,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- embedding.fo 2001/06/28 08:05:59 1.3
+++ embedding.fo 2001/08/30 10:09:02 1.4
@@ -939,7 +939,7 @@
<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 @@
<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 @@
</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 @@
</svg:g>
</svg:svg>
</fo:instream-foreign-object>
--->
+
</fo:block>
</fo:table-cell>
</fo:table-row>
1.3 +5 -0 xml-fop/docs/examples/svg/external.fo
Index: external.fo
===================================================================
RCS file: /home/cvs/xml-fop/docs/examples/svg/external.fo,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- external.fo 2001/06/28 08:05:58 1.2
+++ external.fo 2001/08/30 10:09:02 1.3
@@ -120,6 +120,11 @@
</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>
1.1 xml-fop/docs/examples/svg/view.svg
Index: view.svg
===================================================================
<?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>
1.8 +35 -8 xml-fop/src/org/apache/fop/svg/SVGElement.java
Index: SVGElement.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/svg/SVGElement.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SVGElement.java 2001/07/30 20:29:34 1.7
+++ SVGElement.java 2001/08/30 10:09:02 1.8
@@ -1,5 +1,5 @@
/*
- * $Id: SVGElement.java,v 1.7 2001/07/30 20:29:34 tore Exp $
+ * $Id: SVGElement.java,v 1.8 2001/08/30 10:09:02 keiron Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
@@ -26,6 +26,8 @@
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 @@
*
* @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 @@
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 @@
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);
@@ -143,6 +160,16 @@
/* return status */
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");
}
}
1.87 +13 -1 xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java
Index: PDFRenderer.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFRenderer.java,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -r1.86 -r1.87
--- PDFRenderer.java 2001/08/23 06:14:33 1.86
+++ PDFRenderer.java 2001/08/30 10:09:02 1.87
@@ -1,5 +1,5 @@
/*
- * $Id: PDFRenderer.java,v 1.86 2001/08/23 06:14:33 keiron Exp $
+ * $Id: PDFRenderer.java,v 1.87 2001/08/30 10:09:02 keiron Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
@@ -387,6 +387,7 @@
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 @@
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());
1.5 +9 -1 xml-fop/src/org/apache/fop/layout/inline/ForeignObjectArea.java
Index: ForeignObjectArea.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/layout/inline/ForeignObjectArea.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ForeignObjectArea.java 2001/07/30 20:29:29 1.4
+++ ForeignObjectArea.java 2001/08/30 10:09:03 1.5
@@ -1,5 +1,5 @@
/*
- * $Id: ForeignObjectArea.java,v 1.4 2001/07/30 20:29:29 tore Exp $
+ * $Id: ForeignObjectArea.java,v 1.5 2001/08/30 10:09:03 keiron Exp $
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
@@ -90,6 +90,14 @@
public void setContentSizeAuto(boolean wa, boolean ha) {
cwauto = wa;
chauto = ha;
+ }
+
+ public boolean isContentWidthAuto() {
+ return cwauto;
+ }
+
+ public boolean isContentHeightAuto() {
+ return chauto;
}
public void setAlign(int align) {
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org