String test = "Hello -this is a string of text";
这样的东西:...每当在ITEXT 7 Text
或Paragraph
中使用该文本字符串时,它将使"this"
Italic 或某些设置Style
。
几乎使用特殊字符使Text
使用itext7:
Style
中出现我需要这样的东西,因为该程序的用户将需要用某些单词斜体。
用户将TextArea
输入以定义String
。我保存了字符串,然后只制作一个Text
或Paragraph
来容纳该字符串:
Cell location = new Cell()
.add(new Paragraph(test);
i虽然使用TextFlow
,但由于使用Javafx CSS,这将无法使用ITEXT7。
我想到了这个,它有效,但不是很漂亮...
private Paragraph formatText(String string) {
Paragraph paragraph = new Paragraph();
Stream.of(string)
.map(w -> w.split(" "))
.flatMap(Arrays::stream)
.forEach(w -> {
Text word;
if (w.startsWith("~")) {
String replace = w.replace("~", "");
word = new Text(replace);
word.setItalic();
} else if (w.startsWith("*")) {
String replace = w.replace("*", "");
word = new Text(replace);
word.setItalic();
} else {
word = new Text(w);
}
paragraph.add(word);
});
return paragraph;
}