]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Move text layout code into TextLayoutManager; add generatesInlineAreas to FObj
authorKaren Lease <klease@apache.org>
Sun, 11 Nov 2001 22:09:37 +0000 (22:09 +0000)
committerKaren Lease <klease@apache.org>
Sun, 11 Nov 2001 22:09:37 +0000 (22:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194559 13f79535-47bb-0310-9956-ffa450edef68

12 files changed:
src/org/apache/fop/fo/FOText.java
src/org/apache/fop/fo/FObj.java
src/org/apache/fop/fo/FObjMixed.java
src/org/apache/fop/fo/flow/Block.java
src/org/apache/fop/fo/flow/BlockContainer.java
src/org/apache/fop/fo/flow/ListBlock.java
src/org/apache/fop/fo/flow/ListItem.java
src/org/apache/fop/fo/flow/Table.java
src/org/apache/fop/fo/flow/TableAndCaption.java
src/org/apache/fop/fo/pagination/PageSequence.java
src/org/apache/fop/fo/pagination/RegionBA.java
src/org/apache/fop/fo/pagination/RegionBefore.java

index 8c02cc07ef9516c0928d0178e7899b1babe5ed17..84b9c667b4c61e32794c37803ed9145286015f7e 100644 (file)
@@ -56,8 +56,7 @@ public class FOText extends FObj {
         super(null);
         this.start = 0;
         this.ca = new char[e - s];
-        for (int i = s; i < e; i++)
-            ca[i - s] = chars[i];
+       System.arraycopy(chars, s, ca, 0, e-s);
         this.length = e - s;
         textInfo = ti;
     }
@@ -78,166 +77,19 @@ public class FOText extends FObj {
         return false;
     }
 
-    public Status layout(Area area) throws FOPException {
-        if (!(area instanceof BlockArea)) {
-            log.error("text outside block area"
-                                   + new String(ca, start, length));
-            return new Status(Status.OK);
-        }
-        if (this.marker == START) {
-            this.ts = new TextState();
-            ts.setUnderlined(textInfo.underlined);
-            ts.setOverlined(textInfo.overlined);
-            ts.setLineThrough(textInfo.lineThrough);
-
-            this.marker = this.start;
-        }
-        int orig_start = this.marker;
-        this.marker = addText((BlockArea)area, textInfo.fs, textInfo.red, textInfo.green, textInfo.blue,
-                              textInfo.wrapOption, this.getLinkSet(),
-                              textInfo.whiteSpaceCollapse, ca, this.marker, length,
-                              ts, textInfo.verticalAlign);
-        if (this.marker == -1) {
-
+    // Just to keep PageNumber and PageNumber citation happy for now.
+    // The real code is moved to TextLayoutManager!
 
-            // commented out by Hani Elabed, 11/28/2000
-            // if this object has been laid out
-            // successfully, leave it alone....
-            // Now, to prevent the array index out of
-            // bound of LineArea.addText(), I have added
-            // the following test at the beginning of that method.
-            // if( start == -1 ) return -1;
-            // see LineArea.addText()
-
-            // this.marker = 0;
-            return new Status(Status.OK);
-        } else if (this.marker != orig_start) {
-            return new Status(Status.AREA_FULL_SOME);
-        } else {
-            return new Status(Status.AREA_FULL_NONE);
-        }
-    }
-
-    // font-variant support : addText is a wrapper for addRealText
-    // added by Eric SCHAEFFER
     public static int addText(BlockArea ba, FontState fontState, float red,
                               float green, float blue, int wrapOption,
                               LinkSet ls, int whiteSpaceCollapse,
                               char data[], int start, int end,
                               TextState textState, int vAlign) {
-        if (fontState.getFontVariant() == FontVariant.SMALL_CAPS) {
-            FontState smallCapsFontState;
-            try {
-                int smallCapsFontHeight =
-                    (int)(((double)fontState.getFontSize()) * 0.8d);
-                smallCapsFontState = new FontState(fontState.getFontInfo(),
-                                                   fontState.getFontFamily(),
-                                                   fontState.getFontStyle(),
-                                                   fontState.getFontWeight(),
-                                                   smallCapsFontHeight,
-                                                   FontVariant.NORMAL);
-            } catch (FOPException ex) {
-                smallCapsFontState = fontState;
-                //log.error("Error creating small-caps FontState: "
-                //                       + ex.getMessage());
-            }
-
-            // parse text for upper/lower case and call addRealText
-            char c;
-            boolean isLowerCase;
-            int caseStart;
-            FontState fontStateToUse;
-            for (int i = start; i < end; ) {
-                caseStart = i;
-                c = data[i];
-                isLowerCase = (java.lang.Character.isLetter(c)
-                               && java.lang.Character.isLowerCase(c));
-                while (isLowerCase
-                        == (java.lang.Character.isLetter(c)
-                            && java.lang.Character.isLowerCase(c))) {
-                    if (isLowerCase) {
-                        data[i] = java.lang.Character.toUpperCase(c);
-                    }
-                    i++;
-                    if (i == end)
-                        break;
-                    c = data[i];
-                }
-                if (isLowerCase) {
-                    fontStateToUse = smallCapsFontState;
-                } else {
-                    fontStateToUse = fontState;
-                }
-                int index = addRealText(ba, fontStateToUse, red, green, blue,
-                                        wrapOption, ls, whiteSpaceCollapse,
-                                        data, caseStart, i, textState,
-                                        vAlign);
-                if (index != -1) {
-                    return index;
-                }
-            }
-
-            return -1;
-        }
-
-        // font-variant normal
-        return addRealText(ba, fontState, red, green, blue, wrapOption, ls,
-                           whiteSpaceCollapse, data, start, end, textState,
-                           vAlign);
-    }
-
-    protected static int addRealText(BlockArea ba, FontState fontState,
-                                     float red, float green, float blue,
-                                     int wrapOption, LinkSet ls,
-                                     int whiteSpaceCollapse, char data[],
-                                     int start, int end, TextState textState,
-                                     int vAlign) {
-        int ts, te;
-        char[] ca;
-
-        ts = start;
-        te = end;
-        ca = data;
-
-        LineArea la = ba.getCurrentLineArea();
-        if (la == null) {
-            return start;
-        }
-
-        la.changeFont(fontState);
-        la.changeColor(red, green, blue);
-        la.changeWrapOption(wrapOption);
-        la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
-        la.changeVerticalAlign(vAlign);
-        // la.changeHyphenation(language, country, hyphenate,
-        // hyphenationChar, hyphenationPushCharacterCount,
-        // hyphenationRemainCharacterCount);
-        ba.setupLinkSet(ls);
-
-        ts = la.addText(ca, ts, te, ls, textState);
-        // this.hasLines = true;
-
-        while (ts != -1) {
-            la = ba.createNextLineArea();
-            if (la == null) {
-                return ts;
-            }
-            la.changeFont(fontState);
-            la.changeColor(red, green, blue);
-            la.changeWrapOption(wrapOption);
-            la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
-            // la.changeHyphenation(language, country, hyphenate,
-            // hyphenationChar, hyphenationPushCharacterCount,
-            // hyphenationRemainCharacterCount);
-            ba.setupLinkSet(ls);
-
-            ts = la.addText(ca, ts, te, ls, textState);
-        }
-        return -1;
+       return 0;
     }
 
     public LayoutManager getLayoutManager() {
-       return new TextLayoutManager(this, ca);
+       return new TextLayoutManager(this, ca, textInfo);
     }
 }
 
