use of com.ibm.icu.text.ArabicShaping in project Osmand by osmandapp.
the class Reshaper method reshape.
public static String reshape(String s) {
// }
try {
ArabicShaping as = new ArabicShaping(ArabicShaping.LETTERS_SHAPE | ArabicShaping.LENGTH_GROW_SHRINK);
try {
s = as.shape(s);
} catch (ArabicShapingException e) {
LOG.error(e.getMessage(), e);
}
Bidi line = new Bidi(s.length(), s.length());
line.setPara(s, Bidi.LEVEL_DEFAULT_LTR, null);
byte direction = line.getDirection();
if (direction != Bidi.MIXED) {
// unidirectional
if (line.isLeftToRight()) {
return s;
} else {
char[] chs = new char[s.length()];
for (int i = 0; i < chs.length; i++) {
chs[i] = s.charAt(chs.length - i - 1);
}
return new String(chs);
}
} else {
// // mixed-directional
int count = line.countRuns();
// if (styleRunCount <= 1) {
// int style = styleRuns[0].style;
// // iterate over directional runs
// for (i = 0; i < count; ++i) {
// run = line.getVisualRun(i);
// renderRun(text, run.getStart(), run.getLimit(),
// run.getDirection(), style);
// }
// }
StringBuilder res = new StringBuilder();
// iterate over both directional and style runs
for (int i = 0; i < count; ++i) {
BidiRun run = line.getVisualRun(i);
int st = run.getStart();
int e = run.getLimit();
int j = run.getDirection() == Bidi.LTR ? st : e - 1;
int l = run.getDirection() == Bidi.LTR ? e : st - 1;
boolean plus = run.getDirection() == Bidi.LTR;
while (j != l) {
res.append(s.charAt(j));
if (plus) {
j++;
} else {
j--;
}
}
}
return res.toString();
}
} catch (RuntimeException e) {
LOG.error(e.getMessage(), e);
return s;
}
}
use of com.ibm.icu.text.ArabicShaping in project Minechem by iopleke.
the class EnhancedFontRenderer method bidiReorder.
/**
* Apply Unicode Bidirectional Algorithm to string and return a new possibly reordered string for visual rendering.
*/
private String bidiReorder(String string) {
try {
Bidi bidi = new Bidi((new ArabicShaping(8)).shape(string), 127);
bidi.setReorderingMode(0);
return bidi.writeReordered(2);
} catch (ArabicShapingException arabicshapingexception) {
return string;
}
}
use of com.ibm.icu.text.ArabicShaping in project OsmAnd-tools by osmandapp.
the class ArabicShaper method main.
public static void main(String[] args) throws ArabicShapingException {
ArabicShaping as = new ArabicShaping(ArabicShaping.LETTERS_SHAPE | ArabicShaping.LENGTH_GROW_SHRINK);
String s = "אנשים 12";
// for (int i = 0; i < s.length(); i++) {
// System.out.println(s.charAt(i));
// }
Bidi bd = new Bidi(s.length(), s.length());
bd.setPara(s, Bidi.LEVEL_DEFAULT_LTR, null);
System.out.println(bd.baseIsLeftToRight());
String r = as.shape(s);
// for (int i = 0; i < r.length(); i++) {
// System.out.println(r.charAt(i));
// }
System.out.println(r);
}
use of com.ibm.icu.text.ArabicShaping in project Galacticraft by micdoodle8.
the class GuiCelestialSelection method bidiReorder.
protected String bidiReorder(String p_147647_1_) {
try {
Bidi bidi = new Bidi((new ArabicShaping(8)).shape(p_147647_1_), 127);
bidi.setReorderingMode(0);
return bidi.writeReordered(2);
} catch (ArabicShapingException arabicshapingexception) {
return p_147647_1_;
}
}
Aggregations