aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKeiron Liddle <keiron@apache.org>2002-07-05 09:21:48 +0000
committerKeiron Liddle <keiron@apache.org>2002-07-05 09:21:48 +0000
commit177b517adc5f990d4ca6abea0c64dc633d15b672 (patch)
treea6949d8829cc6c8922f9e5746826add942513fdb /src
parent00e397fb0c50eb215aed37f03c7c9c427be318e8 (diff)
downloadxmlgraphics-fop-177b517adc5f990d4ca6abea0c64dc633d15b672.tar.gz
xmlgraphics-fop-177b517adc5f990d4ca6abea0c64dc633d15b672.zip
alignment and scaling for instream-foreign-object using viewport
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194971 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/org/apache/fop/fo/flow/ExternalGraphic.java17
-rw-r--r--src/org/apache/fop/fo/flow/InstreamForeignObject.java141
-rw-r--r--src/org/apache/fop/render/pdf/PDFRenderer.java16
-rw-r--r--src/org/apache/fop/render/pdf/PDFXMLHandler.java20
4 files changed, 152 insertions, 42 deletions
diff --git a/src/org/apache/fop/fo/flow/ExternalGraphic.java b/src/org/apache/fop/fo/flow/ExternalGraphic.java
index 37f896677..614c6953d 100644
--- a/src/org/apache/fop/fo/flow/ExternalGraphic.java
+++ b/src/org/apache/fop/fo/flow/ExternalGraphic.java
@@ -146,7 +146,7 @@ public class ExternalGraphic extends FObj {
// 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 @@ public class ExternalGraphic extends FObj {
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;
diff --git a/src/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/org/apache/fop/fo/flow/InstreamForeignObject.java
index 91797175b..ec0e914a3 100644
--- a/src/org/apache/fop/fo/flow/InstreamForeignObject.java
+++ b/src/org/apache/fop/fo/flow/InstreamForeignObject.java
@@ -10,6 +10,7 @@ package org.apache.fop.fo.flow;
// 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.apache.fop.layoutmgr.LayoutInfo;
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 @@ public class InstreamForeignObject extends FObj {
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 @@ public class InstreamForeignObject extends FObj {
//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 @@ public class InstreamForeignObject extends FObj {
// 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 @@ public class InstreamForeignObject extends FObj {
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();
diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java
index 12bf786be..177d17cae 100644
--- a/src/org/apache/fop/render/pdf/PDFRenderer.java
+++ b/src/org/apache/fop/render/pdf/PDFRenderer.java
@@ -492,7 +492,7 @@ public class PDFRenderer extends PrintRenderer {
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 @@ public class PDFRenderer extends PrintRenderer {
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 class PDFRenderer extends PrintRenderer {
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 @@ public class PDFRenderer extends PrintRenderer {
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 @@ public class PDFRenderer extends PrintRenderer {
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);
}
diff --git a/src/org/apache/fop/render/pdf/PDFXMLHandler.java b/src/org/apache/fop/render/pdf/PDFXMLHandler.java
index cf733b2df..f0a524788 100644
--- a/src/org/apache/fop/render/pdf/PDFXMLHandler.java
+++ b/src/org/apache/fop/render/pdf/PDFXMLHandler.java
@@ -48,8 +48,8 @@ public static final String OUTPUT_STREAM = "outputStream";
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 @@ public static final String PDF_YPOS = "ypos";
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 @@ public static final String PDF_YPOS = "ypos";
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 @@ public static final String PDF_YPOS = "ypos";
*/
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 @@ public static final String PDF_YPOS = "ypos";
// 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;