mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-25 08:27:19 +02:00
Merge pull request #21599 from Snuffleupagus/CompiledFont-rm-hasBuiltPath
Combine the `getPathJs` and `hasBuiltPath` methods in the `CompiledFont` class
This commit is contained in:
commit
5266f13ea4
@ -33,10 +33,6 @@ import {
|
||||
import { CheckedOperatorList, OperatorList } from "./operator_list.js";
|
||||
import { CMapFactory, IdentityCMap } from "./cmap.js";
|
||||
import { Cmd, Dict, EOF, isName, Name, Ref, RefSet } from "./primitives.js";
|
||||
import {
|
||||
compileFontPathInfo,
|
||||
compilePatternInfo,
|
||||
} from "./obj_bin_transform_core.js";
|
||||
import {
|
||||
compileType3Glyph,
|
||||
FontFlags,
|
||||
@ -83,6 +79,7 @@ import { BaseStream } from "./base_stream.js";
|
||||
import { bidi } from "./bidi.js";
|
||||
import { ColorSpace } from "./colorspace.js";
|
||||
import { ColorSpaceUtils } from "./colorspace_utils.js";
|
||||
import { compilePatternInfo } from "./obj_bin_transform_core.js";
|
||||
import { getFontSubstitution } from "./font_substitutions.js";
|
||||
import { getGlyphsUnicode } from "./glyphlist.js";
|
||||
import { getMetrics } from "./metrics.js";
|
||||
@ -4809,10 +4806,10 @@ class PartialEvaluator {
|
||||
function buildPath(fontChar) {
|
||||
const glyphName = `${font.loadedName}_path_${fontChar}`;
|
||||
try {
|
||||
if (font.renderer.hasBuiltPath(fontChar)) {
|
||||
return;
|
||||
const buffer = font.renderer.getPath(fontChar);
|
||||
if (!buffer) {
|
||||
return; // Previously compiled, and sent to the main-thread.
|
||||
}
|
||||
const buffer = compileFontPathInfo(font.renderer.getPathJs(fontChar));
|
||||
handler.send("commonobj", [glyphName, "FontPath", buffer], [buffer]);
|
||||
} catch (reason) {
|
||||
if (evaluatorOptions.ignoreErrors) {
|
||||
|
||||
@ -26,6 +26,7 @@ import {
|
||||
warn,
|
||||
} from "../shared/util.js";
|
||||
import { CFFParser } from "./cff_parser.js";
|
||||
import { compileFontPathInfo } from "./obj_bin_transform_core.js";
|
||||
import { getGlyphsUnicode } from "./glyphlist.js";
|
||||
import { isNumberArray } from "./core_utils.js";
|
||||
import { StandardEncoding } from "./encodings.js";
|
||||
@ -781,9 +782,9 @@ class Commands {
|
||||
}
|
||||
|
||||
class CompiledFont {
|
||||
#compiledGlyphs = new Map();
|
||||
#compiledCharCodes = new Set();
|
||||
|
||||
#compiledCharCodeToGlyphId = new Map();
|
||||
#compiledGlyphs = new Map();
|
||||
|
||||
constructor(fontMatrix) {
|
||||
if (
|
||||
@ -806,9 +807,16 @@ class CompiledFont {
|
||||
);
|
||||
}
|
||||
|
||||
getPathJs(unicode) {
|
||||
getPath(unicode) {
|
||||
const { charCode, glyphId } = lookupCmap(this.cmap, unicode);
|
||||
|
||||
if (
|
||||
this.#compiledGlyphs.has(glyphId) &&
|
||||
this.#compiledCharCodes.has(charCode)
|
||||
) {
|
||||
return null; // Previously compiled.
|
||||
}
|
||||
|
||||
const path = this.#compiledGlyphs.getOrInsertComputed(glyphId, () => {
|
||||
try {
|
||||
return this.compileGlyph(this.glyphs[glyphId], glyphId);
|
||||
@ -816,12 +824,12 @@ class CompiledFont {
|
||||
return ex; // Avoid attempting to re-compile a corrupt glyph.
|
||||
}
|
||||
});
|
||||
this.#compiledCharCodeToGlyphId.getOrInsert(charCode, glyphId);
|
||||
this.#compiledCharCodes.add(charCode);
|
||||
|
||||
if (path instanceof Error) {
|
||||
throw path;
|
||||
}
|
||||
return path;
|
||||
return compileFontPathInfo(path);
|
||||
}
|
||||
|
||||
compileGlyph(code, glyphId) {
|
||||
@ -854,14 +862,6 @@ class CompiledFont {
|
||||
compileGlyphImpl() {
|
||||
unreachable("Children classes should implement this.");
|
||||
}
|
||||
|
||||
hasBuiltPath(unicode) {
|
||||
const { charCode, glyphId } = lookupCmap(this.cmap, unicode);
|
||||
return (
|
||||
this.#compiledGlyphs.has(glyphId) &&
|
||||
this.#compiledCharCodeToGlyphId.has(charCode)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TrueTypeCompiled extends CompiledFont {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user