-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathInlineCodeColumnWrapExample.java
More file actions
121 lines (106 loc) · 5.86 KB
/
Copy pathInlineCodeColumnWrapExample.java
File metadata and controls
121 lines (106 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.demcha.examples.features.tables;
import com.demcha.compose.GraphCompose;
import com.demcha.compose.document.api.DocumentPageSize;
import com.demcha.compose.document.api.DocumentSession;
import com.demcha.compose.document.node.TableNode;
import com.demcha.compose.document.style.DocumentColor;
import com.demcha.compose.document.style.DocumentInsets;
import com.demcha.compose.document.style.DocumentStroke;
import com.demcha.compose.document.style.DocumentTextDecoration;
import com.demcha.compose.document.style.DocumentTextStyle;
import com.demcha.compose.document.table.DocumentTableCell;
import com.demcha.compose.document.table.DocumentTableColumn;
import com.demcha.compose.document.table.DocumentTableStyle;
import com.demcha.compose.font.FontName;
import com.demcha.examples.support.ExampleOutputPaths;
import java.nio.file.Path;
import java.util.List;
/**
* Runnable showcase for long inline-code coordinates inside table columns.
*
* <p>A composed cell holding a single long {@code inlineCode(...)} token — a
* Maven coordinate, fully-qualified class name or URL — no longer overflows its
* column. In a narrow <b>fixed</b> column the chip breaks <em>inside</em> the
* cell, preferring its {@code . : / -} seams and char-splitting only as a last
* resort, with the rounded fill intact on every fragment. In an <b>auto</b>
* column the column grows to fit the coordinate on one line instead of
* collapsing.</p>
*
* @author Artem Demchyshyn
*/
public final class InlineCodeColumnWrapExample {
private static final DocumentColor INK = DocumentColor.rgb(34, 38, 50);
private static final DocumentColor MUTED = DocumentColor.rgb(102, 106, 118);
private static final DocumentColor RULE = DocumentColor.rgb(180, 188, 200);
private static final DocumentColor HEADER_FILL = DocumentColor.rgb(20, 60, 75);
private static final DocumentColor ROW_TINT = DocumentColor.rgb(244, 247, 252);
private static final List<String> COORDINATES = List.of(
"org.junit.jupiter:junit-jupiter:5.10.2",
"io.github.demchaav:graph-compose:1.9.0",
"https://repo1.maven.org/maven2/");
private InlineCodeColumnWrapExample() {
}
public static Path generate() throws Exception {
Path outputFile = ExampleOutputPaths.prepare("features/tables", "inline-code-column-wrap.pdf");
DocumentTextStyle title = DocumentTextStyle.builder()
.fontName(FontName.HELVETICA_BOLD).size(20).color(INK)
.decoration(DocumentTextDecoration.BOLD).build();
DocumentTextStyle caption = DocumentTextStyle.builder()
.fontName(FontName.HELVETICA_OBLIQUE).size(10).color(MUTED).build();
DocumentTextStyle body = DocumentTextStyle.builder()
.fontName(FontName.HELVETICA).size(10.5).color(INK).build();
DocumentTextStyle headerText = DocumentTextStyle.builder()
.fontName(FontName.HELVETICA_BOLD).size(11).color(DocumentColor.WHITE)
.decoration(DocumentTextDecoration.BOLD).build();
DocumentTableStyle headerStyle = DocumentTableStyle.builder()
.fillColor(HEADER_FILL).stroke(DocumentStroke.of(RULE, 0.6))
.padding(DocumentInsets.of(8)).textStyle(headerText).build();
DocumentTableStyle bodyCellStyle = DocumentTableStyle.builder()
.stroke(DocumentStroke.of(RULE, 0.6)).padding(DocumentInsets.of(8)).textStyle(body).build();
DocumentTableStyle tintedCellStyle = DocumentTableStyle.builder()
.fillColor(ROW_TINT).stroke(DocumentStroke.of(RULE, 0.6))
.padding(DocumentInsets.of(8)).textStyle(body).build();
try (DocumentSession document = GraphCompose.document(outputFile)
.pageSize(DocumentPageSize.A4)
.margin(36, 36, 36, 36)
.create()) {
document.pageFlow()
.name("CodeWrapShowcase")
.spacing(8)
.addParagraph("Long inline-code coordinates stay inside the column", title)
.addParagraph(
"A composed cell with one long inlineCode(...) token used to spill over the "
+ "next column. It now breaks at its . : / - seams inside a narrow FIXED "
+ "column (char-splitting only when a segment is still too wide), and an "
+ "AUTO column grows to fit it on one line.", caption)
.build();
List<List<DocumentTableCell>> rows = new java.util.ArrayList<>();
rows.add(List.of(
DocumentTableCell.text("Fixed 104pt").withStyle(headerStyle),
DocumentTableCell.text("Auto").withStyle(headerStyle)));
for (int i = 0; i < COORDINATES.size(); i++) {
String coordinate = COORDINATES.get(i);
DocumentTableStyle cellStyle = i % 2 == 0 ? bodyCellStyle : tintedCellStyle;
rows.add(List.of(
DocumentTableCell.node(document.dsl().paragraph().inlineCode(coordinate).build())
.withStyle(cellStyle),
DocumentTableCell.node(document.dsl().paragraph().inlineCode(coordinate).build())
.withStyle(cellStyle)));
}
document.add(new TableNode(
"CodeWrapTable",
List.of(DocumentTableColumn.fixed(104),
DocumentTableColumn.auto()),
rows,
bodyCellStyle,
null,
DocumentInsets.zero(),
DocumentInsets.zero()));
document.buildPdf();
}
return outputFile;
}
public static void main(String[] args) throws Exception {
System.out.println("Generated: " + generate());
}
}