-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathExample.ts
177 lines (154 loc) · 5.76 KB
/
Example.ts
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
import * as leer from '../lib/Leerraum';
const oswald = 'fonts/Oswald-Light.ttf';
const abel = 'fonts/Abel-Regular.ttf';
const leading = 24;
function rgb(r, g, b) {
return '#' + ('0' + r.toString(16)).slice(-2) + ('0' + g.toString(16)).slice(-2) + ('0' + b.toString(16)).slice(-2);
}
const gridText = ' a grid is a structure (usually two-dimensional) made up of a series of intersecting straight (vertical, horizontal, and angular) or curved guide lines used to structure content. The grid serves as an armature or framework on which a designer can organize graphic elements (images, glyphs, paragraphs, etc.) in a rational, easy-to-absorb manner. A grid can be used to organize graphic elements in relation to a page, in relation to other graphic elements on the page, or relation to other parts of the same graphic element or shape.';
const gridText2 = ' have seen significant use in print media, interest from web developers has only recently seen a resurgence. Website design frameworks producing HTML and CSS had existed for a while before newer frameworks popularised the use of grid-based layouts. Some grid systems specify fixed-width elements with pixels, and some are "fluid", meaning that they call for page element sizing to be in relative units like percentages, rather than absolute units like pixels or points.';
const s: leer.Span =
{
fontFamily: abel,
fontSize: 12,
hyphenate: true,
text: '',
style: {
fillColor: '#333333',
},
};
const p: leer.Paragraph =
{
align: 'left',
leading: leading,
paragraphLeading: 0,
tolerance: 10,
spans: []
};
function gap(leading_?): leer.Renderer {
return leer.renderParagraph(
{ ...p,
leading: 0,
paragraphLeading: leading_ !== undefined ? leading_ : leading * 2,
spans: [s]
});
}
function title(title: string): leer.Paragraph {
return { ...p,
leading: leading * 3,
paragraphLeading: leading,
spans:
[
{ ...s,
fontFamily: oswald,
hyphenate: false,
fontSize: 64,
text: title,
},
]
};
}
function subtitle(subtitle: string): leer.Paragraph {
return { ...p,
align: 'justify',
paragraphLeading: leading,
spans:
[
{ ...s,
fontSize: 21,
text: subtitle,
},
],
};
}
function text(emphasized: string, text: string): leer.Text {
return [
{ ...p,
align: 'justify',
paragraphLeading: leading,
spans:
[
{ ...s,
fontSize: 21,
text: emphasized,
},
{ ...s,
fontSize: 12,
text: text,
},
],
},
];
}
function fillerText(text: string, lines: number): leer.Renderer {
return leer.renderText(Array(lines).fill(0).map((_, line) => {
return { ...p,
tolerance: 20,
spans: [{ ...s, text: text}]
};
}));
}
function regularPolygon(edges: number, offseta: number, offsetx: number, offsety: number, scale: number) {
const step = 360 / edges;
return Array(edges).fill(0).map((_, a) => {
return {
x: offsetx + Math.cos((a * step + offseta) * Math.PI / 180) * scale,
y: offsety + Math.sin((a * step + offseta) * Math.PI / 180) * scale
}
});
}
leer.renderToPDF('example.pdf', leer.formats.A4, [
{
bboxes: leer.columnsWithMargins(leer.formats.A4, 42, 64, 64, 64, 64),
renderer: leer.vertically(
[
leer.renderParagraph(title('РЕШЕТКА')),
leer.renderText(text('In graphic design,', gridText)),
leer.renderParagraph(subtitle('Tables')),
leer.renderTable(12, [70, 70, 70], [
[
fillerText("Cell 1/1", 1),
fillerText("Cell 2/1", 3),
fillerText("Cell 3/1", 2),
],
[
fillerText("Cell 1/2", 1),
fillerText("Cell 2/2", 1),
fillerText("Cell 3/2", 3),
]
]),
gap(leading),
leer.renderText(text('While grid systems', gridText2)),
leer.renderParagraph(subtitle('Polygons')),
gap(leading),
leer.renderPolygon(regularPolygon(8, 0, 100, 100, 100), { fillColor: '#333333' }),
gap(leading),
leer.renderPolygon(regularPolygon(3, 24.8, 110, 100, 100), { fillColor: '#ffffff' }),
])
}
], (page) => {
return [
{
bboxes: leer.withMargins(leer.formats.A4, 0, 0, 0, 0),
renderer: leer.renderPolygon([
{x: 0, y: 0},
{x: leer.formats.A4.width, y: 0},
{x: leer.formats.A4.width, y: leer.formats.A4.height},
{x: 0, y: leer.formats.A4.height}
], {
fillColor: '#91dbcc'
})
},
{
bboxes: leer.withMargins(leer.formats.A4, 0, 0, 0, 0),
renderer: leer.renderPolygon([
{x: 0, y: 0},
{x: leer.formats.A4.width, y: leer.formats.A4.height},
{x: leer.formats.A4.width, y: leer.formats.A4.height - 1 * (leer.formats.A4.height / leer.formats.A4.width)},
{x: 1, y: 0}
], {
fillColor: '#ffffff'
})
},
];
});