if ((tpi != null) && (tpi.composite != null)) {
g2d.setComposite(tpi.composite);
}
//------------------------------------
TextSpanLayout layout = textRun.getLayout();
if (DEBUG) {
int charCount = runaci.getEndIndex() - runaci.getBeginIndex();
System.out.println("================================================");
System.out.println("New text run:");
System.out.println("char count: " + charCount);
System.out.println("range: "
+ runaci.getBeginIndex() + " - " + runaci.getEndIndex());
System.out.println("glyph count: " + layout.getGlyphCount()); //=getNumGlyphs()
}
//Gather all characters of the run
StringBuffer chars = new StringBuffer();
for (runaci.first(); runaci.getIndex() < runaci.getEndIndex();) {
chars.append(runaci.current());
runaci.next();
}
runaci.first();
if (DEBUG) {
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);
AffineTransform localTransform = new AffineTransform();
Point2D prevPos = null;
double prevVisibleCharWidth = 0.0;
GVTGlyphVector gv = layout.getGlyphVector();
for (int index = 0, c = gv.getNumGlyphs(); index < c; index++) {
char ch = chars.charAt(index);
boolean visibleChar = gv.isGlyphVisible(index)
|| (CharUtilities.isAnySpace(ch) && !CharUtilities.isZeroWidthSpace(ch));
if (DEBUG) {
System.out.println("glyph " + index
+ " -> " + layout.getGlyphIndex(index) + " => " + ch);
if (CharUtilities.isAnySpace(ch) && ch != 32) {
System.out.println("Space found: " + Integer.toHexString(ch));
}
if (ch == CharUtilities.ZERO_WIDTH_JOINER) {
System.out.println("ZWJ found: " + Integer.toHexString(ch));