Package org.apache.batik.gvt.text

Examples of org.apache.batik.gvt.text.TextHit


        // for each text run, see if its been hit
        for (int i = 0; i < textRuns.size(); ++i) {
            TextRun textRun = (TextRun)textRuns.get(i);
            TextSpanLayout layout = textRun.getLayout();
            TextHit textHit = layout.hitTestChar((float) x, (float) y);
            if (textHit != null && layout.getBounds().contains(x,y)) {
                return new BasicTextPainter.BasicMark(node, layout, textHit);
            }
        }
View Full Code Here


        List textRuns = getTextRuns(node, aci);

        aci.first();
        int charIndex = ((Integer)aci.getAttribute
                         (GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
        TextHit textHit = new TextHit(charIndex, false);
        return new BasicTextPainter.BasicMark
            (node, ((TextRun)textRuns.get(0)).getLayout(), textHit);
    }
View Full Code Here

        int lastGlyphIndex = lastLayout.getGlyphCount()-1;
        aci.last();

        int charIndex = ((Integer)aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
        TextHit textHit = new TextHit(charIndex, false);
        return  new BasicTextPainter.BasicMark(node, lastLayout, textHit);
    }
View Full Code Here

        // for each text run, see if its been hit
        for (int i = 0; i < textRuns.size(); ++i) {
            TextRun textRun = (TextRun)textRuns.get(i);
            TextSpanLayout layout = textRun.getLayout();
            TextHit textHit = layout.hitTestChar((float) x, (float) y);
            if (textHit != null && layout.getBounds().contains(x,y)) {
                textHit.setTextNode(node);
                textHit.setFontRenderContext(frc);
                cachedMark = new BasicTextPainter.Mark(x, y, layout, textHit);
                cachedNode = node;
                return cachedMark;
            }
        }

        if (cachedNode != node) {
            // did not hit any of the layouts and the cachedMark is invalid for
            // this text node, so create a dummy mark
            TextHit textHit = new TextHit(0, false);
            textHit.setTextNode(node);
            textHit.setFontRenderContext(frc);
            cachedMark = new BasicTextPainter.Mark(x,y,((TextRun)textRuns.get(0)).getLayout(), textHit);
            cachedNode = node;
        }
         return cachedMark;
    }
View Full Code Here

        List textRuns = getTextRuns(node, aci, frc);

        aci.first();
        int charIndex = ((Integer)aci.getAttribute(
            GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
        TextHit textHit = new TextHit(charIndex, false);
        textHit.setTextNode(node);
        textHit.setFontRenderContext(frc);
        cachedMark = new BasicTextPainter.Mark(x,y,((TextRun)textRuns.get(0)).getLayout(), textHit);
        cachedNode = node;
        return cachedMark;
    }
View Full Code Here

        TextSpanLayout lastLayout = ((TextRun)textRuns.get(textRuns.size()-1)).getLayout();
        int lastGlyphIndex = lastLayout.getGlyphCount()-1;
        aci.last();
        int charIndex = ((Integer)aci.getAttribute(
            GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
        TextHit textHit = new TextHit(charIndex, false);
        textHit.setTextNode(node);
        textHit.setFontRenderContext(frc);
        cachedMark = new BasicTextPainter.Mark(x,y,lastLayout,textHit);
        cachedNode = node;
        return cachedMark;
    }
View Full Code Here

            return null;
        }
        aci.setIndex(hit.getCharIndex() + aci.getBeginIndex());
        int charIndex = ((Integer)aci.getAttribute(
            GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
        return new TextHit(charIndex, hit.isLeadingEdge());
    }
View Full Code Here

     * @return a TextHit object encapsulating the character index for
     *     successful hits and whether the hit is on the character
     *     leading edge.
     */
    public TextHit hitTestChar(float x, float y) {
        TextHit textHit = null;

        // if this layout is transformed, need to apply the inverse
        // transform to the point
        if (transform != null) {
            try {
                Point2D p = new Point2D.Float(x, y);
                transform.inverseTransform(p, p);
                x = (float) p.getX();
                y = (float) p.getY();
            } catch (java.awt.geom.NoninvertibleTransformException nite) {;}
        }

        int currentChar = aci.getBeginIndex();
        for (int i = 0; i < gv.getNumGlyphs(); i++) {
            Shape gbounds = gv.getGlyphLogicalBounds(i);
            if (gbounds != null) {
                Rectangle2D gbounds2d = gbounds.getBounds2D();

                if (gbounds.contains(x, y)) {
                    boolean isRightHalf =
                        (x > (gbounds2d.getX()+(gbounds2d.getWidth()/2d)));
                    boolean isLeadingEdge = !isRightHalf;
                    aci.setIndex(currentChar);
                    int charIndex = ((Integer)aci.getAttribute(
                        GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
                    textHit = new TextHit(charIndex, isLeadingEdge);
                    return textHit;
                }
            }
            currentChar += getCharacterCount(i, i);
        }
View Full Code Here

        // for each text run, see if its been hit
        for (int i = 0; i < textRuns.size(); ++i) {
            TextRun textRun = (TextRun)textRuns.get(i);
            TextSpanLayout layout = textRun.getLayout();
            TextHit textHit = layout.hitTestChar((float) x, (float) y);
            if (textHit != null && layout.getBounds().contains(x,y)) {
                textHit.setTextNode(node);
                textHit.setFontRenderContext(frc);
                cachedMark = new BasicTextPainter.Mark(x, y, layout, textHit);
                cachedNode = node;
                return cachedMark;
            }
        }

        if (cachedNode != node) {
            // did not hit any of the layouts and the cachedMark is invalid for
            // this text node, so create a dummy mark
            TextHit textHit = new TextHit(0, false);
            textHit.setTextNode(node);
            textHit.setFontRenderContext(frc);
            cachedMark = new BasicTextPainter.Mark(x,y,((TextRun)textRuns.get(0)).getLayout(), textHit);
            cachedNode = node;
        }
         return cachedMark;
    }
View Full Code Here

        List textRuns = getTextRuns(node, aci, frc);

        aci.first();
        int charIndex = ((Integer)aci.getAttribute(
            GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
        TextHit textHit = new TextHit(charIndex, false);
        textHit.setTextNode(node);
        textHit.setFontRenderContext(frc);
        cachedMark = new BasicTextPainter.Mark(x,y,((TextRun)textRuns.get(0)).getLayout(), textHit);
        cachedNode = node;
        return cachedMark;
    }
View Full Code Here

TOP

Related Classes of org.apache.batik.gvt.text.TextHit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.