Skip to content

Conversation

@ryzokuken
Copy link
Collaborator

Serialize FontPath commands into a binary format
and store it in an ArrayBuffer so that it can
eventually be stored in a SharedArrayBuffer.

This PR is along the same lines as #20197 and #20340

@ryzokuken ryzokuken requested a review from calixteman October 8, 2025 11:52
@ryzokuken ryzokuken self-assigned this Oct 8, 2025
@calixteman
Copy link
Contributor

For the glyph paths, we should use the same format as "described" here:

pdf.js/src/display/canvas.js

Lines 1491 to 1520 in d83cbb2

if (!(path instanceof Path2D)) {
// Using a SVG string is slightly slower than using the following loop.
const path2d = (data[0] = new Path2D());
for (let i = 0, ii = path.length; i < ii; ) {
switch (path[i++]) {
case DrawOPS.moveTo:
path2d.moveTo(path[i++], path[i++]);
break;
case DrawOPS.lineTo:
path2d.lineTo(path[i++], path[i++]);
break;
case DrawOPS.curveTo:
path2d.bezierCurveTo(
path[i++],
path[i++],
path[i++],
path[i++],
path[i++],
path[i++]
);
break;
case DrawOPS.closePath:
path2d.closePath();
break;
default:
warn(`Unrecognized drawing path operator: ${path[i - 1]}`);
break;
}
}
path = path2d;

Using a SVG string is slightly slower and using this binary data would help to make the serialization a bit simpler.

@ryzokuken ryzokuken force-pushed the binary-fontpath branch 2 times, most recently from 6d74dda to 9d2b39d Compare October 14, 2025 13:52
@ryzokuken
Copy link
Collaborator Author

Thanks for the comments, @calixteman @timvandermeij they should be addressed now PTAL.

@Aditi-1400 Aditi-1400 force-pushed the binary-fontpath branch 2 times, most recently from 5991539 to 692031c Compare October 30, 2025 16:09
let buffer;
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
buffer = new ArrayBuffer(path.length * 2);
data = new Float32Array(buffer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it Float16Array ?


describe("FontPath data", function () {
let path;
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests don't run in m-c so this is useless.

Serialize FontPath commands into a binary format
and store it in an ArrayBuffer so that it can
eventually be stored in a SharedArrayBuffer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants