@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()); }
@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()); }
@Test public void styledInheritsFromDefault() { createStyles(); parent.setSize(200, 100); panel.setText("<size_only_style>This some text</size_only_style>", parent); panel.buildLines(); List<TextLayout> lines = panel.getLines(); assertEquals(1, lines.size()); String onlyLine = lines.get(0).toString(); assertSubString("name=" + defaultFontFace, onlyLine); assertSubString("size=" + "25", onlyLine); assertSubString("style=" + defaultFontStyle, onlyLine); StyledText first = panel.getTextChunks().get(0); assertEquals(defaultTextColor, first.getColor()); }
@Test public void styledTextOnSameLine() { createStyles(); parent.setSize(200, 100); panel.setText("This <my_other_style>some </my_other_style> text", parent); panel.buildLines(); List<TextLayout> lines = panel.getLines(); assertEquals(1, lines.size()); String onlyLine = lines.get(0).toString(); assertSubString("name=Cuneiform", onlyLine); assertSubString("size=19", onlyLine); assertSubString("style=italic", onlyLine); assertSubString("name=" + defaultFontFace, onlyLine); assertSubString("size=" + defaultFontSize, onlyLine); assertSubString("style=" + defaultFontStyle, onlyLine); }
@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("family=Helvetica", layout.toString()); assertSubString("name=Helvetica", layout.toString()); assertSubString("style=bold", layout.toString()); assertSubString("size=20", layout.toString()); }