]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
implemented leader pattern: space, dots and use content
authorKeiron Liddle <keiron@apache.org>
Fri, 23 Aug 2002 13:45:25 +0000 (13:45 +0000)
committerKeiron Liddle <keiron@apache.org>
Fri, 23 Aug 2002 13:45:25 +0000 (13:45 +0000)
implemented title for pdf renderer
todo: sort out how leader creates areas and offset of areas

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195114 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/area/inline/InlineParent.java
src/org/apache/fop/area/inline/Space.java
src/org/apache/fop/fo/Title.java
src/org/apache/fop/fo/flow/Leader.java
src/org/apache/fop/fo/pagination/PageSequence.java
src/org/apache/fop/layoutmgr/ContentLayoutManager.java [new file with mode: 0644]
src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java
src/org/apache/fop/pdf/PDFDocument.java
src/org/apache/fop/render/AbstractRenderer.java
src/org/apache/fop/render/pdf/PDFRenderer.java

index 8ea743d9c6d1041da80f49133b81980d98a88ccf..cc733b9ad0b00040b55f477612e7116572b0d1e9 100644 (file)
@@ -16,7 +16,7 @@ import java.util.ArrayList;
 
 // this is an inline area that can have other inlines as children
 public class InlineParent extends InlineArea {
-    ArrayList inlines = new ArrayList();
+    protected ArrayList inlines = new ArrayList();
 
     public InlineParent() {
     }
index 1ba825524a003b8126bd06038d7c7b4e96dfc86b..7b98b3c17bf6863c4e723bcaa29802895fd56122 100644 (file)
@@ -10,8 +10,6 @@ package org.apache.fop.area.inline;
 import org.apache.fop.render.Renderer;
 
 public class Space extends Stretch {
-    public boolean collapse = true;
-    public boolean fixed = false;
 
     public void render(Renderer renderer) {
         renderer.renderInlineSpace(this);
index 9122296db88319c4c989d1ed58c8c3a9a6480639..7799f70eed8b53c3cb87edd22e0a63d9c6f3f18b 100644 (file)
@@ -15,9 +15,13 @@ import org.apache.fop.fo.flow.*;
 import org.apache.fop.fo.properties.*;
 import org.apache.fop.apps.FOPException;
 
+import org.apache.fop.layoutmgr.LMiter;
+import org.apache.fop.layoutmgr.InlineStackingBPLayoutManager;
+import org.apache.fop.layoutmgr.ContentLayoutManager;
+
 /**
  */
-public class Title extends ToBeImplementedElement {
+public class Title extends FObjMixed {
 
     public Title(FONode parent) {
         super(parent);
@@ -28,6 +32,18 @@ public class Title extends ToBeImplementedElement {
                  new org.apache.fop.area.Title();
         // use special layout manager to add the inline areas
         // to the Title.
+        InlineStackingBPLayoutManager lm;
+        lm = new InlineStackingBPLayoutManager(this,
+                     new LMiter(children.listIterator()));
+        lm.init();
+
+        // get breaks then add areas to title
+
+        ContentLayoutManager clm = new ContentLayoutManager(title);
+        lm.setParentLM(clm);
+
+        clm.fillArea(lm);
+
         return title;
     }
 
index bf0906f14b35bd8ccbb1f3e2990ac367181692cb..15d383b31b51b2dee7dac9bc6a02106c1d19460a 100644 (file)
@@ -16,11 +16,22 @@ import org.apache.fop.layout.*;
 import org.apache.fop.layout.FontState;
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.layoutmgr.LayoutManager;
+import org.apache.fop.layoutmgr.InlineStackingBPLayoutManager;
 import org.apache.fop.layoutmgr.LeafNodeLayoutManager;
+import org.apache.fop.layoutmgr.ContentLayoutManager;
 import org.apache.fop.layoutmgr.LayoutContext;
+import org.apache.fop.layoutmgr.LMiter;
 import org.apache.fop.area.MinOptMax;
+import org.apache.fop.area.inline.Space;
+import org.apache.fop.area.inline.Word;
+import org.apache.fop.area.inline.Stretch;
+import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.util.CharUtilities;
+import org.apache.fop.apps.StructureHandler;
+import org.apache.fop.area.Trait;
 
 import java.util.List;
+import java.util.ArrayList;
 
 /**
  * Implements fo:leader; main property of leader leader-pattern.
@@ -31,6 +42,10 @@ public class Leader extends FObjMixed {
     int ruleStyle;
     int ruleThickness;
     int leaderPattern;
+    int patternWidth;
+    protected FontInfo fontInfo = null;
+    protected FontState fontState;
+    protected InlineArea leaderArea = null;
 
     public Leader(FONode parent) {
         super(parent);
@@ -48,20 +63,122 @@ public class Leader extends FObjMixed {
     }
 
     protected InlineArea getInlineArea(int refIPD) {
-        setup();
-
-        org.apache.fop.area.inline.Leader leader = new org.apache.fop.area.inline.Leader();
-
+        if(leaderArea == null) {
+            createLeaderArea();
+        }
         MinOptMax alloc = getAllocationIPD(refIPD);
-        leader.setAllocationIPD(alloc);
-        leader.setWidth(alloc.opt);
+        if(leaderArea instanceof Stretch) {
+            ((Stretch)leaderArea).setAllocationIPD(alloc);
+        } else if(leaderArea instanceof FilledArea) {
+            ((FilledArea)leaderArea).setAllocationIPD(alloc);
+        }
+        leaderArea.setWidth(alloc.opt);
+        return leaderArea;
+    }
+
+    protected void createLeaderArea() {
+        setup();
 
         if(leaderPattern == LeaderPattern.RULE) {
+            org.apache.fop.area.inline.Leader leader = new org.apache.fop.area.inline.Leader();
+
             leader.setRuleStyle(ruleStyle);
             leader.setRuleThickness(ruleThickness);
+
+            leaderArea = leader;
+        } else if (leaderPattern == LeaderPattern.SPACE) {
+            Space space = new Space();
+
+            leaderArea = space;
+        } else if(leaderPattern == LeaderPattern.DOTS) {
+            Word w = new Word();
+            char dot = '.'; // userAgent.getLeaderDotChar();
+
+            w.setWord("" + dot);
+            w.addTrait(Trait.FONT_NAME, fontState.getFontName());
+            w.addTrait(Trait.FONT_SIZE,
+                             new Integer(fontState.getFontSize()));
+            // set offset of dot within inline parent
+            w.setOffset(fontState.getAscender());
+            int width = CharUtilities.getCharWidth(dot, fontState);
+            Space spacer = null;
+            if(patternWidth > width) {
+                spacer = new Space();
+                spacer.setWidth(patternWidth - width);
+                width = patternWidth;
+            }
+            FilledArea fa = new FilledArea();
+            fa.setUnitWidth(width);
+            fa.addChild(w);
+            if(spacer != null) {
+                fa.addChild(spacer);
+            }
+
+            leaderArea = fa;
+        } else if(leaderPattern == LeaderPattern.USECONTENT) {
+            InlineStackingBPLayoutManager lm;
+            lm = new InlineStackingBPLayoutManager(this,
+                     new LMiter(children.listIterator()));
+            lm.init();
+
+            // get breaks then add areas to FilledArea
+            FilledArea fa = new FilledArea();
+
+            ContentLayoutManager clm = new ContentLayoutManager(fa);
+            lm.setParentLM(clm);
+
+            clm.fillArea(lm);
+            int width = clm.getStackingSize();
+            Space spacer = null;
+            if(patternWidth > width) {
+                spacer = new Space();
+                spacer.setWidth(patternWidth - width);
+                width = patternWidth;
+            }
+            fa.setUnitWidth(width);
+            if(spacer != null) {
+                fa.addChild(spacer);
+            }
+            leaderArea = fa;
         }
+    }
+
+    protected static class FilledArea extends InlineParent {
+        MinOptMax alloc;
+        int unitWidth;
+
+        public FilledArea() {
+        }
+
+        public void setUnitWidth(int w) {
+            unitWidth = w;
+        }
+
+        public void setAllocationIPD(MinOptMax all) {
+            alloc = all;
+        }
+
+        public MinOptMax getAllocationIPD() {
+            return alloc;
+        }
+
+        public void addChild(InlineArea childArea) {
+            inlines.add(childArea);
+        }
+
+        public List getChildAreas() {
+            int units = (int)(getWidth() / unitWidth);
+            ArrayList newList = new ArrayList();
+            for(int count = 0; count < units; count++) {
+                newList.addAll(inlines);
+            }
+            return newList;
+        }
+    }
 
-        return leader;
+    public void setStructHandler(StructureHandler st) {
+        super.setStructHandler(st);
+        fontInfo = st.getFontInfo();
     }
 
     public void setup() {
@@ -77,7 +194,7 @@ public class Leader extends FObjMixed {
         BackgroundProps bProps = propMgr.getBackgroundProps();
 
         // Common Font Properties
-        //this.fontState = propMgr.getFontState(area.getFontInfo());
+        this.fontState = propMgr.getFontState(fontInfo);
 
         // Common Margin Properties-Inline
         MarginInlineProps mProps = propMgr.getMarginInlineProps();
@@ -136,7 +253,7 @@ public class Leader extends FObjMixed {
         }
 
         // if leaderPatternWidth = 0 = default = use-font-metric
-        int leaderPatternWidth =
+        patternWidth =
             this.properties.get("leader-pattern-width").getLength().mvalue();
 
     }
index 8664d663c5871c5f87048cfe5d60f599e2f7bbd5..b37b7f24adc2de6828d8fa275d7fa1035760ab8f 100644 (file)
@@ -232,8 +232,6 @@ public class PageSequence extends FObj {
                     getLogger().warn("fo:title should be first in page-sequence");
                 } else {
                     this.titleFO = (Title)child;
-                    structHandler.startPageSequence(this, titleFO, layoutMasterSet);
-                    sequenceStarted = true;
                 }
             } else if (childName.equals("fo:flow")) {
                 if (this.mainFlow != null) {
diff --git a/src/org/apache/fop/layoutmgr/ContentLayoutManager.java b/src/org/apache/fop/layoutmgr/ContentLayoutManager.java
new file mode 100644 (file)
index 0000000..8f3c642
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ */
+
+package org.apache.fop.layoutmgr;
+
+
+import org.apache.fop.area.Area;
+import org.apache.fop.area.MinOptMax;
+
+import java.util.ArrayList;
+
+/**
+ * Content Layout Manager.
+ * For use with objects that contain inline areas such as
+ * leader use-content and title.
+ */
+public class ContentLayoutManager implements LayoutManager {
+    Area holder;
+    int stackSize;
+
+    public ContentLayoutManager(Area area) {
+        holder = area;
+    }
+
+    public void fillArea(BPLayoutManager curLM) {
+
+        ArrayList childBreaks = new ArrayList();
+        MinOptMax stack = new MinOptMax();
+        int ipd = 1000000;
+        BreakPoss bp;
+
+        LayoutContext childLC = new LayoutContext(LayoutContext.NEW_AREA);
+        childLC.setLeadingSpace(new SpaceSpecifier(false));
+        childLC.setTrailingSpace(new SpaceSpecifier(false));
+        // set stackLimit for lines
+        childLC.setStackLimit(new MinOptMax(ipd));
+        childLC.setRefIPD(ipd);
+
+        while (!curLM.isFinished()) {
+            if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) {
+                stack.add(bp.getStackingSize());
+                childBreaks.add(bp);
+            }
+        }
+
+        LayoutContext lc = new LayoutContext(0);
+        lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
+        lc.setLeadingSpace(new SpaceSpecifier(false));
+        lc.setTrailingSpace(new SpaceSpecifier(false));
+        PositionIterator breakPosIter =
+          new BreakPossPosIter(childBreaks, 0, childBreaks.size());
+        curLM.addAreas(breakPosIter, lc);
+        stackSize = stack.opt;
+    }
+
+    public int getStackingSize() {
+        return stackSize;
+    }
+
+    public boolean generatesInlineAreas() {
+        return true;
+    }
+
+    public Area getParentArea (Area childArea) {
+        return holder;
+    }
+
+    public boolean addChild (Area childArea) {
+        holder.addChild(childArea);
+        return true;
+    }
+
+    public void setParentLM(LayoutManager lm) {
+    }
+
+    public int getContentIPD() {
+        return 10000000;
+    }
+
+}
+
index d2c6d42e20484216242576b3a859c3e75e3b452b..d8a00f0f79433be9dcbe0c30f6e6df8de2ad0105 100644 (file)
@@ -79,6 +79,7 @@ public class LeafNodeLayoutManager extends AbstractBPLayoutManager {
                                      BreakPoss.ISLAST);
         bp.setStackingSize(curArea.getAllocationIPD());
         bp.setNonStackingSize(curArea.getAllocationBPD());
+        bp.setTrailingSpace(new SpaceSpecifier(false));
 
         int bpd = curArea.getHeight();
         switch(alignment) {
index 1fcfdf69667b4912beb1852b3491c772a75fb045..a551dc92908e051c93197accc02e4da2963bca3d 100644 (file)
@@ -238,6 +238,10 @@ public class PDFDocument {
         return pdfInfo;
     }
 
+    public PDFInfo getInfo() {
+        return info;
+    }
+
     /**
      * Make a Type 0 sampled function
      *
index 2075a4fd156984e7f96fff4ca91505b7772c8e1c..a21eb13749090c533f39143add856724174a0479 100644 (file)
@@ -82,18 +82,25 @@ public abstract class AbstractRenderer extends AbstractLogEnabled implements Ren
     public String convertTitleToString(Title title) {
         String str = "";
         List children = title.getInlineAreas();
+        str = convertToString(children);
+        return str.trim();
+    }
 
+    private String convertToString(List children) {
+        String str = "";
         for (int count = 0; count < children.size(); count++) {
             InlineArea inline = (InlineArea) children.get(count);
             if (inline instanceof Character) {
                 str += ((Character) inline).getChar();
             } else if (inline instanceof Word) {
                 str += ((Word) inline).getWord();
+            } else if (inline instanceof InlineParent) {
+                str += convertToString(((InlineParent)inline).getChildAreas());
             } else {
                 str += " ";
             }
         }
-        return str.trim();
+        return str;
     }
 
     public void startPageSequence(Title seqTitle) {
@@ -304,11 +311,12 @@ public abstract class AbstractRenderer extends AbstractLogEnabled implements Ren
     }
 
     public void renderInlineParent(InlineParent ip) {
-        // currentBlockIPPosition += ip.getWidth();
-    Iterator iter = ip.getChildAreas().iterator();
-    while (iter.hasNext()) {
+        int saveIP = currentBlockIPPosition;
+        Iterator iter = ip.getChildAreas().iterator();
+        while (iter.hasNext()) {
             ((InlineArea)iter.next()).render(this);
         }
+        currentBlockIPPosition = saveIP + ip.getWidth();
     }
 
     protected void renderBlocks(List blocks) {
index c7059f21c1e9568c635ea2955c6675c9f15361a2..84ac9cb96ef5b237c387b7d9c2e603bed4124496 100644 (file)
@@ -176,6 +176,14 @@ public class PDFRenderer extends PrintRenderer {
         return true;
     }
 
+    public void startPageSequence(Title seqTitle) {
+        if(seqTitle != null) {
+            String str = convertTitleToString(seqTitle);
+            PDFInfo info = this.pdfDoc.getInfo();
+            info.setTitle(str);
+        }
+    }
+
     /**
      * The pdf page is prepared by making the page.
      * The page is made in the pdf document without any contents