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 2002/07/05 11:21:48 UTC
cvs commit: xml-fop/src/org/apache/fop/render/pdf PDFRenderer.java PDFXMLHandler.java
keiron 2002/07/05 02:21:48
Modified: src/org/apache/fop/fo/flow ExternalGraphic.java
InstreamForeignObject.java
src/org/apache/fop/render/pdf PDFRenderer.java
PDFXMLHandler.java
Log:
alignment and scaling for instream-foreign-object using viewport
Revision Changes Path
1.24 +10 -9 xml-fop/src/org/apache/fop/fo/flow/ExternalGraphic.java
Index: ExternalGraphic.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/flow/ExternalGraphic.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- ExternalGraphic.java 4 Jul 2002 14:08:19 -0000 1.23
+++ ExternalGraphic.java 5 Jul 2002 09:21:47 -0000 1.24
@@ -146,7 +146,7 @@
// adjust the larger
double rat1 = cwidth / (fopimage.getWidth() * 1000f);
double rat2 = cheight / (fopimage.getHeight() * 1000f);
- if(rat1 > rat2) {
+ if(rat1 < rat2) {
// reduce cheight
cheight = (int)(rat1 * fopimage.getHeight() * 1000);
} else {
@@ -162,13 +162,14 @@
viewHeight = cheight;
}
- int overflow = properties.get("overflow").getEnum();
- if(overflow == Overflow.HIDDEN) {
- clip = true;
- }
- if(overflow == Overflow.ERROR_IF_OVERFLOW && (cwidth > viewWidth || cheight > viewHeight)) {
- log.error("Image: " + url + " overflows the viewport");
- clip = true;
+ if(cwidth > viewWidth || cheight > viewHeight) {
+ int overflow = properties.get("overflow").getEnum();
+ if(overflow == Overflow.HIDDEN) {
+ clip = true;
+ } else if(overflow == Overflow.ERROR_IF_OVERFLOW) {
+ log.error("Image: " + url + " overflows the viewport");
+ clip = true;
+ }
}
int xoffset = 0;
1.28 +124 -19 xml-fop/src/org/apache/fop/fo/flow/InstreamForeignObject.java
Index: InstreamForeignObject.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/fo/flow/InstreamForeignObject.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- InstreamForeignObject.java 20 Jun 2002 09:14:13 -0000 1.27
+++ InstreamForeignObject.java 5 Jul 2002 09:21:47 -0000 1.28
@@ -10,6 +10,7 @@
// FOP
import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.*;
+import org.apache.fop.datatypes.Length;
import org.apache.fop.area.Area;
import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.Viewport;
@@ -29,21 +30,13 @@
import org.w3c.dom.Document;
import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
import java.util.List;
public class InstreamForeignObject extends FObj {
int breakBefore;
int breakAfter;
- int scaling;
- int width;
- int height;
- int contwidth;
- int contheight;
- boolean wauto;
- boolean hauto;
- boolean cwauto;
- boolean chauto;
int spaceBefore;
int spaceAfter;
int startIndent;
@@ -77,10 +70,12 @@
if (this.children.size() != 1) {
// error
+ return null;
}
FONode fo = (FONode)children.get(0);
if(!(fo instanceof XMLObj)) {
// error
+ return null;
}
XMLObj child = (XMLObj)fo;
@@ -107,8 +102,12 @@
//int h = this.properties.get("height").getLength().mvalue();
// use specified line-height then ignore dimension in height direction
- boolean hasLH = properties.get("line-height").getSpecifiedValue() != null;
- int bpd = 0;
+ boolean hasLH = false;//properties.get("line-height").getSpecifiedValue() != null;
+
+ Length len;
+
+ int bpd = -1;
+ int ipd = -1;
boolean bpdauto = false;
if(hasLH) {
bpd = properties.get("line-height").getLength().mvalue();
@@ -116,17 +115,121 @@
// this property does not apply when the line-height applies
// isn't the block-progression-dimension always in the same
// direction as the line height?
- bpdauto = properties.get("block-progression-dimension").getLength().isAuto();
- bpd = properties.get("block-progression-dimension").getLength().mvalue();
+ len = properties.get("block-progression-dimension.optimum").getLength();
+ if(!len.isAuto()) {
+ bpd = len.mvalue();
+ } else {
+ len = properties.get("height").getLength();
+ if(!len.isAuto()) {
+ bpd = len.mvalue();
+ }
+ }
}
- //boolean ipdauto = properties.get("inline-progression-dimension").getLength().isAuto();
- //int ipd = properties.get("inline-progression-dimension").getLength().mvalue();
+ len = properties.get("inline-progression-dimension.optimum").getLength();
+ if(!len.isAuto()) {
+ ipd = len.mvalue();
+ } else {
+ len = properties.get("width").getLength();
+ if(!len.isAuto()) {
+ ipd = len.mvalue();
+ }
+ }
// if auto then use the intrinsic size of the content scaled
// to the content-height and content-width
+ int cwidth = -1;
+ int cheight = -1;
+ len = properties.get("content-width").getLength();
+ if(!len.isAuto()) {
+ /*if(len.scaleToFit()) {
+ if(ipd != -1) {
+ cwidth = ipd;
+ }
+ } else {*/
+ cwidth = len.mvalue();
+ }
+ len = properties.get("content-height").getLength();
+ if(!len.isAuto()) {
+ /*if(len.scaleToFit()) {
+ if(bpd != -1) {
+ cwidth = bpd;
+ }
+ } else {*/
+ cheight = len.mvalue();
+ }
+
+ Point2D csize = new Point2D.Float(cwidth == -1 ? -1 : cwidth / 1000f, cheight == -1 ? -1 : cheight / 1000f);
+ Point2D size = child.getDimension(csize);
+ if(cwidth == -1) {
+ cwidth = (int)size.getX() * 1000;
+ }
+ if(cheight == -1) {
+ cheight = (int)size.getY() * 1000;
+ }
+ int scaling = properties.get("scaling").getEnum();
+ if(scaling == Scaling.UNIFORM) {
+ // adjust the larger
+ double rat1 = cwidth / (size.getX() * 1000f);
+ double rat2 = cheight / (size.getY() * 1000f);
+ if(rat1 < rat2) {
+ // reduce cheight
+ cheight = (int)(rat1 * size.getY() * 1000);
+ } else {
+ cwidth = (int)(rat2 * size.getX() * 1000);
+ }
+ }
- Point2D size = child.getDimension(new Point2D.Float(-1, -1));
+ if(ipd == -1) {
+ ipd = cwidth;
+ }
+ if(bpd == -1) {
+ bpd = cheight;
+ }
+
+ boolean clip = false;
+ if(cwidth > ipd || cheight > bpd) {
+ int overflow = properties.get("overflow").getEnum();
+ if(overflow == Overflow.HIDDEN) {
+ clip = true;
+ } else if(overflow == Overflow.ERROR_IF_OVERFLOW) {
+ log.error("Instream foreign object overflows the viewport");
+ clip = true;
+ }
+ }
+
+ int xoffset = 0;
+ int yoffset = 0;
+ int da = properties.get("display-align").getEnum();
+ switch(da) {
+ case DisplayAlign.BEFORE:
+ break;
+ case DisplayAlign.AFTER:
+ yoffset = bpd - cheight;
+ break;
+ case DisplayAlign.CENTER:
+ yoffset = (bpd - cheight) / 2;
+ break;
+ case DisplayAlign.AUTO:
+ default:
+ break;
+ }
+
+ int ta = properties.get("text-align").getEnum();
+ switch(ta) {
+ case TextAlign.CENTER:
+ xoffset = (ipd - cwidth) / 2;
+ break;
+ case TextAlign.END:
+ xoffset = ipd - cwidth;
+ break;
+ case TextAlign.START:
+ break;
+ case TextAlign.JUSTIFY:
+ default:
+ break;
+ }
+ Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight);
Document doc = child.getDocument();
String ns = child.getDocumentNamespace();
@@ -135,8 +238,10 @@
ForeignObject foreign = new ForeignObject(doc, ns);
areaCurrent = new Viewport(foreign);
- areaCurrent.setWidth((int)size.getX() * 1000);
- areaCurrent.setHeight((int)size.getY() * 1000);
+ areaCurrent.setWidth(ipd);
+ areaCurrent.setHeight(bpd);
+ areaCurrent.setContentPosition(placement);
+ areaCurrent.setClip(clip);
areaCurrent.setOffset(0);
areaCurrent.info = new LayoutInfo();
areaCurrent.info.alignment = properties.get("vertical-align").getEnum();
1.109 +9 -9 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.108
retrieving revision 1.109
diff -u -r1.108 -r1.109
--- PDFRenderer.java 4 Jul 2002 14:08:20 -0000 1.108
+++ PDFRenderer.java 5 Jul 2002 09:21:47 -0000 1.109
@@ -492,7 +492,7 @@
Document doc = ((XMLImage)fopimage).getDocument();
String ns = ((XMLImage)fopimage).getNameSpace();
- renderDocument(doc, ns);
+ renderDocument(doc, ns, pos);
} else if("image/svg+xml".equals(mime)) {
if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
return;
@@ -500,7 +500,7 @@
Document doc = ((XMLImage)fopimage).getDocument();
String ns = ((XMLImage)fopimage).getNameSpace();
- renderDocument(doc, ns);
+ renderDocument(doc, ns, pos);
} else if("image/eps".equals(mime)) {
if(!fopimage.load(FopImage.ORIGINAL_DATA, userAgent)) {
return;
@@ -552,10 +552,10 @@
public void renderForeignObject(ForeignObject fo, Rectangle2D pos) {
Document doc = fo.getDocument();
String ns = fo.getNameSpace();
- renderDocument(doc, ns);
+ renderDocument(doc, ns, pos);
}
- public void renderDocument(Document doc, String ns) {
+ public void renderDocument(Document doc, String ns, Rectangle2D pos) {
RendererContext context;
context = new RendererContext(mimeType);
context.setUserAgent(userAgent);
@@ -565,8 +565,8 @@
context.setProperty(PDFXMLHandler.PDF_STATE, currentState);
context.setProperty(PDFXMLHandler.PDF_PAGE, currentPage);
context.setProperty(PDFXMLHandler.PDF_STREAM, currentStream);
- context.setProperty(PDFXMLHandler.PDF_X, new Integer(currentBlockIPPosition));
- context.setProperty(PDFXMLHandler.PDF_Y, new Integer(currentBPPosition));
+ context.setProperty(PDFXMLHandler.PDF_XPOS, new Integer(currentBlockIPPosition + (int)pos.getX()));
+ context.setProperty(PDFXMLHandler.PDF_YPOS, new Integer(currentBPPosition + (int)pos.getY()));
FontState fs = null;
try {
fs = new FontState(fontInfo, "Helvetica", "",
@@ -578,8 +578,8 @@
context.setProperty(PDFXMLHandler.PDF_FONT_STATE, fs);
context.setProperty(PDFXMLHandler.PDF_FONT_NAME, currentFontName);
context.setProperty(PDFXMLHandler.PDF_FONT_SIZE, new Integer(currentFontSize));
- context.setProperty(PDFXMLHandler.PDF_XPOS, new Integer(currentBlockIPPosition));
- context.setProperty(PDFXMLHandler.PDF_YPOS, new Integer(currentBPPosition));
+ context.setProperty(PDFXMLHandler.PDF_WIDTH, new Integer((int)pos.getWidth()));
+ context.setProperty(PDFXMLHandler.PDF_HEIGHT, new Integer((int)pos.getHeight()));
userAgent.renderXML(context, doc, ns);
}
1.7 +13 -9 xml-fop/src/org/apache/fop/render/pdf/PDFXMLHandler.java
Index: PDFXMLHandler.java
===================================================================
RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/pdf/PDFXMLHandler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PDFXMLHandler.java 1 Jul 2002 14:42:43 -0000 1.6
+++ PDFXMLHandler.java 5 Jul 2002 09:21:48 -0000 1.7
@@ -48,8 +48,8 @@
public static final String PDF_STATE = "pdfState";
public static final String PDF_PAGE = "pdfPage";
public static final String PDF_STREAM = "pdfStream";
-public static final String PDF_X = "x";
-public static final String PDF_Y = "y";
+public static final String PDF_WIDTH = "width";
+public static final String PDF_HEIGHT = "height";
public static final String PDF_FONT_STATE = "fontState";
public static final String PDF_FONT_NAME = "fontName";
public static final String PDF_FONT_SIZE = "fontSize";
@@ -78,8 +78,8 @@
pdfi.pdfState = (PDFState)context.getProperty(PDF_STATE);
pdfi.pdfPage = (PDFPage)context.getProperty(PDF_PAGE);
pdfi.currentStream = (PDFStream)context.getProperty(PDF_STREAM);
- pdfi.x = ((Integer)context.getProperty(PDF_X)).intValue();
- pdfi.y = ((Integer)context.getProperty(PDF_Y)).intValue();
+ pdfi.width = ((Integer)context.getProperty(PDF_WIDTH)).intValue();
+ pdfi.height = ((Integer)context.getProperty(PDF_HEIGHT)).intValue();
pdfi.fs = (FontState)context.getProperty(PDF_FONT_STATE);
pdfi.currentFontName = (String)context.getProperty(PDF_FONT_NAME);
pdfi.currentFontSize = ((Integer)context.getProperty(PDF_FONT_SIZE)).intValue();
@@ -94,8 +94,8 @@
PDFState pdfState;
PDFPage pdfPage;
public PDFStream currentStream;
- int x;
- int y;
+ int width;
+ int height;
FontState fs;
String currentFontName;
int currentFontSize;
@@ -109,8 +109,8 @@
*/
protected class SVGHandler {
protected void renderSVGDocument(RendererContext context, Document doc, PDFInfo pdfInfo) {
- float sx = 1, sy = 1;
- int xOffset = pdfInfo.x, yOffset = pdfInfo.y;
+ int xOffset = pdfInfo.currentXPosition;
+ int yOffset = pdfInfo.currentYPosition;
SVGUserAgent ua
= new SVGUserAgent(context.getUserAgent(), new AffineTransform());
@@ -138,6 +138,10 @@
// get the 'width' and 'height' attributes of the SVG document
float w = (float)ctx.getDocumentSize().getWidth() * 1000f;
float h = (float)ctx.getDocumentSize().getHeight() * 1000f;
+
+ float sx = pdfInfo.width / (float)w;
+ float sy = pdfInfo.height / (float)h;
+
ctx = null;
builder = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org