Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/fallbacks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ The full structured rows are exported as `SUBSTITUTION_EVIDENCE` for richer repo

These maintainer tools use ignored `.cache` files and are not shipped in the package.

`bun run acquire` downloads open-font candidates into `.cache/sources`. Sources come in two shapes: zip archives and pinned source trees. Set `DOCFONTS_SOURCE_CACHE` to use another cache directory, or pass `--source google-fonts` to acquire one source.
`bun run acquire` downloads open-font candidates into `.cache/sources`. Sources come in two shapes: release archives (zip or tar.gz) and pinned source trees. Set `DOCFONTS_SOURCE_CACHE` to use another cache directory, or pass `--source google-fonts` to acquire one source.

`bun run compare` checks a private reference font against acquired OTF/TTF candidates and prints a ranked Latin advance-width table. It writes no fonts, paths, or results to the tree.

Expand Down
67 changes: 67 additions & 0 deletions packages/fallbacks/acquire.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ describe("source acquisition catalog", () => {
"AGPL-3.0-FE",
"Apache-2.0",
"UFL-1.0",
"GPL-2.0-FE",
"Bitstream-Vera-DejaVu",
]);
for (const source of SOURCE_RELEASES) {
expect(source.sourceId).toMatch(/^[a-z0-9]+(-[a-z0-9]+)*$/);
Expand All @@ -38,6 +40,8 @@ describe("source acquisition catalog", () => {
expect(allowedLicenses.has(source.licenseFamily)).toBe(true);
expect(source.downloadUrl.startsWith("https://")).toBe(true);
expect(source.expectedFiles.length).toBeGreaterThan(0);
if (source.archiveFormat !== undefined)
expect(["zip", "tar.gz"]).toContain(source.archiveFormat);
}
}
});
Expand Down Expand Up @@ -111,6 +115,69 @@ describe("source acquisition catalog", () => {
]);
});

test("carries the priority Liberation, Selawik, and DejaVu sources", () => {
const byId = new Map(
SOURCE_RELEASES.map((source) => [source.sourceId, source]),
);
for (const id of [
"liberation-fonts",
"liberation-sans-narrow",
"selawik",
"dejavu",
])
expect(byId.has(id)).toBe(true);
});

test("declares tar.gz sources and defaults the rest to zip", () => {
const byId = new Map(
SOURCE_RELEASES.map((source) => [source.sourceId, source]),
);
const archiveFormatOf = (id: string) => {
const source = byId.get(id);
if (!source || source.kind === "github-tree") return undefined;
return source.archiveFormat ?? "zip";
};

expect(archiveFormatOf("liberation-fonts")).toBe("tar.gz");
expect(archiveFormatOf("liberation-sans-narrow")).toBe("tar.gz");
expect(archiveFormatOf("selawik")).toBe("zip");
expect(archiveFormatOf("dejavu")).toBe("zip");
// Pre-existing sources never set the field, so they keep extracting as zip.
expect(archiveFormatOf("urw-base35")).toBe("zip");
expect(byId.get("urw-base35")).not.toHaveProperty("archiveFormat");
});

test("anchors every Selawik 1.01 TTF, WOFF, and WOFF2 member", () => {
const source = SOURCE_RELEASES.find(
(candidate) => candidate.sourceId === "selawik",
);
expect(source?.kind !== "github-tree").toBe(true);
if (!source || source.kind === "github-tree") return;

// Selawik 1.01 ships five weights, each as .ttf, .woff, and .woff2.
const weights = ["selawk", "selawkb", "selawkl", "selawksb", "selawksl"];
const expected = weights.flatMap((stem) => [
`${stem}.ttf`,
`${stem}.woff`,
`${stem}.woff2`,
]);
expect([...source.expectedFiles].sort()).toEqual([...expected].sort());
});

test("uses the GPL font exception and DejaVu license families", () => {
const byId = new Map(
SOURCE_RELEASES.map((source) => [source.sourceId, source]),
);
const narrow = byId.get("liberation-sans-narrow");
const dejavu = byId.get("dejavu");
expect(narrow?.kind !== "github-tree" && narrow?.licenseFamily).toBe(
"GPL-2.0-FE",
);
expect(dejavu?.kind !== "github-tree" && dejavu?.licenseFamily).toBe(
"Bitstream-Vera-DejaVu",
);
});

test("spans more than one project and license family", () => {
expect(
new Set(SOURCE_RELEASES.map((source) => source.project)).size,
Expand Down
52 changes: 52 additions & 0 deletions packages/fallbacks/compare.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect, test } from "bun:test";
import { execFileSync } from "node:child_process";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
Expand Down Expand Up @@ -465,3 +466,54 @@ describe("collectCandidates (GitHub tree sources)", () => {
}
});
});

describe("collectCandidates (archive sources)", () => {
test("reads tar.gz archive sources from the acquire snapshot format", () => {
const cacheDir = mkdtempSync(join(tmpdir(), "docfonts-tar-source-"));
try {
const sourceId = "tar-example";
const root = join(cacheDir, "archive-root");
mkdirSync(join(root, "fonts"), { recursive: true });
writeFileSync(
join(root, "fonts", "Example-Regular.ttf"),
syntheticFont(),
);
writeFileSync(
join(root, "fonts", "Example.woff"),
new Uint8Array([1, 2]),
);
execFileSync(
"tar",
[
"-czf",
join(cacheDir, `${sourceId}.tar.gz`),
"-C",
root,
"fonts/Example-Regular.ttf",
"fonts/Example.woff",
],
{ stdio: "ignore" },
);

const source: SnapshotSource = {
sourceId,
family: "Example",
targetFamilies: ["Some Proprietary"],
kind: "archive",
archiveFormat: "tar.gz",
};

const candidates = collectCandidates(source, cacheDir);
expect(candidates.map((candidate) => candidate.file)).toEqual([
"Example-Regular.ttf",
]);
const score = scoreAdvances(
sampleMetrics(parseFont(syntheticFont())),
sampleMetrics(parseFont(candidates[0].bytes)),
);
expect(score.tier).toBe("metric_safe");
} finally {
rmSync(cacheDir, { recursive: true, force: true });
}
});
});
Loading
Loading