Search in sources :

Example 1 with TextLineComponent

use of sun.font.TextLineComponent in project jdk8u_jdk by JetBrains.

the class TextMeasurer method calcLineBreak.

private int calcLineBreak(final int pos, final float maxAdvance) {
    // either of these statements removes the bug:
    //generateComponents(0, fChars.length);
    //generateComponents(pos, fChars.length);
    int startPos = pos;
    float width = maxAdvance;
    int tlcIndex;
    int tlcStart = fComponentStart;
    for (tlcIndex = 0; tlcIndex < fComponents.length; tlcIndex++) {
        int gaLimit = tlcStart + fComponents[tlcIndex].getNumCharacters();
        if (gaLimit > startPos) {
            break;
        } else {
            tlcStart = gaLimit;
        }
    }
    for (; tlcIndex < fComponents.length; tlcIndex++) {
        TextLineComponent tlc = fComponents[tlcIndex];
        int numCharsInGa = tlc.getNumCharacters();
        int lineBreak = tlc.getLineBreakIndex(startPos - tlcStart, width);
        if (lineBreak == numCharsInGa && tlcIndex < fComponents.length) {
            width -= tlc.getAdvanceBetween(startPos - tlcStart, lineBreak);
            tlcStart += numCharsInGa;
            startPos = tlcStart;
        } else {
            return tlcStart + lineBreak;
        }
    }
    if (fComponentLimit < fChars.length) {
        // format more text and try again
        //if (haveLayoutWindow) {
        //    outOfWindow++;
        //}
        generateComponents(pos, fChars.length);
        return calcLineBreak(pos, maxAdvance);
    }
    return fChars.length;
}
Also used : TextLineComponent(sun.font.TextLineComponent)

Example 2 with TextLineComponent

use of sun.font.TextLineComponent in project jdk8u_jdk by JetBrains.

the class TextLine method fastCreateTextLine.

/**
     * Create a TextLine from the text.  The Font must be able to
     * display all of the text.
     * attributes==null is equivalent to using an empty Map for
     * attributes
     */
public static TextLine fastCreateTextLine(FontRenderContext frc, char[] chars, Font font, CoreMetrics lm, Map<? extends Attribute, ?> attributes) {
    boolean isDirectionLTR = true;
    byte[] levels = null;
    int[] charsLtoV = null;
    Bidi bidi = null;
    int characterCount = chars.length;
    boolean requiresBidi = false;
    byte[] embs = null;
    AttributeValues values = null;
    if (attributes != null) {
        values = AttributeValues.fromMap(attributes);
        if (values.getRunDirection() >= 0) {
            isDirectionLTR = values.getRunDirection() == 0;
            requiresBidi = !isDirectionLTR;
        }
        if (values.getBidiEmbedding() != 0) {
            requiresBidi = true;
            byte level = (byte) values.getBidiEmbedding();
            embs = new byte[characterCount];
            for (int i = 0; i < embs.length; ++i) {
                embs[i] = level;
            }
        }
    }
    if (!requiresBidi) {
        requiresBidi = Bidi.requiresBidi(chars, 0, chars.length);
    }
    if (requiresBidi) {
        int bidiflags = values == null ? Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT : values.getRunDirection();
        bidi = new Bidi(chars, 0, embs, 0, chars.length, bidiflags);
        if (!bidi.isLeftToRight()) {
            levels = BidiUtils.getLevels(bidi);
            int[] charsVtoL = BidiUtils.createVisualToLogicalMap(levels);
            charsLtoV = BidiUtils.createInverseMap(charsVtoL);
            isDirectionLTR = bidi.baseIsLeftToRight();
        }
    }
    Decoration decorator = Decoration.getDecoration(values);
    // no extra info yet, bidi determines run and line direction
    int layoutFlags = 0;
    TextLabelFactory factory = new TextLabelFactory(frc, chars, bidi, layoutFlags);
    TextLineComponent[] components = new TextLineComponent[1];
    components = createComponentsOnRun(0, chars.length, chars, charsLtoV, levels, factory, font, lm, frc, decorator, components, 0);
    int numComponents = components.length;
    while (components[numComponents - 1] == null) {
        numComponents -= 1;
    }
    if (numComponents != components.length) {
        TextLineComponent[] temp = new TextLineComponent[numComponents];
        System.arraycopy(components, 0, temp, 0, numComponents);
        components = temp;
    }
    return new TextLine(frc, components, lm.baselineOffsets, chars, 0, chars.length, charsLtoV, levels, isDirectionLTR);
}
Also used : Bidi(java.text.Bidi) TextLabelFactory(sun.font.TextLabelFactory) AttributeValues(sun.font.AttributeValues) TextLineComponent(sun.font.TextLineComponent) Decoration(sun.font.Decoration)

Example 3 with TextLineComponent

use of sun.font.TextLineComponent in project jdk8u_jdk by JetBrains.

the class TextLine method getComponents.

/**
     * Returns an array (in logical order) of the TextLineComponents representing
     * the text.  The components are both logically and visually contiguous.
     */
