Пример #1
0
  @Test
  public void textChunksOverwrittenOnCompile() throws Exception {
    panel.setText("Here is some original text.", parent);
    panel.buildLines();

    int originalChunks = panel.getTextChunks().size();

    panel.buildLines();

    assertEquals(originalChunks, panel.getTextChunks().size());
  }
Пример #2
0
  @Test
  public void observerAddedForLineStyling() throws Exception {
    panel.setText("some text", parent);
    panel.buildLines();

    Style style = panel.getTextChunks().get(0).getStyle();
    assertEquals(true, style.hasObserver(panel));
  }
Пример #3
0
  @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());
  }
Пример #4
0
  @Test
  public void textColor() throws Exception {
    createStyles();
    panel.setText("text <my_other_style>here</my_other_style> man", parent);
    panel.buildLines();

    StyledText first = panel.getTextChunks().get(0);
    assertEquals(defaultTextColor, first.getColor());

    StyledText second = panel.getTextChunks().get(1);
    assertEquals(new Color(0x0000FF), second.getColor());

    StyledText third = panel.getTextChunks().get(2);
    assertEquals(defaultTextColor, third.getColor());
  }
Пример #5
0
  @Test
  public void unrecognizedInterlacedStyle() {
    createStyles();
    parent.setSize(200, 100);
    panel.setText(
        "This is <my_other_style>some </my_other_style><bogus_style>fantastic</bogus_style><my_style>text</my_style>",
        parent);
    panel.buildLines();

    List<StyledText> chunks = panel.getTextChunks();
    assertEquals(4, chunks.size());

    StyledText interlacedLayout = chunks.get(2);
    assertNoSubString("name=Cuneiform", interlacedLayout.toString());
    assertNoSubString("size=19", interlacedLayout.toString());
  }
Пример #6
0
  @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());
  }
Пример #7
0
  @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());
  }
Пример #8
0
  @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);
  }
Пример #9
0
  @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());
  }
Пример #10
0
  @Test
  public void multipleStylesAppliedToLine() throws Exception {
    createStyles();

    parent.setSize(200, 100);
    panel.setText("<my_style>some </my_style><my_other_style>text</my_other_style>", parent);
    panel.buildLines();

    List<StyledText> chunks = panel.getTextChunks();

    StyledText layout = chunks.get(0);
    assertEquals(5, layout.getText().length());
    assertSubString("family=Helvetica", layout.toString());
    assertSubString("name=Helvetica", layout.toString());
    assertSubString("style=bold", layout.toString());
    assertSubString("size=20", layout.toString());

    StyledText layout2 = chunks.get(1);
    assertEquals(5, layout.getText().length());
    assertSubString("family=Dialog", layout2.toString());
    assertSubString("name=Cuneiform", layout2.toString());
    assertSubString("style=italic", layout2.toString());
    assertSubString("size=19", layout2.toString());
  }