-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext-formatting.ts
More file actions
480 lines (458 loc) · 15.4 KB
/
text-formatting.ts
File metadata and controls
480 lines (458 loc) · 15.4 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
import { RichTextDocumentBuilder, pt } from "../../lib"
const builder = new RichTextDocumentBuilder()
// Setup colors for the demo
builder.withColor("red", { red: 255, green: 0, blue: 0 })
builder.withColor("blue", { red: 0, green: 0, blue: 255 })
builder.withColor("green", { red: 0, green: 128, blue: 0 })
builder.withColor("orange", { red: 255, green: 165, blue: 0 })
builder.withColor("purple", { red: 128, green: 0, blue: 128 })
builder.withColor("veryLightGray", { red: 240, green: 240, blue: 240 })
builder.withColor("lightGray", { red: 220, green: 220, blue: 220 })
builder.withColor("darkGray", { red: 64, green: 64, blue: 64 })
builder.withColor("lightBlue", { red: 173, green: 216, blue: 230 })
builder.withColor("yellow", { red: 255, green: 255, blue: 0 })
// Add fonts for the demo
builder.withFont("arial", { name: "Arial", family: "swiss" })
builder.withFont("times", { name: "Times New Roman", family: "roman" })
builder.withFont("courier", { name: "Courier New", family: "modern" })
builder.withFont("verdana", { name: "Verdana", family: "swiss" })
// Create a new section
builder.withSection((section) => {
// Document title
section.body.withTitle("RTF Text & Paragraph Formatting Demo")
// Section 1: Basic Text Formatting
section.body.withHeading("1. Basic Text Formatting", 1)
section.body.withText("This section demonstrates basic character-level formatting options:").closeParagraph()
section.body
.withText(
"Basic styles: ",
{ bold: true },
"Bold",
{},
", ",
{ italic: true },
"Italic",
{},
", ",
{ underline: true },
"Underlined",
{},
", ",
{ bold: true, italic: true },
"Bold Italic",
{},
", and ",
{ bold: true, italic: true, underline: true },
"All Three",
{},
"."
)
.closeParagraph()
section.body
.withText(
"Underline variations: ",
{ underline: true },
"Single",
{},
", ",
{ underline: "double" },
"Double",
{},
", ",
{ underline: "dotted" },
"Dotted",
{},
", ",
{ underline: "dash" },
"Dashed",
{},
", and ",
{ underline: "wave" },
"Wavy",
{},
"."
)
.closeParagraph()
section.body
.withText(
"Text effects: ",
{ strikethrough: true },
"Strikethrough",
{},
", ",
{ strikethrough: "double" },
"Double Strikethrough",
{},
", ",
{ flags: ["superscript"] },
"Superscript",
{},
", ",
{ flags: ["subscript"] },
"Subscript",
{},
", ",
{ flags: ["smallCaps"] },
"Small Caps",
{},
", and ",
{ flags: ["allCaps"] },
"All Caps",
{},
"."
)
.closeParagraph()
section.body.withHeading("2. Colors and Fonts", 1)
section.body.withText("Demonstrating text colors and different font families:").closeParagraph()
section.body
.withText(
"Colors: ",
{ colorAlias: "red" },
"Red",
{},
", ",
{ colorAlias: "blue" },
"Blue",
{},
", ",
{ colorAlias: "green" },
"Green",
{},
", ",
{ colorAlias: "orange" },
"Orange",
{},
", and ",
{ colorAlias: "purple" },
"Purple",
{},
"."
)
.closeParagraph()
section.body
.withText(
"Background colors: ",
{ highlightColorAlias: "yellow" },
"Yellow highlight",
{},
", ",
{ highlightColorAlias: "lightBlue" },
"Light blue highlight",
{},
", and ",
{ colorAlias: "red", highlightColorAlias: "yellow" },
"Red on yellow",
{},
"."
)
.closeParagraph()
section.body
.withText(
"Font families: ",
{ fontAlias: "arial" },
"Arial (Swiss)",
{},
", ",
{ fontAlias: "times" },
"Times New Roman (Roman)",
{},
", ",
{ fontAlias: "courier" },
"Courier New (Modern)",
{},
", and ",
{ fontAlias: "verdana" },
"Verdana (Swiss)",
{},
"."
)
.closeParagraph()
// Section 3: Font Sizes
section.body.withHeading("3. Font Sizes", 1)
section.body.withText("Various font sizes available:").closeParagraph()
section.body
.withText(
{ fontSize: pt(8) },
"8pt",
{},
" • ",
{ fontSize: pt(10) },
"10pt",
{},
" • ",
{ fontSize: pt(12) },
"12pt",
{},
" • ",
{ fontSize: pt(14) },
"14pt",
{},
" • ",
{ fontSize: pt(16) },
"16pt",
{},
" • ",
{ fontSize: pt(18) },
"18pt",
{},
" • ",
{ fontSize: pt(24) },
"24pt",
{},
" • ",
{ fontSize: pt(36) },
"36pt"
)
.closeParagraph()
// Section 4: Character Spacing and Scaling
section.body.withHeading("4. Character Spacing and Scaling", 1)
section.body.withText("Advanced character formatting:").closeParagraph()
section.body
.withText("Character spacing: ", { characterSpacing: pt(-2) }, "Condensed", {}, " | ", {}, "Normal", {}, " | ", { characterSpacing: pt(4) }, "Expanded")
.closeParagraph()
section.body
.withText(
"Horizontal scaling: ",
{ horizontalScaling: 0.75 },
"75%",
{},
" | ",
{ horizontalScaling: 1.0 },
"100%",
{},
" | ",
{ horizontalScaling: 1.5 },
"150%"
)
.closeParagraph()
// Section 5: Paragraph Alignment
section.body.withHeading("5. Paragraph Alignment", 1)
section.body.withText("Different paragraph alignment options:").closeParagraph()
section.body.withParagraph((p) => {
p.left()
p.withText(
"This paragraph is left-aligned. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
)
})
section.body.withParagraph((p) => {
p.center()
p.withText(
"This paragraph is center-aligned. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
)
})
section.body.withParagraph((p) => {
p.right()
p.withText(
"This paragraph is right-aligned. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
)
})
section.body.withParagraph((p) => {
p.justify()
p.withText(
"This paragraph is justified. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
)
})
// Section 6: Paragraph Spacing
section.body.withHeading("6. Paragraph Spacing", 1)
section.body.withText("Controlling spacing before and after paragraphs:").closeParagraph()
section.body.withParagraph((p) =>
p
.spacing(pt(0))
.border("bottom", { width: pt(0.5), colorAlias: "darkGray" })
.withText("Paragraph without space after or before.")
)
section.body.withParagraph((p) => {
p.spaceBefore(pt(0)).spaceAfter(pt(5))
p.withText("Paragraph with 5pt space after.")
})
section.body.withParagraph((p) =>
p
.spacing(pt(0))
.border("vertical", { width: pt(0.5), colorAlias: "darkGray" })
.withText("Paragraph without space after or before.")
)
section.body.withParagraph((p) => {
p.spaceBefore(pt(10)).spaceAfter(pt(5))
p.withText("Paragraph with 10pt space before and 5pt after.")
})
section.body.withParagraph((p) =>
p
.spacing(pt(0))
.border("vertical", { width: pt(0.5), colorAlias: "darkGray" })
.withText("Paragraph without space after or before.")
)
section.body.withParagraph((p) => {
p.spaceBefore(pt(20)).spaceAfter(pt(10))
p.withText("Paragraph with 20pt space before and 10pt after.")
})
section.body.withParagraph((p) =>
p
.spacing(pt(0))
.border("top", { width: pt(0.5), colorAlias: "darkGray" })
.withText("Paragraph without space after or before.")
)
// Section 7: Line Spacing
section.body.withHeading("7. Line Spacing", 1)
section.body.withText("Different line spacing options:").closeParagraph()
section.body.withParagraph((p) => {
p.lineSpacing(pt(12))
p.withText(
"Single line spacing. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation."
)
})
section.body.withParagraph((p) => {
p.lineSpacing(pt(18))
p.withText(
"1.5 line spacing. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation."
)
})
section.body.withParagraph((p) => {
p.lineSpacing(pt(24))
p.withText(
"Double line spacing. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation."
)
})
// Section 8: Indentation
section.body.withHeading("8. Paragraph Indentation", 1)
section.body.withText("Various indentation options:").closeParagraph()
section.body.withParagraph((p) => {
p.leftIndent(pt(36))
p.withText(
"Left indented paragraph (0.5 inch). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
)
})
section.body.withParagraph((p) => {
p.rightIndent(pt(36))
p.withText(
"Right indented paragraph (0.5 inch). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
)
})
section.body.withParagraph((p) => {
p.leftIndent(pt(72))
p.rightIndent(pt(36))
p.withText(
"Both left (1 inch) and right (0.5 inch) indented. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
)
})
section.body.withParagraph((p) => {
p.leftIndent(pt(36))
p.firstLineIndent(pt(18))
p.withText(
"First line indented more than the rest. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris."
)
})
section.body.withParagraph((p) => {
p.leftIndent(pt(54))
p.firstLineIndent(pt(-18))
p.withText(
"Hanging indent (first line outdented). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris."
)
})
// Section 9: Paragraph Borders
section.body.withHeading("9. Paragraph Borders", 1)
section.body.withText("Paragraphs can have various border styles:").closeParagraph()
section.body.withParagraph((p) => {
p.border("all", { width: pt(1), colorAlias: "blue" })
p.withText("Paragraph with a blue single border on all sides.")
})
section.body.withParagraph((p) => {
p.border("top", { width: pt(2), colorAlias: "red" })
p.border("bottom", { width: pt(2), colorAlias: "red" })
p.withText("Paragraph with red double borders on top and bottom only.")
})
section.body.withParagraph((p) => {
p.border("left", { width: pt(3), colorAlias: "green" })
p.leftIndent(pt(10))
p.withText("Paragraph with a thick green dotted left border and left indent.")
})
// Section 10: Paragraph Shading
section.body.withHeading("10. Paragraph Shading", 1)
section.body.withText("Paragraphs can have background shading:").closeParagraph()
section.body.withParagraph((p) => {
p.backgroundColor("veryLightGray")
p.withText("Paragraph with 10% gray shading.")
})
section.body.withParagraph((p) => {
p.backgroundColor("lightGray")
p.withText("Paragraph with 25% gray shading.")
})
section.body.withParagraph((p) => {
p.backgroundColor("lightBlue")
p.withText("Paragraph with 50% shading and light blue background.")
})
// Section 11: Keep Together Options
section.body.withHeading("11. Paragraph Keep Options", 1)
section.body.withText("Control how paragraphs break across pages:").closeParagraph()
section.body.withParagraph((p) => {
p.flags("keepNext")
p.withText("This paragraph is kept together with the next one (keepNext).")
})
section.body.withText("This paragraph follows the previous one and they should stay together.").closeParagraph()
section.body.withParagraph((p) => {
p.flags("keepLines")
p.withText(
"This paragraph's lines are kept together on the same page (keepLines). Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
)
})
// Section 12: Page Breaks
section.body.withHeading("12. Page Break Control", 1)
section.body.withText("The next paragraph forces a page break before it:").closeParagraph()
section.body.withParagraph((p) => {
p.flags("pageBreakBefore")
p.center()
p.withText({ bold: true, fontSize: pt(24) }, "NEW PAGE")
})
section.body.withText("This content appears on the new page after the page break.")
// Section 13: Complex Mixed Formatting
section.body.withHeading("13. Complex Mixed Formatting", 1)
section.body.withText("Combining multiple formatting options in a single paragraph:").closeParagraph()
section.body.withParagraph((p) => {
p.justify()
p.leftIndent(pt(36))
p.rightIndent(pt(18))
p.spaceBefore(pt(12)).spaceAfter(pt(6))
p.lineSpacing(pt(18))
p.border("all", { width: pt(1), colorAlias: "darkGray" })
p.backgroundColor("veryLightGray")
p.withText(
"This paragraph demonstrates ",
{ bold: true, colorAlias: "blue" },
"complex formatting",
{},
" with justified alignment, indentation, spacing, borders, and shading. ",
{},
"It contains ",
{ italic: true, colorAlias: "red" },
"mixed character formatting",
{},
" including different ",
{ fontAlias: "courier" },
"fonts",
{},
", ",
{ fontSize: pt(14) },
"sizes",
{},
", and ",
{ underline: true, colorAlias: "green" },
"effects",
{},
" all within the same paragraph structure."
)
})
// Section 14: Special Characters and Symbols
section.body.withHeading("14. Special Characters", 1)
section.body.withText("RTF supports various special characters and symbols:").closeParagraph()
section.body.withText("Common symbols: © ® ™ § ¶ • – — \" \" ' ' … ± × ÷ ≤ ≥ ≠ ∞ ∑ ∏ ∆ Ω").closeParagraph()
section.body.withText("Currency symbols: $ ¢ £ ¥ € ₹ ₽ ₩ ₨ ₡ ₪ ₫ ₱").closeParagraph()
section.body.withText("Arrows: ← ↑ → ↓ ↔ ↕ ⇐ ⇑ ⇒ ⇓ ⇔ ⇕").closeParagraph()
section.body.withText("Mathematical symbols: ∫ ∂ ∇ √ ∛ ∜ ∝ ∞ ∅ ∈ ∉ ∩ ∪ ⊂ ⊃ ⊆ ⊇").closeParagraph()
// Footer
section.body.withParagraph((p) => {
p.spaceBefore(pt(24)).spaceAfter(pt(12))
p.center()
p.border("top", { width: pt(1), colorAlias: "darkGray" })
p.withText({ italic: true, colorAlias: "darkGray" }, "RTF Text & Paragraph Formatting Demo")
})
})
export default builder