index f4b6b52e641704d8b36d51dca919c56731a78253..325a937c105428090767380e03c54a38bb40880c 100644 (file)
@@ -176,6 +176,11 @@ public class FObj extends FONode {
         return false;
     }
 
+
+    public boolean generatesInlineAreas() {
+        return true;
+    }
+
     /**
      * Set writing mode for this FO.
      * Find nearest ancestor, including self, which generates
index 32eb46651d5863976ef157e639fc80a9c5543dd6..5a535be8461035ad83b526fc86342477bc8121dc 100644 (file)
@@ -9,7 +9,9 @@ package org.apache.fop.fo;
 
 import org.apache.fop.layout.Area;
 import org.apache.fop.layout.FontState;
+import org.apache.fop.layout.FontInfo;
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.StreamRenderer;
 import org.apache.fop.datatypes.ColorType;
 
 /**
@@ -18,30 +20,26 @@ import org.apache.fop.datatypes.ColorType;
  */
 public class FObjMixed extends FObj {
     FOText.TextInfo textInfo = null;
+    FontInfo fontInfo=null;
 
     public FObjMixed(FONode parent) {
         super(parent);
     }
 
+    public void setStreamRenderer(StreamRenderer st) {
+       fontInfo = st.getFontInfo();
+    }
+
     protected void addCharacters(char data[], int start, int length) {
         if(textInfo == null) {
            textInfo = new FOText.TextInfo();
-            String fontFamily =
-                getProperty("font-family").getString();
-            String fontStyle =
-                getProperty("font-style").getString();
-            String fontWeight =
-                getProperty("font-weight").getString();
-            int fontSize =
-                getProperty("font-size").getLength().mvalue();
-            // font-variant support
-            // added by Eric SCHAEFFER
-            int fontVariant =
-                getProperty("font-variant").getEnum();
-
-            //textInfo.fs = new FontState(area.getFontInfo(), fontFamily,
-            //                        fontStyle, fontWeight, fontSize,
-            //                        fontVariant);
+
+           try {
+               textInfo.fs = propMgr.getFontState(fontInfo);
+           } catch (FOPException fopex) {
+               log.error("Error setting FontState for characters: " +
+                         fopex.getMessage());
+           }
 
             ColorType c = getProperty("color").getColorType();
             textInfo.red = c.red();
index f548b9e1c93b447c2ccd841359d39d18437017c8..196cf6aa02c3ee94d55a6d79002906faf73a267e 100644 (file)
@@ -356,4 +356,8 @@ public class Block extends FObjMixed {
        return new BlockLayoutManager(this);
     }
 
+
+    public boolean generatesInlineAreas() {
+        return false;
+    }
 }
index fc218cb7691dfc9b5697f55ded9d25d51bc5893f..40150620993ee78129192790e07ead20c0f47e3c 100644 (file)
@@ -167,6 +167,10 @@ public class BlockContainer extends FObj {
         return true;
     }
 
+    public boolean generatesInlineAreas() {
+        return false;
+    }
+
     public int getSpan() {
         return this.span;
     }
index f66c7ab251a210a97ac2c4755e963200d4cff007..8c8d65d60bdbc3c713d901479159186b6889c8ba 100644 (file)
@@ -164,4 +164,9 @@ public class ListBlock extends FObj {
         return new Status(Status.OK);
     }
 
+    public boolean generatesInlineAreas() {
+        return false;
+    }
+
+
 }
index e16d59ce26d21dc047a410a3f669738f09275804..68af21547d4b571111d89f707e17dc184ac6763b 100644 (file)
@@ -168,4 +168,8 @@ public class ListItem extends FObj {
             return 0;                              // not laid out yet
     }
 
+    public boolean generatesInlineAreas() {
+        return false;
+    }
+
 }
