lib/ttf/tables/gsub.js
function createLookupList(font) {
  var ligatures = font.ligatures;

  var groupedLigatures = {};

  // Group ligatures by first code point
  _.forEach(ligatures, function (ligature) {
    var first = ligature.unicode[0];

    if (!_.has(groupedLigatures, first)) {
      groupedLigatures[first] = [];
    }
    groupedLigatures[first].push(ligature);
  });

  var ligatureGroups = [];

  _.forEach(groupedLigatures, function (ligatures, codePoint) {
    codePoint = parseInt(codePoint, 10);
    // Order ligatures by length, descending
    // “Ligatures with more components must be stored ahead of those with fewer components in order to be found”
    // From: http://partners.adobe.com/public/developer/opentype/index_tag7.html#liga
    ligatures.sort(function (ligA, ligB) {
      return ligB.unicode.length - ligA.unicode.length;
    });
    ligatureGroups.push({
      codePoint: codePoint,
      ligatures: ligatures,
      startGlyph: font.codePoints[codePoint]
    });
  });

  ligatureGroups.sort(function (a, b) {
    return a.startGlyph.id - b.startGlyph.id;
  });

  var offset = (0
    + 2 // Lookup count
    + 2 // Lookup[0] offset
  );

  var set = createLigatureList(font, ligatureGroups);

  var length = (0
    + offset
    + set.length
  );

  var buffer = new ByteBuffer(length);

  // Lookup count
  buffer.writeUint16(1);

  // Lookup[0] offset
  buffer.writeUint16(offset);

  // Lookup[0]
  buffer.writeBytes(set.buffer);

  return buffer;
}
function createLookupList(font) {
  var ligatures = font.ligatures;

  var groupedLigatures = {};

  // Group ligatures by first code point
  _.forEach(ligatures, function (ligature) {
    var first = ligature.unicode[0];

    if (!_.has(groupedLigatures, first)) {
      groupedLigatures[first] = [];
    }
    groupedLigatures[first].push(ligature);
  });

  var ligatureGroups = [];

  _.forEach(groupedLigatures, function (ligatures, codePoint) {
    codePoint = parseInt(codePoint, 10);
    // Order ligatures by length, descending
    // “Ligatures with more components must be stored ahead of those with fewer components in order to be found”
    // From: http://partners.adobe.com/public/developer/opentype/index_tag7.html#liga
    ligatures.sort(function (ligA, ligB) {
      return ligB.unicode.length - ligA.unicode.length;
    });
    ligatureGroups.push({
      codePoint: codePoint,
      ligatures: ligatures,
      startGlyph: font.codePoints[codePoint]
    });
  });

  ligatureGroups.sort(function (a, b) {
    return a.startGlyph.id - b.startGlyph.id;
  });

  var offset = (0
    + 2 // Lookup count
    + 2 // Lookup[0] offset
  );

  var set = createLigatureList(font, ligatureGroups);

  var length = (0
    + offset
    + set.length
  );

  var buffer = new ByteBuffer(length);

  // Lookup count
  buffer.writeUint16(1);

  // Lookup[0] offset
  buffer.writeUint16(offset);

  // Lookup[0]
  buffer.writeBytes(set.buffer);

  return buffer;
}
function createLookupList ( font ) { var ligatures = font . ligatures ; var groupedLigatures = { } ; // Group ligatures by first code point _ . forEach ( ligatures , function ( ligature ) { var first = ligature . unicode [ 0 ] ; if ( ! _ . has ( groupedLigatures , first ) ) { groupedLigatures [ first ] = [ ] ; } groupedLigatures [ first ] . push ( ligature ) ; } ) ; var ligatureGroups = [ ] ; _ . forEach ( groupedLigatures , function ( ligatures , codePoint ) { codePoint = parseInt ( codePoint , 10 ) ; // Order ligatures by length, descending // “Ligatures with more components must be stored ahead of those with fewer components in order to be found” // From: http://partners.adobe.com/public/developer/opentype/index_tag7.html#liga ligatures . sort ( function ( ligA , ligB ) { return ligB . unicode . length - ligA . unicode . length ; } ) ; ligatureGroups . push ( { codePoint : codePoint , ligatures : ligatures , startGlyph : font . codePoints [ codePoint ] } ) ; } ) ; ligatureGroups . sort ( function ( a , b ) { return a . startGlyph . id - b . startGlyph . id ; } ) ; var offset = ( 0 + 2 // Lookup count + 2 // Lookup[0] offset ) ; var set = createLigatureList ( font , ligatureGroups ) ; var length = ( 0 + offset + set . length ) ; var buffer = new ByteBuffer ( length ) ; // Lookup count buffer . writeUint16 ( 1 ) ; // Lookup[0] offset buffer . writeUint16 ( offset ) ; // Lookup[0] buffer . writeBytes ( set . buffer ) ; return buffer ; }
Add a lookup for each ligature
Add a lookup for each ligature