From 4c36038f8c07cc6de1673c0ff3d055fc2431893e Mon Sep 17 00:00:00 2001 From: Keiron Liddle Date: Tue, 30 Jan 2001 04:50:26 +0000 Subject: [PATCH] places svg inline first part in moving towards proper inline areas git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194004 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/fo/flow/InstreamForeignObject.java | 30 ++++++++--- src/org/apache/fop/layout/BlockArea.java | 1 + src/org/apache/fop/layout/LineArea.java | 50 ++++++++++++++++++- .../fop/layout/inline/ForeignObjectArea.java | 29 ++++++++--- .../apache/fop/layout/inline/InlineArea.java | 2 +- .../apache/fop/render/pdf/PDFRenderer.java | 9 +++- 6 files changed, 103 insertions(+), 18 deletions(-) diff --git a/src/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/org/apache/fop/fo/flow/InstreamForeignObject.java index fe8b2f3db..15c23853d 100644 --- a/src/org/apache/fop/fo/flow/InstreamForeignObject.java +++ b/src/org/apache/fop/fo/flow/InstreamForeignObject.java @@ -180,11 +180,11 @@ public class InstreamForeignObject extends FObj { /* if is embedded in a block area */ if (area instanceof BlockArea) { /* temporarily end the block area */ - area.end(); +// area.end(); } if(this.areaCurrent == null) { this.areaCurrent = - new ForeignObjectArea(fs, area.getAllocationWidth(), area.spaceLeft()); + new ForeignObjectArea(fs, area.getAllocationWidth()); this.areaCurrent.start(); areaCurrent.setWidth(this.width); @@ -234,6 +234,22 @@ public class InstreamForeignObject extends FObj { } } + if (area instanceof BlockArea) { + BlockArea ba = (BlockArea)area; + LineArea la = ba.getCurrentLineArea(); + la.addPending(); + if(areaCurrent.getEffectiveWidth() > la.getRemainingWidth()) { + la = ba.createNextLineArea(); + if(la == null) { + return new Status(Status.AREA_FULL_NONE); + } + } + la.addInlineArea(areaCurrent); + } else { + area.addChild(areaCurrent); + area.increaseHeight(areaCurrent.getEffectiveHeight()); + } + if (this.isInLabel) { startIndent += bodyIndent; /* endIndent += (areaCurrent.getEffectiveWidth() @@ -257,27 +273,27 @@ public class InstreamForeignObject extends FObj { /* if there is a space-before */ if (spaceBefore != 0) { /* add a display space */ - area.addDisplaySpace(spaceBefore); +// area.addDisplaySpace(spaceBefore); } /* add the SVG area to the containing area */ - area.addChild(areaCurrent); +// area.addChild(areaCurrent); areaCurrent.setPage(area.getPage()); /* increase the height of the containing area accordingly */ - area.increaseHeight(areaCurrent.getEffectiveHeight()); +// area.increaseHeight(areaCurrent.getEffectiveHeight()); /* if there is a space-after */ if (spaceAfter != 0) { /* add a display space */ - area.addDisplaySpace(spaceAfter); +// area.addDisplaySpace(spaceAfter); } /* if is embedded in a block area */ if (area instanceof BlockArea) { /* re-start the block area */ - area.start(); +// area.start(); } if (breakAfter == BreakAfter.PAGE) { diff --git a/src/org/apache/fop/layout/BlockArea.java b/src/org/apache/fop/layout/BlockArea.java index e36dbc4c2..4defdde76 100644 --- a/src/org/apache/fop/layout/BlockArea.java +++ b/src/org/apache/fop/layout/BlockArea.java @@ -132,6 +132,7 @@ public class BlockArea extends Area { public void addLineArea(LineArea la) { if (!la.isEmpty()) { + la.verticalAlign(); this.addDisplaySpace(this.halfLeading); int size = la.getHeight(); this.addChild(la); diff --git a/src/org/apache/fop/layout/LineArea.java b/src/org/apache/fop/layout/LineArea.java index 9b20ed73b..ebbeaeb4c 100644 --- a/src/org/apache/fop/layout/LineArea.java +++ b/src/org/apache/fop/layout/LineArea.java @@ -183,6 +183,7 @@ public class LineArea extends Area { new PageNumberInlineArea(currentFontState, this.red, this.green, this.blue, refid, width); + pia.setYOffset(placementOffset); pendingAreas.addElement(pia); pendingWidth += width; wordWidth = 0; @@ -293,6 +294,7 @@ public class LineArea extends Area { this.red, this.green, this.blue, new String(data, wordStart, wordLength), wordWidth); + ia.setYOffset(placementOffset); ia.setUnderlined(ul); addChild(ia); if (ls != null) { @@ -411,6 +413,7 @@ public class LineArea extends Area { this.green, this.blue, new String(data, wordStart, wordLength), wordWidth); + pia.setYOffset(placementOffset); pia.setUnderlined(ul); if (ls != null) { @@ -466,6 +469,7 @@ public class LineArea extends Area { new LeaderArea(fontState, red, green, blue, "", leaderLength, leaderPattern, ruleThickness, ruleStyle); + leaderArea.setYOffset(placementOffset); pendingAreas.addElement(leaderArea); break; case LeaderPattern.DOTS: @@ -507,6 +511,7 @@ public class LineArea extends Area { new WordArea(currentFontState, this.red, this.green, this.blue, new String ("."), this.currentFontState.width(46)); + leaderPatternArea.setYOffset(placementOffset); int dotsFactor = (int) Math.floor ( ((double) leaderLength) / ((double) leaderPatternWidth)); @@ -611,6 +616,32 @@ public class LineArea extends Area { } } + /** + * Balance (vertically) the inline areas within this line. + */ + public void verticalAlign() + { + int superHeight = -this.placementOffset; + int maxHeight = this.allocationHeight; + Enumeration e = children.elements(); + while (e.hasMoreElements()) { + Box b = (Box) e.nextElement(); + if(b instanceof InlineArea) { + InlineArea ia = (InlineArea)b; + if(ia.getHeight() > maxHeight) { + maxHeight = ia.getHeight(); + } + int vert = ia.getVerticalAlign(); +/* if(vert == VerticalAlign.SUPER) { + int tbe = fontState.getAscender(); + ia.setYOffset(placementOffset - (tbe - h)); + }*/ + } else { + } + } + this.allocationHeight = maxHeight; + } + public void changeColor(float red, float green, float blue) { this.red = red; this.green = green; @@ -646,7 +677,8 @@ public class LineArea extends Area { } public boolean isEmpty() { - return (prev == 0); + return !(pendingAreas.size() > 0 || children.size() > 0); +// return (prev == 0); } public Vector getPendingAreas() { @@ -700,6 +732,7 @@ public class LineArea extends Area { WordArea leaderPatternArea = new WordArea(currentFontState, this.red, this.green, this.blue, new String (leaderChars), leaderLength); + leaderPatternArea.setYOffset(placementOffset); return leaderPatternArea; } @@ -858,6 +891,18 @@ public class LineArea extends Area { return width; } + public int getRemainingWidth() + { + return this.getContentWidth() - this.getCurrentXPosition(); + } + + public void addInlineArea(Area box) + { + addPending(); + addChild(box); + prev = TEXT; + finalWidth += box.getContentWidth(); + } /** adds a single character to the line area tree*/ public int addCharacter (char data, LinkSet ls, boolean ul) { @@ -877,6 +922,7 @@ public class LineArea extends Area { ia = new WordArea(currentFontState, this.red, this.green, this.blue, new Character(data).toString(),width); + ia.setYOffset(placementOffset); ia.setUnderlined(ul); pendingAreas.addElement(ia); if (Character.isSpaceChar(data)) { @@ -902,12 +948,14 @@ public class LineArea extends Area { hia = new WordArea(currentFontState, this.red, this.green, this.blue, new Character(startChar).toString(),1); + hia.setYOffset(placementOffset); this.addChild(hia); } int wordWidth = this.getWordWidth(word); hia = new WordArea(currentFontState, this.red, this.green, this.blue, word,word.length()); + hia.setYOffset(placementOffset); this.addChild(hia); //calculate the space needed diff --git a/src/org/apache/fop/layout/inline/ForeignObjectArea.java b/src/org/apache/fop/layout/inline/ForeignObjectArea.java index 2939b9955..7b698814f 100644 --- a/src/org/apache/fop/layout/inline/ForeignObjectArea.java +++ b/src/org/apache/fop/layout/inline/ForeignObjectArea.java @@ -58,8 +58,8 @@ import org.apache.fop.layout.*; import java.util.Vector; import java.util.Enumeration; -public class ForeignObjectArea extends Area { - +public class ForeignObjectArea extends InlineArea { + protected int xOffset = 0; /* text-align of contents */ protected int align; @@ -78,17 +78,14 @@ public class ForeignObjectArea extends Area { protected int aheight; /* width */ protected int width; - /* height */ - protected int height; boolean wauto; boolean hauto; boolean cwauto; boolean chauto; int overflow; - public ForeignObjectArea(FontState fontState, int width, - int height) { - super(fontState, width, height); + public ForeignObjectArea(FontState fontState, int width) { + super(fontState, width, 0, 0, 0); } public void render(Renderer renderer) { @@ -96,6 +93,24 @@ public class ForeignObjectArea extends Area { renderer.renderForeignObjectArea(this); } + /** + * This is NOT the content width of the instream-foreign-object. + * This is the content width for a Box. + */ + public int getContentWidth() + { + return getEffectiveWidth(); + } + + /** + * This is NOT the content height of the instream-foreign-object. + * This is the content height for a Box. + */ + public int getHeight() + { + return getEffectiveHeight(); + } + public int getXOffset() { return this.xOffset; diff --git a/src/org/apache/fop/layout/inline/InlineArea.java b/src/org/apache/fop/layout/inline/InlineArea.java index be929ea80..5193b9752 100644 --- a/src/org/apache/fop/layout/inline/InlineArea.java +++ b/src/org/apache/fop/layout/inline/InlineArea.java @@ -58,7 +58,7 @@ import org.apache.fop.layout.*; public abstract class InlineArea extends Area { private int yOffset = 0; - private int height = 0; + protected int height = 0; private int verticalAlign = 0; protected String pageNumberId = null; private float red, green, blue; diff --git a/src/org/apache/fop/render/pdf/PDFRenderer.java b/src/org/apache/fop/render/pdf/PDFRenderer.java index 0f29c65e6..d15d68058 100644 --- a/src/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/org/apache/fop/render/pdf/PDFRenderer.java @@ -516,7 +516,7 @@ public class PDFRenderer implements Renderer { currentStream.add("Q\n"); currentStream.add("BT\n"); this.currentXPosition += area.getEffectiveWidth(); - this.currentYPosition -= area.getEffectiveHeight(); +// this.currentYPosition -= area.getEffectiveHeight(); } /** @@ -669,7 +669,12 @@ public class PDFRenderer implements Renderer { Enumeration e = area.getChildren().elements(); while (e.hasMoreElements()) { Box b = (Box) e.nextElement(); - this.currentYPosition = ry - area.getPlacementOffset(); + if(b instanceof InlineArea) { + InlineArea ia = (InlineArea)b; + this.currentYPosition = ry - ia.getYOffset(); + } else { + this.currentYPosition = ry - area.getPlacementOffset(); + } b.render(this); } -- 2.39.5