Skip to content

Commit 4b1f64f

Browse files
committed
Change the NOOP fallback, in CompiledFont, to return a TypedArray
In PR 20367 the `CompiledFont.prototype.getPathJs` method was changed to return TypedArray data, however the `NOOP` fallback was (likely accidentally) left an empty string. The compilation of font-paths in PR 20346 was then implemented such that an empty string just happened to be ignored silently, however the assert added in PR 20894 allowed me to spot this return value inconsistency. *Please note:* Since this only applies to missing or broken glyphs, that wouldn't be rendered anyway, this doesn't show up in reference tests.
1 parent 979d9c3 commit 4b1f64f

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

src/core/font_renderer.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
FeatureTest,
2121
FONT_IDENTITY_MATRIX,
2222
FormatError,
23+
shadow,
2324
unreachable,
2425
Util,
2526
warn,
@@ -736,8 +737,6 @@ function compileCharString(charStringCode, cmds, font, glyphId) {
736737
parse(charStringCode);
737738
}
738739

739-
const NOOP = "";
740-
741740
class Commands {
742741
cmds = [];
743742

@@ -774,12 +773,13 @@ class Commands {
774773
}
775774

776775
getPath() {
777-
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
776+
if (
777+
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
778+
FeatureTest.isFloat16ArraySupported
779+
) {
778780
return new Float16Array(this.cmds);
779781
}
780-
return new (
781-
FeatureTest.isFloat16ArraySupported ? Float16Array : Float32Array
782-
)(this.cmds);
782+
return new Float32Array(this.cmds);
783783
}
784784
}
785785

@@ -797,6 +797,17 @@ class CompiledFont {
797797
this.compiledCharCodeToGlyphId = Object.create(null);
798798
}
799799

800+
static get NOOP() {
801+
return shadow(
802+
this,
803+
"NOOP",
804+
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
805+
FeatureTest.isFloat16ArraySupported
806+
? new Float16Array(0)
807+
: new Float32Array(0)
808+
);
809+
}
810+
800811
getPathJs(unicode) {
801812
const { charCode, glyphId } = lookupCmap(this.cmap, unicode);
802813
let fn = this.compiledGlyphs[glyphId],
@@ -805,7 +816,7 @@ class CompiledFont {
805816
try {
806817
fn = this.compileGlyph(this.glyphs[glyphId], glyphId);
807818
} catch (ex) {
808-
fn = NOOP; // Avoid attempting to re-compile a corrupt glyph.
819+
fn = CompiledFont.NOOP; // Avoid attempting to re-compile a corrupt glyph.
809820

810821
compileEx = ex;
811822
}
@@ -821,7 +832,7 @@ class CompiledFont {
821832

822833
compileGlyph(code, glyphId) {
823834
if (!code?.length || code[0] === 14) {
824-
return NOOP;
835+
return CompiledFont.NOOP;
825836
}
826837

827838
let fontMatrix = this.fontMatrix;

0 commit comments

Comments
 (0)