Search in sources :

Example 6 with TextLayout

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

the class TextPanelTest method buildingLines.

@Test
public void buildingLines() throws Exception {
    panel.setText("some text", parent);
    panel.buildLines();
    List<TextLayout> lines = panel.getLines();
    assertEquals(1, lines.size());
    TextLayout layout = lines.get(0);
    assertEquals(9, layout.getCharacterCount());
    assertSubString("family=" + defaultFontFace, layout.toString());
    assertSubString("name=" + defaultFontFace, layout.toString());
    assertSubString("size=" + defaultFontSize, layout.toString());
}
Also used : TextLayout(java.awt.font.TextLayout) Test(org.junit.Test)

Example 7 with TextLayout

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

the class TextPanelTest method styledAcrossLineBreak.

@Test
public void styledAcrossLineBreak() {
    createStyles();
    parent.setSize(200, 100);
    panel.setText("This <my_other_style>some\n more</my_other_style> text", parent);
    panel.buildLines();
    List<TextLayout> lines = panel.getLines();
    assertEquals(2, lines.size());
    TextLayout first = lines.get(0);
    TextLayout second = lines.get(1);
    assertSubString("name=Cuneiform", first.toString());
    assertSubString("name=" + defaultFontFace, first.toString());
    assertSubString("name=Cuneiform", second.toString());
    assertSubString("name=" + defaultFontFace, second.toString());
}
Also used : TextLayout(java.awt.font.TextLayout) Test(org.junit.Test)

Example 8 with TextLayout

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

the class TextPanelTest method stylingAppliedToLine.

@Test
public void stylingAppliedToLine() throws Exception {
    createStyles();
    parent.setSize(200, 100);
    panel.setText("<my_style>some text</my_style>", parent);
    panel.buildLines();
    List<TextLayout> lines = panel.getLines();
    TextLayout layout = lines.get(0);
    assertEquals(1, lines.size());
    assertEquals(9, layout.getCharacterCount());
    assertSubString("name=Helvetica", layout.toString());
    assertSubString("style=bold", layout.toString());
    assertSubString("size=20", layout.toString());
}
Also used : TextLayout(java.awt.font.TextLayout) Test(org.junit.Test)

Example 9 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 10 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)

Aggregations

TextLayout (java.awt.font.TextLayout)104 AttributedString (java.text.AttributedString)32 Graphics2D (java.awt.Graphics2D)24 FontRenderContext (java.awt.font.FontRenderContext)21 Font (java.awt.Font)18 AttributedCharacterIterator (java.text.AttributedCharacterIterator)17 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)16 Point (java.awt.Point)11 Rectangle (java.awt.Rectangle)9 Paint (java.awt.Paint)8 AffineTransform (java.awt.geom.AffineTransform)8 Rectangle2D (java.awt.geom.Rectangle2D)8 Color (java.awt.Color)7 Shape (java.awt.Shape)6 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