Search in sources :

Example 31 with TextLayout

use of java.awt.font.TextLayout in project limelight by slagyr.

the class TextPanel method buildLines.

public synchronized void buildLines() {
    consumableArea = panel.getChildConsumableBounds();
    lines = new LinkedList<TextLayout>();
    if (text != null && text.length() > 0) {
        StyledTextParser parser = new StyledTextParser();
        textChunks = parser.parse(text);
        final Scene root = getRoot();
        if (// TODO MDM - It happens.... but how?  Ah!  Need to acquire tree lock when removing panels.
        root != null) {
            Map<String, RichStyle> styleMap = root.getStyles();
            for (StyledText styledText : textChunks) styledText.setupStyles(styleMap, getStyle(), this);
            // TODO MDM StyleObservers may cause a memory leak.  Styles keep track of panels that are no longer used?
            addLines();
        }
    }
}
Also used : StyledText(limelight.ui.text.StyledText) RichStyle(limelight.styles.RichStyle) StyledTextParser(limelight.ui.text.StyledTextParser) AttributedString(java.text.AttributedString) TextLayout(java.awt.font.TextLayout)

Example 32 with TextLayout

use of java.awt.font.TextLayout in project limelight by slagyr.

the class TextPanel method addLines.

private synchronized void addLines() {
    AttributedString aText = prepareAttributedString();
    AttributedCharacterIterator styledTextIterator = aText.getIterator();
    List<Integer> newlineLocations = getNewlineLocations(styledTextIterator);
    LineBreakMeasurer lbm = new LineBreakMeasurer(styledTextIterator, getRenderContext());
    float width = (float) consumableArea.width;
    if (width <= 0)
        return;
    TextLayout layout;
    int startOfNextLayout;
    int currentLine = 0;
    int endIndex = styledTextIterator.getEndIndex();
    do {
        if (currentLine < newlineLocations.size())
            startOfNextLayout = newlineLocations.get(currentLine) + 1;
        else
            startOfNextLayout = endIndex + 1;
        layout = lbm.nextLayout(width, startOfNextLayout, false);
        lines.add(layout);
        if (lbm.getPosition() == startOfNextLayout)
            currentLine += 1;
    } while (layout != null && lbm.getPosition() < endIndex);
}
Also used : AttributedString(java.text.AttributedString) LineBreakMeasurer(java.awt.font.LineBreakMeasurer) AttributedCharacterIterator(java.text.AttributedCharacterIterator) TextLayout(java.awt.font.TextLayout)

Example 33 with TextLayout

use of java.awt.font.TextLayout in project limelight by slagyr.

the class TextPanel method calculateDimensions.

private void calculateDimensions() {
    consumedHeight = 0;
    consumedWidth = 0;
    synchronized (this) {
        for (TextLayout layout : lines) {
            consumedHeight += (layout.getAscent() + layout.getDescent() + layout.getLeading());
            double lineWidth = widthOf(layout);
            if (lineWidth > consumedWidth)
                consumedWidth = lineWidth;
        }
    }
}
Also used : TextLayout(java.awt.font.TextLayout)

Example 34 with TextLayout

use of java.awt.font.TextLayout in project hid-serial by rayshobby.

the class GLinearTrackControl method drawLimits.

