jdk/src/share/classes/java/text/Bidi.java
author naoto
Tue, 31 Aug 2010 11:27:10 -0700
changeset 6489 9e7015635425
parent 5506 202f599c92aa
child 19054 a64012cb49d6
permissions -rw-r--r--
4700857: RFE: separating user locale and user interface locale Reviewed-by: okutsu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4510
diff changeset
     2
 * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4510
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4510
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4510
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4510
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4510
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright IBM Corp. 1999-2003 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * The original version of this source code and documentation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * copyrighted and owned by IBM. These materials are provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * under terms of a License Agreement between IBM and Sun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * patents. This notice and attribution to IBM may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
package java.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
    38
import sun.text.bidi.BidiBase;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This class implements the Unicode Bidirectional Algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * A Bidi object provides information on the bidirectional reordering of the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * used to create it.  This is required, for example, to properly display Arabic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * or Hebrew text.  These languages are inherently mixed directional, as they order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * numbers from left-to-right while ordering most other text from right-to-left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Once created, a Bidi object can be queried to see if the text it represents is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * all left-to-right or all right-to-left.  Such objects are very lightweight and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * this text is relatively easy to process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * If there are multiple runs of text, information about the runs can be accessed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * by indexing to get the start, limit, and level of a run.  The level represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * both the direction and the 'nesting level' of a directional run.  Odd levels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * are right-to-left, while even levels are left-to-right.  So for example level
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * 0 represents left-to-right text, while level 1 represents right-to-left text, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * level 2 represents left-to-right text embedded in a right-to-left run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public final class Bidi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /** Constant indicating base direction is left-to-right. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public static final int DIRECTION_LEFT_TO_RIGHT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /** Constant indicating base direction is right-to-left. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static final int DIRECTION_RIGHT_TO_LEFT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Constant indicating that the base direction depends on the first strong
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * directional character in the text according to the Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Bidirectional Algorithm.  If no strong directional character is present,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * the base direction is left-to-right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final int DIRECTION_DEFAULT_LEFT_TO_RIGHT = -2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Constant indicating that the base direction depends on the first strong
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * directional character in the text according to the Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Bidirectional Algorithm.  If no strong directional character is present,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * the base direction is right-to-left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final int DIRECTION_DEFAULT_RIGHT_TO_LEFT = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
    85
    private BidiBase bidiBase;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Create Bidi from the given paragraph of text and base direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param paragraph a paragraph of text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param flags a collection of flags that control the algorithm.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * algorithm understands the flags DIRECTION_LEFT_TO_RIGHT, DIRECTION_RIGHT_TO_LEFT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * DIRECTION_DEFAULT_LEFT_TO_RIGHT, and DIRECTION_DEFAULT_RIGHT_TO_LEFT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Other values are reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public Bidi(String paragraph, int flags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (paragraph == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            throw new IllegalArgumentException("paragraph is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   100
        bidiBase = new BidiBase(paragraph.toCharArray(), 0, null, 0, paragraph.length(), flags);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Create Bidi from the given paragraph of text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * The RUN_DIRECTION attribute in the text, if present, determines the base
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * direction (left-to-right or right-to-left).  If not present, the base
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * direction is computes using the Unicode Bidirectional Algorithm, defaulting to left-to-right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * if there are no strong directional characters in the text.  This attribute, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * present, must be applied to all the text in the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * The BIDI_EMBEDDING attribute in the text, if present, represents embedding level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * information.  Negative values from -1 to -62 indicate overrides at the absolute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * of the level.  Positive values from 1 to 62 indicate embeddings.  Where values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * zero or not defined, the base embedding level as determined by the base direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * is assumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * The NUMERIC_SHAPING attribute in the text, if present, converts European digits to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * other decimal digits before running the bidi algorithm.  This attribute, if present,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * must be applied to all the text in the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param paragraph a paragraph of text with optional character and paragraph attribute information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
4510
b3885d5c3fba 6909070: Missing package statements in java.text.Bidi @see links
darcy
parents: 2956
diff changeset
   124
     * @see java.awt.font.TextAttribute#BIDI_EMBEDDING
b3885d5c3fba 6909070: Missing package statements in java.text.Bidi @see links
darcy
parents: 2956
diff changeset
   125
     * @see java.awt.font.TextAttribute#NUMERIC_SHAPING
b3885d5c3fba 6909070: Missing package statements in java.text.Bidi @see links
darcy
parents: 2956
diff changeset
   126
     * @see java.awt.font.TextAttribute#RUN_DIRECTION
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public Bidi(AttributedCharacterIterator paragraph) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (paragraph == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            throw new IllegalArgumentException("paragraph is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   133
        bidiBase = new BidiBase(0, 0);
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   134
        bidiBase.setPara(paragraph);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Create Bidi from the given text, embedding, and direction information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * The embeddings array may be null.  If present, the values represent embedding level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * information.  Negative values from -1 to -61 indicate overrides at the absolute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * of the level.  Positive values from 1 to 61 indicate embeddings.  Where values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * zero, the base embedding level as determined by the base direction is assumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param text an array containing the paragraph of text to process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param textStart the index into the text array of the start of the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param embeddings an array containing embedding values for each character in the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * This can be null, in which case it is assumed that there is no external embedding information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param embStart the index into the embedding array of the start of the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param paragraphLength the length of the paragraph in the text and embeddings arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param flags a collection of flags that control the algorithm.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * algorithm understands the flags DIRECTION_LEFT_TO_RIGHT, DIRECTION_RIGHT_TO_LEFT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * DIRECTION_DEFAULT_LEFT_TO_RIGHT, and DIRECTION_DEFAULT_RIGHT_TO_LEFT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Other values are reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public Bidi(char[] text, int textStart, byte[] embeddings, int embStart, int paragraphLength, int flags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (text == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            throw new IllegalArgumentException("text is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (paragraphLength < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            throw new IllegalArgumentException("bad length: " + paragraphLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (textStart < 0 || paragraphLength > text.length - textStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            throw new IllegalArgumentException("bad range: " + textStart +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                               " length: " + paragraphLength +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                               " for text of length: " + text.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (embeddings != null && (embStart < 0 || paragraphLength > embeddings.length - embStart)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            throw new IllegalArgumentException("bad range: " + embStart +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                               " length: " + paragraphLength +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                               " for embeddings of length: " + text.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   172
        bidiBase = new BidiBase(text, textStart, embeddings, embStart, paragraphLength, flags);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Create a Bidi object representing the bidi information on a line of text within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * the paragraph represented by the current Bidi.  This call is not required if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * entire paragraph fits on one line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param lineStart the offset from the start of the paragraph to the start of the line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param lineLimit the offset from the start of the paragraph to the limit of the line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public Bidi createLineBidi(int lineStart, int lineLimit) {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   183
        AttributedString astr = new AttributedString("");
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   184
        Bidi newBidi = new Bidi(astr.getIterator());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   186
        return bidiBase.setLine(this, bidiBase, newBidi, newBidi.bidiBase,lineStart, lineLimit);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Return true if the line is not left-to-right or right-to-left.  This means it either has mixed runs of left-to-right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * and right-to-left text, or the base direction differs from the direction of the only run of text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @return true if the line is not left-to-right or right-to-left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public boolean isMixed() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   195
        return bidiBase.isMixed();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Return true if the line is all left-to-right text and the base direction is left-to-right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @return true if the line is all left-to-right text and the base direction is left-to-right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public boolean isLeftToRight() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   203
        return bidiBase.isLeftToRight();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Return true if the line is all right-to-left text, and the base direction is right-to-left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @return true if the line is all right-to-left text, and the base direction is right-to-left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public boolean isRightToLeft() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   211
        return bidiBase.isRightToLeft();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Return the length of text in the line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @return the length of text in the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public int getLength() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   219
        return bidiBase.getLength();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Return true if the base direction is left-to-right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @return true if the base direction is left-to-right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public boolean baseIsLeftToRight() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   227
        return bidiBase.baseIsLeftToRight();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Return the base level (0 if left-to-right, 1 if right-to-left).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return the base level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public int getBaseLevel() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   235
        return bidiBase.getParaLevel();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Return the resolved level of the character at offset.  If offset is <0 or >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * the length of the line, return the base direction level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param offset the index of the character for which to return the level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @return the resolved level of the character at offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public int getLevelAt(int offset) {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   245
        return bidiBase.getLevelAt(offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Return the number of level runs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @return the number of level runs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public int getRunCount() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   253
        return bidiBase.countRuns();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Return the level of the nth logical run in this line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param run the index of the run, between 0 and <code>getRunCount()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @return the level of the run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public int getRunLevel(int run) {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   262
        return bidiBase.getRunLevel(run);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Return the index of the character at the start of the nth logical run in this line, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * an offset from the start of the line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param run the index of the run, between 0 and <code>getRunCount()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @return the start of the run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public int getRunStart(int run) {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   272
        return bidiBase.getRunStart(run);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Return the index of the character past the end of the nth logical run in this line, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * an offset from the start of the line.  For example, this will return the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * of the line for the last run on the line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param run the index of the run, between 0 and <code>getRunCount()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return limit the limit of the run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public int getRunLimit(int run) {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   283
        return bidiBase.getRunLimit(run);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Return true if the specified text requires bidi analysis.  If this returns false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * the text will display left-to-right.  Clients can then avoid constructing a Bidi object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Text in the Arabic Presentation Forms area of Unicode is presumed to already be shaped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * and ordered for display, and so will not cause this function to return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param text the text containing the characters to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @param start the start of the range of characters to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @param limit the limit of the range of characters to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @return true if the range of characters requires bidi analysis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public static boolean requiresBidi(char[] text, int start, int limit) {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   298
        return BidiBase.requiresBidi(text, start, limit);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Reorder the objects in the array into visual order based on their levels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * This is a utility function to use when you have a collection of objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * representing runs of text in logical order, each run containing text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * at a single level.  The elements at <code>index</code> from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * <code>objectStart</code> up to <code>objectStart + count</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * in the objects array will be reordered into visual order assuming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * each run of text has the level indicated by the corresponding element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * in the levels array (at <code>index - objectStart + levelStart</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @param levels an array representing the bidi level of each object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @param levelStart the start position in the levels array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @param objects the array of objects to be reordered into visual order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @param objectStart the start position in the objects array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @param count the number of objects to reorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public static void reorderVisually(byte[] levels, int levelStart, Object[] objects, int objectStart, int count) {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   318
        BidiBase.reorderVisually(levels, levelStart, objects, objectStart, count);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Display the bidi internal state, used in debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public String toString() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   325
        return bidiBase.toString();
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   326
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
}