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());
}
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());
}
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());
}
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();
}
}
}
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);
}
Aggregations