protected void drawLimits() {
    Graphics2D g2d = buffer.g2;
    float px, py;
    TextLayout line;
    if (limitsInvalid) {
        ssStartLimit = new StyledString(getNumericDisplayString(startLimit));
        ssEndLimit = new StyledString(getNumericDisplayString(endLimit));
        limitsInvalid = false;
    }
    switch(textOrientation) {
        case ORIENT_LEFT:
            line = ssStartLimit.getLines(g2d).getFirst().layout;
            px = -trackLength / 2 + line.getDescent();
            py = trackOffset + line.getVisibleAdvance();
            buffer.pushMatrix();
            buffer.translate(px, py);
            buffer.rotate(-PI / 2);
            line.draw(g2d, 0, 0);
            buffer.popMatrix();
            line = ssEndLimit.getLines(g2d).getFirst().layout;
            px = trackLength / 2 + line.getDescent();
            py = trackOffset + line.getVisibleAdvance();
            buffer.pushMatrix();
            buffer.translate(px, py);
            buffer.rotate(-PI / 2);
            line.draw(g2d, 0, 0);
            buffer.popMatrix();
            break;
        case ORIENT_RIGHT:
            line = ssStartLimit.getLines(g2d).getFirst().layout;
            px = -trackLength / 2 - line.getDescent();
            py = trackOffset;
            buffer.pushMatrix();
            buffer.translate(px, py);
            buffer.rotate(PI / 2);
            line.draw(g2d, 0, 0);
            buffer.popMatrix();
            line = ssEndLimit.getLines(g2d).getFirst().layout;
            px = trackLength / 2 - line.getDescent();
            py = trackOffset;
            buffer.pushMatrix();
            buffer.translate(px, py);
            buffer.rotate(PI / 2);
            line.draw(g2d, 0, 0);
            buffer.popMatrix();
            break;
        case ORIENT_TRACK:
            line = ssStartLimit.getLines(g2d).getFirst().layout;
            px = -(trackLength + trackWidth) / 2;
            py = trackOffset + line.getAscent();
            line.draw(g2d, px, py);
            line = ssEndLimit.getLines(g2d).getFirst().layout;
            px = (trackLength + trackWidth) / 2 - line.getVisibleAdvance();
            py = trackOffset + line.getAscent();
            line.draw(g2d, px, py);
            break;
    }
}
Also used : Graphics2D(java.awt.Graphics2D) TextLayout(java.awt.font.TextLayout)

Example 35 with TextLayout

use of java.awt.font.TextLayout in project hid-serial by rayshobby.

the class GPanel method updateBuffer.

protected void updateBuffer() {
    if (bufferInvalid) {
        Graphics2D g2d = buffer.g2;
        buffer.beginDraw();
        buffer.background(buffer.color(255, 0));
        buffer.noStroke();
        buffer.fill(palette[4]);
        if (tabOnly) {
            buffer.rect(0, 0, tabWidth, tabHeight);
        } else {
            buffer.rect(0, 0, width, tabHeight);
        }
        stext.getLines(g2d);
        g2d.setColor(jpalette[12]);
        TextLayout tl = stext.getTLIforLineNo(0).layout;
        tl.draw(g2d, 4, 2 + tl.getAscent());
        if (!tabOnly) {
            buffer.noStroke();
            buffer.fill(palette[5]);
            buffer.rect(0, tabHeight, width, height - tabHeight);
        }
        buffer.endDraw();
    }
}
Also used : Graphics2D(java.awt.Graphics2D) TextLayout(java.awt.font.TextLayout)

Aggregations

TextLayout (java.awt.font.TextLayout)108 AttributedString (java.text.AttributedString)32 Graphics2D (java.awt.Graphics2D)25 FontRenderContext (java.awt.font.FontRenderContext)25 Font (java.awt.Font)20 AttributedCharacterIterator (java.text.AttributedCharacterIterator)17 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)16 Point (java.awt.Point)11 Rectangle (java.awt.Rectangle)10 Rectangle2D (java.awt.geom.Rectangle2D)10 Color (java.awt.Color)9 Paint (java.awt.Paint)8 AffineTransform (java.awt.geom.AffineTransform)8 Shape (java.awt.Shape)7 TextLayoutInfo (g4p_controls.StyledString.TextLayoutInfo)5 Dimension (java.awt.Dimension)5 TextHitInfo (java.awt.font.TextHitInfo)4 ArrayList (java.util.ArrayList)4 Graphics (java.awt.Graphics)3 Insets (java.awt.Insets)3