Skip to content

Open source CapCut alternative.

TypeScript

feat(cut): bundle Prompt Black for a font cycle's heavy geometric face

David Lea26a77c808c2
diff --git a/site/package-lock.json b/site/package-lock.json
index bbb65edf..c228f59f 100644
--- a/site/package-lock.json
+++ b/site/package-lock.json
@@ -56,6 +56,7 @@
"@fontsource/permanent-marker": "^5.3.0",
"@fontsource/playfair-display": "^5.3.0",
"@fontsource/poppins": "^5.3.0",
+ "@fontsource/prompt": "^5.3.0",
"@fontsource/roboto": "^5.3.0",
"@fontsource/roboto-mono": "^5.3.0",
"@fontsource/rubik": "^5.3.0",
@@ -2834,6 +2835,15 @@
"url": "https://github.com/sponsors/ayuhito"
}
},
+ "node_modules/@fontsource/prompt": {
+ "version": "5.3.0",
+ "resolved": "https://registry.npmjs.org/@fontsource/prompt/-/prompt-5.3.0.tgz",
+ "integrity": "sha512-cU4VVn7G0wSI3pu3a7tynpTQ5hk3Lm9nEjTOBLhVYsqbOlvVIj6Tc1f3450BOGSpDiPOxmYGj/D7rE/z/TYPJg==",
+ "license": "OFL-1.1",
+ "funding": {
+ "url": "https://github.com/sponsors/ayuhito"
+ }
+ },
"node_modules/@fontsource/roboto": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/@fontsource/roboto/-/roboto-5.3.0.tgz",
diff --git a/site/package.json b/site/package.json
index ef81c6a8..1b437ddb 100644
--- a/site/package.json
+++ b/site/package.json
@@ -98,6 +98,7 @@
"@fontsource/permanent-marker": "^5.3.0",
"@fontsource/playfair-display": "^5.3.0",
"@fontsource/poppins": "^5.3.0",
+ "@fontsource/prompt": "^5.3.0",
"@fontsource/roboto": "^5.3.0",
"@fontsource/roboto-mono": "^5.3.0",
"@fontsource/rubik": "^5.3.0",
diff --git a/site/scripts/stage-cut-fonts.mjs b/site/scripts/stage-cut-fonts.mjs
index f9d52b87..4449a93f 100644
--- a/site/scripts/stage-cut-fonts.mjs
+++ b/site/scripts/stage-cut-fonts.mjs
@@ -73,6 +73,7 @@ const FAMILIES = [
{ id: "rubik", label: "Rubik", family: "Rubik", weights: [400, 500, 700, 900] },
{ id: "jost", label: "Jost", family: "Jost", weights: [400, 500, 600, 700] },
{ id: "gloria-hallelujah", label: "Gloria Hallelujah", family: "Gloria Hallelujah", weights: [400] },
+ { id: "prompt", label: "Prompt", family: "Prompt", weights: [900] },
{
family: "Roboto",
weights: [400, 500, 600, 700],
diff --git a/site/src/cut/lib/fixtures/font-cycle-heavy-geometric.webp b/site/src/cut/lib/fixtures/font-cycle-heavy-geometric.webp
new file mode 100644
index 00000000..2948879f
Binary files /dev/null and b/site/src/cut/lib/fixtures/font-cycle-heavy-geometric.webp differ
diff --git a/site/src/cut/lib/fontCatalog.ts b/site/src/cut/lib/fontCatalog.ts
index 1a74f4fe..5fbf21f6 100644
--- a/site/src/cut/lib/fontCatalog.ts
+++ b/site/src/cut/lib/fontCatalog.ts
@@ -49,6 +49,7 @@ export const GOOGLE_FONTS: BundledFont[] = [
{ id: "rubik", label: "Rubik", weights: [400, 500, 700, 900] },
{ id: "jost", label: "Jost", weights: [400, 500, 600, 700] },
{ id: "gloria-hallelujah", label: "Gloria Hallelujah", weights: [400] },
+ { id: "prompt", label: "Prompt", weights: [900] },
];
export const GOOGLE_FONT_IDS = GOOGLE_FONTS.map((f) => f.id);
diff --git a/site/src/cut/lib/fontMatch.test.ts b/site/src/cut/lib/fontMatch.test.ts
index 0dee5214..dbfdfd3e 100644
--- a/site/src/cut/lib/fontMatch.test.ts
+++ b/site/src/cut/lib/fontMatch.test.ts
@@ -1,11 +1,14 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
-import { Canvas, FontLibrary } from "skia-canvas";
+import { createRequire } from "node:module";
+import path from "node:path";
+import { Canvas, FontLibrary, loadImage } from "skia-canvas";
/** skia's font registry, under a name the hook lint leaves alone. */
const fontLibrary = FontLibrary;
import { SETTINGS } from "@/lib/config/registry";
import { setRasterFactory, type RasterFactory, type RasterSurface } from "./raster";
-import { inkMaskOf, rankFaces, type TitleFace } from "./fontMatch";
+import { GOOGLE_FONTS } from "./fontCatalog";
+import { bundledFaces, inkMaskOf, rankFaces, type TitleFace } from "./fontMatch";
import { fontStack, registerFonts } from "./types";
// Which bundled face a piece of type on a reference frame is set in: the
@@ -137,3 +140,45 @@ describe("font suggestions", () => {
await expect(rankFaces(ref, "TRAVEL DESTINATION", CANDIDATES, fontStack)).rejects.toThrow(/2 lines/);
});
});
+
+// Type cut off a reference itself: a reel whose "TRAVEL DESTINATION" title
+// cycles through faces. Each fixture is one held frame's title line, at the
+// frame's own pixels, ranked against every bundled family at its bundled
+// weights, the candidates suggest_font hands rankFaces. The system set is
+// left out: it draws in whatever faces the host has.
+describe("faces off a reference frame", () => {
+ const resolve = createRequire(import.meta.url).resolve;
+ const pkg = (label: string) => label.toLowerCase().replace(/[^a-z0-9]+/g, "-");
+ let catalog: TitleFace[] = [];
+
+ beforeAll(() => {
+ for (const f of GOOGLE_FONTS) {
+ const p = pkg(f.label);
+ const files = path.join(path.dirname(resolve(`@fontsource/${p}/package.json`)), "files");
+ const face = (w: number, style: string) => path.join(files, `${p}-latin-${w}-${style}.woff2`);
+ fontLibrary.use(f.label, [...f.weights.map((w) => face(w, "normal")), ...(f.italics ?? []).map((w) => face(w, "italic"))]);
+ registerFonts([{ id: f.id, label: f.label, stack: `"${f.label}"` }]);
+ }
+ const ids = new Set(GOOGLE_FONTS.map((f) => f.id));
+ catalog = bundledFaces().filter((f) => ids.has(f.font));
+ });
+
+ async function frameInk(name: string) {
+ const img = await loadImage(new URL(`./fixtures/${name}`, import.meta.url).pathname);
+ const c = new Canvas(img.width, img.height);
+ const ctx = c.getContext("2d");
+ ctx.drawImage(img, 0, 0);
+ const d = ctx.getImageData(0, 0, img.width, img.height);
+ return inkMaskOf(d.data, d.width, d.height);
+ }
+
+ test("the cycle's heavy geometric face matches Prompt Black", async () => {
+ // Held from 6.57 s to 6.87 s, yellow on purple, 85 px of crop. Before
+ // Prompt was bundled the closest face was Montserrat Black at 0.70, under
+ // the good mark, so the tool said nothing bundled matched.
+ const ranked = await rankFaces(await frameInk("font-cycle-heavy-geometric.webp"), "TRAVEL DESTINATION", catalog, fontStack);
+ expect(ranked[0]).toMatchObject({ font: "prompt", weight: 900 });
+ expect(ranked[0].score).toBeGreaterThanOrEqual(good);
+ expect(ranked.find((m) => m.font !== "prompt")!.score).toBeLessThan(good);
+ });
+});
diff --git a/site/src/cut/lib/googleFonts.ts b/site/src/cut/lib/googleFonts.ts
index 8aaabc0d..921076a6 100644
--- a/site/src/cut/lib/googleFonts.ts
+++ b/site/src/cut/lib/googleFonts.ts
@@ -88,6 +88,8 @@ import "@fontsource/jost/500.css";
import "@fontsource/jost/600.css";
import "@fontsource/jost/700.css";
import "@fontsource/gloria-hallelujah/400.css";
+// Black only: the heavy geometric face of a reference's font cycle.
+import "@fontsource/prompt/900.css";
import { GOOGLE_FONTS } from "./fontCatalog";
import { registerFonts } from "./types";