Home | History | Annotate | Download | only in text
      1 /*
      2  * Copyright (C) 2006 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  * AndroidCharacter exposes some character properties that are not
     21  * easily accessed from java.lang.Character.
     22  */
     23 public class AndroidCharacter
     24 {
     25     public static final int EAST_ASIAN_WIDTH_NEUTRAL = 0;
     26     public static final int EAST_ASIAN_WIDTH_AMBIGUOUS = 1;
     27     public static final int EAST_ASIAN_WIDTH_HALF_WIDTH = 2;
     28     public static final int EAST_ASIAN_WIDTH_FULL_WIDTH = 3;
     29     public static final int EAST_ASIAN_WIDTH_NARROW = 4;
     30     public static final int EAST_ASIAN_WIDTH_WIDE = 5;
     31 
     32     /**
     33      * Fill in the first <code>count</code> bytes of <code>dest</code> with the
     34      * directionalities from the first <code>count</code> chars of <code>src</code>.
     35      * This is just like Character.getDirectionality() except it is a
     36      * batch operation.
     37      */
     38     public native static void getDirectionalities(char[] src, byte[] dest,
     39                                                   int count);
     40 
     41     /**
     42      * Calculate the East Asian Width of a character according to
     43      * <a href="http://unicode.org/reports/tr11/">Unicode TR#11</a>. The return
     44      * will be one of {@link #EAST_ASIAN_WIDTH_NEUTRAL},
     45      * {@link #EAST_ASIAN_WIDTH_AMBIGUOUS}, {@link #EAST_ASIAN_WIDTH_HALF_WIDTH},
     46      * {@link #EAST_ASIAN_WIDTH_FULL_WIDTH}, {@link #EAST_ASIAN_WIDTH_NARROW},
     47      * or {@link #EAST_ASIAN_WIDTH_WIDE}.
     48      *
     49      * @param input the character to measure
     50      * @return the East Asian Width for input
     51      */
     52     public native static int getEastAsianWidth(char input);
     53 
     54     /**
     55      * Fill the first <code>count</code> bytes of <code>dest</code> with the
     56      * East Asian Width from <code>count</code> chars of <code>src</code>
     57      * starting at <code>start</code>. East Asian Width is calculated based on
     58      * <a href="http://unicode.org/reports/tr11/">Unicode TR#11</a>. Each entry
     59      * in <code>dest</code> will be one of {@link #EAST_ASIAN_WIDTH_NEUTRAL},
     60      * {@link #EAST_ASIAN_WIDTH_AMBIGUOUS}, {@link #EAST_ASIAN_WIDTH_HALF_WIDTH},
     61      * {@link #EAST_ASIAN_WIDTH_FULL_WIDTH}, {@link #EAST_ASIAN_WIDTH_NARROW},
     62      * or {@link #EAST_ASIAN_WIDTH_WIDE}.
     63      *
     64      * @param src character array of input to measure
     65      * @param start first character in array to measure
     66      * @param count maximum number of characters to measure
     67      * @param dest byte array of results for each character in src
     68      */
     69     public native static void getEastAsianWidths(char[] src, int start,
     70                                                  int count, byte[] dest);
     71 
     72     /**
     73      * Replace the specified slice of <code>text</code> with the chars'
     74      * right-to-left mirrors (if any), returning true if any
     75      * replacements were made.
     76      *
     77      * @param text array of characters to apply mirror operation
     78      * @param start first character in array to mirror
     79      * @param count maximum number of characters to mirror
     80      * @return true if replacements were made
     81      */
     82     public native static boolean mirror(char[] text, int start, int count);
     83 
     84     /**
     85      * Return the right-to-left mirror (or the original char if none)
     86      * of the specified char.
     87      */
     88     public native static char getMirror(char ch);
     89 }
     90