PHP 8.2.30
Preview: GPOS.js Size: 6.41 KB
/home/byroehnu/.trash/node_modules11/fontkit/src/tables/GPOS.js

import * as r from 'restructure';
import {ScriptList, FeatureList, LookupList, Coverage, ClassDef, Device, Context, ChainingContext} from './opentype';
import {FeatureVariations} from './variations';

let ValueFormat = new r.Bitfield(r.uint16, [
  'xPlacement', 'yPlacement',
  'xAdvance', 'yAdvance',
  'xPlaDevice', 'yPlaDevice',
  'xAdvDevice', 'yAdvDevice'
]);

let types = {
  xPlacement: r.int16,
  yPlacement: r.int16,
  xAdvance:   r.int16,
  yAdvance:   r.int16,
  xPlaDevice: new r.Pointer(r.uint16, Device, { type: 'global', relativeTo: ctx => ctx.rel }),
  yPlaDevice: new r.Pointer(r.uint16, Device, { type: 'global', relativeTo: ctx => ctx.rel }),
  xAdvDevice: new r.Pointer(r.uint16, Device, { type: 'global', relativeTo: ctx => ctx.rel }),
  yAdvDevice: new r.Pointer(r.uint16, Device, { type: 'global', relativeTo: ctx => ctx.rel })
};

class ValueRecord {
  constructor(key = 'valueFormat') {
    this.key = key;
  }

  buildStruct(parent) {
    let struct = parent;
    while (!struct[this.key] && struct.parent) {
      struct = struct.parent;
    }

    if (!struct[this.key]) return;

    let fields = {};
    fields.rel = () => struct._startOffset;

    let format = struct[this.key];
    for (let key in format) {
      if (format[key]) {
        fields[key] = types[key];
      }
    }

    return new r.Struct(fields);
  }

  size(val, ctx) {
    return this.buildStruct(ctx).size(val, ctx);
  }

  decode(stream, parent) {
    let res = this.buildStruct(parent).decode(stream, parent);
    delete res.rel;
    return res;
  }
}

let PairValueRecord = new r.Struct({
  secondGlyph:    r.uint16,
  value1:         new ValueRecord('valueFormat1'),
  value2:         new ValueRecord('valueFormat2')
});

let PairSet = new r.Array(PairValueRecord, r.uint16);

let Class2Record = new r.Struct({
  value1: new ValueRecord('valueFormat1'),
  value2: new ValueRecord('valueFormat2')
});

let Anchor = new r.VersionedStruct(r.uint16, {
  1: { // Design units only
    xCoordinate:    r.int16,
    yCoordinate:    r.int16
  },

  2: { // Design units plus contour point
    xCoordinate:    r.int16,
    yCoordinate:    r.int16,
    anchorPoint:    r.uint16
  },

  3: { // Design units plus Device tables
    xCoordinate:    r.int16,
    yCoordinate:    r.int16,
    xDeviceTable:   new r.Pointer(r.uint16, Device),
    yDeviceTable:   new r.Pointer(r.uint16, Device)
  }
});

let EntryExitRecord = new r.Struct({
  entryAnchor:    new r.Pointer(r.uint16, Anchor, {type: 'parent'}),
  exitAnchor:     new r.Pointer(r.uint16, Anchor, {type: 'parent'})
});

let MarkRecord = new r.Struct({
  class:      r.uint16,
  markAnchor: new r.Pointer(r.uint16, Anchor, {type: 'parent'})
});

let MarkArray = new r.Array(MarkRecord, r.uint16);

let BaseRecord  = new r.Array(new r.Pointer(r.uint16, Anchor), t => t.parent.classCount);
let BaseArray   = new r.Array(BaseRecord, r.uint16);

let ComponentRecord = new r.Array(new r.Pointer(r.uint16, Anchor), t => t.parent.parent.classCount);
let LigatureAttach  = new r.Array(ComponentRecord, r.uint16);
let LigatureArray   = new r.Array(new r.Pointer(r.uint16, LigatureAttach), r.uint16);

