Skip to content

Commit

Permalink
remove ttc code that would have never worked
Browse files Browse the repository at this point in the history
browsers don't support ttc, neither does/will node-canvas or any
other (@napi-rs/canvas, skia-canvas) backend I know of
  • Loading branch information
chearon committed Jan 8, 2025
1 parent b6c232f commit aa45480
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions src/text-font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export class FaceMatch {
}
}

const registeredFonts = new Map<string, FaceMatch[]>();
const registeredFonts = new Map<string, FaceMatch>();

export interface RegisterFontOptions {
paint?: boolean;
Expand Down Expand Up @@ -502,34 +502,27 @@ export async function registerFont(
}

const blob = hb.createBlob(buffer);
const matches: FaceMatch[] = [];

for (let i = 0, l = blob.countFaces(); i < l; ++i) {
const match = new FaceMatch(blob, i, stringUrl);
// Browsers don't support registering collections because there would be
// no way to clearly associate one description with one buffer.
if (blob.countFaces() !== 1) {
throw new Error(`Error registering ${stringUrl}. Note that TTC fonts are not supported.`);
}

// Browsers don't support registering collections because there would be
// no way to clearly associate one description with one buffer. I suppose
// this should be enforced elsewhere too...
if (options.paint && i === 0 && l === 1) {
registerPaintFont(match, buffer, url);
}
const match = new FaceMatch(blob, 0, stringUrl);

matches.push(match);
}
if (options.paint) registerPaintFont(match, buffer, url);

registeredFonts.set(stringUrl, matches);
registeredFonts.set(stringUrl, match);

blob.destroy();
}
}

export function unregisterFont(url: URL): void {
const stringUrl = String(url);
const matches = registeredFonts.get(stringUrl);
if (matches) {
for (const match of matches) match.destroy();
registeredFonts.delete(stringUrl);
}
registeredFonts.get(stringUrl)?.destroy();
registeredFonts.delete(stringUrl);
cascades = new WeakMap();
}

Expand All @@ -542,12 +535,8 @@ class FontCascade {
this.style = style;
}

static fromSet(set: Map<string, FaceMatch[]>, style: Style) {
const list: FaceMatch[] = [];
for (const matches of set.values()) {
for (const match of matches) list.push(match);
}
return new FontCascade(list, style);
static fromSet(set: Map<string, FaceMatch>, style: Style) {
return new FontCascade([...set.values()], style);
}

static stretchToLinear: Record<FontStretch, number> = {
Expand Down Expand Up @@ -754,9 +743,7 @@ export function getCascade(style: Style, lang: string) {
}

export function eachRegisteredFont(cb: (family: FaceMatch) => void) {
for (const matches of registeredFonts.values()) {
for (const match of matches) cb(match);
}
for (const match of registeredFonts.values()) cb(match);
}

const systemFontTrie = new UnicodeTrie(wasm.instance.exports.system_font_trie.value);
Expand Down

0 comments on commit aa45480

Please sign in to comment.