]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Fixed basic-link horizontal position with justification turned on.
authorKelly Campbell <kellyc@apache.org>
Thu, 29 Mar 2001 07:34:57 +0000 (07:34 +0000)
committerKelly Campbell <kellyc@apache.org>
Thu, 29 Mar 2001 07:34:57 +0000 (07:34 +0000)
PR: 953
Obtained from:
Submitted by:
Reviewed by:

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

docs/examples/build.xml
docs/examples/fo/newlinktest.fo [new file with mode: 0644]
src/org/apache/fop/layout/LineArea.java
src/org/apache/fop/layout/LinkSet.java
src/org/apache/fop/layout/LinkedRectangle.java
src/org/apache/fop/layout/inline/InlineArea.java

index 09e3b7b0426bdd0bacac2b9ca7f4556b7ab401d8..5c22ea6e4eb42a7cc5857ac45b16a9e4e99f629d 100644 (file)
@@ -46,6 +46,7 @@
     <fop fofile="${foDir}/table.fo"  pdffile="${testDir}/table.pdf"/>
     <fop fofile="${foDir}/list.fo"   pdffile="${testDir}/list.pdf"/>
     <fop fofile="${foDir}/link.fo"   pdffile="${testDir}/link.pdf"/> 
+    <fop fofile="${foDir}/newlinktest.fo" pdffile="${testDir}/newlinktest.pdf"/>
     <fop fofile="${foDir}/border.fo"   pdffile="${testDir}/border.pdf"/> 
     <fop fofile="${foDir}/extensive.fo"   pdffile="${testDir}/extensive.pdf"/> 
     <fop fofile="${foDir}/images.fo"   pdffile="${testDir}/images.pdf"/> 
@@ -85,6 +86,7 @@
     <fop fofile="${foDir}/table.fo"  pdffile="${referenceDir}/table.pdf"/>
     <fop fofile="${foDir}/list.fo"   pdffile="${referenceDir}/list.pdf"/>
     <fop fofile="${foDir}/link.fo"   pdffile="${referenceDir}/link.pdf"/>
+    <fop fofile="${foDir}/newlinktest.fo"   pdffile="${referenceDir}/newlinktest.pdf"/>
     <fop fofile="${foDir}/border.fo"   pdffile="${referenceDir}/border.pdf"/>
     <fop fofile="${foDir}/extensive.fo"   pdffile="${referenceDir}/extensive.pdf"/>
     <fop fofile="${foDir}/images.fo"   pdffile="${referenceDir}/images.pdf"/>
