lib/ttf/tables/glyf.js
function compactFlags(flags) {
  var result = [];
  var prevFlag = -1;
  var firstRepeat = false;

  _.forEach(flags, function (flag) {
    if (prevFlag === flag) {
      if (firstRepeat) {
        result[result.length - 1] += 8; //current flag repeats previous one, need to set 3rd bit of previous flag and set 1 to the current one
        result.push(1);
        firstRepeat = false;
      } else {
        result[result.length - 1]++; //when flag is repeating second or more times, we need to increase the last flag value
      }
    } else {
      firstRepeat = true;
      prevFlag = flag;
      result.push(flag);
    }
  });
  return result;
}
function compactFlags(flags) {
  var result = [];
  var prevFlag = -1;
  var firstRepeat = false;

  _.forEach(flags, function (flag) {
    if (prevFlag === flag) {
      if (firstRepeat) {
        result[result.length - 1] += 8; //current flag repeats previous one, need to set 3rd bit of previous flag and set 1 to the current one
        result.push(1);
        firstRepeat = false;
      } else {
        result[result.length - 1]++; //when flag is repeating second or more times, we need to increase the last flag value
      }
    } else {
      firstRepeat = true;
      prevFlag = flag;
      result.push(flag);
    }
  });
  return result;
}
function compactFlags ( flags ) { var result = [ ] ; var prevFlag = - 1 ; var firstRepeat = false ; _ . forEach ( flags , function ( flag ) { if ( prevFlag === flag ) { if ( firstRepeat ) { result [ result . length - 1 ] += 8 ; //current flag repeats previous one, need to set 3rd bit of previous flag and set 1 to the current one result . push ( 1 ) ; firstRepeat = false ; } else { result [ result . length - 1 ] ++ ; //when flag is repeating second or more times, we need to increase the last flag value } } else { firstRepeat = true ; prevFlag = flag ; result . push ( flag ) ; } } ) ; return result ; }
repeating flags can be packed
repeating flags can be packed