Examples of TextSpanLayout


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

            // We have to do this here since textLength needs to be
            // handled at the text chunk level. Otherwise tspans get
            // messed up.
            float delta = 0;
            r = (TextRun)textRuns.get(chunk.end-1);
            TextSpanLayout  layout          = r.getLayout();
            GVTGlyphMetrics lastMetrics =
                layout.getGlyphMetrics(layout.getGlyphCount()-1);
            Rectangle2D     lastBounds  = lastMetrics.getBounds2D();

            if (layout.isVertical()) {
                if (lengthAdj == ADJUST_SPACING) {
                    yScale = (float)
                        ((length.floatValue()-lastBounds.getHeight())/
                         (advance.getY()-lastMetrics.getVerticalAdvance()));
                } else {
                    double adv = (advance.getY()-
                                  lastMetrics.getVerticalAdvance() +
                                  lastBounds.getHeight());
                    xScale = (float)(length.floatValue()/adv);
                }
            } else {
                if (lengthAdj == ADJUST_SPACING) {
                    xScale = (float)
                        ((length.floatValue()-lastBounds.getWidth())/
                         (advance.getX()-lastMetrics.getHorizontalAdvance()));
                } else {
                    double adv = (advance.getX()-
                                  lastMetrics.getHorizontalAdvance() +
                                  lastBounds.getWidth());
                    xScale = (float)(length.floatValue()/adv);
                }
            }

            // System.out.println("Adv: " + advance + " Len: " + length +
            //                    " scale: [" + xScale + ", " + yScale + "]");
            Point2D.Float adv = new Point2D.Float(0,0);
            for (int n=chunk.begin; n<chunk.end; ++n) {
                r = (TextRun) textRuns.get(n);
                layout = r.getLayout();
                layout.setScale(xScale, yScale, lengthAdj==ADJUST_SPACING);
                Point2D lAdv = layout.getAdvance2D();
                adv.x += lAdv.getX();
                adv.y += lAdv.getY();
            }
            chunk.advance = adv;
        }

        advance = chunk.advance;

        float dx = 0f;
        float dy = 0f;
        switch(anchorType){
        case TextNode.Anchor.ANCHOR_MIDDLE:
            dx = (float) (-advance.getX()/2d);
            dy = (float) (-advance.getY()/2d);
            break;
        case TextNode.Anchor.ANCHOR_END:
            dx = (float) (-advance.getX());
            dy = (float) (-advance.getY());
            break;
        default:
            break;
            // leave untouched
        }

       
        r = (TextRun) textRuns.get(chunk.begin);
            TextSpanLayout layout = r.getLayout();
            Point2D        offset = layout.getOffset();
        float initX = (float)offset.getX();
        float initY = (float)offset.getY();

        for (int n=chunk.begin; n<chunk.end; ++n) {
            r = (TextRun) textRuns.get(n);
            layout = r.getLayout();
            offset = layout.getOffset();
            if (layout.isVertical()) {
                float adj = (float)((offset.getY()-initY)*yScale);
                offset = new Point2D.Float((float) offset.getX(),
                                           (float)initY+adj+dy);
            } else {
                float adj = (float)((offset.getX()-initX)*xScale);
                offset = new Point2D.Float((float)initX+adj+dx,
                                           (float) offset.getY());
            }
            layout.setOffset(offset);
        }
    }
