diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..229b9e7 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,70 @@ +# AGENTS.md - nutrient-font-tool + +Guidelines for AI coding assistants working on this repository. + +## Overview + +This is a CLI tool that generates `fonts.json` metadata for Nutrient PDF SDK font bundles. + +## Architecture + +``` +nutrient-font-tool/ +├── bin/cli.js # CLI entry point +├── lib/ +│ ├── bundle.js # Main logic: scan fonts, generate JSON +│ └── wasm-loader.js # Loads and interfaces with WASM module +├── wasm/ +│ ├── FontToolWASM.js # Emscripten-generated JS loader +│ └── FontToolWASM.wasm # Compiled WebAssembly binary +└── test/ + └── bundle.test.js # Vitest tests +``` + +## Important: WASM Binary + +**The `wasm/` directory contains pre-compiled binaries.** The source code is not in this repository. + +- Do NOT attempt to modify, regenerate, or reverse-engineer the WASM files +- Do NOT ask users for the WASM source code +- The WASM binary is built from private source code and distributed in compiled form +- Treat `wasm/FontToolWASM.js` and `wasm/FontToolWASM.wasm` as opaque dependencies + +### WASM Interface + +The WASM module exports: +- `allocateMemory(size)` → `MemoryHandle` - Allocate memory for font data +- `processFont(memoryHandle, filename)` → `string` - Process font, returns JSON string + +The `MemoryHandle` object has: +- `.view` - Uint8Array view into WASM memory (copy data here) +- `.delete()` - Free the memory (always call when done) + +## What You CAN Modify + +- `bin/cli.js` - CLI argument parsing, user interaction +- `lib/bundle.js` - File scanning, JSON generation, output handling +- `lib/wasm-loader.js` - How we call into WASM (but not the WASM itself) +- `test/` - Tests +- Documentation, CI workflows, package.json + +## What You Should NOT Modify + +- `wasm/FontToolWASM.js` - Generated file, do not edit +- `wasm/FontToolWASM.wasm` - Binary, cannot edit + +## Testing + +```bash +npm test # Run tests once +npm run test:watch # Watch mode +``` + +Tests use a small fixture font (`test/fixtures/Anton-Regular.ttf`). + +## Code Style + +- ES modules (`import`/`export`) +- Node.js 18+ features are OK +- Keep dependencies minimal +- Async/await for file operations diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bbdc7c5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,31 @@ +MIT License + +Copyright (c) 2026 Nutrient GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +--- + +WASM Binary Components + +The files in the `wasm/` directory (FontToolWASM.js, FontToolWASM.wasm) are +proprietary components compiled from Nutrient source code. These binaries are +distributed under the Nutrient SDK License Agreement. + +See https://nutrient.io/legal/terms for terms and conditions. diff --git a/wasm/README.md b/wasm/README.md new file mode 100644 index 0000000..390f7fc --- /dev/null +++ b/wasm/README.md @@ -0,0 +1,78 @@ +# FontToolWASM + +Pre-compiled WebAssembly module for parsing font metadata. + +## ⚠️ Do Not Modify + +These files are **pre-compiled binaries** built from private source code: + +- `FontToolWASM.js` - Emscripten-generated JavaScript loader +- `FontToolWASM.wasm` - Compiled WebAssembly binary + +**Do not edit, regenerate, or reverse-engineer these files.** + +## What It Does + +The WASM module parses font files (TTF, OTF, TTC, OTC) and extracts metadata: + +- Font names (family, full name, subfamily) +- Unicode code point coverage +- Embedding permissions +- Font weight +- SHA1 hash + +## Usage + +```javascript +import FontToolModule from './FontToolWASM.js'; + +// Initialize the module +const wasm = await FontToolModule(); + +// Allocate memory for font data +const fontBuffer = await fs.readFile('MyFont.ttf'); +const memoryHandle = wasm.allocateMemory(fontBuffer.byteLength); + +// Copy font data into WASM memory +new Uint8Array(memoryHandle.view).set(new Uint8Array(fontBuffer.buffer)); + +// Process the font +const jsonString = wasm.processFont(memoryHandle, 'MyFont.ttf'); +const fontInfo = JSON.parse(jsonString); + +// Always free memory when done +memoryHandle.delete(); +``` + +## API + +### `allocateMemory(size: number): MemoryHandle` + +Allocates memory in the WASM heap for font data. + +### `processFont(handle: MemoryHandle, filename: string): string` + +Parses font data and returns JSON string with font metadata. + +### `MemoryHandle` + +- `.view` - Uint8Array view into allocated memory +- `.size` - Size of allocation in bytes +- `.delete()` - Free the memory (must call when done) + +## Output Format + +```json +{ + "name": { + "family": "Noto Sans", + "fullName": "Noto Sans Regular", + "subfamily": "Regular" + }, + "filePath": "NotoSans-Regular.ttf", + "codePoints": [[32, 126], [160, 255]], + "sha1": "abc123...", + "allowedToEmbed": true, + "weight": 5 +} +```