List of usage examples for java.text Bidi baseIsLeftToRight
public boolean baseIsLeftToRight()
From source file:Main.java
/** * This method determines if the direction of a substring is right-to-left. * If the string is empty that determination is based on the default system language * Locale.getDefault()./* w ww . j a va 2 s . c om*/ * The method can handle invalid substring definitions (start > end etc.), in which case the * method returns False. * * @return True if the text direction is right-to-left, false otherwise. */ public static boolean isRTL(CharSequence s, int start, int end) { if (s == null || s.length() == 0) { // empty string --> determine the direction from the default language return isRTL(Locale.getDefault()); } if (start == end) { // if no character is selected we need to expand the selection start = Math.max(0, --start); if (start == end) { end = Math.min(s.length(), ++end); } } try { Bidi bidi = new Bidi(s.subSequence(start, end).toString(), Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); return !bidi.baseIsLeftToRight(); } catch (IndexOutOfBoundsException e) { return false; } }
From source file:net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.java
protected boolean isLeftToRight(char[] chars) { boolean leftToRight = true; if (Bidi.requiresBidi(chars, 0, chars.length)) { // determining the text direction // using default LTR as there's no way to have other default in the text Bidi bidi = new Bidi(chars, 0, null, 0, chars.length, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT); leftToRight = bidi.baseIsLeftToRight(); }//from w w w. j ava 2 s . com return leftToRight; }