diff --git a/docs/examples/fo/newlinktest.fo b/docs/examples/fo/newlinktest.fo
new file mode 100644 (file)
index 0000000..55df882
--- /dev/null
@@ -0,0 +1,114 @@
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+  <fo:layout-master-set>
+
+    <!-- layout for the first page -->
+    <fo:simple-page-master master-name="first"
+                  margin-top="1in" 
+                  margin-bottom="1in" 
+                  margin-left="1in" 
+                  margin-right="1in">
+      <fo:region-body/>
+    </fo:simple-page-master>
+
+
+  </fo:layout-master-set>
+  <!-- end: defines page layout -->
+
+  <!-- actual layout -->
+  <fo:page-sequence master-name="first">
+
+
+
+
+<fo:flow flow-name="xsl-region-body">
+
+  <fo:block space-after.optimum="3pt" font-family="serif" id="block1">
+     FOP is the world's first print formatter driven by XSL formatting
+     objects. It is a Java 1.1 application that reads a formatting object
+     tree and then turns it into a PDF document. The formatting object
+     tree, can be in the form of an XML document (output by an XSLT engine
+     like XT or Xalan) or can be passed in memory as a DOM Document or (in
+     the case of XT) SAX events.
+  </fo:block>
+
+  <fo:block space-after.optimum="12pt" font-family="serif">FOP is part of Apache's XML project. The homepage of FOP is 
+     <fo:inline font-style="italic" font-family="serif"><fo:basic-link color="blue" external-destination="http://xml.apache.org/fop">http://xml.apache.org/fop</fo:basic-link></fo:inline>
+  </fo:block>
+
+<fo:block space-after.optimum="12pt" font-family="serif" font-weight="bold" text-align="center">
+align="start"
+</fo:block>
+
+<fo:block space-after.optimum="12pt" font-family="serif" text-align="start">
+     Apache FOP is the world's first print formatter driven by XSL formatting
+     objects. It is a Java 1.1 application that reads a <fo:basic-link internal-destination="block1" color="blue">formatting object</fo:basic-link>
+     tree and then turns it into a <fo:basic-link internal-destination="block1" color="blue">PDF document</fo:basic-link>. The formatting object
+     tree, can be in the form of an XML <fo:basic-link internal-destination="block1" color="blue">document</fo:basic-link> (output by an XSLT engine
+     like XT or Xalan) or can be passed in memory as a DOM Document or (in
+     the case of XT) SAX events.
+
+  </fo:block>
+
+<fo:block space-after.optimum="12pt" font-family="serif" font-weight="bold" text-align="center">
+align="center"
+</fo:block>
+
+<fo:block space-after.optimum="12pt" font-family="serif" text-align="center">
+     Apache FOP is the world's first print formatter driven by XSL formatting
+     objects. It is a Java 1.1 application that reads a <fo:basic-link internal-destination="block1" color="blue">formatting object</fo:basic-link>
+     tree and then turns it into a <fo:basic-link internal-destination="block1" color="blue">PDF document</fo:basic-link>. The formatting object
+     tree, can be in the form of an XML <fo:basic-link internal-destination="block1" color="blue">document</fo:basic-link> (output by an XSLT engine
+     like XT or Xalan) or can be passed in memory as a DOM Document or (in
+     the case of XT) SAX events.
+
+  </fo:block>
+
+<fo:block space-after.optimum="12pt" font-family="serif" font-weight="bold" text-align="center">
+align="justify"
+</fo:block>
+
+  <fo:block space-after.optimum="12pt" font-family="serif" text-align="justify">
+     Apache FOP is the world's first print formatter driven by XSL formatting
+     objects. It is a Java 1.1 application that reads a <fo:basic-link internal-destination="block1" color="blue">formatting object</fo:basic-link>
+     tree and then turns it into a <fo:basic-link internal-destination="block1" color="blue">PDF document</fo:basic-link>. The formatting object
+     tree, can be in the form of an XML <fo:basic-link internal-destination="block1" color="blue">document</fo:basic-link> (output by an XSLT engine
+     like XT or Xalan) or can be passed in memory as a DOM Document or (in
+     the case of XT) SAX events.
+
+  </fo:block>
+
+<!-- table start -->
+    <fo:table>
+      <fo:table-column column-width="50mm"/>
+      <fo:table-column column-width="50mm"/>
+      <fo:table-column column-width="50mm"/>
+      <fo:table-body>
+        <fo:table-row>
+          <fo:table-cell ><fo:block>good</fo:block></fo:table-cell>
+          <fo:table-cell ><fo:block>bad</fo:block></fo:table-cell>
+          <fo:table-cell ><fo:block><fo:basic-link internal-destination="block1" color="blue">ugly</fo:basic-link></fo:block></fo:table-cell>
+        </fo:table-row>
+        <fo:table-row>
+          <fo:table-cell ><fo:block>nice</fo:block></fo:table-cell>
+          <fo:table-cell ><fo:block><fo:basic-link internal-destination="block1" color="blue">dice</fo:basic-link></fo:block></fo:table-cell>
+          <fo:table-cell ><fo:block>vice</fo:block></fo:table-cell>
+        </fo:table-row>
+        <fo:table-row>
+          <fo:table-cell ><fo:block>literature</fo:block></fo:table-cell>
+          <fo:table-cell ><fo:block>music</fo:block></fo:table-cell>
+          <fo:table-cell ><fo:block><fo:basic-link internal-destination="block1" color="blue">art</fo:basic-link></fo:block></fo:table-cell>
+        </fo:table-row>
+        <fo:table-row>
+          <fo:table-cell ><fo:block><fo:basic-link internal-destination="block1" color="blue">java</fo:basic-link></fo:block></fo:table-cell>
+          <fo:table-cell ><fo:block>perl</fo:block></fo:table-cell>
+          <fo:table-cell ><fo:block>python</fo:block></fo:table-cell>
+        </fo:table-row>
+      </fo:table-body>
+    </fo:table>
+    <!-- table end -->
+
+
+</fo:flow>
+
+</fo:page-sequence>
+</fo:root>
index 1c0a94f3f8423a45031c7a1e0c74d790133c607d..6425330da6a2ec6eeb4edb4b316049712d946510 100644 (file)
@@ -244,7 +244,7 @@ public class LineArea extends Area {
                                                              ((InlineArea) box).
                                                              getContentWidth(),
                                                              fontState.getFontSize());
