Skip to content

Commit 089364a

Browse files
committed
Encode FontPath data into an ArrayBuffer
Serialize FontPath commands into a binary format and store it in an ArrayBuffer so that it can eventually be stored in a SharedArrayBuffer.
1 parent 520363b commit 089364a

File tree

5 files changed

+464
-408
lines changed

5 files changed

+464
-408
lines changed

src/core/evaluator.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ import {
4040
lookupMatrix,
4141
lookupNormalRect,
4242
} from "./core_utils.js";
43-
import { FontInfo, PatternInfo } from "../shared/obj-bin-transform.js";
43+
import {
44+
FontInfo,
45+
FontPathInfo,
46+
PatternInfo,
47+
} from "../shared/obj-bin-transform.js";
4448
import {
4549
getEncoding,
4650
MacRomanEncoding,
@@ -4663,11 +4667,8 @@ class PartialEvaluator {
46634667
if (font.renderer.hasBuiltPath(fontChar)) {
46644668
return;
46654669
}
4666-
handler.send("commonobj", [
4667-
glyphName,
4668-
"FontPath",
4669-
font.renderer.getPathJs(fontChar),
4670-
]);
4670+
const buffer = FontPathInfo.write(font.renderer.getPathJs(fontChar));
4671+
handler.send("commonobj", [glyphName, "FontPath", buffer], [buffer]);
46714672
} catch (reason) {
46724673
if (evaluatorOptions.ignoreErrors) {
46734674
warn(`buildFontPaths - ignoring ${glyphName} glyph: "${reason}".`);

src/display/api.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ import {
4545
StatTimer,
4646
} from "./display_utils.js";
4747
import { FontFaceObject, FontLoader } from "./font_loader.js";
48-
import { FontInfo, PatternInfo } from "../shared/obj-bin-transform.js";
48+
import {
49+
FontInfo,
50+
FontPathInfo,
51+
PatternInfo,
52+
} from "../shared/obj-bin-transform.js";
4953
import {
5054
getDataProp,
5155
getFactoryUrlProp,
@@ -2803,6 +2807,8 @@ class WorkerTransport {
28032807
}
28042808
break;
28052809
case "FontPath":
2810+
this.commonObjs.resolve(id, new FontPathInfo(exportedData));
2811+
break;
28062812
case "Image":
28072813
this.commonObjs.resolve(id, exportedData);
28082814
break;

src/display/font_loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ class FontFaceObject {
436436
} catch (ex) {
437437
warn(`getPathGenerator - ignoring character: "${ex}".`);
438438
}
439-
const path = makePathFromDrawOPS(cmds);
439+
const path = makePathFromDrawOPS(cmds.path);
440440

441441
if (!this.fontExtraProperties) {
442442
// Remove the raw path-string, since we don't need it anymore.

src/shared/obj-bin-transform.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,4 +881,27 @@ class PatternInfo {
881881
throw new Error(`Unsupported pattern kind: ${kind}`);
882882
}
883883
}
884-
export { CssFontInfo, FontInfo, PatternInfo, SystemFontInfo };
884+
885+
class FontPathInfo {
886+
static write(path) {
887+
console.log(path);
888+
const buffer = new ArrayBuffer(path.length * 2);
889+
const data = new Float16Array(buffer);
890+
data.set(path);
891+
return buffer;
892+
}
893+
894+
#buffer;
895+
896+
constructor(buffer) {
897+
this.#buffer = buffer;
898+
}
899+
900+
get path() {
901+
const array = new Float16Array(this.#buffer);
902+
console.log(array);
903+
return array;
904+
}
905+
}
906+
907+
export { CssFontInfo, FontInfo, FontPathInfo, PatternInfo, SystemFontInfo };

0 commit comments

Comments
 (0)