Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Font Engine Inspector

Real-time font rendering comparison for fonts.sanchaya.net

Compare how your Kannada fonts render across HarfBuzz and your browser, in real-time.

Upload a .ttf or .otf font and instantly see:

  • Native browser rendering (your platform: Safari, Chrome, Firefox, Edge)
  • HarfBuzz reference rendering (ground-truth text shaping engine)
  • Side-by-side comparison with overlay/diff modes
  • Raw glyph metrics (advances, offsets, clusters) for debugging

No pre-generation, no static images β€” pure on-demand rendering.


πŸš€ Quick Start (5 minutes)

Requirements

  • Node.js 16+
  • Python 3.10+
  • npm or yarn

Setup

  1. Clone the repo

    git clone https://github.com/sanchaya/font-engine-inspector.git
    cd font-engine-inspector
  2. Install dependencies

    npm install
    pip install -r requirements.txt --break-system-packages
  3. Run

    npm start
    # Server running on http://localhost:3000
    # View: http://localhost:3000/engine-inspector
  4. Test

    • Upload a Kannada .ttf font
    • Enter test text (try: ΰ²•ΰ²°ΰ³ΰ²¨ΰ²Ύΰ²Ÿΰ²• or ಕ್ಷ)
    • Click Render
    • See results instantly

πŸ“ Project Structure

.
β”œβ”€β”€ src/
β”‚   └── app.js                 # Express.js main app
β”œβ”€β”€ routes/
β”‚   └── engine-inspector.js    # API endpoints (/api/render/hb, /api/test-strings)
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ index.html             # Sanchaya-branded viewer UI
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── sanchaya-theme.css # Deep blue, gold, Kannada-inspired styling
β”‚   β”œβ”€β”€ js/                    # (future: client-side utilities)
β”‚   └── fonts/                 # (optional: reference fonts)
β”œβ”€β”€ bin/
β”‚   └── render-harfbuzz.py     # Python worker: HarfBuzz + FreeType rendering
β”œβ”€β”€ docs/                      # Documentation
β”œβ”€β”€ tests/                      # Unit tests
└── package.json


🎨 Features

Interactive Viewer

  • Drag-and-drop font upload (or file picker)
  • Live text input β€” modify test string, see results
  • Font size slider (12px–200px)
  • OpenType feature toggle β€” enable/disable kern, liga, etc. in JSON format
  • Multiple view modes:
    • Side-by-side β€” browser native vs HarfBuzz
    • Overlay β€” red/blue fringing to spot positioning drift
  • Glyph inspector table β€” see advances, offsets, cluster IDs

Backend API

  • POST /api/render/hb β€” Render text with HarfBuzz + FreeType

    • Accepts multipart font upload or reference to existing font
    • Returns PNG as base64 + raw glyph metrics
  • GET /api/test-strings β€” Curated Kannada test cases

    • 7 categories: conjuncts, reph, vattu, matras, punctuation, mixed text, long passage
    • ~31 test strings targeting real-world kerning trouble spots

Sanchaya Branding

  • Deep blue & gold color palette (Indian heritage aesthetic)
  • Kannada typography integrated in headers
  • Professional UI β€” matches fonts.sanchaya.net design language
  • Responsive design β€” works on mobile, tablet, desktop

πŸ”§ Configuration

Environment Variables

Create a .env file:

# Port to run on (default: 3000)
PORT=3000

# Environment (development or production)
NODE_ENV=development

# Path to fonts directory (optional)
FONTS_DIR=./public/fonts

Python Render Script

The bin/render-harfbuzz.py script is called by Node via subprocess. It:

  1. Loads a font with HarfBuzz
  2. Shapes text (produces glyph IDs, advances, offsets)
  3. Rasterizes glyphs with FreeType
  4. Outputs PNG + JSON glyph data

Usage directly:

python3 bin/render-harfbuzz.py <font.ttf> <text> <output.png> [size] [script] [language] [features]

Example:

python3 bin/render-harfbuzz.py fonts/Kannada.ttf "ಕನ್ನ಑" /tmp/out.png 64 "Knda" "kan" '{"kern": 1}'

πŸ“Š API Reference

POST /api/render/hb

Multipart file upload:

curl -X POST http://localhost:3000/api/render/hb \
  -F "fontFile=@font.ttf" \
  -F "text=ಕನ್ನ಑" \
  -F "fontSize=72" \
  -F "features={\"kern\": 1}"

JSON (for existing fonts):

curl -X POST http://localhost:3000/api/render/hb \
  -H "Content-Type: application/json" \
  -d '{
    "fontPath": "Kannada.ttf",
    "text": "ಕನ್ನ಑",
    "fontSize": 72,
    "script": "Knda",
    "language": "kan",
    "features": {"kern": 1, "liga": 0}
  }'

Response:

{
  "ok": true,
  "image": "data:image/png;base64,...",
  "width": 320,
  "height": 100,
  "glyph_count": 5,
  "font_size": 72,
  "padding": 20,
  "glyphs": [
    {
      "glyph_id": 12,
      "cluster": 0,
      "x_advance": 450,
      "y_advance": 0,
      "x_offset": 0,
      "y_offset": 0
    },
    ...
  ]
}

GET /api/test-strings

Returns curated Kannada test strings organized by category.

curl http://localhost:3000/api/test-strings

Response:

{
  "sets": [
    {
      "id": "conjuncts",
      "label": "Conjuncts (Ottakshara)",
      "note": "Full ligature conjuncts...",
      "strings": ["ಕ್ಷ", "ಜ್ಞ", "ಀ್ರ", ...]
    },
    ...
  ]
}

⚑ Performance

  • First render: ~500ms (Python startup overhead)
  • Subsequent renders: ~200ms (fast shaping/rasterization)
  • Browser native render: <50ms (Canvas 2D)
  • Total UI response: <1 second per render

For production with heavy load, consider:

  • Caching renders by font MD5 + text hash
  • Worker pool to keep Python processes warm
  • Rate limiting to prevent abuse (e.g., 1 render per user per 500ms)

🌍 Deployment

Docker

FROM node:18-bullseye

RUN apt-get update && apt-get install -y python3 python3-pip

WORKDIR /app
COPY . .
RUN npm install
RUN pip install -r requirements.txt

EXPOSE 3000
CMD ["npm", "start"]

Railway, Render, Vercel (with serverless limits)

⚠️ Note: Python subprocess (HarfBuzz rendering) may timeout on serverless platforms. Recommended for traditional VPS/container deployment.

Production Checklist

  • Set NODE_ENV=production
  • Configure PORT in environment
  • Enable CORS if serving on different domain
  • Add rate limiting middleware
  • Enable request logging
  • Set up error monitoring (e.g., Sentry)
  • Cache renders (Redis or in-memory)
  • Test with real-world font files

πŸ§ͺ Testing

# Run Node tests
npm test

# Lint code
npm run lint

# Test Python render script directly
python3 bin/render-harfbuzz.py public/fonts/Kannada.ttf "ಕನ್ನ಑" /tmp/test.png 72

🀝 Contributing

Contributions welcome! Areas for improvement:

  • Add more test strings for other Indic scripts
  • Support for macOS CoreText / Windows DirectWrite rendering
  • Caching layer for high-traffic deployments
  • WebSocket support for real-time font editing
  • Support for variable fonts (wght, wdth axes)
  • Export comparison reports as PDF

Please open issues on GitHub.


πŸ“œ License

MIT License β€” Free for commercial and non-commercial use.

Uses open-source libraries:

πŸ“ž Support


Happy font testing! 🎨

About

Real-time font rendering comparison for fonts.sanchaya.net

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages