< prev index next >

src/java.base/share/classes/sun/text/bidi/BidiBase.java

Print this page




  64 import sun.text.normalizer.UCharacter;
  65 import sun.text.normalizer.UTF16;
  66 
  67 /**
  68  *
  69  * <h2>Bidi algorithm for ICU</h2>
  70  *
  71  * This is an implementation of the Unicode Bidirectional algorithm. The
  72  * algorithm is defined in the <a
  73  * href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>,
  74  * version 13, also described in The Unicode Standard, Version 4.0 .
  75  * <p>
  76  *
  77  * Note: Libraries that perform a bidirectional algorithm and reorder strings
  78  * accordingly are sometimes called "Storage Layout Engines". ICU's Bidi and
  79  * shaping (ArabicShaping) classes can be used at the core of such "Storage
  80  * Layout Engines".
  81  *
  82  * <h3>General remarks about the API:</h3>
  83  *
  84  * The &quot;limit&quot; of a sequence of characters is the position just after
  85  * their last character, i.e., one more than that position.
  86  * <p>
  87  *
  88  * Some of the API methods provide access to &quot;runs&quot;. Such a
  89  * &quot;run&quot; is defined as a sequence of characters that are at the same
  90  * embedding level after performing the Bidi algorithm.
  91  * <p>
  92  *
  93  * <h3>Basic concept: paragraph</h3>
  94  * A piece of text can be divided into several paragraphs by characters
  95  * with the Bidi class <code>Block Separator</code>. For handling of
  96  * paragraphs, see:
  97  * <ul>
  98  * <li>{@link #countParagraphs}
  99  * <li>{@link #getParaLevel}
 100  * <li>{@link #getParagraph}
 101  * <li>{@link #getParagraphByIndex}
 102  * </ul>
 103  *
 104  * <h3>Basic concept: text direction</h3>
 105  * The direction of a piece of text may be:
 106  * <ul>
 107  * <li>{@link #LTR}
 108  * <li>{@link #RTL}
 109  * <li>{@link #MIXED}
 110  * </ul>
 111  *


 124  * specifying the level of a character to <i>override</i> whatever the
 125  * Bidi implementation would resolve it to.</li>
 126  * <li><code>paraLevel</code> can be set to the
 127  * pseudo-level values <code>LEVEL_DEFAULT_LTR</code>
 128  * and <code>LEVEL_DEFAULT_RTL</code>.</li>
 129  * </ul>
 130  *
 131  * <p>The related constants are not real, valid level values.
 132  * <code>DEFAULT_XXX</code> can be used to specify
 133  * a default for the paragraph level for
 134  * when the <code>setPara()</code> method
 135  * shall determine it but there is no
 136  * strongly typed character in the input.<p>
 137  *
 138  * Note that the value for <code>LEVEL_DEFAULT_LTR</code> is even
 139  * and the one for <code>LEVEL_DEFAULT_RTL</code> is odd,
 140  * just like with normal LTR and RTL level values -
 141  * these special values are designed that way. Also, the implementation
 142  * assumes that MAX_EXPLICIT_LEVEL is odd.
 143  *
 144  * <ul><b>See Also:</b>

 145  * <li>{@link #LEVEL_DEFAULT_LTR}
 146  * <li>{@link #LEVEL_DEFAULT_RTL}
 147  * <li>{@link #LEVEL_OVERRIDE}
 148  * <li>{@link #MAX_EXPLICIT_LEVEL}
 149  * <li>{@link #setPara}
 150  * </ul>
 151  *
 152  * <h3>Basic concept: Reordering Mode</h3>
 153  * Reordering mode values indicate which variant of the Bidi algorithm to
 154  * use.
 155  *
 156  * <ul><b>See Also:</b>

 157  * <li>{@link #setReorderingMode}
 158  * <li>{@link #REORDER_DEFAULT}
 159  * <li>{@link #REORDER_NUMBERS_SPECIAL}
 160  * <li>{@link #REORDER_GROUP_NUMBERS_WITH_R}
 161  * <li>{@link #REORDER_RUNS_ONLY}
 162  * <li>{@link #REORDER_INVERSE_NUMBERS_AS_L}
 163  * <li>{@link #REORDER_INVERSE_LIKE_DIRECT}
 164  * <li>{@link #REORDER_INVERSE_FOR_NUMBERS_SPECIAL}
 165  * </ul>
 166  *
 167  * <h3>Basic concept: Reordering Options</h3>
 168  * Reordering options can be applied during Bidi text transformations.
 169  * <ul><b>See Also:</b>

 170  * <li>{@link #setReorderingOptions}
 171  * <li>{@link #OPTION_DEFAULT}
 172  * <li>{@link #OPTION_INSERT_MARKS}
 173  * <li>{@link #OPTION_REMOVE_CONTROLS}
 174  * <li>{@link #OPTION_STREAMING}
 175  * </ul>
 176  *
 177  *
 178  * @author Simon Montagu, Matitiahu Allouche (ported from C code written by Markus W. Scherer)
 179  * @stable ICU 3.8
 180  *
 181  *
 182  * <h4> Sample code for the ICU Bidi API </h4>
 183  *
 184  * <h5>Rendering a paragraph with the ICU Bidi API</h5>
 185  *
 186  * This is (hypothetical) sample code that illustrates how the ICU Bidi API
 187  * could be used to render a paragraph of text. Rendering code depends highly on
 188  * the graphics system, therefore this sample code must make a lot of
 189  * assumptions, which may or may not match any existing graphics system's
 190  * properties.
 191  *
 192  * <p>
 193  * The basic assumptions are:
 194  * </p>
 195  * <ul>
 196  * <li>Rendering is done from left to right on a horizontal line.</li>
 197  * <li>A run of single-style, unidirectional text can be rendered at once.
 198  * </li>
 199  * <li>Such a run of text is passed to the graphics system with characters
 200  * (code units) in logical order.</li>
 201  * <li>The line-breaking algorithm is very complicated and Locale-dependent -
 202  * and therefore its implementation omitted from this sample code.</li>
 203  * </ul>
 204  *
 205  * <pre>
 206  *
 207  *  package com.ibm.icu.dev.test.bidi;
 208  *
 209  *  import com.ibm.icu.text.Bidi;
 210  *  import com.ibm.icu.text.BidiRun;
 211  *
 212  *  public class Sample {
 213  *
 214  *      static final int styleNormal = 0;
 215  *      static final int styleSelected = 1;
 216  *      static final int styleBold = 2;
 217  *      static final int styleItalics = 4;
 218  *      static final int styleSuper=8;
 219  *      static final int styleSub = 16;
 220  *
 221  *      static class StyleRun {
 222  *          int limit;
 223  *          int style;
 224  *
 225  *          public StyleRun(int limit, int style) {


 434  *                  }
 435  *                  if (limit == length) {
 436  *                      break;
 437  *                  }
 438  *                  start = limit;
 439  *                  styleRunStart = styleRunLimit - 1;
 440  *                  if (start >= styleRuns[styleRunStart].limit) {
 441  *                      ++styleRunStart;
 442  *                  }
 443  *              }
 444  *          }
 445  *      }
 446  *
 447  *      public static void main(String[] args)
 448  *      {
 449  *          renderParagraph("Some Latin text...", Bidi.LTR, null, 0, 80);
 450  *          renderParagraph("Some Hebrew text...", Bidi.RTL, null, 0, 60);
 451  *      }
 452  *  }
 453  *
 454  * </pre>
 455  */
 456 
 457 public class BidiBase {
 458 
 459     class Point {
 460         int pos;    /* position in text */
 461         int flag;   /* flag for LRM/RLM, before/after */
 462     }
 463 
 464     class InsertPoints {
 465         int size;
 466         int confirmed;
 467         Point[] points = new Point[0];
 468     }
 469 
 470     /** Paragraph level setting<p>
 471      *
 472      * Constant indicating that the base direction depends on the first strong
 473      * directional character in the text according to the Unicode Bidirectional
 474      * Algorithm. If no strong directional character is present,


2402      *        <code>getTextAsString</code>.<br>
2403      *
2404      * @param paraLevel specifies the default level for the text;
2405      *        it is typically 0 (LTR) or 1 (RTL).
2406      *        If the method shall determine the paragraph level from the text,
2407      *        then <code>paraLevel</code> can be set to
2408      *        either <code>LEVEL_DEFAULT_LTR</code>
2409      *        or <code>LEVEL_DEFAULT_RTL</code>; if the text contains multiple
2410      *        paragraphs, the paragraph level shall be determined separately for
2411      *        each paragraph; if a paragraph does not include any strongly typed
2412      *        character, then the desired default is used (0 for LTR or 1 for RTL).
2413      *        Any other value between 0 and <code>MAX_EXPLICIT_LEVEL</code>
2414      *        is also valid, with odd levels indicating RTL.
2415      *
2416      * @param embeddingLevels (in) may be used to preset the embedding and
2417      *        override levels, ignoring characters like LRE and PDF in the text.
2418      *        A level overrides the directional property of its corresponding
2419      *        (same index) character if the level has the
2420      *        <code>LEVEL_OVERRIDE</code> bit set.<br><br>
2421      *        Except for that bit, it must be
2422      *        <code>paraLevel<=embeddingLevels[]<=MAX_EXPLICIT_LEVEL</code>,
2423      *        with one exception: a level of zero may be specified for a
2424      *        paragraph separator even if <code>paraLevel&gt;0</code> when multiple
2425      *        paragraphs are submitted in the same call to <code>setPara()</code>.<br><br>
2426      *        <strong>Caution: </strong>A reference to this array, not a copy
2427      *        of the levels, will be stored in the <code>Bidi</code> object;
2428      *        the <code>embeddingLevels</code>
2429      *        should not be modified to avoid unexpected results on subsequent
2430      *        Bidi operations. However, the <code>setPara()</code> and
2431      *        <code>setLine()</code> methods may modify some or all of the
2432      *        levels.<br><br>
2433      *        <strong>Note:</strong> the <code>embeddingLevels</code> array must
2434      *        have one entry for each character in <code>text</code>.
2435      *
2436      * @throws IllegalArgumentException if the values in embeddingLevels are
2437      *         not within the allowed range
2438      *
2439      * @see #LEVEL_DEFAULT_LTR
2440      * @see #LEVEL_DEFAULT_RTL
2441      * @see #LEVEL_OVERRIDE
2442      * @see #MAX_EXPLICIT_LEVEL
2443      * @stable ICU 3.8
2444      */


2663      * in the text. This attribute, if present, must be applied to all the text
2664      * in the paragraph.<p>
2665      *
2666      * The BIDI_EMBEDDING attribute in the text, if present, represents
2667      * embedding level information. Negative values from -1 to -62 indicate
2668      * overrides at the absolute value of the level. Positive values from 1 to
2669      * 62 indicate embeddings. Where values are zero or not defined, the base
2670      * embedding level as determined by the base direction is assumed.<p>
2671      *
2672      * The NUMERIC_SHAPING attribute in the text, if present, converts European
2673      * digits to other decimal digits before running the bidi algorithm. This
2674      * attribute, if present, must be applied to all the text in the paragraph.
2675      *
2676      * If the entire text is all of the same directionality, then
2677      * the method may not perform all the steps described by the algorithm,
2678      * i.e., some levels may not be the same as if all steps were performed.
2679      * This is not relevant for unidirectional text.<br>
2680      * For example, in pure LTR text with numbers the numbers would get
2681      * a resolved level of 2 higher than the surrounding text according to
2682      * the algorithm. This implementation may set all resolved levels to
2683      * the same value in such a case.<p>
2684      *
2685      * @param paragraph a paragraph of text with optional character and
2686      *        paragraph attribute information
2687      * @stable ICU 3.8
2688      */
2689     public void setPara(AttributedCharacterIterator paragraph)
2690     {
2691         byte paraLvl;
2692         char ch = paragraph.first();
2693         Boolean runDirection =
2694             (Boolean) paragraph.getAttribute(TextAttributeConstants.RUN_DIRECTION);
2695         Object shaper = paragraph.getAttribute(TextAttributeConstants.NUMERIC_SHAPING);
2696         if (runDirection == null) {
2697             paraLvl = INTERNAL_LEVEL_DEFAULT_LTR;
2698         } else {
2699             paraLvl = (runDirection.equals(TextAttributeConstants.RUN_DIRECTION_LTR)) ?
2700                         (byte)Bidi.DIRECTION_LEFT_TO_RIGHT : (byte)Bidi.DIRECTION_RIGHT_TO_LEFT;
2701         }
2702 
2703         byte[] lvls = null;


2800      *         level may vary if the required paraLevel is LEVEL_DEFAULT_LTR or
2801      *         LEVEL_DEFAULT_RTL.  In that case, the level of the first paragraph
2802      *         is returned.
2803      *
2804      * @throws IllegalStateException if this call is not preceded by a successful
2805      *         call to <code>setPara</code> or <code>setLine</code>
2806      *
2807      * @see #LEVEL_DEFAULT_LTR
2808      * @see #LEVEL_DEFAULT_RTL
2809      * @see #getParagraph
2810      * @see #getParagraphByIndex
2811      * @stable ICU 3.8
2812      */
2813     public byte getParaLevel()
2814     {
2815         verifyValidParaOrLine();
2816         return paraLevel;
2817     }
2818 
2819     /**
2820      * Get the index of a paragraph, given a position within the text.<p>
2821      *
2822      * @param charIndex is the index of a character within the text, in the
2823      *        range <code>[0..getProcessedLength()-1]</code>.
2824      *
2825      * @return The index of the paragraph containing the specified position,
2826      *         starting from 0.
2827      *
2828      * @throws IllegalStateException if this call is not preceded by a successful
2829      *         call to <code>setPara</code> or <code>setLine</code>
2830      * @throws IllegalArgumentException if charIndex is not within the legal range
2831      *
2832      * @see com.ibm.icu.text.BidiRun
2833      * @see #getProcessedLength
2834      * @stable ICU 3.8
2835      */
2836     public int getParagraphIndex(int charIndex)
2837     {
2838         verifyValidParaOrLine();
2839         BidiBase bidi = paraBidi;             /* get Para object if Line object */
2840         verifyRange(charIndex, 0, bidi.length);




  64 import sun.text.normalizer.UCharacter;
  65 import sun.text.normalizer.UTF16;
  66 
  67 /**
  68  *
  69  * <h2>Bidi algorithm for ICU</h2>
  70  *
  71  * This is an implementation of the Unicode Bidirectional algorithm. The
  72  * algorithm is defined in the <a
  73  * href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>,
  74  * version 13, also described in The Unicode Standard, Version 4.0 .
  75  * <p>
  76  *
  77  * Note: Libraries that perform a bidirectional algorithm and reorder strings
  78  * accordingly are sometimes called "Storage Layout Engines". ICU's Bidi and
  79  * shaping (ArabicShaping) classes can be used at the core of such "Storage
  80  * Layout Engines".
  81  *
  82  * <h3>General remarks about the API:</h3>
  83  *
  84  * The "limit" of a sequence of characters is the position just after
  85  * their last character, i.e., one more than that position.
  86  * <p>
  87  *
  88  * Some of the API methods provide access to "runs". Such a
  89  * "run" is defined as a sequence of characters that are at the same
  90  * embedding level after performing the Bidi algorithm.

  91  *
  92  * <h3>Basic concept: paragraph</h3>
  93  * A piece of text can be divided into several paragraphs by characters
  94  * with the Bidi class <code>Block Separator</code>. For handling of
  95  * paragraphs, see:
  96  * <ul>
  97  * <li>{@link #countParagraphs}
  98  * <li>{@link #getParaLevel}
  99  * <li>{@link #getParagraph}
 100  * <li>{@link #getParagraphByIndex}
 101  * </ul>
 102  *
 103  * <h3>Basic concept: text direction</h3>
 104  * The direction of a piece of text may be:
 105  * <ul>
 106  * <li>{@link #LTR}
 107  * <li>{@link #RTL}
 108  * <li>{@link #MIXED}
 109  * </ul>
 110  *


 123  * specifying the level of a character to <i>override</i> whatever the
 124  * Bidi implementation would resolve it to.</li>
 125  * <li><code>paraLevel</code> can be set to the
 126  * pseudo-level values <code>LEVEL_DEFAULT_LTR</code>
 127  * and <code>LEVEL_DEFAULT_RTL</code>.</li>
 128  * </ul>
 129  *
 130  * <p>The related constants are not real, valid level values.
 131  * <code>DEFAULT_XXX</code> can be used to specify
 132  * a default for the paragraph level for
 133  * when the <code>setPara()</code> method
 134  * shall determine it but there is no
 135  * strongly typed character in the input.<p>
 136  *
 137  * Note that the value for <code>LEVEL_DEFAULT_LTR</code> is even
 138  * and the one for <code>LEVEL_DEFAULT_RTL</code> is odd,
 139  * just like with normal LTR and RTL level values -
 140  * these special values are designed that way. Also, the implementation
 141  * assumes that MAX_EXPLICIT_LEVEL is odd.
 142  *
 143  * <p><b>See Also:</b>
 144  * <ul>
 145  * <li>{@link #LEVEL_DEFAULT_LTR}
 146  * <li>{@link #LEVEL_DEFAULT_RTL}
 147  * <li>{@link #LEVEL_OVERRIDE}
 148  * <li>{@link #MAX_EXPLICIT_LEVEL}
 149  * <li>{@link #setPara}
 150  * </ul>
 151  *
 152  * <h3>Basic concept: Reordering Mode</h3>
 153  * Reordering mode values indicate which variant of the Bidi algorithm to
 154  * use.
 155  *
 156  * <p><b>See Also:</b>
 157  * <ul>
 158  * <li>{@link #setReorderingMode}
 159  * <li>{@link #REORDER_DEFAULT}
 160  * <li>{@link #REORDER_NUMBERS_SPECIAL}
 161  * <li>{@link #REORDER_GROUP_NUMBERS_WITH_R}
 162  * <li>{@link #REORDER_RUNS_ONLY}
 163  * <li>{@link #REORDER_INVERSE_NUMBERS_AS_L}
 164  * <li>{@link #REORDER_INVERSE_LIKE_DIRECT}
 165  * <li>{@link #REORDER_INVERSE_FOR_NUMBERS_SPECIAL}
 166  * </ul>
 167  *
 168  * <h3>Basic concept: Reordering Options</h3>
 169  * Reordering options can be applied during Bidi text transformations.
 170  * <p><b>See Also:</b>
 171  * <ul>
 172  * <li>{@link #setReorderingOptions}
 173  * <li>{@link #OPTION_DEFAULT}
 174  * <li>{@link #OPTION_INSERT_MARKS}
 175  * <li>{@link #OPTION_REMOVE_CONTROLS}
 176  * <li>{@link #OPTION_STREAMING}
 177  * </ul>
 178  *
 179  *
 180  * @author Simon Montagu, Matitiahu Allouche (ported from C code written by Markus W. Scherer)
 181  * @stable ICU 3.8
 182  *
 183  *
 184  * <h4> Sample code for the ICU Bidi API </h4>
 185  *
 186  * <h5>Rendering a paragraph with the ICU Bidi API</h5>
 187  *
 188  * This is (hypothetical) sample code that illustrates how the ICU Bidi API
 189  * could be used to render a paragraph of text. Rendering code depends highly on
 190  * the graphics system, therefore this sample code must make a lot of
 191  * assumptions, which may or may not match any existing graphics system's
 192  * properties.
 193  *
 194  * <p>
 195  * The basic assumptions are:
 196  * </p>
 197  * <ul>
 198  * <li>Rendering is done from left to right on a horizontal line.</li>
 199  * <li>A run of single-style, unidirectional text can be rendered at once.
 200  * </li>
 201  * <li>Such a run of text is passed to the graphics system with characters
 202  * (code units) in logical order.</li>
 203  * <li>The line-breaking algorithm is very complicated and Locale-dependent -
 204  * and therefore its implementation omitted from this sample code.</li>
 205  * </ul>
 206  *
 207  * <pre>{@code
 208  *
 209  *  package com.ibm.icu.dev.test.bidi;
 210  *
 211  *  import com.ibm.icu.text.Bidi;
 212  *  import com.ibm.icu.text.BidiRun;
 213  *
 214  *  public class Sample {
 215  *
 216  *      static final int styleNormal = 0;
 217  *      static final int styleSelected = 1;
 218  *      static final int styleBold = 2;
 219  *      static final int styleItalics = 4;
 220  *      static final int styleSuper=8;
 221  *      static final int styleSub = 16;
 222  *
 223  *      static class StyleRun {
 224  *          int limit;
 225  *          int style;
 226  *
 227  *          public StyleRun(int limit, int style) {


 436  *                  }
 437  *                  if (limit == length) {
 438  *                      break;
 439  *                  }
 440  *                  start = limit;
 441  *                  styleRunStart = styleRunLimit - 1;
 442  *                  if (start >= styleRuns[styleRunStart].limit) {
 443  *                      ++styleRunStart;
 444  *                  }
 445  *              }
 446  *          }
 447  *      }
 448  *
 449  *      public static void main(String[] args)
 450  *      {
 451  *          renderParagraph("Some Latin text...", Bidi.LTR, null, 0, 80);
 452  *          renderParagraph("Some Hebrew text...", Bidi.RTL, null, 0, 60);
 453  *      }
 454  *  }
 455  *
 456  * }</pre>
 457  */
 458 
 459 public class BidiBase {
 460 
 461     class Point {
 462         int pos;    /* position in text */
 463         int flag;   /* flag for LRM/RLM, before/after */
 464     }
 465 
 466     class InsertPoints {
 467         int size;
 468         int confirmed;
 469         Point[] points = new Point[0];
 470     }
 471 
 472     /** Paragraph level setting<p>
 473      *
 474      * Constant indicating that the base direction depends on the first strong
 475      * directional character in the text according to the Unicode Bidirectional
 476      * Algorithm. If no strong directional character is present,


2404      *        <code>getTextAsString</code>.<br>
2405      *
2406      * @param paraLevel specifies the default level for the text;
2407      *        it is typically 0 (LTR) or 1 (RTL).
2408      *        If the method shall determine the paragraph level from the text,
2409      *        then <code>paraLevel</code> can be set to
2410      *        either <code>LEVEL_DEFAULT_LTR</code>
2411      *        or <code>LEVEL_DEFAULT_RTL</code>; if the text contains multiple
2412      *        paragraphs, the paragraph level shall be determined separately for
2413      *        each paragraph; if a paragraph does not include any strongly typed
2414      *        character, then the desired default is used (0 for LTR or 1 for RTL).
2415      *        Any other value between 0 and <code>MAX_EXPLICIT_LEVEL</code>
2416      *        is also valid, with odd levels indicating RTL.
2417      *
2418      * @param embeddingLevels (in) may be used to preset the embedding and
2419      *        override levels, ignoring characters like LRE and PDF in the text.
2420      *        A level overrides the directional property of its corresponding
2421      *        (same index) character if the level has the
2422      *        <code>LEVEL_OVERRIDE</code> bit set.<br><br>
2423      *        Except for that bit, it must be
2424      *        {@code paraLevel<=embeddingLevels[]<=MAX_EXPLICIT_LEVEL},
2425      *        with one exception: a level of zero may be specified for a
2426      *        paragraph separator even if {@code paraLevel > 0} when multiple
2427      *        paragraphs are submitted in the same call to <code>setPara()</code>.<br><br>
2428      *        <strong>Caution: </strong>A reference to this array, not a copy
2429      *        of the levels, will be stored in the <code>Bidi</code> object;
2430      *        the <code>embeddingLevels</code>
2431      *        should not be modified to avoid unexpected results on subsequent
2432      *        Bidi operations. However, the <code>setPara()</code> and
2433      *        <code>setLine()</code> methods may modify some or all of the
2434      *        levels.<br><br>
2435      *        <strong>Note:</strong> the <code>embeddingLevels</code> array must
2436      *        have one entry for each character in <code>text</code>.
2437      *
2438      * @throws IllegalArgumentException if the values in embeddingLevels are
2439      *         not within the allowed range
2440      *
2441      * @see #LEVEL_DEFAULT_LTR
2442      * @see #LEVEL_DEFAULT_RTL
2443      * @see #LEVEL_OVERRIDE
2444      * @see #MAX_EXPLICIT_LEVEL
2445      * @stable ICU 3.8
2446      */


2665      * in the text. This attribute, if present, must be applied to all the text
2666      * in the paragraph.<p>
2667      *
2668      * The BIDI_EMBEDDING attribute in the text, if present, represents
2669      * embedding level information. Negative values from -1 to -62 indicate
2670      * overrides at the absolute value of the level. Positive values from 1 to
2671      * 62 indicate embeddings. Where values are zero or not defined, the base
2672      * embedding level as determined by the base direction is assumed.<p>
2673      *
2674      * The NUMERIC_SHAPING attribute in the text, if present, converts European
2675      * digits to other decimal digits before running the bidi algorithm. This
2676      * attribute, if present, must be applied to all the text in the paragraph.
2677      *
2678      * If the entire text is all of the same directionality, then
2679      * the method may not perform all the steps described by the algorithm,
2680      * i.e., some levels may not be the same as if all steps were performed.
2681      * This is not relevant for unidirectional text.<br>
2682      * For example, in pure LTR text with numbers the numbers would get
2683      * a resolved level of 2 higher than the surrounding text according to
2684      * the algorithm. This implementation may set all resolved levels to
2685      * the same value in such a case.
2686      *
2687      * @param paragraph a paragraph of text with optional character and
2688      *        paragraph attribute information
2689      * @stable ICU 3.8
2690      */
2691     public void setPara(AttributedCharacterIterator paragraph)
2692     {
2693         byte paraLvl;
2694         char ch = paragraph.first();
2695         Boolean runDirection =
2696             (Boolean) paragraph.getAttribute(TextAttributeConstants.RUN_DIRECTION);
2697         Object shaper = paragraph.getAttribute(TextAttributeConstants.NUMERIC_SHAPING);
2698         if (runDirection == null) {
2699             paraLvl = INTERNAL_LEVEL_DEFAULT_LTR;
2700         } else {
2701             paraLvl = (runDirection.equals(TextAttributeConstants.RUN_DIRECTION_LTR)) ?
2702                         (byte)Bidi.DIRECTION_LEFT_TO_RIGHT : (byte)Bidi.DIRECTION_RIGHT_TO_LEFT;
2703         }
2704 
2705         byte[] lvls = null;


2802      *         level may vary if the required paraLevel is LEVEL_DEFAULT_LTR or
2803      *         LEVEL_DEFAULT_RTL.  In that case, the level of the first paragraph
2804      *         is returned.
2805      *
2806      * @throws IllegalStateException if this call is not preceded by a successful
2807      *         call to <code>setPara</code> or <code>setLine</code>
2808      *
2809      * @see #LEVEL_DEFAULT_LTR
2810      * @see #LEVEL_DEFAULT_RTL
2811      * @see #getParagraph
2812      * @see #getParagraphByIndex
2813      * @stable ICU 3.8
2814      */
2815     public byte getParaLevel()
2816     {
2817         verifyValidParaOrLine();
2818         return paraLevel;
2819     }
2820 
2821     /**
2822      * Get the index of a paragraph, given a position within the text.
2823      *
2824      * @param charIndex is the index of a character within the text, in the
2825      *        range <code>[0..getProcessedLength()-1]</code>.
2826      *
2827      * @return The index of the paragraph containing the specified position,
2828      *         starting from 0.
2829      *
2830      * @throws IllegalStateException if this call is not preceded by a successful
2831      *         call to <code>setPara</code> or <code>setLine</code>
2832      * @throws IllegalArgumentException if charIndex is not within the legal range
2833      *
2834      * @see com.ibm.icu.text.BidiRun
2835      * @see #getProcessedLength
2836      * @stable ICU 3.8
2837      */
2838     public int getParagraphIndex(int charIndex)
2839     {
2840         verifyValidParaOrLine();
2841         BidiBase bidi = paraBidi;             /* get Para object if Line object */
2842         verifyRange(charIndex, 0, bidi.length);


< prev index next >