]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Added basic support for forward page-number-citations
authorJordan Naftolin <jordan@apache.org>
Wed, 5 Jul 2000 23:06:58 +0000 (23:06 +0000)
committerJordan Naftolin <jordan@apache.org>
Wed, 5 Jul 2000 23:06:58 +0000 (23:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193455 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/datatypes/IDNode.java
src/org/apache/fop/datatypes/IDReferences.java
src/org/apache/fop/fo/flow/PageNumberCitation.java
src/org/apache/fop/layout/BlockArea.java
src/org/apache/fop/layout/InlineArea.java
src/org/apache/fop/layout/LineArea.java
src/org/apache/fop/render/pdf/PDFRenderer.java

index 2645566a4f1da50a917f6527b7f586418e31e345..0ef57e895038a039c46618788223591910fb9794 100644 (file)
@@ -96,7 +96,7 @@ public class IDNode
      * 
      * @return page number of this node
      */
-    protected String getPageNumber()
+    public String getPageNumber()
     {             
         return(pageNumber != -1)?new Integer(pageNumber).toString():null;
     }
index ef511f5c63057262a247e2d6ff434ef9bb959a9a..083c10adb599dc749df2adcc6c1056b46725c56e 100644 (file)
@@ -52,6 +52,7 @@
 package org.apache.fop.datatypes;
 
 import org.apache.fop.pdf.PDFGoTo;
+import org.apache.fop.layout.AreaContainer;
 
 
 // Java
@@ -125,7 +126,7 @@ public class IDReferences {
     public void configureID(String id, Area area)
     {
         if ( id!=null && !id.equals("") ) {
-            setPosition(id,area.getPage().getBody().getXPosition()-ID_PADDING,area.getPage().getBody().getYPosition() - area.getAbsoluteHeight()+ID_PADDING);                                                
+            setPosition(id,area.getPage().getBody().getXPosition()+area.getTableCellXOffset()-ID_PADDING,area.getPage().getBody().getYPosition() - area.getAbsoluteHeight()+ID_PADDING);                                                
             setPageNumber(id,area.getPage().getNumber());
                 area.getPage().addToIDList(id);                                    
             }
index d9faf67c3d437f068cbc7297f99beb98862f8129..a5b8be56f474ff525fe3ecb73cda1cc686260bf1 100644 (file)
@@ -186,12 +186,19 @@ public class PageNumberCitation extends FObj
         IDReferences idReferences= area.getIDReferences();       
 
         String pageNumber=idReferences.getPageNumber(refId);                
-        String output = (pageNumber!=null)?pageNumber:"?";
-
 
         int orig_start = this.marker;
 
-        this.marker = ((BlockArea) area).addText(fs, red, green, blue, wrapOption, null, whiteSpaceTreatment, output.toCharArray(), 0, output.length());
+        if(pageNumber!=null)  // if we already know the page number
+        {
+            String output=pageNumber;
+            this.marker = ((BlockArea) area).addText(fs, red, green, blue, wrapOption, null, whiteSpaceTreatment, output.toCharArray(), 0, output.length());
+        }
+        else  // add pageNumberCitation to area to be resolved during rendering
+        {        
+            this.marker = ((BlockArea) area).addPageNumberCitation(fs, red, green, blue, wrapOption, null, whiteSpaceTreatment, refId);        
+        }
+                
 
         if ( this.marker == -1 )
         {
index 4831b0feaa971b3e77d4d402fa2bab46f9631648..3cb5a777280c64530a571cda617f66286b6ad4fd 100644 (file)
@@ -115,6 +115,28 @@ public class BlockArea extends Area {
        }
     }
 
+    public int addPageNumberCitation(FontState fontState, float red, float green,
+                      float blue, int wrapOption, LinkSet ls,
+                      int whiteSpaceTreatment, String refid) {
+
+        this.currentLineArea.changeFont(fontState);
+       this.currentLineArea.changeColor(red, green, blue);
+       this.currentLineArea.changeWrapOption(wrapOption);
+       this.currentLineArea.changeWhiteSpaceTreatment(whiteSpaceTreatment);
+
+        if (ls != null) {
+            this.currentLinkSet = ls;
+           ls.setYOffset(currentHeight);
+       }
+
+       this.currentLineArea.addPageNumberCitation(refid,ls);            
+       this.hasLines = true;
+        
+        return -1;
+
+    }
+
+Imaginary Buffer Line
     public int addText(FontState fontState, float red, float green,
                       float blue, int wrapOption, LinkSet ls,
                       int whiteSpaceTreatment, char data[],
index 239270a7a126e25f65f485d25892756c19134ccc..f55c6b9fc09954311a5858bfc0c847ba01fee1e3 100644 (file)
@@ -55,6 +55,7 @@ import org.apache.fop.render.Renderer;
 public class InlineArea extends Area {
 
     private String text;
+    protected String pageNumberId=null;
     private float red, green, blue;
 
     public InlineArea(FontState fontState, float red, float green, float blue, String text, int width) {
@@ -85,4 +86,8 @@ public class InlineArea extends Area {
     public String getText() {
        return this.text;
     }
+
+    public String getPageNumberID() {
+        return pageNumberId;
+    }
 }
index edfbee2d17815a72e16738a2da2fc47006d60730..182cf62c8001d6075d9b20fb7513b1d2d9c22fc4 100644 (file)
@@ -67,6 +67,8 @@ import org.apache.fop.fo.properties.TextAlign; // for enumerated
 import org.apache.fop.fo.properties.TextAlignLast; // for enumerated
 // values 
 
+import org.apache.fop.datatypes.IDNode;
+
 public class LineArea extends Area {
        
     protected int lineHeight;
@@ -149,6 +151,29 @@ public class LineArea extends Area {
        renderer.renderLineArea(this);
     }
 
+    public int addPageNumberCitation(String refid, LinkSet ls)
+    {
+       
+       /* We should add code here to handle the case where the page number doesn't fit on the current line
+       */
+
+        //Space must be alloted to the page number, so currently we give it 3 spaces 
+        int width= currentFontState.width(32) * 3;
+        
+        PageNumberInlineArea pia = new PageNumberInlineArea(currentFontState,
+        this.red, this.green,
+        this.blue,
+        refid,
+        width);                        
+                
+        pendingAreas.addElement(pia);
+        pendingWidth += width;
+        wordWidth = 0;
+
+        return -1;
+    }
+
+
     public int addText(char odata[], int start, int end, LinkSet ls) {
        boolean overrun = false;
 
index db68fe7640439890b31169016e078c3a6a627474..0fe1609a79eaca8d29627da7cb4b7e5b613f646f 100644 (file)
@@ -74,13 +74,16 @@ import java.util.Vector;
  * Renderer that renders areas to PDF
  */
 public class PDFRenderer implements Renderer {
-       
+                       
        /** the PDF Document being created */
        protected PDFDocument pdfDoc;
 
        /** the /Resources object of the PDF document being created */
        protected PDFResources pdfResources;
 
+       /** the IDReferences for this document */
+       protected IDReferences idReferences;
+
        /** the current stream to add PDF commands to */
        PDFStream currentStream;
 
@@ -145,7 +148,7 @@ public class PDFRenderer implements Renderer {
         public void render(AreaTree areaTree, PrintWriter writer)
         throws IOException, FOPException {      
             MessageHandler.logln("rendering areas to PDF");
-            IDReferences idReferences=areaTree.getIDReferences();           
+            idReferences=areaTree.getIDReferences();           
             this.pdfResources = this.pdfDoc.getResources();            
             this.pdfDoc.setIDReferences(idReferences);
             Enumeration e = areaTree.getPages().elements(); 
@@ -431,7 +434,14 @@ public class PDFRenderer implements Renderer {
                         +(rx/1000f) + " " + (bl/1000f)
                         + " Tm (");
 
-       String s = area.getText();
+       String s;
+       if ( area.getPageNumberID()!=null ) { // this text is a page number, so resolve it
+            s = idReferences.getPageNumber(area.getPageNumberID());            
+        }
+        else {
+            s = area.getText();
+        }
+       
        int l = s.length();
 
        for (int i=0; i < l; i++) {