|
4 | 4 | <meta name="description" content="A JavaScript library to manipulate the letterforms of text from the browser or node.js.">
|
5 | 5 | <meta charset="utf-8">
|
6 | 6 | <link rel="stylesheet" href="site.css">
|
7 |
| - |
| 7 | +<!-- This style tag used for dynamically loading uploaded fonts. --> |
| 8 | +<style id="OpentypeCustomFontTag"></style> |
8 | 9 | <div class="header">
|
9 | 10 | <div class="container">
|
10 | 11 | <h1><a href="./">opentype.js</a></h1>
|
@@ -130,8 +131,12 @@ <h1>Free Software</h1>
|
130 | 131 | }
|
131 | 132 | var glyph = font.glyphs.get(glyphIndex),
|
132 | 133 | html = '<dl>';
|
133 |
| - html += '<dt>name</dt><dd>'+glyph.name+'</dd>'; |
134 |
| - |
| 134 | + html += '<dt>glyphName</dt><dd>'+glyph.name+'</dd>'; |
| 135 | + const char = String.fromCodePoint.apply(null, glyph.unicodes); |
| 136 | + html += '<dt>glyph</dt><dd style="font-family:\'OpentypeCustomFont\'">'+char+'</dd>'; |
| 137 | + const hex = char.codePointAt(0).toString(16); |
| 138 | + html += '<dt>htmlCode</dt><dd>&#x'+hex+';</dd>'; |
| 139 | + html += '<dt>cssCode</dt><dd>content: \'\\'+hex+'\';</dd>'; |
135 | 140 | if (glyph.unicodes.length > 0) {
|
136 | 141 | html += '<dt>unicode</dt><dd>'+ glyph.unicodes.map(formatUnicode).join(', ') +'</dd>';
|
137 | 142 | }
|
@@ -412,6 +417,15 @@ <h1>Free Software</h1>
|
412 | 417 | const data = await file.arrayBuffer();
|
413 | 418 | onFontLoaded(opentype.parse(isWoff2 ? Module.decompress(data) : data));
|
414 | 419 | showErrorMessage('');
|
| 420 | + const styleTag = document.getElementById("OpentypeCustomFontTag"); |
| 421 | + const blob = new Blob([data], { type: 'application/octet-stream' }); |
| 422 | + const url = URL.createObjectURL(blob); |
| 423 | + styleTag.innerHTML = ` |
| 424 | + @font-face { |
| 425 | + font-family: 'OpentypeCustomFont'; |
| 426 | + src: url(${url}); |
| 427 | + } |
| 428 | + `.trim(); |
415 | 429 | } catch (err) {
|
416 | 430 | showErrorMessage(err.toString());
|
417 | 431 | }
|
|
0 commit comments