# Core Font Definition System

Core classes for programmatic font creation.

## Classes

### FontDefinition

Main class representing a complete font.

```javascript
const font = new FontDefinition('MyFont', {
  unitsPerEm: 1000,
  ascender: 800,
  descender: -200,
  xHeight: 500,
  capHeight: 700
});

// Add glyphs
font.addGlyph(glyphA);
font.addGlyph(glyphB);

// Add kerning
font.addKerning('A', 'V', -50);

// Set metadata
font.setMetadata({
  copyright: '© 2024',
  designer: 'Your Name'
});
```

### GlyphDefinition

Represents a single character/glyph.

```javascript
const glyphA = new GlyphDefinition('A', 600);

// Add contours
glyphA.createContour(contour => {
  contour.addPoint(100, 0, true);
  contour.addPoint(500, 0, true);
  contour.addPoint(300, 700, true);
  contour.close();
});
```

### Contour

Represents a path within a glyph.

```javascript
const contour = new Contour();
contour.addPoint(100, 0, true);    // on-curve point
contour.addPoint(500, 0, true);    // on-curve point
contour.addPoint(300, 700, true);  // on-curve point
contour.close();                   // Close the path
```

## Serialization

Use `FontSerializer` to save/load fonts:

```javascript
// Serialize to JSON
const json = FontSerializer.serialize(font);

// Deserialize from JSON
const font = FontSerializer.deserialize(json);

// Save to file (browser)
FontSerializer.saveToFile(font, 'myfont');

// Load from file (browser)
const font = await FontSerializer.loadFromFile(file);
```

## JSON Format

Fonts are serialized to a JSON format that can be used by both JavaScript and Python exporters:

```json
{
  "name": "MyFont",
  "familyName": "MyFont",
  "styleName": "Regular",
  "metrics": {
    "unitsPerEm": 1000,
    "ascender": 800,
    "descender": -200,
    "xHeight": 500,
    "capHeight": 700
  },
  "glyphs": {
    "A": {
      "char": "A",
      "unicode": 65,
      "width": 600,
      "contours": [
        {
          "points": [
            {"x": 100, "y": 0, "onCurve": true},
            {"x": 500, "y": 0, "onCurve": true},
            {"x": 300, "y": 700, "onCurve": true}
          ]
        }
      ]
    }
  },
  "kerning": {
    "AV": -50
  }
}
```