let GPOSLookup = new r.VersionedStruct('lookupType', {
  1: new r.VersionedStruct(r.uint16, { // Single Adjustment
    1: { // Single positioning value
      coverage:       new r.Pointer(r.uint16, Coverage),
      valueFormat:    ValueFormat,
      value:          new ValueRecord()
    },
    2: {
      coverage:       new r.Pointer(r.uint16, Coverage),
      valueFormat:    ValueFormat,
      valueCount:     r.uint16,
      values:         new r.LazyArray(new ValueRecord(), 'valueCount')
    }
  }),

  2: new r.VersionedStruct(r.uint16, { // Pair Adjustment Positioning
    1: { // Adjustments for glyph pairs
      coverage:       new r.Pointer(r.uint16, Coverage),
      valueFormat1:   ValueFormat,
      valueFormat2:   ValueFormat,
      pairSetCount:   r.uint16,
      pairSets:       new r.LazyArray(new r.Pointer(r.uint16, PairSet), 'pairSetCount')
    },

    2: { // Class pair adjustment
      coverage:       new r.Pointer(r.uint16, Coverage),
      valueFormat1:   ValueFormat,
      valueFormat2:   ValueFormat,
      classDef1:      new r.Pointer(r.uint16, ClassDef),
      classDef2:      new r.Pointer(r.uint16, ClassDef),
      class1Count:    r.uint16,
      class2Count:    r.uint16,
      classRecords:   new r.LazyArray(new r.LazyArray(Class2Record, 'class2Count'), 'class1Count')
    }
  }),

  3: { // Cursive Attachment Positioning
    format:             r.uint16,
    coverage:           new r.Pointer(r.uint16, Coverage),
    entryExitCount:     r.uint16,
    entryExitRecords:   new r.Array(EntryExitRecord, 'entryExitCount')
  },

  4: { // MarkToBase Attachment Positioning
    format:             r.uint16,
    markCoverage:       new r.Pointer(r.uint16, Coverage),
    baseCoverage:       new r.Pointer(r.uint16, Coverage),
    classCount:         r.uint16,
    markArray:          new r.Pointer(r.uint16, MarkArray),
    baseArray:          new r.Pointer(r.uint16, BaseArray)
  },

  5: { // MarkToLigature Attachment Positioning
    format:             r.uint16,
    markCoverage:       new r.Pointer(r.uint16, Coverage),
    ligatureCoverage:   new r.Pointer(r.uint16, Coverage),
    classCount:         r.uint16,
    markArray:          new r.Pointer(r.uint16, MarkArray),
    ligatureArray:      new r.Pointer(r.uint16, LigatureArray)
  },

  6: { // MarkToMark Attachment Positioning
    format:             r.uint16,
    mark1Coverage:      new r.Pointer(r.uint16, Coverage),
    mark2Coverage:      new r.Pointer(r.uint16, Coverage),
    classCount:         r.uint16,
    mark1Array:         new r.Pointer(r.uint16, MarkArray),
    mark2Array:         new r.Pointer(r.uint16, BaseArray)
  },

  7: Context,          // Contextual positioning
  8: ChainingContext,  // Chaining contextual positioning

  9: { // Extension Positioning
    posFormat:   r.uint16,
    lookupType:  r.uint16,   // cannot also be 9
    extension:   new r.Pointer(r.uint32, null)
  }
});

// Fix circular reference
GPOSLookup.versions[9].extension.type = GPOSLookup;

export default new r.VersionedStruct(r.uint32, {
  header: {
    scriptList:     new r.Pointer(r.uint16, ScriptList),
    featureList:    new r.Pointer(r.uint16, FeatureList),
    lookupList:     new r.Pointer(r.uint16, new LookupList(GPOSLookup))
  },

  0x00010000: {},
  0x00010001: {
    featureVariations: new r.Pointer(r.uint32, FeatureVariations)
  }
});

// export GPOSLookup for JSTF table
export { GPOSLookup };

Directory Contents

Dirs: 0 × Files: 49

