-
Notifications
You must be signed in to change notification settings - Fork 11
/
FontsForHTML5.ns
86 lines (81 loc) · 2.53 KB
/
FontsForHTML5.ns
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
Newspeak3
'Root'
class FontsForHTML5 usingPlatform: p (* :exemplar: platform fonts *) = (
(*
Font support for Newspeak.
Copyright Gene Z. Ragan 2021
*)
|
private Map = p collections Map.
private DefaultSize <Float> = 12.0.
|
) (
public class FontConfig = (
|
public designs <Map[Symbol, Strings]> = computeDesignMap.
public leading <Map[Symbol, Strings]> = computeLeadingMap.
public weights <Map[Symbol, Integer]> = computeWeightMap.
|
) (
private computeDesignMap ^ <Map[Symbol, String]> = (
^Map new
at: #default put: 'system, -apple-system, sans-serif';
at: #serif put: 'Cambria, Utopia, Times, Times New Roman, serif';
at: #monospaced put: 'Consolas, Monaco, Courier, monospace';
yourself.
)
private computeLeadingMap ^ <Map[Symbol, String]> = (
^Map new
at: #standard put: 'normal';
at: #tight put: '0.5';
at: #loose put: '1.5';
yourself.
)
private computeWeightMap ^ <Map[Symbol, Integer]> = (
^Map new
at: #ultralight put: 100;
at: #thin put: 200;
at: #light put: 300;
at: #regular put: 400;
at: #medium put: 500;
at: #semibold put: 600;
at: #bold put: 700;
at: #heavy put: 800;
at: #black put: 900;
yourself.
)
) : (
)
public class Font config: c <FontConfig> (* :exemplar: Font config: FontConfig new*) = (
|
public size <Float> ::= DefaultSize.
public design <Symbol> ::= #default.
public weight <Symbol> ::= #regular.
public style <Symbol> ::= #normal.
public decoration <Symbol> ::= #none.
public leading <Symbol> ::= #standard.
public smallCaps <Boolean>
public monospaceDigits <Boolean>
config <FontConfig> = c.
|
) (
public applyStyle: element <Alien[HTMLElement]> = (
|
css = element at: 'style'.
|
css
at: 'font-style' put: style asString;
at: 'font-weight' put: (config weights at: weight);
at: 'line-height' put: (config leading at: leading).
#linethrough = decoration
ifTrue: [
css at: 'text-decoration' put: 'line-through'.
]
ifFalse: [
css at: 'text-decoration' put: decoration asString.
].
)
) : (
)
) : (
)