From fbde68e319c63088f6b09bf126bbf5bfb5a113e3 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Thu, 24 Nov 2005 19:41:11 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@348788 13f79535-47bb-0310-9956-ffa450edef68 --- .../layoutmgr/inline/LeaderLayoutManager.java | 1 + .../apache/fop/render/pdf/PDFRenderer.java | 59 ++++++-------- .../org/apache/fop/render/ps/PSRenderer.java | 76 ++++++++++++++++++- 3 files changed, 98 insertions(+), 38 deletions(-) diff --git a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java index 9731cc960..cad328e82 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LeaderLayoutManager.java @@ -121,6 +121,7 @@ public class LeaderLayoutManager extends LeafNodeLayoutManager { leaderArea = new Space(); leaderArea.setBPD(1); } + leaderArea.addTrait(Trait.COLOR, fobj.getColor()); } else if (fobj.getLeaderPattern() == EN_SPACE) { leaderArea = new Space(); leaderArea.setBPD(1); diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index ec6b6f152..66fdd9b03 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -1498,59 +1498,47 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { 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 @@ public class PDFRenderer extends AbstractPathOrientedRenderer { } currentStream.add("h\n"); currentStream.add("f\n"); - } - + break; + default: + throw new UnsupportedOperationException("rule style not supported"); } restoreGraphicsState(); diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java index 0f7da6b02..1b87bbeba 100644 --- a/src/java/org/apache/fop/render/ps/PSRenderer.java +++ b/src/java/org/apache/fop/render/ps/PSRenderer.java @@ -48,6 +48,7 @@ import org.apache.fop.area.inline.Character; 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 @@ public class PSRenderer extends AbstractPathOrientedRenderer { /** @see org.apache.fop.render.AbstractPathOrientedRenderer#clip() */ protected void clip() { writeln("clip newpath"); - //writeln("newpath"); } /** @@ -202,8 +202,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer { 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 @@ public class PSRenderer extends AbstractPathOrientedRenderer { 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) */ -- 2.39.5