Skip to content

Commit 692031c

Browse files
ryzokukenAditi-1400
authored andcommitted
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 692031c

File tree

5 files changed

+496
-411
lines changed

5 files changed

+496
-411
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: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { assert, MeshFigureType } from "./util.js";
16+
import { assert, FeatureTest, MeshFigureType } from "./util.js";
1717

1818
class CssFontInfo {
1919
#buffer;
@@ -881,4 +881,39 @@ 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+
let data;
888+
let buffer;
889+
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
890+
buffer = new ArrayBuffer(path.length * 2);
891+
data = new Float32Array(buffer);
892+
} else if (FeatureTest.isFloat16ArraySupported) {
893+
buffer = new ArrayBuffer(path.length * 2);
894+
data = new Float16Array(buffer);
895+
} else {
896+
buffer = new ArrayBuffer(path.length * 4);
897+
data = new Float32Array(buffer);
898+
}
899+
data.set(path);
900+
return buffer;
901+
}
902+
903+
#buffer;
904+
905+
constructor(buffer) {
906+
this.#buffer = buffer;
907+
}
908+
909+
get path() {
910+
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
911+
return new Float16Array(this.#buffer);
912+
}
913+
return FeatureTest.isFloat16ArraySupported
914+
? new Float16Array(this.#buffer)
915+
: new Float32Array(this.#buffer);
916+
}
917+
}
918+
919+
export { CssFontInfo, FontInfo, FontPathInfo, PatternInfo, SystemFontInfo };

0 commit comments

Comments
 (0)