Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
}
// 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));
import unicode from 'unicode-properties';
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');
import fs from 'fs';
import UnicodeTrie from 'unicode-trie';
import data from './data.json';
import buildUnicodeProperties from './index';
const trie = new UnicodeTrie(fs.readFileSync(__dirname + '/data.trie'));
const unicodeProperties = buildUnicodeProperties(data, trie);
export default unicodeProperties;
import UnicodeTrie from 'unicode-trie';
import base64 from 'base64-js';
import data from './data.json';
import trieData from './trie.json';
import buildUnicodeProperties from './index';
const trie = new UnicodeTrie(base64.toByteArray(trieData.data));
const unicodeProperties = buildUnicodeProperties(data, trie);
export default unicodeProperties;
import DefaultShaper from './DefaultShaper';
import unicode from 'unicode-properties';
import UnicodeTrie from 'unicode-trie';
const trie = new UnicodeTrie(require('fs').readFileSync(__dirname + '/data.trie'));
const FEATURES = ['isol', 'fina', 'fin2', 'fin3', 'medi', 'med2', 'init'];
const ShapingClasses = {
Non_Joining: 0,
Left_Joining: 1,
Right_Joining: 2,
Dual_Joining: 3,
Join_Causing: 3,
ALAPH: 4,
'DALATH RISH': 5,
Transparent: 6
};
const ISOL = 'isol';
const FINA = 'fina';
const FIN2 = 'fin2';
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);
}
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());