From db84b66469dd76d53f1025a1c3ab7f89c71a68f8 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Fri, 22 Aug 2008 14:05:09 +0000 Subject: [PATCH] Fixed text stroking in SVG when the stroke-width is zero. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_95@688085 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/svg/PDFTextPainter.java | 41 ++++++++++--------- status.xml | 3 ++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/java/org/apache/fop/svg/PDFTextPainter.java b/src/java/org/apache/fop/svg/PDFTextPainter.java index 7154c68a9..ac78f52da 100644 --- a/src/java/org/apache/fop/svg/PDFTextPainter.java +++ b/src/java/org/apache/fop/svg/PDFTextPainter.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -43,6 +43,7 @@ import org.apache.batik.gvt.renderer.StrokingTextPainter; import org.apache.batik.gvt.text.GVTAttributedCharacterIterator; import org.apache.batik.gvt.text.TextPaintInfo; import org.apache.batik.gvt.text.TextSpanLayout; + import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontTriplet; @@ -61,7 +62,7 @@ import org.apache.fop.util.CharUtilities; public class PDFTextPainter extends StrokingTextPainter { private static final boolean DEBUG = false; - + private boolean strokeText = false; private FontInfo fontInfo; @@ -97,7 +98,7 @@ public class PDFTextPainter extends StrokingTextPainter { if ((tpi != null) && (tpi.composite != null)) { g2d.setComposite(tpi.composite); } - + //------------------------------------ TextSpanLayout layout = textRun.getLayout(); if (DEBUG) { @@ -105,7 +106,7 @@ public class PDFTextPainter extends StrokingTextPainter { System.out.println("================================================"); System.out.println("New text run:"); System.out.println("char count: " + charCount); - System.out.println("range: " + System.out.println("range: " + runaci.getBeginIndex() + " - " + runaci.getEndIndex()); System.out.println("glyph count: " + layout.getGlyphCount()); //=getNumGlyphs() } @@ -120,29 +121,31 @@ public class PDFTextPainter extends StrokingTextPainter { System.out.println("Text: " + chars); pdf.currentStream.write("%Text: " + chars + "\n"); } - + GeneralPath debugShapes = null; if (DEBUG) { debugShapes = new GeneralPath(); } - + Font[] fonts = findFonts(runaci); if (fonts == null || fonts.length == 0) { //Draw using Java2D textRun.getLayout().draw(g2d); continue; } - + textUtil.saveGraphicsState(); textUtil.concatMatrixCurrentTransform(); Shape imclip = g2d.getClip(); pdf.writeClip(imclip); - + applyColorAndPaint(tpi, pdf); - + textUtil.beginTextObject(); textUtil.setFonts(fonts); - textUtil.setTextRenderingMode(tpi.fillPaint != null, tpi.strokePaint != null, false); + boolean stroke = (tpi.strokePaint != null) + && (tpi.strokeStroke != null); + textUtil.setTextRenderingMode(tpi.fillPaint != null, stroke, false); AffineTransform localTransform = new AffineTransform(); Point2D prevPos = null; @@ -153,7 +156,7 @@ public class PDFTextPainter extends StrokingTextPainter { boolean visibleChar = gv.isGlyphVisible(index) || (CharUtilities.isAnySpace(ch) && !CharUtilities.isZeroWidthSpace(ch)); if (DEBUG) { - System.out.println("glyph " + index + System.out.println("glyph " + index + " -> " + layout.getGlyphIndex(index) + " => " + ch); if (CharUtilities.isAnySpace(ch) && ch != 32) { System.out.println("Space found: " + Integer.toHexString(ch)); @@ -193,9 +196,9 @@ public class PDFTextPainter extends StrokingTextPainter { localTransform.concatenate(glyphTransform); } localTransform.scale(1, -1); - - boolean yPosChanged = (prevPos == null - || prevPos.getY() != p.getY() + + boolean yPosChanged = (prevPos == null + || prevPos.getY() != p.getY() || glyphTransform != null); if (yPosChanged) { if (index > 0) { @@ -213,7 +216,7 @@ public class PDFTextPainter extends StrokingTextPainter { textUtil.adjustGlyphTJ(adjust * 1000); } if (DEBUG) { - System.out.println("==> x diff: " + xdiff + ", " + effxdiff + System.out.println("==> x diff: " + xdiff + ", " + effxdiff + ", charWidth: " + cw); } } @@ -226,7 +229,7 @@ public class PDFTextPainter extends StrokingTextPainter { } char paintChar = (CharUtilities.isAnySpace(ch) ? ' ' : ch); textUtil.writeTJChar(paintChar); - + //Update last position prevPos = p; prevVisibleCharWidth = textUtil.getCurrentFont().getCharWidth(chars.charAt(index)); @@ -263,7 +266,7 @@ public class PDFTextPainter extends StrokingTextPainter { } pdf.applyAlpha(fillAlpha, PDFGraphics2D.OPAQUE); } - + private Font[] findFonts(AttributedCharacterIterator aci) { List fonts = new java.util.ArrayList(); List gvtFonts = (List) aci.getAttribute( @@ -338,5 +341,5 @@ public class PDFTextPainter extends StrokingTextPainter { } return (Font[])fonts.toArray(new Font[fonts.size()]); } - + } \ No newline at end of file diff --git a/status.xml b/status.xml index 68575fe81..0d7bba547 100644 --- a/status.xml +++ b/status.xml @@ -53,6 +53,9 @@ + + Fixed text stroking in SVG when the stroke-width is zero. + Fixed ID resolution for nested bookmarks with duplicated IDs. -- 2.39.5