]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
move fo/flow/PageNumberCitation.getInlineArea() to layoutmgr/AddLMVisitor.getPageNumb...
authorWilliam Victor Mote <vmote@apache.org>
Tue, 26 Aug 2003 16:48:28 +0000 (16:48 +0000)
committerWilliam Victor Mote <vmote@apache.org>
Tue, 26 Aug 2003 16:48:28 +0000 (16:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196843 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/flow/PageNumberCitation.java
src/java/org/apache/fop/layoutmgr/AddLMVisitor.java

index 3bd69a79b072c7d428ad3682e93d3fc2a1ba78db..c959d2488784596a56259b28f5e48408dae10962 100644 (file)
 package org.apache.fop.fo.flow;
 
 // FOP
-import org.apache.fop.area.PageViewport;
-import org.apache.fop.area.Trait;
-import org.apache.fop.area.inline.InlineArea;
-import org.apache.fop.area.inline.UnresolvedPageNumber;
-import org.apache.fop.area.inline.Word;
 import org.apache.fop.datatypes.ColorType;
 import org.apache.fop.fo.FOTreeVisitor;
 import org.apache.fop.fo.FONode;
@@ -93,7 +88,6 @@ public class PageNumberCitation extends FObj {
     private String pageNumber;
     private String refId;
     private TextState ts;
-    private InlineArea inline = null;
     private boolean unresolved = false;
 
     /**
@@ -111,52 +105,11 @@ public class PageNumberCitation extends FObj {
         fontInfo = foih.getFontInfo();
     }
 
-    // if id can be resolved then simply return a word, otherwise
-    // return a resolveable area
-    public InlineArea getInlineArea(LayoutProcessor parentLM) {
-        if (refId.equals("")) {
-            getLogger().error("page-number-citation must contain \"ref-id\"");
-            return null;
-        }
-        PageViewport page = parentLM.resolveRefID(refId);
-        if (page != null) {
-            String str = page.getPageNumber();
-            // get page string from parent, build area
-            Word word = new Word();
-            inline = word;
-            int width = getStringWidth(str);
-            word.setWord(str);
-            inline.setIPD(width);
-            inline.setHeight(fontState.getAscender()
-                             - fontState.getDescender());
-            inline.setOffset(fontState.getAscender());
-
-            inline.addTrait(Trait.FONT_NAME, fontState.getFontName());
-            inline.addTrait(Trait.FONT_SIZE,
-                            new Integer(fontState.getFontSize()));
-            unresolved = false;
-        } else {
-            unresolved = true;
-            inline = new UnresolvedPageNumber(refId);
-            String str = "MMM"; // reserve three spaces for page number
-            int width = getStringWidth(str);
-            inline.setIPD(width);
-            inline.setHeight(fontState.getAscender()
-                             - fontState.getDescender());
-            inline.setOffset(fontState.getAscender());
-
-            inline.addTrait(Trait.FONT_NAME, fontState.getFontName());
-            inline.addTrait(Trait.FONT_SIZE,
-                            new Integer(fontState.getFontSize()));
-        }
-        return inline;
-    }
-
     /**
      * @param str string to be measured
      * @return width (in millipoints ??) of the string
      */
-    protected int getStringWidth(String str) {
+    public int getStringWidth(String str) {
         int width = 0;
         for (int count = 0; count < str.length(); count++) {
             width += CharUtilities.getCharWidth(str.charAt(count),
@@ -222,16 +175,20 @@ public class PageNumberCitation extends FObj {
         return refId;
     }
 
-    public InlineArea getInline() {
-        return inline;
-    }
-
     public boolean getUnresolved() {
         return unresolved;
     }
 
+    public void setUnresolved(boolean isUnresolved) {
+        unresolved = isUnresolved;
+    }
+
     public void acceptVisitor(FOTreeVisitor fotv) {
         fotv.serveVisitor(this);
     }
 
+    public Font getFontState() {
+        return fontState;
+    }
+
 }
index 2054d9ca53b21147b06afd5b9d260ec6a6aaa1aa..1a54440a76531e4391c5fb05ec561377da9a357b 100644 (file)
@@ -60,6 +60,7 @@ 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.UnresolvedPageNumber;
 import org.apache.fop.area.inline.Word;
 import org.apache.fop.area.inline.Image;
 import org.apache.fop.area.inline.Viewport;
@@ -712,7 +713,8 @@ public class AddLMVisitor extends FOTreeVisitor {
          LayoutManager lm;
          lm = new LeafNodeLayoutManager() {
                      public InlineArea get(LayoutContext context) {
-                         return node.getInlineArea(parentLM);
+                         curArea = getPageNumberCitationInlineArea(node, parentLM);
+                         return curArea;
                      }
 
                      public void addAreas(PositionIterator posIter,
@@ -720,7 +722,7 @@ public class AddLMVisitor extends FOTreeVisitor {
                          super.addAreas(posIter, context);
                          if (node.getUnresolved()) {
                              parentLM.addUnresolvedArea(node.getRefId(),
-                                                        (Resolveable) node.getInline());
+                                                        (Resolveable) curArea);
                          }
                      }
 
@@ -733,6 +735,49 @@ public class AddLMVisitor extends FOTreeVisitor {
          currentLMList.add(lm);
      }
 
+     // if id can be resolved then simply return a word, otherwise
+     // return a resolveable area
+     public InlineArea getPageNumberCitationInlineArea(PageNumberCitation node,
+             LayoutProcessor parentLM) {
+         if (node.getRefId().equals("")) {
+             node.getLogger().error("page-number-citation must contain \"ref-id\"");
+             return null;
+         }
+         PageViewport page = parentLM.resolveRefID(node.getRefId());
+         InlineArea inline = null;
+         if (page != null) {
+             String str = page.getPageNumber();
+             // get page string from parent, build area
+             Word word = new Word();
+             inline = word;
+             int width = node.getStringWidth(str);
+             word.setWord(str);
+             inline.setIPD(width);
+             inline.setHeight(node.getFontState().getAscender()
+                              - node.getFontState().getDescender());
+             inline.setOffset(node.getFontState().getAscender());
+
+             inline.addTrait(Trait.FONT_NAME, node.getFontState().getFontName());
+             inline.addTrait(Trait.FONT_SIZE,
+                             new Integer(node.getFontState().getFontSize()));
+             node.setUnresolved(false);
+         } else {
+             node.setUnresolved(true);
+             inline = new UnresolvedPageNumber(node.getRefId());
+             String str = "MMM"; // reserve three spaces for page number
+             int width = node.getStringWidth(str);
+             inline.setIPD(width);
+             inline.setHeight(node.getFontState().getAscender()
+                              - node.getFontState().getDescender());
+             inline.setOffset(node.getFontState().getAscender());
+
+             inline.addTrait(Trait.FONT_NAME, node.getFontState().getFontName());
+             inline.addTrait(Trait.FONT_SIZE,
+                             new Integer(node.getFontState().getFontSize()));
+         }
+         return inline;
+     }
+
      public void serveVisitor(Table node) {
          TableLayoutManager tlm = new TableLayoutManager();
          tlm.setUserAgent(node.getUserAgent());