Search in sources :

Example 1 with ArabicShapingException

use of com.ibm.icu.text.ArabicShapingException 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;
    }
}
Also used : ArabicShaping(com.ibm.icu.text.ArabicShaping) ArabicShapingException(com.ibm.icu.text.ArabicShapingException) Bidi(com.ibm.icu.text.Bidi) BidiRun(com.ibm.icu.text.BidiRun)

Example 2 with ArabicShapingException

use of com.ibm.icu.text.ArabicShapingException 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;
    }
}
Also used : ArabicShaping(com.ibm.icu.text.ArabicShaping) Bidi(com.ibm.icu.text.Bidi) ArabicShapingException(com.ibm.icu.text.ArabicShapingException)

Example 3 with ArabicShapingException

use of com.ibm.icu.text.ArabicShapingException 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_;
    }
}
Also used : ArabicShaping(com.ibm.icu.text.ArabicShaping) Bidi(com.ibm.icu.text.Bidi) ArabicShapingException(com.ibm.icu.text.ArabicShapingException)

Aggregations

ArabicShaping (com.ibm.icu.text.ArabicShaping)3 ArabicShapingException (com.ibm.icu.text.ArabicShapingException)3 Bidi (com.ibm.icu.text.Bidi)3 BidiRun (com.ibm.icu.text.BidiRun)1