MCPcopy
hub / github.com/jimp-dev/jimp / loadBitmapFontData

Function loadBitmapFontData

plugins/plugin-print/src/load-bitmap-font.ts:87–133  ·  view source on GitHub ↗
(
  bufferOrUrl: string | Buffer
)

Source from the content-addressed store, hash-verified

85 * @returns
86 */
87export async function loadBitmapFontData(
88 bufferOrUrl: string | Buffer
89): Promise<LoadedFont> {
90 if (isWebWorker && typeof bufferOrUrl === "string") {
91 const res = await fetch(bufferOrUrl);
92 const text = await res.text();
93 const json = convertXML(text);
94
95 const font = json.font.children.reduce(
96 // eslint-disable-next-line @typescript-eslint/no-explicit-any
97 (acc: Record<string, any>, i: any) => ({ ...acc, ...i }),
98 {}
99 );
100 const pages: LoadedFont["pages"] = [];
101 const chars: LoadedFont["chars"] = [];
102 const kernings: LoadedFont["kernings"] = [];
103
104 for (let i = 0; i < font.pages.children.length; i++) {
105 const p = font.pages.children[i].page;
106 const id = parseInt(p.id, 10);
107 pages[id] = parseNumbersInObject(p.file);
108 }
109
110 for (let i = 0; i < font.chars.children.length; i++) {
111 chars.push(parseNumbersInObject(font.chars.children[i].char));
112 }
113
114 for (let i = 0; i < font.kernings.children.length; i++) {
115 kernings.push(parseNumbersInObject(font.kernings.children[i].kerning));
116 }
117
118 return {
119 info: font.info,
120 common: font.common,
121 pages,
122 chars,
123 kernings,
124 } satisfies LoadedFont;
125 } else if (typeof bufferOrUrl === "string") {
126 const res = await fetch(bufferOrUrl);
127 const text = await res.text();
128
129 return parseFont(bufferOrUrl, text);
130 } else {
131 return parseFont("", bufferOrUrl);
132 }
133}
134
135type RawFont = Awaited<ReturnType<typeof loadBitmapFontData>>;
136export type ResolveBmFont = Omit<BmFont, "pages"> & Pick<RawFont, "pages">;

Callers 1

loadFontFunction · 0.85

Calls 2

parseNumbersInObjectFunction · 0.85
parseFontFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…