Name Size Perms Modified Actions
4.07 KB lrw-r--r-- 2026-02-14 19:19:20
Edit Download
405 B lrw-r--r-- 2026-02-14 19:19:20
Edit Download
3.02 KB lrw-r--r-- 2026-02-14 19:19:20
Edit Download
754 B lrw-r--r-- 2026-02-14 19:19:20
Edit Download
3.93 KB lrw-r--r-- 2026-02-14 19:19:22
Edit Download
1.29 KB lrw-r--r-- 2026-02-14 19:19:22
Edit Download
757 B lrw-r--r-- 2026-02-14 19:19:22
Edit Download
167 B lrw-r--r-- 2026-02-14 19:19:22
Edit Download
1.38 KB lrw-r--r-- 2026-02-14 19:19:22
Edit Download
696 B lrw-r--r-- 2026-02-14 19:19:22
Edit Download
1.50 KB lrw-r--r-- 2026-02-14 19:19:22
Edit Download
1.85 KB lrw-r--r-- 2026-02-14 19:19:24
Edit Download
825 B lrw-r--r-- 2026-02-14 19:19:24
Edit Download
348 B lrw-r--r-- 2026-02-14 19:19:24
Edit Download
864 B lrw-r--r-- 2026-02-14 19:19:26
Edit Download
531 B lrw-r--r-- 2026-02-14 19:19:26
Edit Download
1.73 KB lrw-r--r-- 2026-02-14 19:19:28
Edit Download
103 B lrw-r--r-- 2026-02-14 19:19:28
Edit Download
6.41 KB lrw-r--r-- 2026-02-14 19:19:36
Edit Download
2.75 KB lrw-r--r-- 2026-02-14 19:19:38
Edit Download
859 B lrw-r--r-- 2026-02-14 19:19:38
Edit Download
496 B lrw-r--r-- 2026-02-14 19:19:38
Edit Download
1.25 KB lrw-r--r-- 2026-02-14 19:19:38
Edit Download
1.01 KB lrw-r--r-- 2026-02-14 19:19:38
Edit Download
324 B lrw-r--r-- 2026-02-14 19:19:38
Edit Download
1.28 KB lrw-r--r-- 2026-02-14 19:19:38
Edit Download
2.25 KB lrw-r--r-- 2026-02-14 19:19:38
Edit Download
1.74 KB lrw-r--r-- 2026-02-14 19:19:38
Edit Download
2.17 KB lrw-r--r-- 2026-02-14 19:19:38
Edit Download
3.07 KB lrw-r--r-- 2026-02-14 19:19:38
Edit Download
625 B lrw-r--r-- 2026-02-14 19:19:38
Edit Download
321 B lrw-r--r-- 2026-02-14 19:19:38
Edit Download
1.19 KB lrw-r--r-- 2026-02-14 19:19:40
Edit Download
2.03 KB lrw-r--r-- 2026-02-14 19:19:40
Edit Download
3.24 KB lrw-r--r-- 2026-02-14 19:19:40
Edit Download
303 B lrw-r--r-- 2026-02-14 19:19:40
Edit Download
6.67 KB lrw-r--r-- 2026-02-14 19:19:40
Edit Download
3.56 KB lrw-r--r-- 2026-02-14 19:19:40
Edit Download
733 B lrw-r--r-- 2026-02-14 19:19:40
Edit Download
1.38 KB lrw-r--r-- 2026-02-14 19:19:40
Edit Download
199 B lrw-r--r-- 2026-02-14 19:19:40
Edit Download
604 B lrw-r--r-- 2026-02-14 19:19:40
Edit Download
2.40 KB lrw-r--r-- 2026-02-14 19:19:40
Edit Download
1.73 KB lrw-r--r-- 2026-02-14 19:19:40
Edit Download
1.13 KB lrw-r--r-- 2026-02-14 19:19:40
Edit Download
421 B lrw-r--r-- 2026-02-14 19:19:40
Edit Download
382 B lrw-r--r-- 2026-02-14 19:19:40
Edit Download
2.28 KB lrw-r--r-- 2026-02-14 19:19:40
Edit Download
977 B lrw-r--r-- 2026-02-14 19:19:40
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).