Skip to content

Commit

Permalink
add webfontloader to check status of web fonts at rendering time. #13
Browse files Browse the repository at this point in the history
  • Loading branch information
wissenbach committed Apr 7, 2017
1 parent 4294590 commit 215be2b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
47 changes: 39 additions & 8 deletions svg_rendering/page/debug.html
Expand Up @@ -10,6 +10,7 @@
<link rel="stylesheet" href="css/pure-custom.css">
<link rel="stylesheet" href="css/basic_layout.css">

<script type="text/javascript" src="./js-gen/webfontloader.js"></script>
<script type="text/javascript" src="./js-gen/Y_extract.js"></script>
<script type="text/javascript" src="./js-gen/svg-utils.js"></script>
<script type="text/javascript" src="./js-gen/faust.js"></script>
Expand Down Expand Up @@ -71,16 +72,16 @@ <h1>Transcript Generation Debugging</h1>

<script type="text/javascript">
var parseQueryString = function( queryString ) {
var params = {}, queries, temp, i, l;
var params = {}, queries, temp, i, l;

// Split into key/value pairs
queries = queryString.split("&");
// Split into key/value pairs
queries = queryString.split("&");

// Convert the array of strings into an object
for ( i = 0, l = queries.length; i < l; i++ ) {
// Convert the array of strings into an object
for ( i = 0, l = queries.length; i < l; i++ ) {
temp = queries[i].split('=');
params[temp[0]] = temp[1];
}
}

return params;
};
Expand All @@ -90,7 +91,37 @@ <h1>Transcript Generation Debugging</h1>
console.log(json);
var help = document.getElementById("debughelp");
help.parentNode.removeChild(help);
Faust.io(json, transcriptGeneration.createDiplomaticSvg);
</script>


var fontError = false;
var webFontConfig = {
custom: {
families: ['Ubuntu', 'Ubuntu Monospace', 'Gentium Plus']
// we don not need to specify urls as they are specified in the css files
},
// do not time out if font can't be loaded
timeout: Number.MAX_VALUE,
active: function() {
// if we made it this far without 'fontinactive' occurring, then all
// fonts have been loaded
if (!fontError) {
Faust.io(json, transcriptGeneration.createDiplomaticSvg);
} else {}

},
fontinactive: function(familyName, fvd) {
// font could not be loaded, abort
fontError = true;
var message = "Error: web font could not be loaded: " + familyName + " " + fvd;

var htmlMessage = document.createElement('div');
htmlMessage.innerHTML = message;
document.body.append(htmlMessage);
throw(message);
}
};

WebFont.load(webFontConfig);
</script>
</body>
</html>
18 changes: 18 additions & 0 deletions svg_rendering/page/js-gen/webfontloader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 215be2b

Please sign in to comment.