|
5 | 5 | <meta charset="utf-8">
|
6 | 6 | <link rel="stylesheet" href="site.css">
|
7 | 7 | <script src="site.js"></script>
|
8 |
| - |
| 8 | +<!-- This style tag used for dynamically loading uploaded fonts. --> |
| 9 | +<style id="OpentypeCustomFontTag"></style> |
9 | 10 | <div class="header">
|
10 | 11 | <div class="container">
|
11 | 12 | <h1><a href="./">opentype.js</a></h1>
|
@@ -143,9 +144,13 @@ <h1>Free Software</h1>
|
143 | 144 | }
|
144 | 145 | var glyph = font.glyphs.get(glyphIndex),
|
145 | 146 | html = '<dl>';
|
146 |
| - html += '<dt>name</dt><dd>'+glyph.name+'</dd>'; |
147 |
| - |
| 147 | + html += '<dt>glyphName</dt><dd>'+glyph.name+'</dd>'; |
148 | 148 | if (glyph.unicodes.length > 0) {
|
| 149 | + const char = String.fromCodePoint.apply(null, glyph.unicodes); |
| 150 | + html += '<dt>glyph</dt><dd style="font-family:\'OpentypeCustomFont\'">'+char+'</dd>'; |
| 151 | + const hex = char.codePointAt(0).toString(16); |
| 152 | + html += '<dt>htmlCode</dt><dd>&#x'+hex+';</dd>'; |
| 153 | + html += '<dt>cssCode</dt><dd>content: \'\\'+hex+'\';</dd>'; |
149 | 154 | html += '<dt>unicode</dt><dd>'+ glyph.unicodes.map(formatUnicode).join(', ') +'</dd>';
|
150 | 155 | }
|
151 | 156 | html += '<dt>index</dt><dd>'+glyph.index+'</dd>';
|
@@ -338,7 +343,7 @@ <h1>Free Software</h1>
|
338 | 343 | options,
|
339 | 344 | { fill: typeof paletteIndex !== 'undefined' ? window.font.palettes.getColor(paletteIndex, window.fontOptions.usePalette) : '#000000' }
|
340 | 345 | );
|
341 |
| - |
| 346 | + |
342 | 347 | if (/(^#ffffff)|(00$)/.test(overwriteOptions.fill)) {
|
343 | 348 | overwriteOptions.fill = '#000000';
|
344 | 349 | }
|
@@ -399,7 +404,7 @@ <h1>Free Software</h1>
|
399 | 404 | updateVariationOptions();
|
400 | 405 | }
|
401 | 406 | const selectedPage = document.querySelector('.page-selected');
|
402 |
| - const pageIndex = Array.from(selectedPage.parentElement.children).indexOf(selectedPage); |
| 407 | + const pageIndex = Array.from(selectedPage.parentElement.children).indexOf(selectedPage); |
403 | 408 | displayGlyphPage(pageIndex);
|
404 | 409 | const glyphIndex = document.querySelector('[data-glyph-index]')?.dataset.glyphIndex;
|
405 | 410 | if(glyphIndex) {
|
@@ -558,10 +563,19 @@ <h1>Free Software</h1>
|
558 | 563 | } catch (err) {
|
559 | 564 | showErrorMessage('Error loading font from localStorage');
|
560 | 565 | error = err;
|
561 |
| - } |
| 566 | + } |
562 | 567 |
|
563 | 568 | onFontLoaded(opentype.parse(isWoff2 ? Module.decompress(data) : data, { lowMemory: true }));
|
564 | 569 | if ( !error ) showErrorMessage('');
|
| 570 | + const styleTag = document.getElementById("OpentypeCustomFontTag"); |
| 571 | + const blob = new Blob([data], { type: 'application/octet-stream' }); |
| 572 | + const url = URL.createObjectURL(blob); |
| 573 | + styleTag.innerHTML = ` |
| 574 | + @font-face { |
| 575 | + font-family: 'OpentypeCustomFont'; |
| 576 | + src: url(${url}); |
| 577 | + } |
| 578 | + `.trim(); |
565 | 579 | } catch (err) {
|
566 | 580 | showErrorMessage(err.toString());
|
567 | 581 | throw err;
|
|
0 commit comments