* 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.
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;
public class PDFTextPainter extends StrokingTextPainter {
private static final boolean DEBUG = false;
-
+
private boolean strokeText = false;
private FontInfo fontInfo;
if ((tpi != null) && (tpi.composite != null)) {
g2d.setComposite(tpi.composite);
}
-
+
//------------------------------------
TextSpanLayout layout = textRun.getLayout();
if (DEBUG) {
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()
}
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;
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));
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) {
textUtil.adjustGlyphTJ(adjust * 1000);
}
if (DEBUG) {
- System.out.println("==> x diff: " + xdiff + ", " + effxdiff
+ System.out.println("==> x diff: " + xdiff + ", " + effxdiff
+ ", charWidth: " + cw);
}
}
}
char paintChar = (CharUtilities.isAnySpace(ch) ? ' ' : ch);
textUtil.writeTJChar(paintChar);
-
+
//Update last position
prevPos = p;
prevVisibleCharWidth = textUtil.getCurrentFont().getCharWidth(chars.charAt(index));
}
pdf.applyAlpha(fillAlpha, PDFGraphics2D.OPAQUE);
}
-
+
private Font[] findFonts(AttributedCharacterIterator aci) {
List fonts = new java.util.ArrayList();
List gvtFonts = (List) aci.getAttribute(
}
return (Font[])fonts.toArray(new Font[fonts.size()]);
}
-
+
}
\ No newline at end of file