Skip to content

Commit db11170

Browse files
committed
Add glyphName, htmlCode, cssCode to glyph inspector.
1 parent a769436 commit db11170

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

docs/glyph-inspector.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<meta name="description" content="A JavaScript library to manipulate the letterforms of text from the browser or node.js.">
55
<meta charset="utf-8">
66
<link rel="stylesheet" href="site.css">
7-
7+
<!-- This style tag used for dynamically loading uploaded fonts. -->
8+
<style id="OpentypeCustomFontTag"></style>
89
<div class="header">
910
<div class="container">
1011
<h1><a href="./">opentype.js</a></h1>
@@ -130,8 +131,12 @@ <h1>Free Software</h1>
130131
}
131132
var glyph = font.glyphs.get(glyphIndex),
132133
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>&amp;#x'+hex+';</dd>';
139+
html += '<dt>cssCode</dt><dd>content: \'\\'+hex+'\';</dd>';
135140
if (glyph.unicodes.length > 0) {
136141
html += '<dt>unicode</dt><dd>'+ glyph.unicodes.map(formatUnicode).join(', ') +'</dd>';
137142
}
@@ -412,6 +417,15 @@ <h1>Free Software</h1>
412417
const data = await file.arrayBuffer();
413418
onFontLoaded(opentype.parse(isWoff2 ? Module.decompress(data) : data));
414419
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();
415429
} catch (err) {
416430
showErrorMessage(err.toString());
417431
}

0 commit comments

Comments
 (0)