Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ $(document).ready(function() {
fileButton = document.getElementById('file');
fileButton.addEventListener('change', onReadFile, false);
var fontFileName = 'fonts/arialbd.ttf';
opentype.load(fontFileName, function(err, font) {
var amount, glyph, ctx, x, y, fontSize;
if (err) {
showErrorMessage(err.toString());
return;
}
const buffer = fetch(fontFileName).then(res => res.arrayBuffer());
buffer.then(data => {
const font = opentype.parse(data);
onFontLoaded(font);
});
prepareGlyphList();
Expand Down Expand Up @@ -150,7 +147,7 @@ function renderGlyphItem(canvas, glyphIndex) {
ctx.fillStyle = '#AAA';
ctx.font = '9px "Open Sans"';
ctx.fillText(glyphIndex, 2, cellHeight - 2);
var glyph = font.glyphs[glyphIndex],
var glyph = font.glyphs.glyphs[glyphIndex],
glyphWidth = glyph.advanceWidth * fontScale,
xmin = (cellWidth - glyphWidth) / 2,
xmax = (cellWidth + glyphWidth) / 2,
Expand Down Expand Up @@ -239,7 +236,7 @@ function displayGlyphData(glyphIndex) {
container.innerHTML = '';
return;
}
var glyph = font.glyphs[glyphIndex],
var glyph = font.glyphs.glyphs[glyphIndex],
html;
html = '<div><dt>name</dt><dd>' + glyph.name + '</dd></div>';

Expand Down Expand Up @@ -289,7 +286,7 @@ function displayGlyph(glyphIndex) {

if (glyphIndex < 0) return;

var glyph = font.glyphs[glyphIndex],
var glyph = font.glyphs.glyphs[glyphIndex],
glyphWidth = glyph.advanceWidth * glyphScale,
xmin = (canvas.width / window.devicePixelRatio - glyphWidth) / 2,
xmax = (canvas.width / window.devicePixelRatio + glyphWidth) / 2,
Expand Down Expand Up @@ -331,7 +328,7 @@ function drawPoints(glyph, ctx, x, y, fontSize) {
x = x !== undefined ? x : 0;
y = y !== undefined ? y : 0;
fontSize = fontSize !== undefined ? fontSize : 24;
scale = 1 / glyph.font.unitsPerEm * fontSize;
scale = 1 / font.unitsPerEm * fontSize;

blueCircles = [];
redCircles = [];
Expand Down
2 changes: 1 addition & 1 deletion views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link href='css/index.css' rel='stylesheet' type='text/css'/>
<script src="js/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="js/jquery.nicescroll.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/opentype.js/0.4.4/opentype.min.js"></script>
<script src="https://opentype.js.org/dist/opentype.js"></script>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested with opentype 1.3.4. should add comment for the version?

<script src="js/index.js" type="text/javascript"></script>
</head>
<body>
Expand Down