How to use dfa - 4 common examples

To help you get started, we’ve selected a few dfa 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 / UniversalShaper.js View on Github external
import DefaultShaper from './DefaultShaper';
import StateMachine from 'dfa';
import UnicodeTrie from 'unicode-trie';
import GlyphInfo from '../GlyphInfo';
import useData from './use.json';

const {categories, decompositions} = useData;
const trie = new UnicodeTrie(require('fs').readFileSync(__dirname + '/use.trie'));
const stateMachine = new StateMachine(useData);

/**
 * This shaper is an implementation of the Universal Shaping Engine, which
 * uses Unicode data to shape a number of scripts without a dedicated shaping engine.
 * See https://www.microsoft.com/typography/OpenTypeDev/USE/intro.htm.
 */
export default class UniversalShaper extends DefaultShaper {
  static zeroMarkWidths = 'BEFORE_GPOS';
  static planFeatures(plan) {
    plan.addStage(setupSyllables);

    // Default glyph pre-processing group
    plan.addStage(['locl', 'ccmp', 'nukt', 'akhn']);

    // Reordering group
    plan.addStage(clearSubstitutionFlags);
github foliojs / fontkit / src / opentype / shapers / IndicShaper.js View on Github external
import * as Script from '../../layout/Script';
import GlyphInfo from '../GlyphInfo';
import indicMachine from './indic.json';
import useData from './use.json';
import {
  CATEGORIES,
  POSITIONS,
  CONSONANT_FLAGS,
  JOINER_FLAGS,
  HALANT_OR_COENG_FLAGS, INDIC_CONFIGS,
  INDIC_DECOMPOSITIONS
} from './indic-data';

const {decompositions} = useData;
const trie = new UnicodeTrie(require('fs').readFileSync(__dirname + '/indic.trie'));
const stateMachine = new StateMachine(indicMachine);

/**
 * The IndicShaper supports indic scripts e.g. Devanagari, Kannada, etc.
 * Based on code from Harfbuzz: https://github.com/behdad/harfbuzz/blob/master/src/hb-ot-shape-complex-indic.cc
 */
export default class IndicShaper extends DefaultShaper {
  static zeroMarkWidths = 'NONE';
  static planFeatures(plan) {
    plan.addStage(setupSyllables);

    plan.addStage(['locl', 'ccmp']);

    plan.addStage(initialReordering);

    plan.addStage('nukt');
    plan.addStage('akhn');
github foliojs / fontkit / src / opentype / shapers / gen-use.js View on Github external
function decompose(code) {
  let decomposition = [];
  let codepoint = codepoints[code];
  for (let c of codepoint.decomposition) {
    let codes = decompose(c);
    codes = codes.length > 0 ? codes : [c];
    decomposition.push(...codes);
  }

  return decomposition;
}

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

let stateMachine = compile(fs.readFileSync(__dirname + '/use.machine', 'utf8'), symbols);
let json = Object.assign({
  categories: Object.keys(symbols),
  decompositions: decompositions
}, stateMachine);

fs.writeFileSync(__dirname + '/use.json', JSON.stringify(json));
github foliojs / fontkit / src / opentype / shapers / gen-indic.js View on Github external
}

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));

dfa

A state machine compiler

MIT
Latest version published 5 years ago

Package Health Score

67 / 100
Full package analysis

Popular dfa functions