]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
places svg inline
authorKeiron Liddle <keiron@apache.org>
Tue, 30 Jan 2001 04:50:26 +0000 (04:50 +0000)
committerKeiron Liddle <keiron@apache.org>
Tue, 30 Jan 2001 04:50:26 +0000 (04:50 +0000)
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

src/org/apache/fop/fo/flow/InstreamForeignObject.java
src/org/apache/fop/layout/BlockArea.java
src/org/apache/fop/layout/LineArea.java
src/org/apache/fop/layout/inline/ForeignObjectArea.java
src/org/apache/fop/layout/inline/InlineArea.java
src/org/apache/fop/render/pdf/PDFRenderer.java

index fe8b2f3db9a65fc9b804b021083595c3592833d0..15c23853da904e1af6bab5cd71a4a7cdbed866a1 100644 (file)
@@ -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) {
index e36dbc4c2472b4a48d086012bde4e6890f1f5849..4defdde767c270404c0354f06918642bebfd6876 100644 (file)
@@ -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);
index 9b20ed73b1bad53ed8749022f04364cf408ef080..ebbeaeb4c21660d6f54ed42a33deb9cabc3eea87 100644 (file)
@@ -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
index 2939b99559d3320b321794c525b1e89087da6002..7b698814f9c143d5027c5d1c8dc7eb966d369c09 100644 (file)
@@ -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;
index be929ea80acfcd0ca90979e10fca8ffeb71d550b..5193b9752d1e0b5ba94b8128a68591661be8aac4 100644 (file)
@@ -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;
index 0f29c65e67d82c66ee97b36090152cf5db65580f..d15d6805845199dfe48ca47306b238326f438e84 100644 (file)
@@ -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);
         }