index 8ab0d3ce122b44437f13c6f134e04917cb30b598..38e4a79af26783ef88ffaa548e1122bd87c4f9c9 100644 (file)
@@ -511,6 +511,11 @@ public class Table extends FObj {
             return 0;    // not laid out yet
     }
 
+    public boolean generatesInlineAreas() {
+        return false;
+    }
+
+
     /**
      * Initialize table inline-progression-properties values
      */
index 33dae362c4cc1d7f2dd25b855a82adde139d57eb..cca6c2ef70b6e54ff4db9d6fc2419d12e09828ac 100644 (file)
@@ -48,4 +48,8 @@ public class TableAndCaption extends ToBeImplementedElement {
 
         return super.layout(area);
     }
+
+    public boolean generatesInlineAreas() {
+        return false;
+    }
 }
index da1e22883a306dafc07ca8fb26f418f22b0db1d6..1e05cef5c9d97ac82dedfc55aac6b006abe0cd3e 100644 (file)
@@ -21,6 +21,7 @@ import org.apache.fop.layout.PageMaster;
 import org.apache.fop.area.AreaTree;
 import org.apache.fop.area.PageViewport;
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.StreamRenderer;
 
 import org.apache.fop.layoutmgr.PageLayoutManager;
 
@@ -46,6 +47,10 @@ public class PageSequence extends FObj {
     //
     // associations
     //
+    /**
+     * Use to layout and render the page sequence.
+     */
+    private StreamRenderer streamRenderer;
 
     /**
      * The parent root object
@@ -266,12 +271,14 @@ public class PageSequence extends FObj {
        }
     }
 
+
+    public void setStreamRenderer(StreamRenderer st) {
+       this.streamRenderer = st;
+    }
+
     public void end() {
        try {
-           AreaTree at = new AreaTree();
-           at.setTreeModel(AreaTree.createStorePagesModel());
-           at.startPageSequence(null);
-           format(at);
+           this.streamRenderer.render(this);
        } catch (FOPException fopex) {
            log.error("Error in PageSequence.end(): " +
                      fopex.getMessage());
@@ -314,6 +321,8 @@ public class PageSequence extends FObj {
        // If no main flow, nothing to layout!
        if (this.mainFlow == null) return;
 
+       areaTree.startPageSequence(null);
+
        // Initialize if already used?
         this.layoutMasterSet.resetPageMasters();
 
index db526e765752310ec464e457038c80fb8e8f7591..7efb3c29115811f77234b13c332fc321a963cc02 100644 (file)
@@ -27,6 +27,7 @@ public abstract class RegionBA extends RegionBASE {
     }
 
     public void end() {
+       super.end();
         bPrecedence =
            (this.properties.get("precedence").getEnum()==Precedence.TRUE);
     }
index 0b33ccec18e00d6b91f2b6b55afd5e315af394bd..f829ef6b53b95fee0b4b80614a9fb47a9b7678c6 100644 (file)
@@ -22,9 +22,9 @@ public class RegionBefore extends RegionBA {
         super(parent);
     }
 
-    public void handleAttrs(Attributes attlist) throws FOPException {
-        super.handleAttrs(attlist);
-    }
+//     public void handleAttrs(Attributes attlist) throws FOPException {
+//         super.handleAttrs(attlist);
+//     }
 
 
     protected String getDefaultRegionName() {