-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestfont.js
41 lines (31 loc) · 1.26 KB
/
testfont.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(function() {
"use strict";
var type2 = new Type2();
var customFunctions = ["default"];
var loader = new Loader(type2, customFunctions);
function buildPlainFont(charstrings) {
charstrings["alphabet"] = loader.charstring(["default"]);
charstrings["rectangle"] = loader.charstring(["default"]);
return charstrings;
}
function buildFont() {
var subroutines = type2.getSubroutines();
var charstrings = loader.getCharstrings(type2);
var plain = buildPlainFont(charstrings);
var substitutions = loader.getSubstitutions();
var font = loader.buildFontObject(plain, subroutines, substitutions);
// Show the OpenType GSUB table:
SFNT.utils.buildTables(font.stub["GSUB"], window, "#gsub", false, false, false, true);
// Build a CSS stylesheet that loads the font as base64-encoded WOFF resource:
SFNT.utils.addStyleSheet(font, "customfont", "custom");
// how big is this font?
var binary = font.toData();
var fsize = document.querySelector(".fsize");
fsize.textContent = binary.length;
// And add a download link for easy debugging, for good measure.
var a = document.getElementById("download-plain");
a.href = font.toDataURL();
a.download = "font.otf";
}
loader.handleSheets(buildFont);
}());