Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
lookupMatrix,
lookupNormalRect,
} from "./core_utils.js";
import { FontInfo, FontPathInfo } from "../shared/obj-bin-transform.js";
import {
getEncoding,
MacRomanEncoding,
Expand Down Expand Up @@ -72,7 +73,6 @@ import { BaseStream } from "./base_stream.js";
import { bidi } from "./bidi.js";
import { ColorSpace } from "./colorspace.js";
import { ColorSpaceUtils } from "./colorspace_utils.js";
import { FontInfo } from "../shared/obj-bin-transform.js";
import { getFontSubstitution } from "./font_substitutions.js";
import { getGlyphsUnicode } from "./glyphlist.js";
import { getMetrics } from "./metrics.js";
Expand Down Expand Up @@ -4660,11 +4660,8 @@ class PartialEvaluator {
if (font.renderer.hasBuiltPath(fontChar)) {
return;
}
handler.send("commonobj", [
glyphName,
"FontPath",
font.renderer.getPathJs(fontChar),
]);
const buffer = FontPathInfo.write(font.renderer.getPathJs(fontChar));
handler.send("commonobj", [glyphName, "FontPath", buffer], [buffer]);
} catch (reason) {
if (evaluatorOptions.ignoreErrors) {
warn(`buildFontPaths - ignoring ${glyphName} glyph: "${reason}".`);
Expand Down
6 changes: 1 addition & 5 deletions src/core/font_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,10 +770,6 @@ class Commands {
restore() {
this.currentTransform = this.transformStack.pop() || [1, 0, 0, 1, 0, 0];
}

getSVG() {
return this.cmds.join("");
}
}

class CompiledFont {
Expand Down Expand Up @@ -836,7 +832,7 @@ class CompiledFont {
this.compileGlyphImpl(code, cmds, glyphId);
cmds.add("Z");

return cmds.getSVG();
return cmds.cmds;
}

compileGlyphImpl() {
Expand Down
4 changes: 3 additions & 1 deletion src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
StatTimer,
} from "./display_utils.js";
import { FontFaceObject, FontLoader } from "./font_loader.js";
import { FontInfo, FontPathInfo } from "../shared/obj-bin-transform.js";
import {
getDataProp,
getFactoryUrlProp,
Expand All @@ -67,7 +68,6 @@ import { DOMCMapReaderFactory } from "display-cmap_reader_factory";
import { DOMFilterFactory } from "./filter_factory.js";
import { DOMStandardFontDataFactory } from "display-standard_fontdata_factory";
import { DOMWasmFactory } from "display-wasm_factory";
import { FontInfo } from "../shared/obj-bin-transform.js";
import { GlobalWorkerOptions } from "./worker_options.js";
import { Metadata } from "./metadata.js";
import { OptionalContentConfig } from "./optional_content_config.js";
Expand Down Expand Up @@ -2803,6 +2803,8 @@ class WorkerTransport {
}
break;
case "FontPath":
this.commonObjs.resolve(id, new FontPathInfo(exportedData));
break;
case "Image":
case "Pattern":
this.commonObjs.resolve(id, exportedData);
Expand Down
2 changes: 1 addition & 1 deletion src/display/font_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class FontFaceObject {
} catch (ex) {
warn(`getPathGenerator - ignoring character: "${ex}".`);
}
const path = new Path2D(cmds || "");
const path = new Path2D(cmds?.getSVG() || "");

if (!this.fontExtraProperties) {
// Remove the raw path-string, since we don't need it anymore.
Expand Down
77 changes: 76 additions & 1 deletion src/shared/obj-bin-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,79 @@ class FontInfo {
}
}

export { CssFontInfo, FontInfo, SystemFontInfo };
class FontPathInfo {
static write(path) {
let lengthEstimate = 0;
const commands = [];
for (const cmd of path) {
const code = cmd.charCodeAt(0);
let args = null;
if (code === 67 || code === 76 || code === 77) {
args = cmd.slice(1).split(" ");
lengthEstimate += 1 + args.length * 8;
} else if (code === 90) {
lengthEstimate += 1;
} else {
throw new Error(`Invalid path command: ${cmd}`);
}
commands.push({ code, args });
}

const buffer = new ArrayBuffer(4 + lengthEstimate);
const view = new DataView(buffer);
let offset = 0;

view.setUint32(offset, commands.length);
offset += 4;
for (const { code, args } of commands) {
view.setUint8(offset, code);
offset += 1;
if (args) {
for (const arg of args) {
view.setFloat64(offset, parseFloat(arg), true);
offset += 8;
}
}
}

assert(offset === buffer.byteLength, "FontPathInfo.write: Buffer overflow");
return buffer;
}

#buffer;

#view;

constructor(buffer) {
this.#buffer = buffer;
this.#view = new DataView(this.#buffer);
}

getSVG() {
const length = this.#view.getUint32(0);
const cmds = [];
let offset = 4;
for (let i = 0; i < length; i++) {
const code = String.fromCharCode(this.#view.getUint8(offset));
offset += 1;
// eslint-disable-next-line no-nested-ternary
const numArgs = code === "M" || code === "L" ? 2 : code === "C" ? 6 : 0;
let args = null;
if (numArgs > 0) {
args = [];
for (let j = 0; j < numArgs; j++) {
args.push(this.#view.getFloat64(offset, true));
offset += 8;
}
}
cmds.push(code + (args ? args.join(" ") : ""));
}
assert(
offset === this.#buffer.byteLength,
"FontPathInfo.toString: Buffer overflow"
);
return cmds.join("");
}
}

export { CssFontInfo, FontInfo, FontPathInfo, SystemFontInfo };
164 changes: 0 additions & 164 deletions test/unit/bin_font_info_spec.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/clitests.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"app_options_spec.js",
"autolinker_spec.js",
"bidi_spec.js",
"bin_font_info_spec.js",
"canvas_factory_spec.js",
"cff_parser_spec.js",
"cmap_spec.js",
Expand All @@ -33,6 +32,7 @@
"murmurhash3_spec.js",
"network_utils_spec.js",
"node_stream_spec.js",
"obj_bin_transform_spec.js",
"parser_spec.js",
"pdf.image_decoders_spec.js",
"pdf.worker_spec.js",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/jasmine-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ async function initializePDFJS(callback) {
"pdfjs-test/unit/app_options_spec.js",
"pdfjs-test/unit/autolinker_spec.js",
"pdfjs-test/unit/bidi_spec.js",
"pdfjs-test/unit/bin_font_info_spec.js",
"pdfjs-test/unit/canvas_factory_spec.js",
"pdfjs-test/unit/cff_parser_spec.js",
"pdfjs-test/unit/cmap_spec.js",
Expand All @@ -76,6 +75,7 @@ async function initializePDFJS(callback) {
"pdfjs-test/unit/murmurhash3_spec.js",
"pdfjs-test/unit/network_spec.js",
"pdfjs-test/unit/network_utils_spec.js",
"pdfjs-test/unit/obj_bin_transform_spec.js",
"pdfjs-test/unit/parser_spec.js",
"pdfjs-test/unit/pdf.image_decoders_spec.js",
"pdfjs-test/unit/pdf.worker_spec.js",
Expand Down
Loading