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 je...@apache.org on 2005/11/24 20:41:20 UTC

svn commit: r348788 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop: layoutmgr/inline/LeaderLayoutManager.java render/pdf/PDFRenderer.java render/ps/PSRenderer.java

Author: jeremias
Date: Thu Nov 24 11:41:11 2005
New Revision: 348788

URL: http://svn.apache.org/viewcvs?rev=348788&view=rev
Log:
Improvements for leader painting in PDF. "dots" are actually dots now, nicer ridge/groove with lightenColor(), reusing code from border painting.
Leader in PostScript Renderer now, too.
LeaderLM did not set the leader color and the PDF Renderer didn't act on it.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java?rev=348788&r1=348787&r2=348788&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java Thu Nov 24 11:41:11 2005
@@ -121,6 +121,7 @@
                 leaderArea = new Space();
                 leaderArea.setBPD(1);
             }
+            leaderArea.addTrait(Trait.COLOR, fobj.getColor());
         } else if (fobj.getLeaderPattern() == EN_SPACE) {
             leaderArea = new Space();
             leaderArea.setBPD(1);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java?rev=348788&r1=348787&r2=348788&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java Thu Nov 24 11:41:11 2005
@@ -1498,59 +1498,47 @@
         currentState.push();
         saveGraphicsState();
         int style = area.getRuleStyle();
-        boolean alt = false;
-        switch(style) {
-            case EN_SOLID:
-                currentStream.add("[] 0 d\n");
-            break;
-            case EN_DOTTED:
-                currentStream.add("[2] 0 d\n");
-            break;
-            case EN_DASHED:
-                currentStream.add("[6 4] 0 d\n");
-            break;
-            case EN_DOUBLE:
-            case EN_GROOVE:
-            case EN_RIDGE:
-                alt = true;
-            break;
-        }
         float startx = (currentIPPosition + area.getBorderAndPaddingWidthStart()) / 1000f;
         float starty = (currentBPPosition + area.getOffset()) / 1000f;
         float endx = (currentIPPosition + area.getBorderAndPaddingWidthStart() 
                         + area.getIPD()) / 1000f;
-        // PDF draws lines centered on the Y coordiante, therefore we need to
-        // add half of the line thickness to the Y positions.
-        if (!alt) {
-            updateLineWidth(area.getRuleThickness() / 1000f);
-            drawLine(startx, starty + area.getRuleThickness() / 2000f
-                    , endx, starty + area.getRuleThickness() / 2000f);
-        } else {
-            if (style == EN_DOUBLE) {
-                float third = area.getRuleThickness() / 3000f;
-                updateLineWidth(third);
-                drawLine(startx, starty + 0.5f * third, endx, starty + 0.5f * third);
+        float ruleThickness = area.getRuleThickness() / 1000f;
+        ColorType col = (ColorType)area.getTrait(Trait.COLOR);
 
-                drawLine(startx, (starty + 2.5f * third), endx, (starty + 2.5f * third));
-            } else {
+        switch (style) {
+            case EN_SOLID:
+            case EN_DASHED:
+            case EN_DOUBLE:
+                drawBorderLine(startx, starty, endx, starty + ruleThickness, 
+                        true, true, style, col);
+                break;
+            case EN_DOTTED:
+                clipRect(startx, starty, endx - startx, ruleThickness);
+                //This displaces the dots to the right by half a dot's width
+                //TODO There's room for improvement here
+                currentStream.add("1 0 0 1 " + (ruleThickness / 2) + " 0 cm\n");
+                drawBorderLine(startx, starty, endx, starty + ruleThickness, 
+                        true, true, style, col);
+                break;
+            case EN_GROOVE:
+            case EN_RIDGE:
                 float half = area.getRuleThickness() / 2000f;
 
-                currentStream.add("1 g\n");
+                setColor(lightenColor(toColor(col), 0.6f), true, null);
                 currentStream.add(startx + " " + starty + " m\n");
                 currentStream.add(endx + " " + starty + " l\n");
                 currentStream.add(endx + " " + (starty + 2 * half) + " l\n");
                 currentStream.add(startx + " " + (starty + 2 * half) + " l\n");
                 currentStream.add("h\n");
                 currentStream.add("f\n");
+                setColor(toColor(col), true, null);
                 if (style == EN_GROOVE) {
-                    currentStream.add("0 g\n");
                     currentStream.add(startx + " " + starty + " m\n");
                     currentStream.add(endx + " " + starty + " l\n");
                     currentStream.add(endx + " " + (starty + half) + " l\n");
                     currentStream.add((startx + half) + " " + (starty + half) + " l\n");
                     currentStream.add(startx + " " + (starty + 2 * half) + " l\n");
                 } else {
-                    currentStream.add("0 g\n");
                     currentStream.add(endx + " " + starty + " m\n");
                     currentStream.add(endx + " " + (starty + 2 * half) + " l\n");
                     currentStream.add(startx + " " + (starty + 2 * half) + " l\n");
@@ -1559,8 +1547,9 @@
                 }
                 currentStream.add("h\n");
                 currentStream.add("f\n");
-            }
-
+                break;
+            default:
+                throw new UnsupportedOperationException("rule style not supported");
         }
 
         restoreGraphicsState();

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java?rev=348788&r1=348787&r2=348788&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java Thu Nov 24 11:41:11 2005
@@ -48,6 +48,7 @@
 import org.apache.fop.area.inline.ForeignObject;
 import org.apache.fop.area.inline.Image;
 import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.area.inline.Leader;
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.datatypes.ColorType;
 import org.apache.fop.apps.FOUserAgent;
@@ -187,7 +188,6 @@
     /** @see org.apache.fop.render.AbstractPathOrientedRenderer#clip() */
     protected void clip() {
         writeln("clip newpath");
-        //writeln("newpath");
     }
     
     /**
@@ -202,8 +202,7 @@
     protected void clipRect(float x, float y, float width, float height) {
         try {
             gen.defineRect(x, y, width, height);
-            gen.writeln("clip");
-            //comment("clip here");
+            clip();
         } catch (IOException ioe) {
             handleIOTrouble(ioe);
         }
@@ -969,6 +968,77 @@
         super.renderInlineParent(ip);
     }
     
+    /**
+     * @see org.apache.fop.render.AbstractRenderer#renderLeader(org.apache.fop.area.inline.Leader)
+     */
+    public void renderLeader(Leader area) {
+        renderInlineAreaBackAndBorders(area);
+
+        endTextObject();
+        saveGraphicsState();
+        int style = area.getRuleStyle();
+        float startx = (currentIPPosition + area.getBorderAndPaddingWidthStart()) / 1000f;
+        float starty = (currentBPPosition + area.getOffset()) / 1000f;
+        float endx = (currentIPPosition + area.getBorderAndPaddingWidthStart() 
+                        + area.getIPD()) / 1000f;
+        float ruleThickness = area.getRuleThickness() / 1000f;
+        ColorType col = (ColorType)area.getTrait(Trait.COLOR);
+
+        try {
+            switch (style) {
+                case EN_SOLID:
+                case EN_DASHED:
+                case EN_DOUBLE:
+                    drawBorderLine(startx, starty, endx, starty + ruleThickness, 
+                            true, true, style, col);
+                    break;
+                case EN_DOTTED:
+                    clipRect(startx, starty, endx - startx, ruleThickness);
+                    //This displaces the dots to the right by half a dot's width
+                    //TODO There's room for improvement here
+                    gen.concatMatrix(1, 0, 0, 1, ruleThickness / 2, 0);
+                    drawBorderLine(startx, starty, endx, starty + ruleThickness, 
+                            true, true, style, col);
+                    break;
+                case EN_GROOVE:
+                case EN_RIDGE:
+                    float half = area.getRuleThickness() / 2000f;
+    
+                    gen.useRGBColor(lightenColor(toColor(col), 0.6f));
+                    moveTo(startx, starty);
+                    lineTo(endx, starty);
+                    lineTo(endx, starty + 2 * half);
+                    lineTo(startx, starty + 2 * half);
+                    closePath();
+                    gen.writeln(" fill newpath");
+                    gen.useRGBColor(toColor(col));
+                    if (style == EN_GROOVE) {
+                        moveTo(startx, starty);
+                        lineTo(endx, starty);
+                        lineTo(endx, starty + half);
+                        lineTo(startx + half, starty + half);
+                        lineTo(startx, starty + 2 * half);
+                    } else {
+                        moveTo(endx, starty);
+                        lineTo(endx, starty + 2 * half);
+                        lineTo(startx, starty + 2 * half);
+                        lineTo(startx, starty + half);
+                        lineTo(endx - half, starty + half);
+                    }
+                    closePath();
+                    gen.writeln(" fill newpath");
+                    break;
+                default:
+                    throw new UnsupportedOperationException("rule style not supported");
+            }
+        } catch (IOException ioe) {
+            handleIOTrouble(ioe);
+        }
+
+        restoreGraphicsState();
+        super.renderLeader(area);
+    }
+
     /**
      * @see org.apache.fop.render.AbstractRenderer#renderImage(Image, Rectangle2D)
      */



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