Skip to content

Commit 391c26b

Browse files
committed
Make worker work again after latest font changes
1 parent 2e7df01 commit 391c26b

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

fonts.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
"use strict";
55

6+
var isWorker = (typeof window == "undefined");
7+
68
/**
79
* Maximum file size of the font.
810
*/
@@ -36,9 +38,12 @@ var kDisableFonts = false;
3638

3739
var Fonts = (function () {
3840
var kScalePrecision = 40;
39-
var fonts = Object.create(null);
40-
var ctx = document.createElement("canvas").getContext("2d");
41-
ctx.scale(1 / kScalePrecision, 1);
41+
var fonts = Object.create(null);
42+
43+
if (!isWorker) {
44+
var ctx = document.createElement("canvas").getContext("2d");
45+
ctx.scale(1 / kScalePrecision, 1);
46+
}
4247

4348
function Font(name, data, properties) {
4449
this.name = name;
@@ -120,7 +125,6 @@ var Fonts = (function () {
120125

121126
var FontLoader = {
122127
bind: function(fonts) {
123-
var worker = (typeof window == "undefined");
124128
var ready = true;
125129

126130
for (var i = 0; i < fonts.length; i++) {
@@ -140,7 +144,7 @@ var FontLoader = {
140144
for (var j = 0; j < length; j++)
141145
str += String.fromCharCode(data[j]);
142146

143-
worker ? obj.bindWorker(str) : obj.bindDOM(str);
147+
isWorker ? obj.bindWorker(str) : obj.bindDOM(str);
144148
}
145149

146150
return ready;

worker/client.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ FontWorker.prototype = {
5959
"fonts": function(data) {
6060
// console.log("got processed fonts from worker", Object.keys(data));
6161
for (name in data) {
62-
// Update the
63-
Fonts[name].properties = {
62+
// Update the encoding property.
63+
var font = Fonts.lookup(name);
64+
font.properties = {
6465
encoding: data[name].encoding
6566
}
66-
67+
6768
// Call `Font.prototype.bindDOM` to make the font get loaded on the page.
6869
Font.prototype.bindDOM.call(
69-
Fonts[name],
70+
font,
7071
data[name].str,
7172
// IsLoadedCallback.
7273
this.$handleFontLoadedCallback
@@ -84,19 +85,9 @@ FontWorker.prototype = {
8485
continue;
8586
}
8687

87-
// Store only the data on Fonts that is needed later on, such that we
88-
// hold track on as lease memory as possible.
89-
Fonts[font.name] = {
90-
name: font.name,
91-
mimetype: font.mimetype,
92-
// This is set later on the worker replay. For some fonts, the encoding
93-
// is calculated during the conversion process happening on the worker
94-
// and therefore is not available right now.
95-
// properties: {
96-
// encoding: font.properties.encoding
97-
// },
98-
cache: Object.create(null)
99-
};
88+
// Register the font but don't pass in any real data. The idea is to
89+
// store as less data as possible to reduce memory usage.
90+
Fonts.registerFont(font.name, Object.create(null), Object.create(null));
10091

10192
// Mark this font to be handled later.
10293
notLoaded.push(font);

0 commit comments

Comments
 (0)