You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by sp...@apache.org on 2011/06/15 20:37:13 UTC

svn commit: r1136144 [4/5] - in /xmlgraphics/fop/branches/Temp_ComplexScripts: ./ src/codegen/complexscripts/arab/ttx/ src/documentation/intermediate-format-ng/ src/java/org/apache/fop/area/ src/java/org/apache/fop/area/inline/ src/java/org/apache/fop/...

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/AbstractPathOrientedRenderer.java Wed Jun 15 18:37:11 2011
@@ -65,29 +65,31 @@ public abstract class AbstractPathOrient
      * @param block the block to render the traits
      */
     protected void handleBlockTraits(Block block) {
-        int borderPaddingStart = block.getBorderAndPaddingWidthStart();
-        int borderPaddingBefore = block.getBorderAndPaddingWidthBefore();
+        float borderPaddingStart = block.getBorderAndPaddingWidthStart() / 1000f;
+        float borderPaddingEnd = block.getBorderAndPaddingWidthEnd() / 1000f;
+        float borderPaddingBefore = block.getBorderAndPaddingWidthBefore() / 1000f;
+        float borderPaddingAfter = block.getBorderAndPaddingWidthAfter() / 1000f;
 
         float startx = currentIPPosition / 1000f;
         float starty = currentBPPosition / 1000f;
         float width = block.getIPD() / 1000f;
         float height = block.getBPD() / 1000f;
 
-        /* using start-indent now
-        Integer spaceStart = (Integer) block.getTrait(Trait.SPACE_START);
-        if (spaceStart != null) {
-            startx += spaceStart.floatValue() / 1000f;
-        }*/
-        startx += block.getStartIndent() / 1000f;
-        startx -= block.getBorderAndPaddingWidthStart() / 1000f;
-
-        width += borderPaddingStart / 1000f;
-        width += block.getBorderAndPaddingWidthEnd() / 1000f;
-        height += borderPaddingBefore / 1000f;
-        height += block.getBorderAndPaddingWidthAfter() / 1000f;
+        int level = block.getBidiLevel();
+        if ( ( level == -1 ) || ( ( level & 1 ) == 0 ) ) {
+            startx += block.getStartIndent() / 1000f; 
+            startx -= borderPaddingStart;
+        } else {
+            startx += block.getEndIndent() / 1000f; 
+            startx -= borderPaddingEnd;
+        }
 
-        drawBackAndBorders(block, startx, starty,
-            width, height);
+        width += borderPaddingStart;
+        width += borderPaddingEnd;
+        height += borderPaddingBefore;
+        height += borderPaddingAfter;
+
+        drawBackAndBorders(block, startx, starty, width, height);
     }
 
     /**
@@ -106,7 +108,12 @@ public abstract class AbstractPathOrient
 
         // adjust the current position according to region borders and padding
         currentBPPosition = referenceArea.getBorderAndPaddingWidthBefore();
-        currentIPPosition = referenceArea.getBorderAndPaddingWidthStart();
+        int level = region.getBidiLevel();
+        if ( ( level == -1 ) || ( ( level & 1 ) == 0 ) ) {
+            currentIPPosition = referenceArea.getBorderAndPaddingWidthStart();
+        } else {
+            currentIPPosition = referenceArea.getBorderAndPaddingWidthEnd();
+        }
         // draw background (traits are in the RegionViewport)
         // and borders (traits are in the RegionReference)
         drawBackAndBorders(region, referenceArea, startx, starty, width, height);
@@ -153,9 +160,9 @@ public abstract class AbstractPathOrient
 
         drawBackground(startx, starty, width, height,
                 (Trait.Background) backgroundArea.getTrait(Trait.BACKGROUND),
-                bpsBefore, bpsAfter, bpsStart, bpsEnd);
+                    bpsBefore, bpsAfter, bpsStart, bpsEnd, backgroundArea.getBidiLevel());
         drawBorders(startx, starty, width, height,
-                bpsBefore, bpsAfter, bpsStart, bpsEnd);
+                    bpsBefore, bpsAfter, bpsStart, bpsEnd, borderArea.getBidiLevel());
     }
 
     /**
@@ -171,11 +178,44 @@ public abstract class AbstractPathOrient
      * @param bpsAfter the border-after traits
      * @param bpsStart the border-start traits
      * @param bpsEnd the border-end traits
+     * @param level of bidirectional embedding
      */
     protected void drawBackground(                               // CSOK: ParameterNumber
             float startx, float starty, float width, float height, Trait.Background back,
             BorderProps bpsBefore, BorderProps bpsAfter,
-            BorderProps bpsStart, BorderProps bpsEnd) {
+            BorderProps bpsStart, BorderProps bpsEnd, int level) {
+        BorderProps bpsTop = bpsBefore;
+        BorderProps bpsBottom = bpsAfter;
+        BorderProps bpsLeft;
+        BorderProps bpsRight;
+        if ( ( level == -1 ) || ( ( level & 1 ) == 0 ) ) {
+            bpsLeft = bpsStart;
+            bpsRight = bpsEnd;
+        } else {
+            bpsLeft = bpsEnd;
+            bpsRight = bpsStart;
+        }
+        drawBackground(startx, starty, width, height, back, bpsTop, bpsBottom, bpsLeft, bpsRight);
+    }
+
+    /**
+     * Draw the background.
+     * This draws the background given the position and the traits.
+     *
+     * @param startx the start x position
+     * @param starty the start y position
+     * @param width the width of the area
+     * @param height the height of the area
+     * @param back the background traits
+     * @param bpsTop the border specification on the top edge
+     * @param bpsBottom the border traits associated with bottom edge
+     * @param bpsLeft the border specification on the left edge
+     * @param bpsRight the border specification on the right edge
+     */
+    protected void drawBackground(                               // CSOK: ParameterNumber
+            float startx, float starty, float width, float height, Trait.Background back,
+            BorderProps bpsTop, BorderProps bpsBottom,
+            BorderProps bpsLeft, BorderProps bpsRight) {
         if (back != null) {
             endTextObject();
 
@@ -184,19 +224,19 @@ public abstract class AbstractPathOrient
             float sy = starty;
             float paddRectWidth = width;
             float paddRectHeight = height;
-            if (bpsStart != null) {
-                sx += bpsStart.width / 1000f;
-                paddRectWidth -= bpsStart.width / 1000f;
-            }
-            if (bpsBefore != null) {
-                sy += bpsBefore.width / 1000f;
-                paddRectHeight -= bpsBefore.width / 1000f;
+            if (bpsLeft != null) {
+                sx += bpsLeft.width / 1000f;
+                paddRectWidth -= bpsLeft.width / 1000f;
+            }
+            if (bpsTop != null) {
+                sy += bpsTop.width / 1000f;
+                paddRectHeight -= bpsTop.width / 1000f;
             }
-            if (bpsEnd != null) {
-                paddRectWidth -= bpsEnd.width / 1000f;
+            if (bpsRight != null) {
+                paddRectWidth -= bpsRight.width / 1000f;
             }
-            if (bpsAfter != null) {
-                paddRectHeight -= bpsAfter.width / 1000f;
+            if (bpsBottom != null) {
+                paddRectHeight -= bpsBottom.width / 1000f;
             }
 
             if (back.getColor() != null) {
@@ -256,86 +296,99 @@ public abstract class AbstractPathOrient
      * @param starty the start y position
      * @param width the width of the area
      * @param height the height of the area
-     * @param bpsBefore the border-before traits
-     * @param bpsAfter the border-after traits
-     * @param bpsStart the border-start traits
-     * @param bpsEnd the border-end traits
+     * @param bpsBefore the border traits associated with before edge
+     * @param bpsAfter the border traits associated with after edge
+     * @param bpsStart the border traits associated with start edge
+     * @param bpsEnd the border traits associated with end edge
+     * @param level of bidirectional embedding
      */
     protected void drawBorders(                                  // CSOK: ParameterNumber
             float startx, float starty, float width, float height,
             BorderProps bpsBefore, BorderProps bpsAfter,
-            BorderProps bpsStart, BorderProps bpsEnd) {
+            BorderProps bpsStart, BorderProps bpsEnd, int level) {
         Rectangle2D.Float borderRect = new Rectangle2D.Float(startx, starty, width, height);
-        drawBorders(borderRect, bpsBefore, bpsAfter, bpsStart, bpsEnd);
+        BorderProps bpsTop = bpsBefore;
+        BorderProps bpsBottom = bpsAfter;
+        BorderProps bpsLeft;
+        BorderProps bpsRight;
+        if ( ( level == -1 ) || ( ( level & 1 ) == 0 ) ) {
+            bpsLeft = bpsStart;
+            bpsRight = bpsEnd;
+        } else {
+            bpsLeft = bpsEnd;
+            bpsRight = bpsStart;
+        }
+        drawBorders(borderRect, bpsTop, bpsBottom, bpsLeft, bpsRight);
     }
 
-    private static final int BEFORE = 0;
-    private static final int END = 1;
-    private static final int AFTER = 2;
-    private static final int START = 3;
+    private static final int TOP = 0;
+    private static final int RIGHT = 1;
+    private static final int BOTTOM = 2;
+    private static final int LEFT = 3;
 
     /**
      * Draws borders.
      * @param borderRect the border rectangle
-     * @param bpsBefore the border specification on the before side
-     * @param bpsAfter the border specification on the after side
-     * @param bpsStart the border specification on the start side
-     * @param bpsEnd the border specification on the end side
+     * @param bpsTop the border specification on the top edge
+     * @param bpsBottom the border traits associated with bottom edge
+     * @param bpsLeft the border specification on the left edge
+     * @param bpsRight the border specification on the right edge
      */
     protected void drawBorders(                                  // CSOK: MethodLength
             Rectangle2D.Float borderRect,
-            BorderProps bpsBefore, BorderProps bpsAfter, BorderProps bpsStart, BorderProps bpsEnd) {
+            BorderProps bpsTop, BorderProps bpsBottom, BorderProps bpsLeft, BorderProps bpsRight) {
         //TODO generalize each of the four conditions into using a parameterized drawBorder()
         boolean[] border = new boolean[] {
-                (bpsBefore != null), (bpsEnd != null),
-                (bpsAfter != null), (bpsStart != null)};
+                (bpsTop != null), (bpsRight != null),
+                (bpsBottom != null), (bpsLeft != null)};
         float startx = borderRect.x;
         float starty = borderRect.y;
         float width = borderRect.width;
         float height = borderRect.height;
         float[] borderWidth = new float[] {
-            (border[BEFORE] ? bpsBefore.width / 1000f : 0.0f),
-            (border[END] ? bpsEnd.width / 1000f : 0.0f),
-            (border[AFTER] ? bpsAfter.width / 1000f : 0.0f),
-            (border[START] ? bpsStart.width / 1000f : 0.0f)};
+            (border[TOP] ? bpsTop.width / 1000f : 0.0f),
+            (border[RIGHT] ? bpsRight.width / 1000f : 0.0f),
+            (border[BOTTOM] ? bpsBottom.width / 1000f : 0.0f),
+            (border[LEFT] ? bpsLeft.width / 1000f : 0.0f)};
         float[] clipw = new float[] {
-            BorderProps.getClippedWidth(bpsBefore) / 1000f,
-            BorderProps.getClippedWidth(bpsEnd) / 1000f,
-            BorderProps.getClippedWidth(bpsAfter) / 1000f,
-            BorderProps.getClippedWidth(bpsStart) / 1000f};
-        starty += clipw[BEFORE];
-        height -= clipw[BEFORE];
-        height -= clipw[AFTER];
-        startx += clipw[START];
-        width -= clipw[START];
-        width -= clipw[END];
+            BorderProps.getClippedWidth(bpsTop) / 1000f,
+            BorderProps.getClippedWidth(bpsRight) / 1000f,
+            BorderProps.getClippedWidth(bpsBottom) / 1000f,
+            BorderProps.getClippedWidth(bpsLeft) / 1000f};
+
+        starty += clipw[TOP];
+        height -= clipw[TOP];
+        height -= clipw[BOTTOM];
+        startx += clipw[LEFT];
+        width -= clipw[LEFT];
+        width -= clipw[RIGHT];
 
         boolean[] slant = new boolean[] {
-            (border[START] && border[BEFORE]),
-            (border[BEFORE] && border[END]),
-            (border[END] && border[AFTER]),
-            (border[AFTER] && border[START])};
-        if (bpsBefore != null) {
+            (border[LEFT] && border[TOP]),
+            (border[TOP] && border[RIGHT]),
+            (border[RIGHT] && border[BOTTOM]),
+            (border[BOTTOM] && border[LEFT])};
+        if (bpsTop != null) {
             endTextObject();
 
             float sx1 = startx;
-            float sx2 = (slant[BEFORE] ? sx1 + borderWidth[START] - clipw[START] : sx1);
+            float sx2 = (slant[TOP] ? sx1 + borderWidth[LEFT] - clipw[LEFT] : sx1);
             float ex1 = startx + width;
-            float ex2 = (slant[END] ? ex1 - borderWidth[END] + clipw[END] : ex1);
-            float outery = starty - clipw[BEFORE];
-            float clipy = outery + clipw[BEFORE];
-            float innery = outery + borderWidth[BEFORE];
+            float ex2 = (slant[RIGHT] ? ex1 - borderWidth[RIGHT] + clipw[RIGHT] : ex1);
+            float outery = starty - clipw[TOP];
+            float clipy = outery + clipw[TOP];
+            float innery = outery + borderWidth[TOP];
 
             saveGraphicsState();
             moveTo(sx1, clipy);
             float sx1a = sx1;
             float ex1a = ex1;
-            if (bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
-                    sx1a -= clipw[START];
+            if (bpsTop.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsLeft != null && bpsLeft.mode == BorderProps.COLLAPSE_OUTER) {
+                    sx1a -= clipw[LEFT];
                 }
-                if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
-                    ex1a += clipw[END];
+                if (bpsRight != null && bpsRight.mode == BorderProps.COLLAPSE_OUTER) {
+                    ex1a += clipw[RIGHT];
                 }
                 lineTo(sx1a, outery);
                 lineTo(ex1a, outery);
@@ -346,30 +399,30 @@ public abstract class AbstractPathOrient
             closePath();
             clip();
             drawBorderLine(sx1a, outery, ex1a, innery, true, true,
-                    bpsBefore.style, bpsBefore.color);
+                    bpsTop.style, bpsTop.color);
             restoreGraphicsState();
         }
-        if (bpsEnd != null) {
+        if (bpsRight != null) {
             endTextObject();
 
             float sy1 = starty;
-            float sy2 = (slant[END] ? sy1 + borderWidth[BEFORE] - clipw[BEFORE] : sy1);
+            float sy2 = (slant[RIGHT] ? sy1 + borderWidth[TOP] - clipw[TOP] : sy1);
             float ey1 = starty + height;
-            float ey2 = (slant[AFTER] ? ey1 - borderWidth[AFTER] + clipw[AFTER] : ey1);
-            float outerx = startx + width + clipw[END];
-            float clipx = outerx - clipw[END];
-            float innerx = outerx - borderWidth[END];
+            float ey2 = (slant[BOTTOM] ? ey1 - borderWidth[BOTTOM] + clipw[BOTTOM] : ey1);
+            float outerx = startx + width + clipw[RIGHT];
+            float clipx = outerx - clipw[RIGHT];
+            float innerx = outerx - borderWidth[RIGHT];
 
             saveGraphicsState();
             moveTo(clipx, sy1);
             float sy1a = sy1;
             float ey1a = ey1;
-            if (bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
-                    sy1a -= clipw[BEFORE];
+            if (bpsRight.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsTop != null && bpsTop.mode == BorderProps.COLLAPSE_OUTER) {
+                    sy1a -= clipw[TOP];
                 }
-                if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
-                    ey1a += clipw[AFTER];
+                if (bpsBottom != null && bpsBottom.mode == BorderProps.COLLAPSE_OUTER) {
+                    ey1a += clipw[BOTTOM];
                 }
                 lineTo(outerx, sy1a);
                 lineTo(outerx, ey1a);
@@ -379,30 +432,31 @@ public abstract class AbstractPathOrient
             lineTo(innerx, sy2);
             closePath();
             clip();
-            drawBorderLine(innerx, sy1a, outerx, ey1a, false, false, bpsEnd.style, bpsEnd.color);
+            drawBorderLine(innerx, sy1a, outerx, ey1a, false, false,
+                           bpsRight.style, bpsRight.color);
             restoreGraphicsState();
         }
-        if (bpsAfter != null) {
+        if (bpsBottom != null) {
             endTextObject();
 
             float sx1 = startx;
-            float sx2 = (slant[START] ? sx1 + borderWidth[START] - clipw[START] : sx1);
+            float sx2 = (slant[LEFT] ? sx1 + borderWidth[LEFT] - clipw[LEFT] : sx1);
             float ex1 = startx + width;
-            float ex2 = (slant[AFTER] ? ex1 - borderWidth[END] + clipw[END] : ex1);
-            float outery = starty + height + clipw[AFTER];
-            float clipy = outery - clipw[AFTER];
-            float innery = outery - borderWidth[AFTER];
+            float ex2 = (slant[BOTTOM] ? ex1 - borderWidth[RIGHT] + clipw[RIGHT] : ex1);
+            float outery = starty + height + clipw[BOTTOM];
+            float clipy = outery - clipw[BOTTOM];
+            float innery = outery - borderWidth[BOTTOM];
 
             saveGraphicsState();
             moveTo(ex1, clipy);
             float sx1a = sx1;
             float ex1a = ex1;
-            if (bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
-                    sx1a -= clipw[START];
+            if (bpsBottom.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsLeft != null && bpsLeft.mode == BorderProps.COLLAPSE_OUTER) {
+                    sx1a -= clipw[LEFT];
                 }
-                if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
-                    ex1a += clipw[END];
+                if (bpsRight != null && bpsRight.mode == BorderProps.COLLAPSE_OUTER) {
+                    ex1a += clipw[RIGHT];
                 }
                 lineTo(ex1a, outery);
                 lineTo(sx1a, outery);
@@ -412,30 +466,31 @@ public abstract class AbstractPathOrient
             lineTo(ex2, innery);
             closePath();
             clip();
-            drawBorderLine(sx1a, innery, ex1a, outery, true, false, bpsAfter.style, bpsAfter.color);
+            drawBorderLine(sx1a, innery, ex1a, outery, true, false,
+                           bpsBottom.style, bpsBottom.color);
             restoreGraphicsState();
         }
-        if (bpsStart != null) {
+        if (bpsLeft != null) {
             endTextObject();
 
             float sy1 = starty;
-            float sy2 = (slant[BEFORE] ? sy1 + borderWidth[BEFORE] - clipw[BEFORE] : sy1);
+            float sy2 = (slant[TOP] ? sy1 + borderWidth[TOP] - clipw[TOP] : sy1);
             float ey1 = sy1 + height;
-            float ey2 = (slant[START] ? ey1 - borderWidth[AFTER] + clipw[AFTER] : ey1);
-            float outerx = startx - clipw[START];
-            float clipx = outerx + clipw[START];
-            float innerx = outerx + borderWidth[START];
+            float ey2 = (slant[LEFT] ? ey1 - borderWidth[BOTTOM] + clipw[BOTTOM] : ey1);
+            float outerx = startx - clipw[LEFT];
+            float clipx = outerx + clipw[LEFT];
+            float innerx = outerx + borderWidth[LEFT];
 
             saveGraphicsState();
             moveTo(clipx, ey1);
             float sy1a = sy1;
             float ey1a = ey1;
-            if (bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
-                    sy1a -= clipw[BEFORE];
+            if (bpsLeft.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsTop != null && bpsTop.mode == BorderProps.COLLAPSE_OUTER) {
+                    sy1a -= clipw[TOP];
                 }
-                if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
-                    ey1a += clipw[AFTER];
+                if (bpsBottom != null && bpsBottom.mode == BorderProps.COLLAPSE_OUTER) {
+                    ey1a += clipw[BOTTOM];
                 }
                 lineTo(outerx, ey1a);
                 lineTo(outerx, sy1a);
@@ -445,7 +500,7 @@ public abstract class AbstractPathOrient
             lineTo(innerx, ey2);
             closePath();
             clip();
-            drawBorderLine(outerx, sy1a, innerx, ey1a, false, true, bpsStart.style, bpsStart.color);
+            drawBorderLine(outerx, sy1a, innerx, ey1a, false, true, bpsLeft.style, bpsLeft.color);
             restoreGraphicsState();
         }
     }
@@ -458,11 +513,11 @@ public abstract class AbstractPathOrient
      */
     protected void renderInlineAreaBackAndBorders(InlineArea area) {
         float borderPaddingStart = area.getBorderAndPaddingWidthStart() / 1000f;
+        float borderPaddingEnd = area.getBorderAndPaddingWidthEnd() / 1000f;
         float borderPaddingBefore = area.getBorderAndPaddingWidthBefore() / 1000f;
-        float bpwidth = borderPaddingStart
-                + (area.getBorderAndPaddingWidthEnd() / 1000f);
-        float bpheight = borderPaddingBefore
-                + (area.getBorderAndPaddingWidthAfter() / 1000f);
+        float borderPaddingAfter = area.getBorderAndPaddingWidthAfter() / 1000f;
+        float bpwidth = borderPaddingStart + borderPaddingEnd;
+        float bpheight = borderPaddingBefore + borderPaddingAfter;
 
         float height = area.getBPD() / 1000f;
         if (height != 0.0f || bpheight != 0.0f && bpwidth != 0.0f) {
@@ -504,10 +559,16 @@ public abstract class AbstractPathOrient
             AffineTransform positionTransform = new AffineTransform();
             positionTransform.translate(bv.getXOffset(), bv.getYOffset());
 
+            int level = bv.getBidiLevel();
             int borderPaddingStart = bv.getBorderAndPaddingWidthStart();
+            int borderPaddingEnd = bv.getBorderAndPaddingWidthEnd();
 
             //"left/"top" (bv.getX/YOffset()) specify the position of the content rectangle
-            positionTransform.translate(-borderPaddingStart, -borderPaddingBefore);
+            if ( ( level == -1 ) || ( ( level & 1 ) == 0 ) ) {
+                positionTransform.translate(-borderPaddingStart, -borderPaddingBefore);
+            } else {
+                positionTransform.translate(-borderPaddingEnd, -borderPaddingBefore);
+            }
 
             //Free transformation for the block-container viewport
             String transf;
@@ -528,14 +589,18 @@ public abstract class AbstractPathOrient
 
             //Background and borders
             float borderPaddingWidth
-                = (borderPaddingStart + bv.getBorderAndPaddingWidthEnd()) / 1000f;
+                = (borderPaddingStart + borderPaddingEnd) / 1000f;
             float borderPaddingHeight
                 = (borderPaddingBefore + bv.getBorderAndPaddingWidthAfter()) / 1000f;
             drawBackAndBorders(bv, 0, 0, width + borderPaddingWidth, height + borderPaddingHeight);
 
             //Shift to content rectangle after border painting
             AffineTransform contentRectTransform = new AffineTransform();
-            contentRectTransform.translate(borderPaddingStart, borderPaddingBefore);
+            if ( ( level == -1 ) || ( ( level & 1 ) == 0 ) ) {
+                contentRectTransform.translate(borderPaddingStart, borderPaddingBefore);
+            } else {
+                contentRectTransform.translate(borderPaddingEnd, borderPaddingBefore);
+            }
 
             if (!contentRectTransform.isIdentity()) {
                 establishTransformationMatrix(contentRectTransform);
@@ -686,25 +751,28 @@ public abstract class AbstractPathOrient
      * @param viewport the viewport to handle
      */
     public void renderInlineViewport(InlineViewport viewport) {
-
+        int level = viewport.getBidiLevel();
         float x = currentIPPosition / 1000f;
         float y = (currentBPPosition + viewport.getBlockProgressionOffset()) / 1000f;
         float width = viewport.getIPD() / 1000f;
         float height = viewport.getBPD() / 1000f;
         // TODO: Calculate the border rect correctly.
         float borderPaddingStart = viewport.getBorderAndPaddingWidthStart() / 1000f;
+        float borderPaddingEnd = viewport.getBorderAndPaddingWidthEnd() / 1000f;
         float borderPaddingBefore = viewport.getBorderAndPaddingWidthBefore() / 1000f;
-        float bpwidth = borderPaddingStart
-                + (viewport.getBorderAndPaddingWidthEnd() / 1000f);
-        float bpheight = borderPaddingBefore
-                + (viewport.getBorderAndPaddingWidthAfter() / 1000f);
+        float borderPaddingAfter = viewport.getBorderAndPaddingWidthAfter() / 1000f;
+        float bpwidth = borderPaddingStart + borderPaddingEnd;
+        float bpheight = borderPaddingBefore + borderPaddingAfter;
 
         drawBackAndBorders(viewport, x, y, width + bpwidth, height + bpheight);
 
         if (viewport.hasClip()) {
             saveGraphicsState();
-
-            clipRect(x + borderPaddingStart, y + borderPaddingBefore, width, height);
+            if ( ( level == -1 ) || ( ( level & 1 ) == 0 ) ) {
+                clipRect(x + borderPaddingStart, y + borderPaddingBefore, width, height);
+            } else {
+                clipRect(x + borderPaddingEnd, y + borderPaddingBefore, width, height);
+            }
         }
         super.renderInlineViewport(viewport);
 

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/AbstractRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/AbstractRenderer.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/AbstractRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/AbstractRenderer.java Wed Jun 15 18:37:11 2011
@@ -507,17 +507,10 @@ public abstract class AbstractRenderer
      */
     protected void renderBlocks(Block parent, List blocks) {
         int saveIP = currentIPPosition;
-//        int saveBP = currentBPPosition;
 
         // Calculate the position of the content rectangle.
         if (parent != null && !parent.getTraitAsBoolean(Trait.IS_VIEWPORT_AREA)) {
             currentBPPosition += parent.getBorderAndPaddingWidthBefore();
-            /* This is unnecessary now as we're going to use the *-indent traits
-            currentIPPosition += parent.getBorderAndPaddingWidthStart();
-            Integer spaceStart = (Integer) parent.getTrait(Trait.SPACE_START);
-            if (spaceStart != null) {
-                currentIPPosition += spaceStart.intValue();
-            }*/
         }
 
         // the position of the containing block is used for
@@ -540,9 +533,15 @@ public abstract class AbstractRenderer
                 // a line area is rendered from the top left position
                 // of the line, each inline object is offset from there
                 LineArea line = (LineArea) obj;
-                currentIPPosition = contIP + parent.getStartIndent();
+                if ( parent != null ) {
+                    int level = parent.getBidiLevel();
+                    if ( ( level == -1 ) || ( ( level & 1 ) == 0 ) ) {
+                        currentIPPosition += parent.getStartIndent(); 
+                    } else {
+                        currentIPPosition += parent.getEndIndent(); 
+                    }
+                }
                 renderLineArea(line);
-                //InlineArea child = (InlineArea) line.getInlineAreas().get(0);
                 currentBPPosition += line.getAllocBPD();
             }
             currentIPPosition = saveIP;
@@ -555,6 +554,7 @@ public abstract class AbstractRenderer
      * @param block  The block area
      */
     protected void renderBlock(Block block) {
+        assert block != null;
         List children = block.getChildAreas();
         if (block instanceof BlockViewport) {
             if (children != null) {
@@ -604,7 +604,23 @@ public abstract class AbstractRenderer
         List children = line.getInlineAreas();
         int saveBP = currentBPPosition;
         currentBPPosition += line.getSpaceBefore();
-        currentIPPosition += line.getStartIndent(); 
+        int bl = line.getBidiLevel();
+        if ( bl >= 0 ) {
+            if ( ( bl & 1 ) == 0 ) {
+                currentIPPosition += line.getStartIndent(); 
+            } else {
+                currentIPPosition += line.getEndIndent(); 
+                // if line's content overflows line area, then
+                // ensure that overflow is drawn (extends)
+                // outside of left side of line area
+                int overflow = computeInlinesOverflow ( line );
+                if ( overflow > 0 ) {
+                    currentIPPosition -= overflow;
+                }
+            }
+        } else {
+            currentIPPosition += line.getStartIndent(); 
+        }
         for (int i = 0, l = children.size(); i < l; i++) {
             InlineArea inline = (InlineArea) children.get(i);
             renderInlineArea(inline);
@@ -612,6 +628,16 @@ public abstract class AbstractRenderer
         currentBPPosition = saveBP;
     }
 
+    private int computeInlinesOverflow ( LineArea line ) {
+        List children = line.getInlineAreas();
+        int ipdConsumed = 0;
+        for (int i = 0, l = children.size(); i < l; i++) {
+            InlineArea inline = (InlineArea) children.get(i);
+            ipdConsumed += inline.getIPD();
+        }
+        return ipdConsumed - line.getIPD();
+    }
+
     /**
      * Render the given InlineArea.
      * @param inlineArea inline area text to render
@@ -703,11 +729,16 @@ public abstract class AbstractRenderer
      * @param ip the inline parent to render
      */
     protected void renderInlineParent(InlineParent ip) {
+        int level = ip.getBidiLevel();
         List children = ip.getChildAreas();
         renderInlineAreaBackAndBorders(ip);
         int saveIP = currentIPPosition;
         int saveBP = currentBPPosition;
-        currentIPPosition += ip.getBorderAndPaddingWidthStart();
+        if ( ( level == -1 ) || ( ( level & 1 ) == 0 ) ) {
+            currentIPPosition += ip.getBorderAndPaddingWidthStart();
+        } else {
+            currentIPPosition += ip.getBorderAndPaddingWidthEnd();
+        }
         currentBPPosition += ip.getBlockProgressionOffset();
         for (int i = 0, l = children.size(); i < l; i++) {
             InlineArea inline = (InlineArea) children.get(i);
@@ -722,8 +753,13 @@ public abstract class AbstractRenderer
      * @param ibp the inline block parent to render
      */
     protected void renderInlineBlockParent(InlineBlockParent ibp) {
+        int level = ibp.getBidiLevel();
         renderInlineAreaBackAndBorders(ibp);
-        currentIPPosition += ibp.getBorderAndPaddingWidthStart();
+        if ( ( level == -1 ) || ( ( level & 1 ) == 0 ) ) {
+            currentIPPosition += ibp.getBorderAndPaddingWidthStart();
+        } else {
+            currentIPPosition += ibp.getBorderAndPaddingWidthEnd();
+        }
         // For inline content the BP position is updated by the enclosing line area
         int saveBP = currentBPPosition;
         currentBPPosition += ibp.getBlockProgressionOffset();

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPPainter.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/afp/AFPPainter.java Wed Jun 15 18:37:11 2011
@@ -260,11 +260,11 @@ public class AFPPainter extends Abstract
 
     /** {@inheritDoc} */
     @Override
-    public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after,
-            BorderProps start, BorderProps end) throws IFException {
-        if (before != null || after != null || start != null || end != null) {
+    public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom,
+            BorderProps left, BorderProps right) throws IFException {
+        if (top != null || bottom != null || left != null || right != null) {
             try {
-                this.borderPainter.drawBorders(rect, before, after, start, end);
+                this.borderPainter.drawBorders(rect, top, bottom, left, right);
             } catch (IOException ife) {
                 throw new IFException("IO error while painting borders", ife);
             }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/AbstractIFPainter.java Wed Jun 15 18:37:11 2011
@@ -315,55 +315,55 @@ public abstract class AbstractIFPainter 
     }
 
     /** {@inheritDoc} */
-    public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after,
-            BorderProps start, BorderProps end) throws IFException {
-        if (before != null) {
+    public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom,
+            BorderProps left, BorderProps right) throws IFException {
+        if (top != null) {
             Rectangle b = new Rectangle(
                     rect.x, rect.y,
-                    rect.width, before.width);
-            fillRect(b, before.color);
+                    rect.width, top.width);
+            fillRect(b, top.color);
         }
-        if (end != null) {
+        if (right != null) {
             Rectangle b = new Rectangle(
-                    rect.x + rect.width - end.width, rect.y,
-                    end.width, rect.height);
-            fillRect(b, end.color);
+                    rect.x + rect.width - right.width, rect.y,
+                    right.width, rect.height);
+            fillRect(b, right.color);
         }
-        if (after != null) {
+        if (bottom != null) {
             Rectangle b = new Rectangle(
-                    rect.x, rect.y + rect.height - after.width,
-                    rect.width, after.width);
-            fillRect(b, after.color);
+                    rect.x, rect.y + rect.height - bottom.width,
+                    rect.width, bottom.width);
+            fillRect(b, bottom.color);
         }
-        if (start != null) {
+        if (left != null) {
             Rectangle b = new Rectangle(
                     rect.x, rect.y,
-                    start.width, rect.height);
-            fillRect(b, start.color);
+                    left.width, rect.height);
+            fillRect(b, left.color);
         }
     }
 
     /**
      * Indicates whether the given border segments (if present) have only solid borders, i.e.
      * could be painted in a simplified fashion keeping the output file smaller.
-     * @param before the border segment on the before-side (top)
-     * @param after the border segment on the after-side (bottom)
-     * @param start the border segment on the start-side (left)
-     * @param end the border segment on the end-side (right)
+     * @param top the border segment on the top edge
+     * @param bottom the border segment on the bottom edge
+     * @param left the border segment on the left edge
+     * @param right the border segment on the right edge
      * @return true if any border segment has a non-solid border style
      */
-    protected boolean hasOnlySolidBorders(BorderProps before, BorderProps after,
-            BorderProps start, BorderProps end) {
-        if (before != null && before.style != Constants.EN_SOLID) {
+    protected boolean hasOnlySolidBorders(BorderProps top, BorderProps bottom,
+            BorderProps left, BorderProps right) {
+        if (top != null && top.style != Constants.EN_SOLID) {
             return false;
         }
-        if (after != null && after.style != Constants.EN_SOLID) {
+        if (bottom != null && bottom.style != Constants.EN_SOLID) {
             return false;
         }
-        if (start != null && start.style != Constants.EN_SOLID) {
+        if (left != null && left.style != Constants.EN_SOLID) {
             return false;
         }
-        if (end != null && end.style != Constants.EN_SOLID) {
+        if (right != null && right.style != Constants.EN_SOLID) {
             return false;
         }
         return true;

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/BorderPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/BorderPainter.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/BorderPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/BorderPainter.java Wed Jun 15 18:37:11 2011
@@ -35,35 +35,35 @@ public abstract class BorderPainter {
     /**
      * Draws borders.
      * @param borderRect the border rectangle
-     * @param bpsBefore the border specification on the before side
-     * @param bpsAfter the border specification on the after side
-     * @param bpsStart the border specification on the start side
-     * @param bpsEnd the border specification on the end side
+     * @param bpsTop the border specification on the top side
+     * @param bpsBottom the border specification on the bottom side
+     * @param bpsLeft the border specification on the left side
+     * @param bpsRight the border specification on the end side
      * @throws IOException if an I/O error occurs while creating the borders
      */
     public void drawBorders(Rectangle borderRect,               // CSOK: MethodLength
-            BorderProps bpsBefore, BorderProps bpsAfter,
-            BorderProps bpsStart, BorderProps bpsEnd) throws IOException {
+            BorderProps bpsTop, BorderProps bpsBottom,
+            BorderProps bpsLeft, BorderProps bpsRight) throws IOException {
         int startx = borderRect.x;
         int starty = borderRect.y;
         int width = borderRect.width;
         int height = borderRect.height;
         boolean[] b = new boolean[] {
-            (bpsBefore != null), (bpsEnd != null),
-            (bpsAfter != null), (bpsStart != null)};
+            (bpsTop != null), (bpsRight != null),
+            (bpsBottom != null), (bpsLeft != null)};
         if (!b[0] && !b[1] && !b[2] && !b[3]) {
             return;
         }
         int[] bw = new int[] {
-            (b[0] ? bpsBefore.width : 0),
-            (b[1] ? bpsEnd.width : 0),
-            (b[2] ? bpsAfter.width : 0),
-            (b[3] ? bpsStart.width : 0)};
+            (b[0] ? bpsTop.width : 0),
+            (b[1] ? bpsRight.width : 0),
+            (b[2] ? bpsBottom.width : 0),
+            (b[3] ? bpsLeft.width : 0)};
         int[] clipw = new int[] {
-            BorderProps.getClippedWidth(bpsBefore),
-            BorderProps.getClippedWidth(bpsEnd),
-            BorderProps.getClippedWidth(bpsAfter),
-            BorderProps.getClippedWidth(bpsStart)};
+            BorderProps.getClippedWidth(bpsTop),
+            BorderProps.getClippedWidth(bpsRight),
+            BorderProps.getClippedWidth(bpsBottom),
+            BorderProps.getClippedWidth(bpsLeft)};
         starty += clipw[0];
         height -= clipw[0];
         height -= clipw[2];
@@ -73,7 +73,7 @@ public abstract class BorderPainter {
 
         boolean[] slant = new boolean[] {
             (b[3] && b[0]), (b[0] && b[1]), (b[1] && b[2]), (b[2] && b[3])};
-        if (bpsBefore != null) {
+        if (bpsTop != null) {
             int sx1 = startx;
             int sx2 = (slant[0] ? sx1 + bw[3] - clipw[3] : sx1);
             int ex1 = startx + width;
@@ -86,11 +86,11 @@ public abstract class BorderPainter {
             moveTo(sx1, clipy);
             int sx1a = sx1;
             int ex1a = ex1;
-            if (bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
+            if (bpsTop.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsLeft != null && bpsLeft.mode == BorderProps.COLLAPSE_OUTER) {
                     sx1a -= clipw[3];
                 }
-                if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsRight != null && bpsRight.mode == BorderProps.COLLAPSE_OUTER) {
                     ex1a += clipw[1];
                 }
                 lineTo(sx1a, outery);
@@ -102,10 +102,10 @@ public abstract class BorderPainter {
             closePath();
             clip();
             drawBorderLine(sx1a, outery, ex1a, innery, true, true,
-                    bpsBefore.style, bpsBefore.color);
+                    bpsTop.style, bpsTop.color);
             restoreGraphicsState();
         }
-        if (bpsEnd != null) {
+        if (bpsRight != null) {
             int sy1 = starty;
             int sy2 = (slant[1] ? sy1 + bw[0] - clipw[0] : sy1);
             int ey1 = starty + height;
@@ -118,11 +118,11 @@ public abstract class BorderPainter {
             moveTo(clipx, sy1);
             int sy1a = sy1;
             int ey1a = ey1;
-            if (bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
+            if (bpsRight.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsTop != null && bpsTop.mode == BorderProps.COLLAPSE_OUTER) {
                     sy1a -= clipw[0];
                 }
-                if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsBottom != null && bpsBottom.mode == BorderProps.COLLAPSE_OUTER) {
                     ey1a += clipw[2];
                 }
                 lineTo(outerx, sy1a);
@@ -133,10 +133,11 @@ public abstract class BorderPainter {
             lineTo(innerx, sy2);
             closePath();
             clip();
-            drawBorderLine(innerx, sy1a, outerx, ey1a, false, false, bpsEnd.style, bpsEnd.color);
+            drawBorderLine(innerx, sy1a, outerx, ey1a, false, false,
+                           bpsRight.style, bpsRight.color);
             restoreGraphicsState();
         }
-        if (bpsAfter != null) {
+        if (bpsBottom != null) {
             int sx1 = startx;
             int sx2 = (slant[3] ? sx1 + bw[3] - clipw[3] : sx1);
             int ex1 = startx + width;
@@ -149,11 +150,11 @@ public abstract class BorderPainter {
             moveTo(ex1, clipy);
             int sx1a = sx1;
             int ex1a = ex1;
-            if (bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
+            if (bpsBottom.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsLeft != null && bpsLeft.mode == BorderProps.COLLAPSE_OUTER) {
                     sx1a -= clipw[3];
                 }
-                if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsRight != null && bpsRight.mode == BorderProps.COLLAPSE_OUTER) {
                     ex1a += clipw[1];
                 }
                 lineTo(ex1a, outery);
@@ -164,10 +165,11 @@ public abstract class BorderPainter {
             lineTo(ex2, innery);
             closePath();
             clip();
-            drawBorderLine(sx1a, innery, ex1a, outery, true, false, bpsAfter.style, bpsAfter.color);
+            drawBorderLine(sx1a, innery, ex1a, outery, true, false,
+                           bpsBottom.style, bpsBottom.color);
             restoreGraphicsState();
         }
-        if (bpsStart != null) {
+        if (bpsLeft != null) {
             int sy1 = starty;
             int sy2 = (slant[0] ? sy1 + bw[0] - clipw[0] : sy1);
             int ey1 = sy1 + height;
@@ -180,11 +182,11 @@ public abstract class BorderPainter {
             moveTo(clipx, ey1);
             int sy1a = sy1;
             int ey1a = ey1;
-            if (bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
-                if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
+            if (bpsLeft.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsTop != null && bpsTop.mode == BorderProps.COLLAPSE_OUTER) {
                     sy1a -= clipw[0];
                 }
-                if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
+                if (bpsBottom != null && bpsBottom.mode == BorderProps.COLLAPSE_OUTER) {
                     ey1a += clipw[2];
                 }
                 lineTo(outerx, ey1a);
@@ -195,7 +197,7 @@ public abstract class BorderPainter {
             lineTo(innerx, ey2);
             closePath();
             clip();
-            drawBorderLine(outerx, sy1a, innerx, ey1a, false, true, bpsStart.style, bpsStart.color);
+            drawBorderLine(outerx, sy1a, innerx, ey1a, false, true, bpsLeft.style, bpsLeft.color);
             restoreGraphicsState();
         }
     }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFPainter.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFPainter.java Wed Jun 15 18:37:11 2011
@@ -180,15 +180,15 @@ public interface IFPainter {
      * Draws a border rectangle. The border segments are specified through {@link BorderProps}
      * instances.
      * @param rect the rectangle's coordinates and extent
-     * @param before the border segment on the before-side (top)
-     * @param after the border segment on the after-side (bottom)
-     * @param start the border segment on the start-side (left)
-     * @param end the border segment on the end-side (right)
+     * @param top the border segment on the top edge
+     * @param bottom the border segment on the bottom edge
+     * @param left the border segment on the left edge
+     * @param right the border segment on the right edge
      * @throws IFException if an error occurs while handling this event
      */
     void drawBorderRect(Rectangle rect,
-            BorderProps before, BorderProps after,
-            BorderProps start, BorderProps end) throws IFException;
+            BorderProps top, BorderProps bottom,
+            BorderProps left, BorderProps right) throws IFException;
 
     /**
      * Draws a line. NOTE: Currently, only horizontal lines are implemented!

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFParser.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFParser.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFParser.java Wed Jun 15 18:37:11 2011
@@ -645,7 +645,7 @@ public class IFParser implements IFConst
 
         }
 
-        private static final String[] SIDES = new String[] {"before", "after", "start", "end"};
+        private static final String[] SIDES = new String[] {"top", "bottom", "left", "right"};
 
         private class BorderRectHandler extends AbstractElementHandler {
 

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFRenderer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFRenderer.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFRenderer.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFRenderer.java Wed Jun 15 18:37:11 2011
@@ -1324,10 +1324,21 @@ public class IFRenderer extends Abstract
             float startx, float starty,
             float width, float height,
             BorderProps bpsBefore, BorderProps bpsAfter,
-            BorderProps bpsStart, BorderProps bpsEnd) {
+            BorderProps bpsStart, BorderProps bpsEnd, int level) {
         Rectangle rect = toMillipointRectangle(startx, starty, width, height);
         try {
-            painter.drawBorderRect(rect, bpsBefore, bpsAfter, bpsStart, bpsEnd);
+            BorderProps bpsTop = bpsBefore;
+            BorderProps bpsBottom = bpsAfter;
+            BorderProps bpsLeft;
+            BorderProps bpsRight;
+            if ( ( level == -1 ) || ( ( level & 1 ) == 0 ) ) {
+                bpsLeft = bpsStart;
+                bpsRight = bpsEnd;
+            } else {
+                bpsLeft = bpsEnd;
+                bpsRight = bpsStart;
+            }
+            painter.drawBorderRect(rect, bpsTop, bpsBottom, bpsLeft, bpsRight);
         } catch (IFException ife) {
             handleIFException(ife);
         }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFSerializer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFSerializer.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFSerializer.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/intermediate/IFSerializer.java Wed Jun 15 18:37:11 2011
@@ -506,9 +506,9 @@ public class IFSerializer extends Abstra
     }
 
     /** {@inheritDoc} */
-    public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after,
-            BorderProps start, BorderProps end) throws IFException {
-        if (before == null && after == null && start == null && end == null) {
+    public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom,
+            BorderProps left, BorderProps right) throws IFException {
+        if (top == null && bottom == null && left == null && right == null) {
             return;
         }
         try {
@@ -517,17 +517,17 @@ public class IFSerializer extends Abstra
             addAttribute(atts, "y", Integer.toString(rect.y));
             addAttribute(atts, "width", Integer.toString(rect.width));
             addAttribute(atts, "height", Integer.toString(rect.height));
-            if (before != null) {
-                addAttribute(atts, "before", before.toString());
+            if (top != null) {
+                addAttribute(atts, "top", top.toString());
             }
-            if (after != null) {
-                addAttribute(atts, "after", after.toString());
+            if (bottom != null) {
+                addAttribute(atts, "bottom", bottom.toString());
             }
-            if (start != null) {
-                addAttribute(atts, "start", start.toString());
+            if (left != null) {
+                addAttribute(atts, "left", left.toString());
             }
-            if (end != null) {
-                addAttribute(atts, "end", end.toString());
+            if (right != null) {
+                addAttribute(atts, "right", right.toString());
             }
             handler.element(EL_BORDER_RECT, atts);
         } catch (SAXException e) {

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/java2d/Java2DPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/java2d/Java2DPainter.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/java2d/Java2DPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/java2d/Java2DPainter.java Wed Jun 15 18:37:11 2011
@@ -185,11 +185,11 @@ public class Java2DPainter extends Abstr
     }
 
     /** {@inheritDoc} */
-    public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after,
-            BorderProps start, BorderProps end) throws IFException {
-        if (before != null || after != null || start != null || end != null) {
+    public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom,
+            BorderProps left, BorderProps right) throws IFException {
+        if (top != null || bottom != null || left != null || right != null) {
             try {
-                this.borderPainter.drawBorders(rect, before, after, start, end);
+                this.borderPainter.drawBorders(rect, top, bottom, left, right);
             } catch (IOException e) {
                 //Won't happen with Java2D
                 throw new IllegalStateException("Unexpected I/O error");

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pcl/PCLPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pcl/PCLPainter.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pcl/PCLPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pcl/PCLPainter.java Wed Jun 15 18:37:11 2011
@@ -207,13 +207,13 @@ public class PCLPainter extends Abstract
 
     /** {@inheritDoc} */
     public void drawBorderRect(final Rectangle rect,
-            final BorderProps before, final BorderProps after,
-            final BorderProps start, final BorderProps end) throws IFException {
+            final BorderProps top, final BorderProps bottom,
+            final BorderProps left, final BorderProps right) throws IFException {
         if (isSpeedOptimized()) {
-            super.drawBorderRect(rect, before, after, start, end);
+            super.drawBorderRect(rect, top, bottom, left, right);
             return;
         }
-        if (before != null || after != null || start != null || end != null) {
+        if (top != null || bottom != null || left != null || right != null) {
             final Rectangle boundingBox = rect;
             final Dimension dim = boundingBox.getSize();
 
@@ -225,7 +225,7 @@ public class PCLPainter extends Abstract
                     Java2DPainter painter = new Java2DPainter(g2d,
                             getContext(), parent.getFontInfo(), state);
                     try {
-                        painter.drawBorderRect(rect, before, after, start, end);
+                        painter.drawBorderRect(rect, top, bottom, left, right);
                     } catch (IFException e) {
                         //This should never happen with the Java2DPainter
                         throw new RuntimeException("Unexpected error while painting borders", e);

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pdf/PDFPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pdf/PDFPainter.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pdf/PDFPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/pdf/PDFPainter.java Wed Jun 15 18:37:11 2011
@@ -47,6 +47,7 @@ import org.apache.fop.render.intermediat
 import org.apache.fop.render.intermediate.IFUtil;
 import org.apache.fop.render.pdf.PDFLogicalStructureHandler.MarkedContentInfo;
 import org.apache.fop.traits.BorderProps;
+import org.apache.fop.traits.Direction;
 import org.apache.fop.traits.RuleStyle;
 import org.apache.fop.util.CharUtilities;
 
@@ -256,12 +257,12 @@ public class PDFPainter extends Abstract
     }
 
     /** {@inheritDoc} */
-    public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after,
-            BorderProps start, BorderProps end) throws IFException {
-        if (before != null || after != null || start != null || end != null) {
+    public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom,
+            BorderProps left, BorderProps right) throws IFException {
+        if (top != null || bottom != null || left != null || right != null) {
             generator.endTextObject();
             try {
-                this.borderPainter.drawBorders(rect, before, after, start, end);
+                this.borderPainter.drawBorders(rect, top, bottom, left, right);
             } catch (IOException ioe) {
                 throw new IFException("I/O error while drawing borders", ioe);
             }
@@ -398,7 +399,6 @@ public class PDFPainter extends Abstract
         assert text != null;
         assert triplet != null;
         assert dp != null;
-        assert dp.length == text.length();
         String          fk              = getFontInfo().getInternalFontKey(triplet);
         Typeface        tf              = getTypeface(fk);
         if ( tf.isMultiByte() ) {
@@ -411,14 +411,16 @@ public class PDFPainter extends Abstract
             double      yc              = 0f;
             double      xoLast          = 0f;
             double      yoLast          = 0f;
+            double      wox             = wordSpacing;
             tu.writeTextMatrix ( new AffineTransform ( 1, 0, 0, -1, x / 1000f, y / 1000f ) );
             tu.updateTf ( fk, fsPoints, true );
+            generator.updateCharacterSpacing ( letterSpacing / 1000f );
             for ( int i = 0, n = text.length(); i < n; i++ ) {
                 char    ch              = text.charAt ( i );
                 int[]   pa              = ( i < dp.length ) ? dp [ i ] : paZero;
                 double  xo              = xc + pa[0];
                 double  yo              = yc + pa[1];
-                double  xa              = f.getCharWidth(ch);
+                double  xa              = f.getCharWidth(ch) + maybeWordOffsetX ( wox, ch, null );
                 double  ya              = 0;
                 double  xd              = ( xo - xoLast ) / 1000f;
                 double  yd              = ( yo - yoLast ) / 1000f;
@@ -432,4 +434,26 @@ public class PDFPainter extends Abstract
         }
     }
 
+    private double maybeWordOffsetX ( double wox, char ch, Direction dir ) {
+        if ( ( wox != 0 )
+             && CharUtilities.isAdjustableSpace ( ch )
+             && ( ( dir == null ) || dir.isHorizontal() ) ) {
+            return wox;
+        } else {
+            return 0;
+        }
+    }
+
+    /*
+    private double maybeWordOffsetY ( double woy, char ch, Direction dir ) {
+        if ( ( woy != 0 )
+             && CharUtilities.isAdjustableSpace ( ch ) && dir.isVertical()
+             && ( ( dir != null ) && dir.isVertical() ) ) {
+            return woy;
+        } else {
+            return 0;
+        }
+    }
+    */
+
 }

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/ps/PSPainter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/ps/PSPainter.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/ps/PSPainter.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/render/ps/PSPainter.java Wed Jun 15 18:37:11 2011
@@ -235,16 +235,16 @@ public class PSPainter extends AbstractI
     }
 
     /** {@inheritDoc} */
-    public void drawBorderRect(Rectangle rect, BorderProps before, BorderProps after,
-            BorderProps start, BorderProps end) throws IFException {
-        if (before != null || after != null || start != null || end != null) {
+    public void drawBorderRect(Rectangle rect, BorderProps top, BorderProps bottom,
+            BorderProps left, BorderProps right) throws IFException {
+        if (top != null || bottom != null || left != null || right != null) {
             try {
                 endTextObject();
                 if (getPSUtil().getRenderingMode() == PSRenderingMode.SIZE
-                    && hasOnlySolidBorders(before, after, start, end)) {
-                    super.drawBorderRect(rect, before, after, start, end);
+                    && hasOnlySolidBorders(top, bottom, left, right)) {
+                    super.drawBorderRect(rect, top, bottom, left, right);
                 } else {
-                    this.borderPainter.drawBorders(rect, before, after, start, end);
+                    this.borderPainter.drawBorders(rect, top, bottom, left, right);
                 }
             } catch (IOException ioe) {
                 throw new IFException("I/O error in drawBorderRect()", ioe);

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/Direction.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/Direction.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/Direction.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/Direction.java Wed Jun 15 18:37:11 2011
@@ -53,6 +53,22 @@ public final class Direction extends Tra
     }
 
     /**
+     * Determine if direction is vertical or not.
+     * @return true if vertical
+     */
+    public boolean isVertical() {
+        return ( getEnumValue() == Constants.EN_TB ) || ( getEnumValue() == Constants.EN_BT );
+    }
+
+    /**
+     * Determine if direction is horizontal or not.
+     * @return true if horizontal
+     */
+    public boolean isHorizontal() {
+        return ( getEnumValue() == Constants.EN_LR ) || ( getEnumValue() == Constants.EN_RL );
+    }
+
+    /**
      * Returns the enumeration/singleton object based on its name.
      * @param name the name of the enumeration value
      * @return the enumeration object

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/WritingMode.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/WritingMode.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/WritingMode.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/WritingMode.java Wed Jun 15 18:37:11 2011
@@ -101,6 +101,32 @@ public final class WritingMode extends T
     }
 
     /**
+     * Determine if WM is horizontal or not.
+     * @return true if horizontal
+     */
+    public boolean isHorizontal() {
+        switch ( getEnumValue() ) {
+        case Constants.EN_LR_TB:
+        case Constants.EN_RL_TB:
+            return true;
+        case Constants.EN_TB_LR:
+        case Constants.EN_TB_RL:
+            return false;
+        default:
+            assert false;
+            return true;
+        }
+    }
+
+    /**
+     * Determine if WM is vertical or not.
+     * @return true if vertical
+     */
+    public boolean isVertical() {
+        return !isHorizontal();
+    }
+
+    /**
      * Returns the enumeration/singleton object based on its name.
      * @param name the name of the enumeration value
      * @return the enumeration object

Modified: xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/WritingModeTraits.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/WritingModeTraits.java?rev=1136144&r1=1136143&r2=1136144&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/WritingModeTraits.java (original)
+++ xmlgraphics/fop/branches/Temp_ComplexScripts/src/java/org/apache/fop/traits/WritingModeTraits.java Wed Jun 15 18:37:11 2011
@@ -138,4 +138,20 @@ public class WritingModeTraits implement
         writingMode.assignWritingModeTraits ( this );
     }
 
+    /**
+     * Helper function to find the writing mode traits getter (if any) that applies for
+     * a given FO node.
+     * @param fn the node to start searching from
+     * @return the applicable writing mode traits getter, or null if none applies
+     */
+    public static WritingModeTraitsGetter
+        getWritingModeTraitsGetter ( org.apache.fop.fo.FONode fn ) {
+        for ( org.apache.fop.fo.FONode n = fn; n != null; n = n.getParent() ) {
+            if ( n instanceof WritingModeTraitsGetter ) {
+                return (WritingModeTraitsGetter) n;
+            }
+        }
+        return null;
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org