public static TextLineComponent[] getComponents(StyledParagraph styledParagraph, char[] chars, int textStart, int textLimit, int[] charsLtoV, byte[] levels, TextLabelFactory factory) {
    FontRenderContext frc = factory.getFontRenderContext();
    int numComponents = 0;
    TextLineComponent[] tempComponents = new TextLineComponent[1];
    int pos = textStart;
    do {
        int runLimit = Math.min(styledParagraph.getRunLimit(pos), textLimit);
        Decoration decorator = styledParagraph.getDecorationAt(pos);
        Object graphicOrFont = styledParagraph.getFontOrGraphicAt(pos);
        if (graphicOrFont instanceof GraphicAttribute) {
            // AffineTransform baseRot = styledParagraph.getBaselineRotationAt(pos);
            // !!! For now, let's assign runs of text with both fonts and graphic attributes
            // a null rotation (e.g. the baseline rotation goes away when a graphic
            // is applied.
            AffineTransform baseRot = null;
            GraphicAttribute graphicAttribute = (GraphicAttribute) graphicOrFont;
            do {
                int chunkLimit = firstVisualChunk(charsLtoV, levels, pos, runLimit);
                GraphicComponent nextGraphic = new GraphicComponent(graphicAttribute, decorator, charsLtoV, levels, pos, chunkLimit, baseRot);
                pos = chunkLimit;
                ++numComponents;
                if (numComponents >= tempComponents.length) {
                    tempComponents = expandArray(tempComponents);
                }
                tempComponents[numComponents - 1] = nextGraphic;
            } while (pos < runLimit);
        } else {
            Font font = (Font) graphicOrFont;
            tempComponents = createComponentsOnRun(pos, runLimit, chars, charsLtoV, levels, factory, font, null, frc, decorator, tempComponents, numComponents);
            pos = runLimit;
            numComponents = tempComponents.length;
            while (tempComponents[numComponents - 1] == null) {
                numComponents -= 1;
            }
        }
    } while (pos < textLimit);
    TextLineComponent[] components;
    if (tempComponents.length == numComponents) {
        components = tempComponents;
    } else {
        components = new TextLineComponent[numComponents];
        System.arraycopy(tempComponents, 0, components, 0, numComponents);
    }
    return components;
}
Also used : GraphicComponent(sun.font.GraphicComponent) TextLineComponent(sun.font.TextLineComponent) AffineTransform(java.awt.geom.AffineTransform) Font(java.awt.Font) Decoration(sun.font.Decoration)

Example 4 with TextLineComponent

use of sun.font.TextLineComponent in project jdk8u_jdk by JetBrains.

the class TextLine method draw.

public void draw(Graphics2D g2, float x, float y) {
    if (lp == null) {
        for (int i = 0, n = 0; i < fComponents.length; i++, n += 2) {
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
            tlc.draw(g2, locs[n] + x, locs[n + 1] + y);
        }
    } else {
        AffineTransform oldTx = g2.getTransform();
        Point2D.Float pt = new Point2D.Float();
        for (int i = 0, n = 0; i < fComponents.length; i++, n += 2) {
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];
            lp.pathToPoint(locs[n], locs[n + 1], false, pt);
            pt.x += x;
            pt.y += y;
            AffineTransform at = tlc.getBaselineTransform();
            if (at != null) {
                g2.translate(pt.x - at.getTranslateX(), pt.y - at.getTranslateY());
                g2.transform(at);
                tlc.draw(g2, 0, 0);
                g2.setTransform(oldTx);
            } else {
                tlc.draw(g2, pt.x, pt.y);
            }
        }
    }
}
Also used : Point2D(java.awt.geom.Point2D) TextLineComponent(sun.font.TextLineComponent) AffineTransform(java.awt.geom.AffineTransform)

Example 5 with TextLineComponent

use of sun.font.TextLineComponent in project jdk8u_jdk by JetBrains.

the class TextLine method getCharBounds.

public Rectangle2D getCharBounds(int logicalIndex) {
    if (logicalIndex < 0) {
        throw new IllegalArgumentException("Negative logicalIndex.");
    }
    int tlcStart = 0;
    for (int i = 0; i < fComponents.length; i++) {
        int tlcLimit = tlcStart + fComponents[i].getNumCharacters();
        if (tlcLimit > logicalIndex) {
            TextLineComponent tlc = fComponents[i];
            int indexInTlc = logicalIndex - tlcStart;
            Rectangle2D chBounds = tlc.getCharVisualBounds(indexInTlc);
            int vi = getComponentVisualIndex(i);
            chBounds.setRect(chBounds.getX() + locs[vi * 2], chBounds.getY() + locs[vi * 2 + 1], chBounds.getWidth(), chBounds.getHeight());
            return chBounds;
        } else {
            tlcStart = tlcLimit;
        }
    }
    throw new IllegalArgumentException("logicalIndex too large.");
}
Also used : TextLineComponent(sun.font.TextLineComponent) Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

TextLineComponent (sun.font.TextLineComponent)15 AffineTransform (java.awt.geom.AffineTransform)4 Rectangle2D (java.awt.geom.Rectangle2D)4 Point2D (java.awt.geom.Point2D)3 Bidi (java.text.Bidi)3 Decoration (sun.font.Decoration)2 Font (java.awt.Font)1 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 GeneralPath (java.awt.geom.GeneralPath)1 BufferedImage (java.awt.image.BufferedImage)1 AttributeValues (sun.font.AttributeValues)1 CoreMetrics (sun.font.CoreMetrics)1 FontLineMetrics (sun.font.FontLineMetrics)1 GraphicComponent (sun.font.GraphicComponent)1 EmptyPath (sun.font.LayoutPathImpl.EmptyPath)1 SegmentPathBuilder (sun.font.LayoutPathImpl.SegmentPathBuilder)1 TextLabelFactory (sun.font.TextLabelFactory)1