How to use the unicode-trie/builder function in unicode-trie

To help you get started, we’ve selected a few unicode-trie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github foliojs / fontkit / src / opentype / shapers / gen-indic.js View on Github external
}

  // Oriya Bindu is Before_Sub in the spec.
  if (codepoint.code === 0x0B01) {
    position = 'Before_Sub';
  }

  return Math.log2(POSITIONS[position]);
}

let symbols = {};
for (let c in CATEGORIES) {
  symbols[c] = Math.log2(CATEGORIES[c]);
}

let trie = new UnicodeTrieBuilder;
for (let i = 0; i < codepoints.length; i++) {
  let codepoint = codepoints[i];
  if (codepoint) {
    let category = OVERRIDES[codepoint.code] || CATEGORY_MAP[codepoint.indicSyllabicCategory] || 'X';
    let position = getPosition(codepoint, category);

    trie.set(codepoint.code, (symbols[category] << 8) | position);
  }
}

fs.writeFileSync(__dirname + '/indic.trie', trie.toBuffer());

let stateMachine = compile(fs.readFileSync(__dirname + '/indic.machine', 'utf8'), symbols);
fs.writeFileSync(__dirname + '/indic.json', JSON.stringify(stateMachine));
github foliojs / fontkit / src / opentype / shapers / gen-use.js View on Github external
return USE;
}

function getCategory(code) {
  for (let category in CATEGORIES) {
    for (let pattern of CATEGORIES[category]) {
      if (matches(pattern, {UISC: getUISC(code), UGC: code.category, U: code.code})) {
        return getPositionalCategory(code, category);
      }
    }
  }

  return null;
}

let trie = new UnicodeTrieBuilder;
let symbols = {};
let numSymbols = 0;
let decompositions = {};
for (let i = 0; i < codepoints.length; i++) {
  let codepoint = codepoints[i];
  if (codepoint) {
    let category = getCategory(codepoint);
    if (!(category in symbols)) {
      symbols[category] = numSymbols++;
    }

    trie.set(codepoint.code, symbols[category]);

    if (codepoint.indicSyllabicCategory === 'Vowel_Dependent' && codepoint.decomposition.length > 0) {
      decompositions[codepoint.code] = decompose(codepoint.code);
    }
github foliojs / fontkit / src / opentype / shapers / generate-data.js View on Github external
import codepoints from 'codepoints';
import fs from 'fs';
import UnicodeTrieBuilder from 'unicode-trie/builder';

let ShapingClasses = {
  Non_Joining: 0,
  Left_Joining: 1,
  Right_Joining: 2,
  Dual_Joining: 3,
  Join_Causing: 3,
  ALAPH: 4,
  'DALATH RISH': 5,
  Transparent: 6
};

let trie = new UnicodeTrieBuilder;
for (let i = 0; i < codepoints.length; i++) {
  let codepoint = codepoints[i];
  if (codepoint) {
    if (codepoint.joiningGroup === 'ALAPH' || codepoint.joiningGroup === 'DALATH RISH') {
      trie.set(codepoint.code, ShapingClasses[codepoint.joiningGroup] + 1);

    } else if (codepoint.joiningType) {
      trie.set(codepoint.code, ShapingClasses[codepoint.joiningType] + 1);
    }
  }
}

fs.writeFileSync(__dirname + '/data.trie', trie.toBuffer());

unicode-trie

Unicode Trie data structure for fast character metadata lookup, ported from ICU

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis

Popular unicode-trie functions

Similar packages