diff options
author | Keiron Liddle <keiron@apache.org> | 2002-07-05 09:21:48 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-07-05 09:21:48 +0000 |
commit | 177b517adc5f990d4ca6abea0c64dc633d15b672 (patch) | |
tree | a6949d8829cc6c8922f9e5746826add942513fdb /src/org/apache/fop/fo/flow | |
parent | 00e397fb0c50eb215aed37f03c7c9c427be318e8 (diff) | |
download | xmlgraphics-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/org/apache/fop/fo/flow')
-rw-r--r-- | src/org/apache/fop/fo/flow/ExternalGraphic.java | 17 | ||||
-rw-r--r-- | src/org/apache/fop/fo/flow/InstreamForeignObject.java | 141 |
2 files changed, 132 insertions, 26 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(); |