-                                ls.addRect(lr, this);
+                                ls.addRect(lr, this, (InlineArea)box);
                             }
                         }
                         addChild(box);
@@ -277,7 +277,7 @@ public class LineArea extends Area {
                             Rectangle lr = new Rectangle(finalWidth, 0,
                                                          ia.getContentWidth(),
                                                          fontState.getFontSize());
-                            ls.addRect(lr, this);
+                            ls.addRect(lr, this, ia);
                         }
                         finalWidth += wordWidth;
 
@@ -419,7 +419,7 @@ public class LineArea extends Area {
                 Rectangle lr = new Rectangle(finalWidth + spaceWidth +
                                              embeddedLinkStart, spaceWidth,
                                              pia.getContentWidth(), fontState.getFontSize());
-                ls.addRect(lr, this);
+                ls.addRect(lr, this, pia);
             }
 
             embeddedLinkStart += wordWidth;
@@ -606,8 +606,7 @@ public class LineArea extends Area {
                 endIndent += padding;
                 break;
             case TextAlign.JUSTIFY: // justify
-                Vector spaceList = new Vector();
-
+               // first pass - count the spaces
                 int spaceCount = 0;
                 Enumeration e = children.elements();
                 while (e.hasMoreElements()) {
@@ -615,7 +614,6 @@ public class LineArea extends Area {
                     if (b instanceof InlineSpace) {
                         InlineSpace space = (InlineSpace) b;
                         if (space.getResizeable()) {
-                            spaceList.addElement(space);
                             spaceCount++;
                         }
                     }
@@ -626,11 +624,22 @@ public class LineArea extends Area {
                 } else { // no spaces
                     padding = 0;
                 }
-                Enumeration f = spaceList.elements();
-                while (f.hasMoreElements()) {
-                    InlineSpace space2 = (InlineSpace) f.nextElement();
-                    int i = space2.getSize();
-                    space2.setSize(i + padding);
+               // second pass - add additional space
+               spaceCount = 0;
+               e = children.elements();
+               while (e.hasMoreElements()) {
+                    Box b = (Box) e.nextElement();
+                    if (b instanceof InlineSpace) {
+                        InlineSpace space = (InlineSpace) b;
+                        if (space.getResizeable()) {
+                           space.setSize(space.getSize() + padding);
+                           spaceCount++;
+                        }
+                    }
+                   else if (b instanceof InlineArea) {
+                       ((InlineArea)b).setXOffset(spaceCount * padding);
+                   }
+                   
                 }
         }
     }
index 771ce44867e98747df8f0ce0ff83c55a8937c43b..bce16ff59489980cb030f60c57b5c79572b58cb5 100644 (file)
@@ -59,6 +59,8 @@ import java.util.Vector;
 import java.util.Enumeration;
 import java.awt.Rectangle;
 
+import org.apache.fop.layout.inline.InlineArea;
+
 import org.apache.fop.fo.properties.WrapOption; // for enumerated
 // values
 // import org.apache.fop.fo.properties.WhiteSpaceCollapse; // for
@@ -105,8 +107,8 @@ public class LinkSet {
         this.linkType = linkType;
     }
 
-    public void addRect(Rectangle r, LineArea lineArea) {
-        LinkedRectangle linkedRectangle = new LinkedRectangle(r, lineArea);
+    public void addRect(Rectangle r, LineArea lineArea, InlineArea inlineArea) {
+        LinkedRectangle linkedRectangle = new LinkedRectangle(r, lineArea, inlineArea);
         linkedRectangle.setY(this.yoffset);
         if (this.yoffset > maxY) {
             maxY = this.yoffset;
@@ -171,7 +173,9 @@ public class LinkSet {
         Enumeration re = rects.elements();
         while (re.hasMoreElements()) {
             LinkedRectangle r = (LinkedRectangle) re.nextElement();
-            r.setX(r.getX() + r.getLineArea().getStartIndent());
+            r.setX(r.getX() + 
+                  r.getLineArea().getStartIndent() + 
+                  r.getInlineArea().getXOffset());
         }
     }
 
index b23b763da66f5539cc42d8904d99ceab2b4d1583..9956e3a802c286d403b226df11b45bacd15086e9 100644 (file)
@@ -57,6 +57,8 @@ package org.apache.fop.layout;
 // Java
 import java.awt.Rectangle;
 
+import org.apache.fop.layout.inline.InlineArea;
+
 /**
  * an object that stores a rectangle that is linked, and the LineArea
  * that it is logically associated with
@@ -69,14 +71,19 @@ public class LinkedRectangle {
     /** the associated LineArea */
     protected LineArea lineArea;
 
-    public LinkedRectangle(Rectangle link, LineArea lineArea) {
+    /** the associated InlineArea */
+    protected InlineArea inlineArea;
+
+    public LinkedRectangle(Rectangle link, LineArea lineArea, InlineArea inlineArea) {
        this.link = link;
        this.lineArea = lineArea;
+       this.inlineArea = inlineArea;
     }
     
     public LinkedRectangle(LinkedRectangle lr) {
        this.link = new Rectangle( lr.getRectangle() );
        this.lineArea = lr.getLineArea();
+       this.inlineArea = lr.getInlineArea();
     }
 
     public void setRectangle(Rectangle link) {
@@ -91,9 +98,17 @@ public class LinkedRectangle {
        return this.lineArea;
     }
     
-    public void setLineArea() {
+    public void setLineArea(LineArea lineArea) {
        this.lineArea = lineArea;
     }
+
+    public InlineArea getInlineArea() {
+       return this.inlineArea;
+    }
+    
+    public void setLineArea(InlineArea inlineArea) {
+       this.inlineArea = inlineArea;
+    }
     
     public void setX(int x) {
        this.link.x = x;
index c0dedb4b4cde93d7fb6e22887712e2c469a9bc77..6f202bdaec23b6ba4b69b7e65af79a1610838799 100644 (file)
@@ -58,6 +58,9 @@ import org.apache.fop.layout.*;
 public abstract class InlineArea extends Area {
 
     private int yOffset = 0;
+
+    /** amount of space added since the original layout - needed by links */
+    private int xOffset = 0;
     protected int height = 0;
     private int verticalAlign = 0;
     protected String pageNumberId = null;
@@ -114,6 +117,14 @@ public abstract class InlineArea extends Area {
         return this.yOffset;
     }
 
+    public void setXOffset(int xOffset) {
+        this.xOffset = xOffset;
+    }
+
+    public int getXOffset() {
+        return this.xOffset;
+    }
+
     public String getPageNumberID() {
         return pageNumberId;
     }