-
Notifications
You must be signed in to change notification settings - Fork 44
/
index.html
211 lines (184 loc) · 9.49 KB
/
index.html
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
<html>
<head>
<title>Font style matcher</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<meta name="theme-color" content="#fff200">
<link rel="manifest" href="./manifest.json">
<link rel="shortcut icon" href="./images/favicon.ico">
<!-- Add to homescreen for Chrome on Android. Fallback for manifest.json -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="application-name" content="font-style-matcher">
<!-- Add to homescreen for Safari on iOS -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="font-style-matcher">
<!-- Homescreen icons -->
<link rel="apple-touch-icon" href="./images/icon-48x48.png">
<link rel="apple-touch-icon" sizes="72x72" href="./images/icon-72x72.png">
<link rel="apple-touch-icon" sizes="96x96" href="./images/icon-96x96.png">
<link rel="apple-touch-icon" sizes="144x144" href="./images/icon-144x144.png">
<link rel="apple-touch-icon" sizes="192x192" href="./images/icon-192x192.png">
<!-- Tile icon for Windows 8 (144x144 + tile color) -->
<meta name="msapplication-TileColor" content="#fff200">
<meta name="msapplication-TileImage" content="./images/icon-144x144.png">
<link rel="stylesheet" type="text/css" href="./style.css">
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/font-style-matcher/sw.js', {scope: '/font-style-matcher/'}).then(_ => {
console.log('service worker is cool 🐳');
}).catch(e => {
console.error('service worker is not so cool 🔥', e);
throw e;
});
}
</script>
</head>
<body>
<div class="container">
<h1>Font style matcher</h1>
<p>
If you're using a web font, you're bound to see a flash of unstyled text (or FOUC),
between the initial render of your websafe font and the webfont that you've chosen.
This usually results in a jarring shift in layout, due to
sizing discrepancies between the two fonts. To minimize this
discrepancy, you can try to match the fallback font and the intended webfont’s
x-heights and widths <a href="http://helenvholmes.com/writing/type-is-your-right">[1]</a>.
This tool helps you do <b><i>exactly</i></b> that.
</p>
<br>
<div class="columns">
<div>
<div class="input-field" title="Type a different font family, like 'Arial', and tab away from the input to see a preview of it.">
<input value="Georgia" placeholder="Fallback font name"
id="fallbackName" data-target="fallback">
<label>Fallback font</label>
</div>
<br>
<div class="input-field">
<input type="range" value="16"
min="5" max="50" step="1"
id="fallbackSize"
data-target="fallback">
<label>Font size: <span id="fallbackSizeDisplay">16px</span></label>
</div>
<div class="input-field">
<input type="range" value="1.6"
min="0" max="5" step="0.05"
id="fallbackLineHeight"
data-target="fallback">
<label>Line height: <span id="fallbackLineHeightDisplay">1</span></label>
</div>
<div class="input-field">
<input type="range" value="300"
min="100" max="900" step="100"
id="fallbackWeight"
data-target="fallback">
<label>Font weight: <span id="fallbackWeightDisplay">300</span></label>
</div>
<div class="input-field">
<input type="range" value="0" min="-2" max="2" step="0.05"
id="fallbackSpacing"
data-target="fallback">
<label>Letter spacing: <span id="fallbackSpacingDisplay">0px</span></label>
</div>
<div class="input-field">
<input type="range" value="0" min="-2" max="2" step="0.05"
id="fallbackWordSpacing"
data-target="fallback">
<label>Word spacing: <span id="fallbackWordSpacingDisplay">0px</span></label>
</div>
<button class='actionButton clipboardButton' id="fallbackClipboardButton" data-clipboard-text="">
<svg viewBox="0 0 24 24"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"></path></g></svg>
<span>Copy CSS to clipboard</span>
</button>
<p id="fallback">The fox jumped over the lazy dog, the scoundrel.</p>
</div>
<div>
<div class="input-field" title="Type a different font family, like 'Arial', and tab away from the input to see a preview of it.">
<input value="Merriweather" placeholder="Web font name" class="with-checkbox"
id="webfontName" list="families"
data-target="webfont">
<datalist id="families"></datalist>
<label for="webfontName">Web font</label>
<input id="downloadFont" type="checkbox" checked>
<span class="text">Download from Google Fonts</span>, or:
<div>
<button class="actionButton" id="uploadFontBtn">
<svg viewBox="0 0 24 24"><path d="M5 4v2h14V4H5zm0 10h4v6h6v-6h4l-7-7-7 7z"></svg>
<span>Upload font</span>
</button>
<input type="file" accept=".ttf,.otf,.woff,.woff2,.svg" class="uploadFont" id="uploadFont">
</div>
</div>
<br>
<div class="input-field">
<input type="range" value="16"
min="5" max="50" step="1"
id="webfontSize"
data-target="webfont">
<label>Font size: <span id="webfontSizeDisplay">16px</span></label>
</div>
<div class="input-field">
<input type="range" value="1.6"
min="0" max="5" step="0.05"
id="webfontLineHeight"
data-target="webfont">
<label>Line height: <span id="webfontLineHeightDisplay">1</span></label>
</div>
<div class="input-field">
<input type="range" value="300"
min="100" max="900" step="100"
id="webfontWeight"
data-target="webfont">
<label>Font weight: <span id="webfontWeightDisplay">300</span></label>
</div>
<div class="input-field">
<input type="range" value="0" min="-2" max="2" step="0.05"
id="webfontSpacing"
data-target="webfont">
<label>Letter spacing: <span id="webfontSpacingDisplay">0px</span></label>
</div>
<div class="input-field">
<input type="range" value="0" min="-2" max="2" step="0.05"
id="webfontWordSpacing"
data-target="webfont">
<label>Word spacing: <span id="webfontWordSpacingDisplay">0px</span></label>
</div>
<button class='actionButton clipboardButton' id="webfontClipboardButton" data-clipboard-text="">
<svg viewBox="0 0 24 24"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"></path></g></svg>
<span>Copy CSS to clipboard</span>
</button>
<p id="webfont">The fox jumped over the lazy dog, the scoundrel.</p>
</div>
</div>
<h2>Overlapped</h2>
<p>In the default example, Merriweather is taller and wider than Georgia, so if you
bump Georgia's <b>font size</b> up to 18px, and its <b>letter spacing</b> to 0.1px
you'll get a pretty close match!</p>
<p>
<label><input type="checkbox" id="useColours">Use different colours for each font</label><br>
<label><input type="checkbox" id="simulateFout">See layout shift due to FOUC</label>
</p>
<br>
<div class="output">
<div id="fallbackOutput">The fox jumped over the lazy dog, the scoundrel.
<br><br>
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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div id="webfontOutput" contenteditable="true" class="overlap-font">The fox jumped over the lazy dog, the scoundrel.
<br><br>
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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
<footer>
made with ✨ by <a href="https://twitter.com/notwaldorf">monica</a>. inspired
by <a href="https://twitter.com/helenvholmes">helen's</a> blog <a href="http://helenvholmes.com/writing/type-is-your-right">post</a>.
find this on <a href="https://github.com/notwaldorf/font-style-matcher">github</a>
</footer>
</div>
<div class="dropAlert" id="dropAlert">Drop it!</div>
</body>
<script src="https://cdn.jsdelivr.net/clipboard.js/1.5.16/clipboard.min.js"></script>
<script src="./app.js"></script>
</html>