-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathShapeContainerExample.java
More file actions
281 lines (262 loc) · 15.5 KB
/
Copy pathShapeContainerExample.java
File metadata and controls
281 lines (262 loc) · 15.5 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package com.demcha.examples.features.shapes;
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.ParagraphBuilder;
import com.demcha.compose.document.dsl.SectionBuilder;
import com.demcha.compose.document.dsl.ShapeBuilder;
import com.demcha.compose.document.node.DocumentNode;
import com.demcha.compose.document.node.LayerAlign;
import com.demcha.compose.document.node.TextAlign;
import com.demcha.compose.document.node.TextVerticalAlign;
import com.demcha.compose.document.style.ClipPolicy;
import com.demcha.compose.document.style.DocumentColor;
import com.demcha.compose.document.style.DocumentCornerRadius;
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.examples.support.theme.BusinessTheme;
import com.demcha.compose.font.FontName;
import com.demcha.examples.support.ExampleOutputPaths;
import java.nio.file.Path;
/**
* Runnable showcase for the v1.5 shape-as-container DSL.
*/
public final class ShapeContainerExample {
private static final BusinessTheme THEME = BusinessTheme.modern();
private static final DocumentColor INK = DocumentColor.rgb(34, 38, 50);
private static final DocumentColor MUTED = DocumentColor.rgb(102, 106, 118);
private static final DocumentColor DEEP_TEAL = DocumentColor.rgb(20, 60, 75);
private static final DocumentColor GOLD = DocumentColor.rgb(196, 153, 76);
private static final DocumentColor SOFT_GOLD = DocumentColor.rgb(238, 221, 184);
private ShapeContainerExample() {
}
public static Path generate() throws Exception {
Path outputFile = ExampleOutputPaths.prepare("features/shapes", "shape-container.pdf");
try (DocumentSession document = GraphCompose.document(outputFile)
.pageSize(DocumentPageSize.A4)
.pageBackground(THEME.pageBackground())
.margin(28, 28, 28, 28)
.create()) {
document.pageFlow()
.name("ShapeContainerShowcase")
.spacing(14)
.addSection("Hero", section -> section
.softPanel(THEME.palette().surfaceMuted(), 10, 14)
.accentLeft(GOLD, 4)
.spacing(7)
.addParagraph(paragraph -> paragraph
.text("Shape-as-container")
.textStyle(THEME.text().h1())
.margin(DocumentInsets.zero()))
.addRich(rich -> rich
.plain("Compose a shape, place normal document nodes inside it, ")
.accent("and clip the children to the outline", GOLD)
.plain(" while the whole unit paginates atomically.")))
.addRow("ShapeSamples", row -> row
.spacing(18)
.weights(1, 1, 1)
.addSection("CircleColumn", section -> section
.spacing(8)
.addCircle(118, DEEP_TEAL, circle -> circle
.name("InitialCircle")
.padding(12)
.stroke(DocumentStroke.of(GOLD, 1.4))
.center(label("GC", style(FontName.HELVETICA_BOLD, 24,
DocumentTextDecoration.BOLD, DocumentColor.WHITE)))
.position(label("CLIP", style(FontName.HELVETICA_BOLD, 8,
DocumentTextDecoration.BOLD, SOFT_GOLD)),
0, -12, LayerAlign.BOTTOM_CENTER))
.addParagraph(paragraph -> paragraph
.text("A circle owns its label and clips by the ellipse path.")
.textStyle(caption())
.lineSpacing(1.4)
.margin(DocumentInsets.zero())))
.addSection("EllipseColumn", section -> section
.spacing(8)
.addEllipse(168, 92, GOLD, ellipse -> ellipse
.name("OffsetEllipse")
.padding(10)
.stroke(DocumentStroke.of(DEEP_TEAL, 1.0))
.center(label("Overlay", style(FontName.HELVETICA_BOLD, 15,
DocumentTextDecoration.BOLD, INK)))
.topRight(pill(44, 18, DEEP_TEAL))
.position(label("TOP", style(FontName.HELVETICA_BOLD, 7,
DocumentTextDecoration.BOLD, DocumentColor.WHITE)),
-6, 5, LayerAlign.TOP_RIGHT))
.addParagraph(paragraph -> paragraph
.text("Nine-point anchors and offsets use the same vocabulary as LayerStack.")
.textStyle(caption())
.lineSpacing(1.4)
.margin(DocumentInsets.zero())))
.addSection("CardColumn", section -> section
.spacing(8)
.addContainer(card -> card
.name("RoundedFeatureCard")
.roundedRect(178, 112, 16)
.fillColor(DocumentColor.WHITE)
.stroke(DocumentStroke.of(THEME.palette().rule(), 0.8))
.clipPolicy(ClipPolicy.CLIP_PATH)
.padding(12)
.center(cardCopy())
.topRight(pill(46, 18, DEEP_TEAL))
.position(label("NEW", style(FontName.HELVETICA_BOLD, 7,
DocumentTextDecoration.BOLD, DocumentColor.WHITE)),
-6, 5, LayerAlign.TOP_RIGHT))
.addParagraph(paragraph -> paragraph
.text("A rounded rectangle can host sections, rich text, and badge layers.")
.textStyle(caption())
.lineSpacing(1.4)
.margin(DocumentInsets.zero()))))
.addSection("ClipPolicies", section -> section
.softPanel(DocumentColor.WHITE, 8, 12)
.stroke(DocumentStroke.of(THEME.palette().rule(), 0.5))
.spacing(5)
.addParagraph(paragraph -> paragraph
.text("Clip policies")
.textStyle(THEME.text().h3())
.margin(DocumentInsets.zero()))
.addRich(rich -> rich
.plain("Default ")
.bold("CLIP_PATH")
.plain(" clips to the actual outline. ")
.bold("CLIP_BOUNDS")
.plain(" clips to the bounding box, and ")
.bold("OVERFLOW_VISIBLE")
.plain(" keeps child overflow visible for deliberate effects.")))
.addSection("PerCornerRadius", section -> section
.softPanel(DocumentColor.WHITE, 8, 12)
.stroke(DocumentStroke.of(THEME.palette().rule(), 0.5))
.spacing(6)
.addParagraph(paragraph -> paragraph
.text("Per-corner radius")
.textStyle(THEME.text().h3())
.margin(DocumentInsets.zero()))
.addRich(rich -> rich
.plain("roundedRect(w, h, ")
.bold("DocumentCornerRadius.right(r)")
.plain(") rounds corners independently — a card flush on one side, no CLIP_PATH parent."))
.addRow("CornerCards", row -> row
.spacing(12)
.evenWeights()
.addSection("CcUniform", col -> cornerCard(col, "of(r)", DocumentCornerRadius.of(18)))
.addSection("CcLeft", col -> cornerCard(col, "left(r)", DocumentCornerRadius.left(18)))
.addSection("CcRight", col -> cornerCard(col, "right(r)", DocumentCornerRadius.right(18)))
.addSection("CcTop", col -> cornerCard(col, "top(r)", DocumentCornerRadius.top(18)))
.addSection("CcBottom", col -> cornerCard(col, "bottom(r)", DocumentCornerRadius.bottom(18)))))
.addSection("VerticalAlign", section -> section
.softPanel(DocumentColor.WHITE, 8, 12)
.stroke(DocumentStroke.of(THEME.palette().rule(), 0.5))
.spacing(6)
.addParagraph(paragraph -> paragraph
.text("Vertical text seating")
.textStyle(THEME.text().h3())
.margin(DocumentInsets.zero()))
.addRich(rich -> rich
.plain("paragraph.")
.bold("verticalAlign(TextVerticalAlign.TOP / CENTER / BOTTOM)")
.plain(" seats a single line by its cap band inside a taller shape — no lift offsets. ")
.accent("The gold line marks the box centre.", GOLD))
.addRow("VAlignPills", row -> row
.spacing(12)
.evenWeights()
.addSection("SeatDefault", col -> seatColumn(col, TextVerticalAlign.DEFAULT))
.addSection("SeatTop", col -> seatColumn(col, TextVerticalAlign.TOP))
.addSection("SeatCenter", col -> seatColumn(col, TextVerticalAlign.CENTER))
.addSection("SeatBottom", col -> seatColumn(col, TextVerticalAlign.BOTTOM))))
.build();
document.buildPdf();
}
return outputFile;
}
public static void main(String[] args) throws Exception {
System.out.println("Generated: " + generate());
}
private static DocumentNode label(String text, DocumentTextStyle style) {
return new ParagraphBuilder()
.text(text)
.textStyle(style)
.align(TextAlign.CENTER)
.margin(DocumentInsets.zero())
.build();
}
// One tall pill per seat: a gold guide line at the box centre, the same big
// "GC" label seated by TOP / CENTER / BOTTOM, and the mode name underneath.
private static void seatColumn(SectionBuilder col, TextVerticalAlign verticalAlign) {
col.spacing(5)
.addContainer(card -> card
.name("Seat" + verticalAlign)
.roundedRect(112, 80, 18)
.fillColor(DEEP_TEAL)
.center(seatGuide())
.center(valignLabel("GC", verticalAlign)))
.addParagraph(paragraph -> paragraph
.text(verticalAlign.name())
.textStyle(caption())
.align(TextAlign.CENTER)
.margin(DocumentInsets.zero()));
}
private static DocumentNode seatGuide() {
return new ShapeBuilder().size(96, 1.2).fillColor(GOLD).build();
}
private static DocumentNode valignLabel(String text, TextVerticalAlign verticalAlign) {
return new ParagraphBuilder()
.text(text)
.textStyle(style(FontName.HELVETICA_BOLD, 34, DocumentTextDecoration.BOLD, DocumentColor.WHITE))
.align(TextAlign.CENTER)
.verticalAlign(verticalAlign)
.margin(DocumentInsets.zero())
.build();
}
private static DocumentNode pill(double width, double height, DocumentColor color) {
return new ShapeBuilder()
.size(width, height)
.fillColor(color)
.cornerRadius(height / 2.0)
.build();
}
// One tall card per corner preset, clipped to the per-corner outline.
private static void cornerCard(SectionBuilder col, String caption, DocumentCornerRadius corners) {
col.spacing(4)
.addContainer(card -> card
.name("Corner" + caption)
.roundedRect(96, 56, corners)
.fillColor(DEEP_TEAL)
.clipPolicy(ClipPolicy.CLIP_PATH)
.center(label("Aa", style(FontName.HELVETICA_BOLD, 16,
DocumentTextDecoration.BOLD, DocumentColor.WHITE))))
.addParagraph(paragraph -> paragraph
.text(caption)
.textStyle(caption())
.margin(DocumentInsets.zero()));
}
private static DocumentNode cardCopy() {
return new SectionBuilder()
.name("RoundedCardCopy")
.spacing(5)
.addParagraph(paragraph -> paragraph
.text("Feature card")
.textStyle(THEME.text().h3())
.margin(DocumentInsets.zero()))
.addRich(rich -> rich
.plain("Children are still ")
.bold("semantic nodes")
.plain(": paragraphs, sections, badges, and rich text."))
.build();
}
private static DocumentTextStyle caption() {
return style(FontName.HELVETICA, 8.6, DocumentTextDecoration.DEFAULT, MUTED);
}
private static DocumentTextStyle style(FontName font,
double size,
DocumentTextDecoration decoration,
DocumentColor color) {
return DocumentTextStyle.builder()
.fontName(font)
.size(size)
.decoration(decoration)
.color(color)
.build();
}
}