From: William Victor Mote Date: Sun, 24 Aug 2003 22:15:51 +0000 (+0000) Subject: 1. move fo/flow/InstreamForeignObject.getInlineArea() to layoutmgr/AddLMVisitor.getIF... X-Git-Tag: Root_Temp_KnuthStylePageBreaking~1168 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9c658bd06f250388c04f5626b491b6cbbe3470cc;p=xmlgraphics-fop.git 1. move fo/flow/InstreamForeignObject.getInlineArea() to layoutmgr/AddLMVisitor.getIFOInlineArea() 2. remove unneeded field fo/flow/InstreamForeignObject.areaCurrent git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196835 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index ea5688034..5cce1eea0 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -102,7 +102,7 @@ public class FObj extends FONode { /** * The children of this node. */ - protected ArrayList children = null; + public ArrayList children = null; /** * Markers added to this element. @@ -372,7 +372,7 @@ public class FObj extends FONode { return null; } - /** + /** * Add the marker to this formatting object. * If this object can contain markers it checks that the marker * has a unique class-name for this object and that it is diff --git a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java index b8c9f77e1..a7e14cf32 100644 --- a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -50,20 +50,10 @@ */ package org.apache.fop.fo.flow; -// FOP -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -import org.apache.fop.area.inline.ForeignObject; -import org.apache.fop.area.inline.Viewport; -import org.apache.fop.datatypes.Length; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; import org.apache.fop.fo.FOTreeVisitor; -import org.apache.fop.fo.XMLObj; import org.apache.fop.fo.properties.DisplayAlign; -import org.apache.fop.fo.properties.Overflow; -import org.apache.fop.fo.properties.Scaling; import org.apache.fop.fo.properties.TextAlign; import org.w3c.dom.Document; @@ -74,8 +64,6 @@ import org.w3c.dom.Document; */ public class InstreamForeignObject extends FObj { - public Viewport areaCurrent; - /** * constructs an instream-foreign-object object (called by Maker). * @@ -85,157 +73,7 @@ public class InstreamForeignObject extends FObj { super(parent); } - /** - * Get the inline area created by this element. - * - * @return the viewport inline area - */ - public Viewport getInlineArea() { - if (children == null) { - return areaCurrent; - } - - 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; - - // viewport size is determined by block-progression-dimension - // and inline-progression-dimension - - // if replaced then use height then ignore block-progression-dimension - //int h = this.properties.get("height").getLength().mvalue(); - - // use specified line-height then ignore dimension in height direction - 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().getValue(); - } else { - // 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? - len = properties.get("block-progression-dimension.optimum").getLength(); - if (!len.isAuto()) { - bpd = len.getValue(); - } else { - len = properties.get("height").getLength(); - if (!len.isAuto()) { - bpd = len.getValue(); - } - } - } - - len = properties.get("inline-progression-dimension.optimum").getLength(); - if (!len.isAuto()) { - ipd = len.getValue(); - } else { - len = properties.get("width").getLength(); - if (!len.isAuto()) { - ipd = len.getValue(); - } - } - - // 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.getValue(); - } - len = properties.get("content-height").getLength(); - if (!len.isAuto()) { - /*if(len.scaleToFit()) { - if(bpd != -1) { - cwidth = bpd; - } - } else {*/ - cheight = len.getValue(); - } - - Point2D csize = new Point2D.Float(cwidth == -1 ? -1 : cwidth / 1000f, - cheight == -1 ? -1 : cheight / 1000f); - Point2D size = child.getDimension(csize); - if (size == null) { - // error - return null; - } - 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); - } - } - - 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) { - getLogger().error("Instream foreign object overflows the viewport: clipping"); - clip = true; - } - } - - int xoffset = computeXOffset(ipd, cwidth); - int yoffset = computeYOffset(bpd, cheight); - - Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight); - - Document doc = child.getDOMDocument(); - String ns = child.getDocumentNamespace(); - - children = null; - ForeignObject foreign = new ForeignObject(doc, ns); - - areaCurrent = new Viewport(foreign); - areaCurrent.setWidth(ipd); - areaCurrent.setHeight(bpd); - areaCurrent.setContentPosition(placement); - areaCurrent.setClip(clip); - areaCurrent.setOffset(0); - - return areaCurrent; - } - - private int computeXOffset (int ipd, int cwidth) { + public int computeXOffset (int ipd, int cwidth) { int xoffset = 0; int ta = properties.get("text-align").getEnum(); switch (ta) { @@ -254,7 +92,7 @@ public class InstreamForeignObject extends FObj { return xoffset; } - private int computeYOffset(int bpd, int cheight) { + public int computeYOffset(int bpd, int cheight) { int yoffset = 0; int da = properties.get("display-align").getEnum(); switch (da) { diff --git a/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java b/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java index abd590ea0..7b5b4988c 100644 --- a/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java +++ b/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java @@ -58,16 +58,21 @@ import org.apache.fop.area.Trait; import org.apache.fop.area.inline.InlineArea; import org.apache.fop.area.inline.InlineParent; import org.apache.fop.area.inline.FilledArea; +import org.apache.fop.area.inline.ForeignObject; import org.apache.fop.area.inline.Space; import org.apache.fop.area.inline.Word; import org.apache.fop.area.inline.Image; import org.apache.fop.area.inline.Viewport; +import org.apache.fop.datatypes.Length; + import org.apache.fop.fo.FOTreeVisitor; import org.apache.fop.fo.FObj; import org.apache.fop.fo.FObjMixed; +import org.apache.fop.fo.FONode; import org.apache.fop.fo.FOText; import org.apache.fop.fo.TextInfo; +import org.apache.fop.fo.XMLObj; import org.apache.fop.fo.flow.BidiOverride; import org.apache.fop.fo.flow.Inline; import org.apache.fop.fo.flow.BasicLink; @@ -93,6 +98,8 @@ import org.apache.fop.fo.pagination.Flow; import org.apache.fop.fo.properties.LeaderPattern; import org.apache.fop.fo.properties.CommonBorderAndPadding; import org.apache.fop.fo.properties.CommonBackground; +import org.apache.fop.fo.properties.Overflow; +import org.apache.fop.fo.properties.Scaling; import org.apache.fop.layoutmgr.BidiLayoutManager; import org.apache.fop.layoutmgr.LayoutProcessor; @@ -108,6 +115,9 @@ import org.apache.fop.util.CharUtilities; import java.util.List; import java.util.ListIterator; import java.util.ArrayList; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + import org.apache.fop.apps.*; /** @@ -457,18 +467,168 @@ public class AddLMVisitor extends FOTreeVisitor { } public void serveVisitor(InstreamForeignObject node) { - node.areaCurrent = node.getInlineArea(); - if (node.areaCurrent != null) { + Viewport areaCurrent = getIFOInlineArea(node); + if (areaCurrent != null) { LeafNodeLayoutManager lm = new LeafNodeLayoutManager(); lm.setUserAgent(node.getUserAgent()); lm.setFObj(node); - lm.setCurrentArea(node.areaCurrent); + lm.setCurrentArea(areaCurrent); lm.setAlignment(node.properties.get("vertical-align").getEnum()); - lm.setLead(node.areaCurrent.getHeight()); + lm.setLead(areaCurrent.getHeight()); currentLMList.add(lm); } } + /** + * Get the inline area created by this element. + * + * @return the viewport inline area + */ + public Viewport getIFOInlineArea(InstreamForeignObject node) { + if (node.getChildren() == null) { + return null; + } + + if (node.children.size() != 1) { + // error + return null; + } + FONode fo = (FONode)node.children.get(0); + if (!(fo instanceof XMLObj)) { + // error + return null; + } + XMLObj child = (XMLObj)fo; + + // viewport size is determined by block-progression-dimension + // and inline-progression-dimension + + // if replaced then use height then ignore block-progression-dimension + //int h = this.properties.get("height").getLength().mvalue(); + + // use specified line-height then ignore dimension in height direction + boolean hasLH = false;//properties.get("line-height").getSpecifiedValue() != null; + + Length len; + + int bpd = -1; + int ipd = -1; + boolean bpdauto = false; + if (hasLH) { + bpd = node.properties.get("line-height").getLength().getValue(); + } else { + // 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? + len = node.properties.get("block-progression-dimension.optimum").getLength(); + if (!len.isAuto()) { + bpd = len.getValue(); + } else { + len = node.properties.get("height").getLength(); + if (!len.isAuto()) { + bpd = len.getValue(); + } + } + } + + len = node.properties.get("inline-progression-dimension.optimum").getLength(); + if (!len.isAuto()) { + ipd = len.getValue(); + } else { + len = node.properties.get("width").getLength(); + if (!len.isAuto()) { + ipd = len.getValue(); + } + } + + // 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 = node.properties.get("content-width").getLength(); + if (!len.isAuto()) { + /*if(len.scaleToFit()) { + if(ipd != -1) { + cwidth = ipd; + } + } else {*/ + cwidth = len.getValue(); + } + len = node.properties.get("content-height").getLength(); + if (!len.isAuto()) { + /*if(len.scaleToFit()) { + if(bpd != -1) { + cwidth = bpd; + } + } else {*/ + cheight = len.getValue(); + } + + Point2D csize = new Point2D.Float(cwidth == -1 ? -1 : cwidth / 1000f, + cheight == -1 ? -1 : cheight / 1000f); + Point2D size = child.getDimension(csize); + if (size == null) { + // error + return null; + } + if (cwidth == -1) { + cwidth = (int)size.getX() * 1000; + } + if (cheight == -1) { + cheight = (int)size.getY() * 1000; + } + int scaling = node.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); + } + } + + if (ipd == -1) { + ipd = cwidth; + } + if (bpd == -1) { + bpd = cheight; + } + + boolean clip = false; + if (cwidth > ipd || cheight > bpd) { + int overflow = node.properties.get("overflow").getEnum(); + if (overflow == Overflow.HIDDEN) { + clip = true; + } else if (overflow == Overflow.ERROR_IF_OVERFLOW) { + node.getLogger().error("Instream foreign object overflows the viewport: clipping"); + clip = true; + } + } + + int xoffset = node.computeXOffset(ipd, cwidth); + int yoffset = node.computeYOffset(bpd, cheight); + + Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, cheight); + + org.w3c.dom.Document doc = child.getDOMDocument(); + String ns = child.getDocumentNamespace(); + + node.children = null; + ForeignObject foreign = new ForeignObject(doc, ns); + + Viewport areaCurrent = new Viewport(foreign); + areaCurrent.setWidth(ipd); + areaCurrent.setHeight(bpd); + areaCurrent.setContentPosition(placement); + areaCurrent.setClip(clip); + areaCurrent.setOffset(0); + + return areaCurrent; + } + public void serveVisitor(ListItem node) { if (node.getLabel() != null && node.getBody() != null) { ListItemLayoutManager blm = new ListItemLayoutManager();