RemoteLib: re-allow progress with null meta
[fanfix.git] / output / InfoText.java
1 package be.nikiroo.fanfix.output;
2
3 import java.io.IOException;
4
5 import be.nikiroo.fanfix.Instance;
6 import be.nikiroo.fanfix.bundles.StringId;
7 import be.nikiroo.fanfix.data.Chapter;
8 import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
9
10 class InfoText extends Text {
11 // quote chars
12 private char openQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_SINGLE_QUOTE);
13 private char closeQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_SINGLE_QUOTE);
14 private char openDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_DOUBLE_QUOTE);
15 private char closeDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_DOUBLE_QUOTE);
16
17 @Override
18 public String getDefaultExtension(boolean readerTarget) {
19 return "";
20 }
21
22 @Override
23 protected void writeChapterHeader(Chapter chap) throws IOException {
24 writer.write("\n");
25
26 if (chap.getName() != null && !chap.getName().isEmpty()) {
27 writer.write(Instance.getInstance().getTrans().getString(StringId.CHAPTER_NAMED, chap.getNumber(),
28 chap.getName()));
29 } else {
30 writer.write(Instance.getInstance().getTrans().getString(StringId.CHAPTER_UNNAMED, chap.getNumber()));
31 }
32
33 writer.write("\n\n");
34 }
35
36 @Override
37 protected void writeTextLine(ParagraphType type, String line)
38 throws IOException {
39 switch (type) {
40 case NORMAL:
41 case QUOTE:
42 StringBuilder builder = new StringBuilder();
43 for (char car : line.toCharArray()) {
44 if (car == '—') {
45 builder.append("---");
46 } else if (car == '–') {
47 builder.append("--");
48 } else if (car == openDoubleQuote) {
49 builder.append("\"");
50 } else if (car == closeDoubleQuote) {
51 builder.append("\"");
52 } else if (car == openQuote) {
53 builder.append("'");
54 } else if (car == closeQuote) {
55 builder.append("'");
56 } else {
57 builder.append(car);
58 }
59 }
60
61 line = builder.toString();
62 break;
63 default:
64 break;
65 }
66
67 super.writeTextLine(type, line);
68 }
69 }