/** * Paints the text in each text run. Decorations are not painted here. */ protected void paintTextRuns(List textRuns, Graphics2D g2d) { for (int i = 0; i < textRuns.size(); i++) { TextRun textRun = (TextRun)textRuns.get(i); AttributedCharacterIterator runaci = textRun.getACI(); runaci.first(); TextPaintInfo tpi = (TextPaintInfo)runaci.getAttribute(PAINT_INFO); if ((tpi != null) && (tpi.composite != null)) { g2d.setComposite(tpi.composite); } textRun.getLayout().draw(g2d); } }
protected float distanceFirstLastCharacterInRun (CharacterInformation first, CharacterInformation last){ float [] advs = first.layout.getGlyphAdvances(); int firstStart = first.glyphIndexStart; int firstEnd = first.glyphIndexEnd; int lastStart = last.glyphIndexStart; int lastEnd = last.glyphIndexEnd; int start = (firstStart<lastStart)?firstStart:lastStart; int end = (firstEnd<lastEnd)?lastEnd:firstEnd; return advs[end+1] - advs[start]; }
run = (StrokingTextPainter.TextRun)list.get(i); if (!run.getLayout().hasCharacterIndex(info.characterIndex) ) continue; info.glyphIndexEnd = info.layout.getGlyphCount()-1; } else { info.glyphIndexStart = info.layout.getGlyphIndex (info.characterIndex); info.glyphIndexEnd = info.layout.getGlyphCount()-1;
/** * Returns true if the specified Point2D is inside the boundary of this * node, false otherwise. * * @param p the specified Point2D in the user space */ public boolean contains(Point2D p) { // <!> FIXME: should put this code in TextPaint somewhere, // as pointer-events support - same problem with pointer-events // and ShapeNode if (!super.contains(p)) { return false; } List list = getTextRuns(); // place coords in text node coordinate system for (int i = 0 ; i < list.size(); i++) { StrokingTextPainter.TextRun run = (StrokingTextPainter.TextRun)list.get(i); TextSpanLayout layout = run.getLayout(); float x = (float)p.getX(); float y = (float)p.getY(); TextHit textHit = layout.hitTestChar(x, y); if (textHit != null && contains(p, layout.getBounds2D())) { return true; } } return false; }
TextSpanLayout tsl = tr.getLayout(); if (startGlyphIndex == -1) { startGlyphIndex = tsl.getGlyphIndex(result[0]); if (startGlyphIndex != -1) startLayout = tsl; endGlyphIndex = tsl.getGlyphIndex(result[1]); if (endGlyphIndex != -1) endLayout = tsl; return null; int startCharCount = startLayout.getCharacterCount (startGlyphIndex, startGlyphIndex); int endCharCount = endLayout.getCharacterCount (endGlyphIndex, endGlyphIndex); if (startCharCount > 1) { if (result[0] > result[1] && startLayout.isLeftToRight()) { result[0] += startCharCount-1; } else if (result[1] > result[0] && !startLayout.isLeftToRight()) { result[0] -= startCharCount-1; if (result[1] > result[0] && endLayout.isLeftToRight()) { result[1] += endCharCount-1; } else if (result[0] > result[1] && !endLayout.isLeftToRight()) { result[1] -= endCharCount-1;
TextSpanLayout layout = r.getLayout(); GVTGlyphMetrics lastMetrics = layout.getGlyphMetrics(layout.getGlyphCount()-1); GVTLineMetrics lastLineMetrics = layout.getLineMetrics(); Rectangle2D lastBounds = lastMetrics.getBounds2D(); float halfLeading = (lastMetrics.getVerticalAdvance()- if (layout.isVertical()) { if (lengthAdj == ADJUST_SPACING) { yScale = (float) r = (TextRun) textRuns.get(i); layout = r.getLayout(); layout.setScale(xScale, yScale, lengthAdj==ADJUST_SPACING); Point2D lAdv = layout.getAdvance2D(); adv.x += (float)lAdv.getX(); adv.y += (float)lAdv.getY(); AttributedCharacterIterator runaci = r.getACI(); runaci.first(); boolean vertical = layout.isVertical(); Float runX = (Float) runaci.getAttribute(XPOS); Float runY = (Float) runaci.getAttribute(YPOS); layout.setOffset(new Point2D.Float(absX, absY)); Point2D ladv = layout.getAdvance2D(); absX += ladv.getX(); absY += ladv.getY();
Shape s = textRun.getLayout().getDecorationOutline (decorationType); Rectangle2D r2d = s.getBounds2D(); && !textRun.getLayout().isVertical() && !textRun.getLayout().isOnATextPath()) { textRun.getLayout().getDecorationOutline(decorationType); if (decorationRect == null) {
CharacterInformation lastCharacterInRunInfo = null; int chIndex = currentInfo.characterIndex+1; GVTGlyphVector vector = currentInfo.layout.getGlyphVector(); float [] advs = currentInfo.layout.getGlyphAdvances(); boolean [] glyphTrack = new boolean[advs.length]; for( int k = charnum +1; k < charnum +nchars ; k++) { if (currentInfo.layout.isOnATextPath() ){ for (int gi = currentInfo.glyphIndexStart; gi <= currentInfo.glyphIndexEnd; gi++) { newInfo = getCharacterInformation(list, firstChar, k, aci); if (newInfo.layout != currentInfo.layout) { vector = newInfo.layout.getGlyphVector(); advs = newInfo.layout.getGlyphAdvances(); glyphTrack = new boolean[advs.length]; chIndex = currentInfo.characterIndex+1; if ( currentInfo.layout.hasCharacterIndex(chIndex) ){ chIndex++; continue; vector = currentInfo.layout.getGlyphVector(); advs = currentInfo.layout.getGlyphAdvances(); glyphTrack = new boolean[advs.length]; lastCharacterInRunInfo = null; if (currentInfo.layout.isOnATextPath() ){ for (int gi = currentInfo.glyphIndexStart; gi <= currentInfo.glyphIndexEnd; gi++) {
if (!isTextSensitive(elem)) continue; Rectangle2D glBounds = layout.getBounds2D(); if (glBounds != null) { glBounds = at.createTransformedShape(glBounds).getBounds2D(); GVTGlyphVector gv = layout.getGlyphVector(); for (int g = 0; g < gv.getNumGlyphs(); g++) { Shape gBounds = gv.getGlyphLogicalBounds(g);
protected Point2D getStartPoint(CharacterInformation info){ GVTGlyphVector it = info.layout.getGlyphVector(); if (!it.isGlyphVisible(info.glyphIndexStart)) return null; Point2D b = it.getGlyphPosition(info.glyphIndexStart); AffineTransform glyphTransform; glyphTransform = it.getGlyphTransform(info.glyphIndexStart); //glyph are defined starting at position (0,0) Point2D.Float result = new Point2D.Float(0, 0); if ( glyphTransform != null ) //apply the glyph transformation to the start point glyphTransform.transform(result,result); result.x += b.getX(); result.y += b.getY(); return result; }
double advance = font == null ? run.getLayout().getAdvance2D().getX() : getStringWidth(txt, font); double tx = 0; if (anchor != null) { double scaleX = g2d.getTransform().getScaleX(); for (int i = 0; i < txt.length(); i++) { double ad = run.getLayout().getGlyphAdvances()[i] * scaleX; nativeTextHandler.drawString(g2d, txt.charAt(i) + "", (float) (x + tx + ad), (float) y);
GVTGlyphVector gv = layout.getGlyphVector(); if (!(gv.getFont() instanceof FOPGVTFont)) { assert gv.getFont() == null || gv.getFont() instanceof SVGGVTFont; textRun.getLayout().draw(g2d); return; } else { g2d.setStroke(new BasicStroke(0)); g2d.setColor(Color.LIGHT_GRAY); g2d.draw(debugShapes);
protected final void logTextRun(TextRun textRun) { AttributedCharacterIterator runaci = textRun.getACI(); TextSpanLayout layout = textRun.getLayout(); runaci.first(); if (log.isTraceEnabled()) { int charCount = runaci.getEndIndex() - runaci.getBeginIndex(); log.trace("================================================"); log.trace("New text run:"); log.trace("char count: " + charCount); log.trace("range: " + runaci.getBeginIndex() + " - " + runaci.getEndIndex()); log.trace("glyph count: " + layout.getGlyphCount()); //=getNumGlyphs() } }
Rectangle2D glBounds = layout.getBounds2D(); if ( glBounds == null ){ continue;
Point2D layoutAdvance = layout.getAdvance2D(); advance.x += (float)layoutAdvance.getX(); advance.y += (float)layoutAdvance.getY();
/** * @param ch a character * @param layout a text span layout * @param index an index * @param visibleChar visible character flag */ protected final void logCharacter(char ch, TextSpanLayout layout, int index, boolean visibleChar) { if (log.isTraceEnabled()) { log.trace("glyph " + index + " -> " + layout.getGlyphIndex(index) + " => " + ch); if (CharUtilities.isAnySpace(ch) && ch != 32) { log.trace("Space found: " + Integer.toHexString(ch)); } else if (ch == CharUtilities.ZERO_WIDTH_JOINER) { log.trace("ZWJ found: " + Integer.toHexString(ch)); } else if (ch == CharUtilities.SOFT_HYPHEN) { log.trace("Soft hyphen found: " + Integer.toHexString(ch)); } if (!visibleChar) { log.trace("Invisible glyph found: " + Integer.toHexString(ch)); } } }
public double getComputedOrientationAngle(){ return layout.getComputedOrientationAngle(characterIndex); } }
TextSpanLayout layout = r.getLayout(); GVTGlyphMetrics lastMetrics = layout.getGlyphMetrics(layout.getGlyphCount()-1); GVTLineMetrics lastLineMetrics = layout.getLineMetrics(); Rectangle2D lastBounds = lastMetrics.getBounds2D(); float halfLeading = (lastMetrics.getVerticalAdvance()- if (layout.isVertical()) { if (lengthAdj == ADJUST_SPACING) { yScale = (float) r = (TextRun) textRuns.get(i); layout = r.getLayout(); layout.setScale(xScale, yScale, lengthAdj==ADJUST_SPACING); Point2D lAdv = layout.getAdvance2D(); adv.x += (float)lAdv.getX(); adv.y += (float)lAdv.getY(); AttributedCharacterIterator runaci = r.getACI(); runaci.first(); boolean vertical = layout.isVertical(); Float runX = (Float) runaci.getAttribute(XPOS); Float runY = (Float) runaci.getAttribute(YPOS); layout.setOffset(new Point2D.Float(absX, absY)); Point2D ladv = layout.getAdvance2D(); absX += ladv.getX(); absY += ladv.getY();
Shape s = textRun.getLayout().getDecorationOutline (decorationType); Rectangle2D r2d = s.getBounds2D(); && !textRun.getLayout().isVertical() && !textRun.getLayout().isOnATextPath()) { textRun.getLayout().getDecorationOutline(decorationType); if (decorationRect == null) {
CharacterInformation lastCharacterInRunInfo = null; int chIndex = currentInfo.characterIndex+1; GVTGlyphVector vector = currentInfo.layout.getGlyphVector(); float [] advs = currentInfo.layout.getGlyphAdvances(); boolean [] glyphTrack = new boolean[advs.length]; for( int k = charnum +1; k < charnum +nchars ; k++) { if (currentInfo.layout.isOnATextPath() ){ for (int gi = currentInfo.glyphIndexStart; gi <= currentInfo.glyphIndexEnd; gi++) { newInfo = getCharacterInformation(list, firstChar, k, aci); if (newInfo.layout != currentInfo.layout) { vector = newInfo.layout.getGlyphVector(); advs = newInfo.layout.getGlyphAdvances(); glyphTrack = new boolean[advs.length]; chIndex = currentInfo.characterIndex+1; if ( currentInfo.layout.hasCharacterIndex(chIndex) ){ chIndex++; continue; vector = currentInfo.layout.getGlyphVector(); advs = currentInfo.layout.getGlyphAdvances(); glyphTrack = new boolean[advs.length]; lastCharacterInRunInfo = null; if (currentInfo.layout.isOnATextPath() ){ for (int gi = currentInfo.glyphIndexStart; gi <= currentInfo.glyphIndexEnd; gi++) {