1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.text; 18 19 /** 20 * Access the ICU bidi implementation. 21 * @hide 22 */ 23 /* package */ class AndroidBidi { 24 25 public static int bidi(int dir, char[] chs, byte[] chInfo, int n, boolean haveInfo) { 26 if (chs == null || chInfo == null) { 27 throw new NullPointerException(); 28 } 29 30 if (n < 0 || chs.length < n || chInfo.length < n) { 31 throw new IndexOutOfBoundsException(); 32 } 33 34 switch(dir) { 35 case Layout.DIR_REQUEST_LTR: dir = 0; break; 36 case Layout.DIR_REQUEST_RTL: dir = 1; break; 37 case Layout.DIR_REQUEST_DEFAULT_LTR: dir = -2; break; 38 case Layout.DIR_REQUEST_DEFAULT_RTL: dir = -1; break; 39 default: dir = 0; break; 40 } 41 42 int result = runBidi(dir, chs, chInfo, n, haveInfo); 43 result = (result & 0x1) == 0 ? Layout.DIR_LEFT_TO_RIGHT : Layout.DIR_RIGHT_TO_LEFT; 44 return result; 45 } 46 47 private native static int runBidi(int dir, char[] chs, byte[] chInfo, int n, boolean haveInfo); 48 }