Open yousefshakoury opened 4 years ago
looks like
How can we have rtl language support for labels?
import { convertArabic } from "PersianSharper";
costData.labels = labels.map(v => convertArabic(v.costName));
`/** This Is persiansharper.js
], combCharsMap = [ //[ [ 0x0644, 0x0622 ], 0xFEF5, null, null, 0xFEF6 ], / LAM_ALEF_MADDA / //[ [ 0x0644, 0x0623 ], 0xFEF7, null, null, 0xFEF8 ], / LAM_ALEF_HAMZA_ABOVE / //[ [ 0x0644, 0x0625 ], 0xFEF9, null, null, 0xFEFA ], / LAM_ALEF_HAMZA_BELOW / [[0x0644, 0x0627], 0xFEFB, null, null, 0xFEFC], / LAM_ALEF / ], transChars = [ 0x0610, / ARABIC SIGN SALLALLAHOU ALAYHE WASSALLAM / 0x0612, / ARABIC SIGN ALAYHE ASSALLAM / 0x0613, / ARABIC SIGN RADI ALLAHOU ANHU / 0x0614, / ARABIC SIGN TAKHALLUS / 0x0615, / ARABIC SMALL HIGH TAH / 0x064B, / ARABIC FATHATAN / 0x064C, / ARABIC DAMMATAN / 0x064D, / ARABIC KASRATAN / 0x064E, / ARABIC FATHA / 0x064F, / ARABIC DAMMA / 0x0650, / ARABIC KASRA / 0x0651, / ARABIC SHADDA / 0x0652, / ARABIC SUKUN / 0x0653, / ARABIC MADDAH ABOVE / 0x0654, / ARABIC HAMZA ABOVE / 0x0655, / ARABIC HAMZA BELOW / 0x0656, / ARABIC SUBSCRIPT ALEF / 0x0657, / ARABIC INVERTED DAMMA / 0x0658, / ARABIC MARK NOON GHUNNA / 0x0670, / ARABIC LETTER SUPERSCRIPT ALEF / 0x06D6, / ARABIC SMALL HIGH LIGATURE SAD WITH LAM WITH ALEF MAKSURA / 0x06D7, / ARABIC SMALL HIGH LIGATURE QAF WITH LAM WITH ALEF MAKSURA / 0x06D8, / ARABIC SMALL HIGH MEEM INITIAL FORM / 0x06D9, / ARABIC SMALL HIGH LAM ALEF / 0x06DA, / ARABIC SMALL HIGH JEEM / 0x06DB, / ARABIC SMALL HIGH THREE DOTS / 0x06DC, / ARABIC SMALL HIGH SEEN / 0x06DF, / ARABIC SMALL HIGH ROUNDED ZERO / 0x06E0, / ARABIC SMALL HIGH UPRIGHT RECTANGULAR ZERO / 0x06E1, / ARABIC SMALL HIGH DOTLESS HEAD OF KHAH / 0x06E2, / ARABIC SMALL HIGH MEEM ISOLATED FORM / 0x06E3, / ARABIC SMALL LOW SEEN / 0x06E4, / ARABIC SMALL HIGH MADDA / 0x06E7, / ARABIC SMALL HIGH YEH / 0x06E8, / ARABIC SMALL HIGH NOON / 0x06EA, / ARABIC EMPTY CENTRE LOW STOP / 0x06EB, / ARABIC EMPTY CENTRE HIGH STOP / 0x06EC, / ARABIC ROUNDED HIGH STOP WITH FILLED CENTRE / 0x06ED, / ARABIC SMALL LOW MEEM / ];
function CharacterMapContains(c) { for (var i = 0; i < charsMap.length; ++i) if (charsMap[i][0] == c) return true; return false; }
function GetCharRep(c) { for (var i = 0; i < charsMap.length; ++i) if (charsMap[i][0] == c) return charsMap[i]; return false; }
function GetCombCharRep(c1, c2) { for (var i = 0; i < combCharsMap.length; ++i) if (combCharsMap[i][0][0] == c1 && combCharsMap[i][0][1] == c2) return combCharsMap[i]; return false; }
function IsTransparent(c) { for (var i = 0; i < transChars.length; ++i) if (transChars[i] == c) return true; return false; }
export function convertArabic(normal) { var crep, combcrep, shaped = "";
for (var i = 0; i < normal.length; ++i) {
var current = normal.charCodeAt(i);
if (CharacterMapContains(current)) {
var prev = null,
next = null,
prevID = i - 1,
nextID = i + 1;
/*
Transparent characters have no effect in the shaping process.
So, ignore all the transparent characters that are BEFORE the
current character.
*/
for (; prevID >= 0; --prevID) {
if (!IsTransparent(normal.charCodeAt(prevID))) {
break;
}
}
prev = (prevID >= 0) ? normal.charCodeAt(prevID) : null;
crep = prev ? GetCharRep(prev) : false;
if (crep[2] == null && crep[3] == null) {
prev = null;
}
/*
Transparent characters have no effect in the shaping process.
So, ignore all the transparent characters that are AFTER the
current character.
*/
for (; nextID < normal.length; ++nextID) {
if (!IsTransparent(normal.charCodeAt(nextID))) {
break;
}
}
next = (nextID <= normal.length) ? normal.charCodeAt(nextID) : null;
crep = next ? GetCharRep(next) : false;
if (crep[3] == null && crep[4] == null) {
next = null;
}
// /* Combinations */
if (current == 0x0644 && next != null &&
(next == 0x0622 || next == 0x0623 || next == 0x0625 || next == 0x0627)) {
combcrep = GetCombCharRep(current, next);
if (prev != null) {
shaped += String.fromCharCode(combcrep[4]);
} else {
shaped += String.fromCharCode(combcrep[1]);
}
i = i + 1;
continue;
}
crep = GetCharRep(current);
/* Medial */
if (prev != null && next != null && crep[3] != null) {
shaped += String.fromCharCode(crep[3]);
continue;
} else /* Final */
if (prev != null && crep[4] != null) {
shaped += String.fromCharCode(crep[4]);
continue;
} else /* Initial */
if (next != null && crep[2] != null) {
shaped += String.fromCharCode(crep[2]);
continue;
} else /* Isolated */ {
shaped += String.fromCharCode(crep[1]);
}
} else {
shaped += String.fromCharCode(current);
}
}
return shaped;
}
// convert from Arabic Presentation Forms B function convertArabicBack(apfb) { var toReturn = "", selectedChar;
for (var i = 0; i < apfb.length; ++i) {
selectedChar = apfb.charCodeAt(i);
for (var j = 0; j < charsMap.length; ++j) {
if (charsMap[j][4] == selectedChar || charsMap[j][2] == selectedChar ||
charsMap[j][1] == selectedChar || charsMap[j][3] == selectedChar) {
toReturn += String.fromCharCode(charsMap[j][0]);
continue;
}
}
for (var j = 0; j < combCharsMap.length; ++j) {
if (combCharsMap[j][4] == selectedChar || combCharsMap[j][2] == selectedChar ||
combCharsMap[j][1] == selectedChar || combCharsMap[j][3] == selectedChar) {
toReturn += String.fromCharCode(combCharsMap[j][0][0]) + String.fromCharCode(combCharsMap[j][0][1]);
continue;
}
}
toReturn += String.fromCharCode(selectedChar);
}
return toReturn;
} `
The seems it's not support right to left languages (in labels)!!!