Skip to content

Commit 0f2489b

Browse files
committed
Add glyphName, htmlCode, cssCode to glyph inspector
1 parent aa8ad76 commit 0f2489b

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

docs/glyph-inspector.html

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<meta charset="utf-8">
66
<link rel="stylesheet" href="site.css">
77
<script src="site.js"></script>
8-
8+
<!-- This style tag used for dynamically loading uploaded fonts. -->
9+
<style id="OpentypeCustomFontTag"></style>
910
<div class="header">
1011
<div class="container">
1112
<h1><a href="./">opentype.js</a></h1>
@@ -143,9 +144,13 @@ <h1>Free Software</h1>
143144
}
144145
var glyph = font.glyphs.get(glyphIndex),
145146
html = '<dl>';
146-
html += '<dt>name</dt><dd>'+glyph.name+'</dd>';
147-
147+
html += '<dt>glyphName</dt><dd>'+glyph.name+'</dd>';
148148
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>&amp;#x'+hex+';</dd>';
153+
html += '<dt>cssCode</dt><dd>content: \'\\'+hex+'\';</dd>';
149154
html += '<dt>unicode</dt><dd>'+ glyph.unicodes.map(formatUnicode).join(', ') +'</dd>';
150155
}
151156
html += '<dt>index</dt><dd>'+glyph.index+'</dd>';
@@ -338,7 +343,7 @@ <h1>Free Software</h1>
338343
options,
339344
{ fill: typeof paletteIndex !== 'undefined' ? window.font.palettes.getColor(paletteIndex, window.fontOptions.usePalette) : '#000000' }
340345
);
341-
346+
342347
if (/(^#ffffff)|(00$)/.test(overwriteOptions.fill)) {
343348
overwriteOptions.fill = '#000000';
344349
}
@@ -399,7 +404,7 @@ <h1>Free Software</h1>
399404
updateVariationOptions();
400405
}
401406
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);
403408
displayGlyphPage(pageIndex);
404409
const glyphIndex = document.querySelector('[data-glyph-index]')?.dataset.glyphIndex;
405410
if(glyphIndex) {
@@ -558,10 +563,19 @@ <h1>Free Software</h1>
558563
} catch (err) {
559564
showErrorMessage('Error loading font from localStorage');
560565
error = err;
561-
}
566+
}
562567

563568
onFontLoaded(opentype.parse(isWoff2 ? Module.decompress(data) : data, { lowMemory: true }));
564569
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();
565579
} catch (err) {
566580
showErrorMessage(err.toString());
567581
throw err;

0 commit comments

Comments
 (0)