View Full Code Here

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

        // for each text run, get its outline and append it to the overall
        // outline

        for (int i = 0; i < textRuns.size(); ++i) {
            TextRun textRun = (TextRun)textRuns.get(i);
            TextSpanLayout textRunLayout = textRun.getLayout();
            GeneralPath textRunOutline =
    new GeneralPath(textRunLayout.getOutline());

            if (outline == null) {
               outline = textRunOutline;
            } else {
                outline.setWindingRule(GeneralPath.WIND_NON_ZERO);
View Full Code Here

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

            TextRun textRun = (TextRun)textRuns.get(i);
            AttributedCharacterIterator textRunACI = textRun.getACI();
            textRunACI.first();

            TextSpanLayout textRunLayout = textRun.getLayout();

            Stroke stroke = (Stroke) textRunACI.getAttribute
    (GVTAttributedCharacterIterator.TextAttribute.STROKE);

            Paint strokePaint = (Paint) textRunACI.getAttribute
    (GVTAttributedCharacterIterator.TextAttribute.STROKE_PAINT);

            if (stroke != null && strokePaint != null) {
                // this textRun is stroked
                Shape textRunOutline =
        textRunLayout.getOutline();
                textRunStrokeOutline =
        stroke.createStrokedShape(textRunOutline);
            }

            if (textRunStrokeOutline != null) {
View Full Code Here

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

        List textRuns = getTextRuns(node, aci);

        // for each text run, see if it contains the current char.
        for (int i = 0; i < textRuns.size(); ++i) {
            TextRun textRun = (TextRun)textRuns.get(i);
            TextSpanLayout layout = textRun.getLayout();

            int idx = layout.getGlyphIndex(index);
            if (idx != -1) {
                TextHit textHit = new TextHit(index, leadingEdge);
                return new BasicTextPainter.BasicMark
                    (node, layout, textHit);
                                                     
View Full Code Here

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

        List textRuns = getTextRuns(node, aci);

        // 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);
            }
        }

        return null;
View Full Code Here

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

        int[] result = new int[2];
        result[0] = start.getHit().getCharIndex();
        result[1] = finish.getHit().getCharIndex();

        // this next bit is to make sure that ligatures are selected properly
        TextSpanLayout startLayout =  start.getLayout();
        TextSpanLayout finishLayout = finish.getLayout();

        int startGlyphIndex = startLayout.getGlyphIndex(result[0]);
        int finishGlyphIndex = finishLayout.getGlyphIndex(result[1]);
        int startCharCount = startLayout.getCharacterCount(startGlyphIndex, startGlyphIndex);
        int finishCharCount = finishLayout.getCharacterCount(finishGlyphIndex, finishGlyphIndex);
        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 (finishCharCount > 1) {
            if (result[1] > result[0] && finishLayout.isLeftToRight()) {
                result[1] += finishCharCount-1;
            } else if (result[0] > result[1] && !finishLayout.isLeftToRight()) {
                result[1] -= finishCharCount-1;
            }
        }

        return result;
View Full Code Here

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

            int tmpIndex = beginIndex;
            beginIndex = endIndex; endIndex = tmpIndex;
        }

        TextSpanLayout beginLayout = null;
        TextSpanLayout endLayout = null;
        if ((begin != null) && (end != null)) {
            beginLayout = begin.getLayout();
            endLayout   = end.getLayout();
        }

        if ((beginLayout == null) || (endLayout == null)) {
            return null;
        }

        // get the list of text runs
        List textRuns = getTextRuns
            (textNode, textNode.getAttributedCharacterIterator());

        GeneralPath highlightedShape = new GeneralPath();

        // for each text run, append any highlight it may contain for
        // the current selection
        for (int i = 0; i < textRuns.size(); ++i) {
            TextRun textRun = (TextRun)textRuns.get(i);
            TextSpanLayout layout = textRun.getLayout();

            Shape layoutHighlightedShape = layout.getHighlightShape
                (beginIndex, endIndex);

            // append the highlighted shape of this layout to the
            // overall hightlighted shape
            if (( layoutHighlightedShape != null) &&
View Full Code Here

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

        // place coords in text node coordinate system
        for (int i = 0 ; i < list.size(); i++) {
            StrokingTextPainter.TextRun run =
                (StrokingTextPainter.TextRun)list.get(i);
            AttributedCharacterIterator aci = run.getACI();
            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.getBounds())) {
                return true;
            }
        }
        return false;
    }
View Full Code Here

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

        // we now lay all aci's out at 0,0 then move them
        // when we adjust the chunk offsets.
        Point2D.Float offset        = new Point2D.Float(0,0);
        Point2D.Float advance       = new Point2D.Float(0,0);
        boolean isChunkStart  = true;
        TextSpanLayout layout = null;
        do {
            int start = aci.getRunStart(extendedAtts);
            int end   = aci.getRunLimit(extendedAtts);

            AttributedCharacterIterator runaci;
            runaci = new AttributedCharacterSpanIterator(aci, start, end);

            int [] subCharMap = new int[end-start];
            for (int i=0; i<subCharMap.length; i++) {
                subCharMap[i] = charMap[i+start-begin];
            }

            layout = getTextLayoutFactory().createTextLayout
                (runaci, subCharMap, offset, fontRenderContext);
            textRuns.add(new TextRun(layout, runaci, isChunkStart));
            // System.out.println("TextRun: " + start +  "->" + end +
            //                    " Start: " + isChunkStart);

            Point2D layoutAdvance = layout.getAdvance2D();
            // System.out.println("layoutAdv: " + layoutAdvance);
            advance.x +=  (float)layoutAdvance.getX();
            advance.y +=  (float)layoutAdvance.getY();

            ++endChunk;
View Full Code Here

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

        float xScale = 1;
        float yScale = 1;

        r = (TextRun)textRuns.get(chunk.end-1);
        TextSpanLayout  layout          = r.getLayout();
        GVTGlyphMetrics lastMetrics =
            layout.getGlyphMetrics(layout.getGlyphCount()-1);
        Rectangle2D     lastBounds  = lastMetrics.getBounds2D();
       
        Point2D visualAdvance;
       
        if (!doAdjust) {
            visualAdvance = new Point2D.Float
            ((float)(chunk.advance.getX() + lastBounds.getWidth() -
                     lastMetrics.getHorizontalAdvance()),
             (float)(chunk.advance.getY() + lastBounds.getHeight() -
                     lastMetrics.getVerticalAdvance()));
        } else {
            Point2D advance    = chunk.advance;

            // We have to do this here since textLength needs to be
            // handled at the text chunk level. Otherwise tspans get
            // messed up.
            float delta = 0;
            if (layout.isVertical()) {
                if (lengthAdj == ADJUST_SPACING) {
                    yScale = (float)
                        ((length.floatValue()-lastBounds.getHeight())/
                         (advance.getY()-lastMetrics.getVerticalAdvance()));
                } else {
                    double adv = (advance.getY()-
                                  lastMetrics.getVerticalAdvance() +
                                  lastBounds.getHeight());
                    yScale = (float)(length.floatValue()/adv);
                }
                visualAdvance = new Point2D.Float(0, length.floatValue());
            } else {
                if (lengthAdj == ADJUST_SPACING) {
                    xScale = (float)
                        ((length.floatValue()-lastBounds.getWidth())/
                         (advance.getX()-lastMetrics.getHorizontalAdvance()));
                } else {
                    double adv = (advance.getX() + lastBounds.getWidth() -
                                  lastMetrics.getHorizontalAdvance());
                    xScale = (float)(length.floatValue()/adv);
                }
                visualAdvance = new Point2D.Float(length.floatValue(), 0);
            }

            // System.out.println("Adv: " + advance + " Len: " + length +
            //                    " scale: [" + xScale + ", " + yScale + "]");
            Point2D.Float adv = new Point2D.Float(0,0);
            for (int n=chunk.begin; n<chunk.end; ++n) {
                r = (TextRun) textRuns.get(n);
                layout = r.getLayout();
                layout.setScale(xScale, yScale, lengthAdj==ADJUST_SPACING);
                Point2D lAdv = layout.getAdvance2D();
                adv.x += (float)lAdv.getX();
                adv.y += (float)lAdv.getY();
            }
            chunk.advance = adv;
        }

        float dx = 0f;
        float dy = 0f;
        switch(anchorType){
        case TextNode.Anchor.ANCHOR_MIDDLE:
            dx = (float) (-visualAdvance.getX()/2d);
            dy = (float) (-visualAdvance.getY()/2d);
            break;
        case TextNode.Anchor.ANCHOR_END:
            dx = (float) (-visualAdvance.getX());
            dy = (float) (-visualAdvance.getY());
            break;
        default:
            break;
            // leave untouched
        }

        // System.out.println("DX/DY: [" + dx + ", " + dy + "]");
       
        r = (TextRun) textRuns.get(chunk.begin);
        layout = r.getLayout();
        AttributedCharacterIterator runaci = r.getACI();
        runaci.first();
        boolean vertical = layout.isVertical();
        Float runX = (Float) runaci.getAttribute(XPOS);
        Float runY = (Float) runaci.getAttribute(YPOS);
        TextPath textPath =  (TextPath) runaci.getAttribute(TEXTPATH);

        // The point that the next peice of normal text should be
        // layed out from, only used for normal text not text on a path.
        float absX = (float)location.getX();
        float absY = (float)location.getY();
        // TextPath Shift used to account for startOffset.
        float tpShiftX = 0;
        float tpShiftY = 0;

        // Of course X and Y override that...
        if ((runX != null) && (!runX.isNaN())) {
            absX = runX.floatValue();
            tpShiftX = absX;
        }

        if ((runY != null) && (!runY.isNaN())) {
            absY = runY.floatValue();
            tpShiftY = absY;
        }

        // Factor in text-anchor in writing direction.
        // Ignore tpShift in non-writing direction.
        if (vertical) {
            absY     += dy;
            tpShiftY += dy;
            tpShiftX  = 0;
        } else {
            absX     += dx;
            tpShiftX += dx;
            tpShiftY  = 0;
        }

        // System.out.println("ABS: [" + absX + "," + absY + "]");
        for (int n=chunk.begin; n<chunk.end; ++n) {
            r = (TextRun) textRuns.get(n);
            layout = r.getLayout();
            runaci = r.getACI();
            runaci.first();
            textPath =  (TextPath) runaci.getAttribute(TEXTPATH);

            if (textPath == null) {
                layout.setOffset(new Point2D.Float(absX, absY));

                Point2D ladv = layout.getAdvance2D();
                absX += ladv.getX();
                absY += ladv.getY();
            } else {
                layout.setOffset(new Point2D.Float(tpShiftX, tpShiftY));

                Point2D ladv = layout.getAdvance2D();
                tpShiftX += (float)ladv.getX();
                tpShiftY += (float)ladv.getY();

                ladv = layout.getTextPathAdvance();
                absX = (float)ladv.getX();
                absY = (float)ladv.getY();
            }
        }
        return new Point2D.Float(absX, absY);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.