-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathInlineHighlightExample.java
More file actions
154 lines (140 loc) · 7.95 KB
/
Copy pathInlineHighlightExample.java
File metadata and controls
154 lines (140 loc) · 7.95 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.demcha.examples.features.text;
import com.demcha.compose.GraphCompose;
import com.demcha.compose.document.api.DocumentPageSize;
import com.demcha.compose.document.api.DocumentSession;
import com.demcha.compose.document.dsl.RichText;
import com.demcha.compose.document.dsl.SectionBuilder;
import com.demcha.compose.document.style.DocumentColor;
import com.demcha.compose.document.style.DocumentInsets;
import com.demcha.compose.document.style.DocumentTextStyle;
import com.demcha.examples.support.theme.BusinessTheme;
import com.demcha.compose.font.FontName;
import com.demcha.examples.support.ExampleOutputPaths;
import java.nio.file.Path;
import java.util.function.Consumer;
/**
* Runnable showcase for inline highlight "chips" ({@code @since 1.9.0}).
*
* <p>Styled text drawn on a rounded, padded background fill, on the text
* baseline, flowing inside a paragraph — the GitHub inline {@code code} look and
* inline status badges. {@code RichText.code(text)} ships engine defaults
* (monospace + a light chip); {@code chip(text, fg, bg)} colours a badge; and
* {@code highlight(text, style, bg, radius, padding)} is the full primitive.
* On {@code ParagraphBuilder} the calls are {@code inlineCode} / {@code inlineChip}
* / {@code inlineHighlight}.</p>
*/
public final class InlineHighlightExample {
private static final BusinessTheme THEME = BusinessTheme.modern();
private static final DocumentColor MUTED = DocumentColor.rgb(112, 116, 128);
private static final DocumentColor BRAND = DocumentColor.rgb(20, 80, 95);
private static final DocumentColor PANEL = DocumentColor.rgb(248, 244, 234);
// Status-badge palette: ink + a soft tinted fill.
private static final DocumentColor PAID_FG = DocumentColor.rgb(22, 101, 52);
private static final DocumentColor PAID_BG = DocumentColor.rgb(220, 252, 231);
private static final DocumentColor DUE_FG = DocumentColor.rgb(153, 27, 27);
private static final DocumentColor DUE_BG = DocumentColor.rgb(254, 226, 226);
private static final DocumentColor HOLD_FG = DocumentColor.rgb(146, 64, 14);
private static final DocumentColor HOLD_BG = DocumentColor.rgb(254, 243, 199);
private InlineHighlightExample() {
}
public static Path generate() throws Exception {
Path outputFile = ExampleOutputPaths.prepare("features/text", "inline-highlight-chips.pdf");
try (DocumentSession document = GraphCompose.document(outputFile)
.pageSize(DocumentPageSize.A4)
.pageBackground(THEME.pageBackground())
.margin(34, 34, 34, 34)
.create()) {
document.pageFlow()
.name("InlineHighlightShowcase")
.spacing(14)
.addSection("Hero", section -> section
.softPanel(THEME.palette().surfaceMuted(), 10, 16)
.accentLeft(DocumentColor.rgb(97, 40, 217), 4)
.spacing(6)
.addParagraph(p -> p
.text("Inline highlight chips")
.textStyle(THEME.text().h1())
.margin(DocumentInsets.zero()))
.addRich(rich -> rich
.plain("Text on a rounded background, on the baseline ")
.accent("— inline code and status badges", BRAND)
.plain(". Add the ")
.code("graph-compose")
.plain(" dependency from ")
.code("io.github.demchaav")
.plain(".")))
.addSection("Code", section -> labelledRow(section,
"code(text) — monospace on a light chip, engine defaults",
rich -> rich
.plain("Run ").code("./mvnw verify").plain(" then tag ")
.code("v1.9.0").plain(" to publish ").code("graph-compose-emoji")))
.addSection("Badges", section -> labelledRow(section,
"chip(text, fg, bg) — a coloured status badge between words",
rich -> rich
.chip(" Paid ", PAID_FG, PAID_BG).plain(" ")
.chip(" Overdue ", DUE_FG, DUE_BG).plain(" ")
.chip(" On hold ", HOLD_FG, HOLD_BG)))
.addSection("Custom", section -> labelledRow(section,
"highlight(text, style, bg, radius, padding) — the full primitive",
rich -> rich
.plain("Pill ")
.highlight("rounded", chipText(), DocumentColor.rgb(224, 231, 255),
8.0, DocumentInsets.symmetric(2, 8))
.plain(" square ")
.highlight("sharp", chipText(), DocumentColor.rgb(255, 228, 230),
0.0, DocumentInsets.symmetric(2, 6))))
.addSection("Wrapping", section -> labelledRow(section,
"a multi-word highlight wraps across lines — one continuous fill per fragment",
rich -> rich
.plain("Reviewer note: ")
.highlight("this longer highlighted phrase is intentionally verbose so that it "
+ "spans more than one visual line, and the engine still paints a "
+ "continuous rounded chip on each line fragment rather than one "
+ "box per word",
chipText(), DocumentColor.rgb(254, 249, 195),
4.0, DocumentInsets.symmetric(2, 6))
.plain(" — done.")))
.addSection("Footer", section -> section
.accentTop(THEME.palette().rule(), 0.6)
.padding(new DocumentInsets(8, 0, 0, 0))
.addRich(rich -> rich
.plain("Source: ")
.style("examples/.../InlineHighlightExample.java",
DocumentTextStyle.builder()
.fontName(FontName.COURIER)
.size(8)
.color(MUTED)
.build())))
.build();
document.buildPdf();
}
return outputFile;
}
public static void main(String[] args) throws Exception {
System.out.println("Generated: " + generate());
}
private static void labelledRow(SectionBuilder section, String label, Consumer<RichText> body) {
section
.softPanel(PANEL, 6, 12)
.spacing(4)
.addParagraph(p -> p
.text(label)
.textStyle(caption())
.margin(DocumentInsets.zero()))
.addRich(body::accept);
}
private static DocumentTextStyle chipText() {
return DocumentTextStyle.builder()
.fontName(FontName.HELVETICA_BOLD)
.size(9)
.color(DocumentColor.rgb(55, 48, 163))
.build();
}
private static DocumentTextStyle caption() {
return DocumentTextStyle.builder()
.fontName(FontName.HELVETICA_BOLD)
.size(8.5)
.color(MUTED)
.build();
}
}