Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import type { PathCommand } from "../types/typeface.js";
/**
* Serialises an array of PathCommand objects to the typeface.js outline string format.
* The outline string is space-separated tokens: "type [x y] [x1 y1] [x2 y2]".
* An optional scale factor is applied and coordinates are rounded to integers.
*/
export function outlineToString(commands: PathCommand[], scale = 1): string {
let result = "";
for (const cmd of commands) {
result += `${cmd.type} `;
if (cmd.x !== undefined && cmd.y !== undefined) {
result += `${Math.round(cmd.x * scale)} `;
result += `${Math.round(cmd.y * scale)} `;
}
if (cmd.x1 !== undefined && cmd.y1 !== undefined) {
result += `${Math.round(cmd.x1 * scale)} `;
result += `${Math.round(cmd.y1 * scale)} `;
}
if (cmd.x2 !== undefined && cmd.y2 !== undefined) {
result += `${Math.round(cmd.x2 * scale)} `;
result += `${Math.round(cmd.y2 * scale)} `;
}
}
return result;
}