src/java.base/share/classes/java/text/Bidi.java
author naoto
Tue, 15 Oct 2019 09:25:59 -0700
changeset 58603 2312d1a04c49
parent 58288 48e480e56aad
permissions -rw-r--r--
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size 8231984: Clarify semantics of DecimalFormat.getGroupingSize(0) Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2019, 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.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   179
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param lineStart the offset from the start of the paragraph to the start of the line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param lineLimit the offset from the start of the paragraph to the limit of the line.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   182
     * @return a {@code Bidi} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    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
   185
        AttributedString astr = new AttributedString("");
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   186
        Bidi newBidi = new Bidi(astr.getIterator());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 25859
diff changeset
   188
        return bidiBase.setLine(this, bidiBase, newBidi, newBidi.bidiBase, lineStart, lineLimit);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * 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
   193
     * and right-to-left text, or the base direction differs from the direction of the only run of text.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   194
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @return true if the line is not left-to-right or right-to-left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public boolean isMixed() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   198
        return bidiBase.isMixed();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Return true if the line is all left-to-right text and the base direction is left-to-right.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   203
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @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
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public boolean isLeftToRight() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   207
        return bidiBase.isLeftToRight();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * 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
   212
     * @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
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public boolean isRightToLeft() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   215
        return bidiBase.isRightToLeft();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Return the length of text in the line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return the length of text in the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public int getLength() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   223
        return bidiBase.getLength();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Return true if the base direction is left-to-right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @return true if the base direction is left-to-right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public boolean baseIsLeftToRight() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   231
        return bidiBase.baseIsLeftToRight();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Return the base level (0 if left-to-right, 1 if right-to-left).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @return the base level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public int getBaseLevel() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   239
        return bidiBase.getParaLevel();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   243
     * Return the resolved level of the character at offset.  If offset is
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   244
     * {@literal <} 0 or &ge; the length of the line, return the base direction
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   245
     * level.
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 5506
diff changeset
   246
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param offset the index of the character for which to return the level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @return the resolved level of the character at offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public int getLevelAt(int offset) {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   251
        return bidiBase.getLevelAt(offset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Return the number of level runs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return the number of level runs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public int getRunCount() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   259
        return bidiBase.countRuns();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Return the level of the nth logical run in this line.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   264
     * @param run the index of the run, between 0 and {@code getRunCount()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @return the level of the run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public int getRunLevel(int run) {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   268
        return bidiBase.getRunLevel(run);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * 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
   273
     * an offset from the start of the line.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   274
     * @param run the index of the run, between 0 and {@code getRunCount()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return the start of the run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public int getRunStart(int run) {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   278
        return bidiBase.getRunStart(run);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * 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
   283
     * an offset from the start of the line.  For example, this will return the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * of the line for the last run on the line.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   285
     * @param run the index of the run, between 0 and {@code getRunCount()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @return limit the limit of the run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public int getRunLimit(int run) {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   289
        return bidiBase.getRunLimit(run);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Return true if the specified text requires bidi analysis.  If this returns false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * the text will display left-to-right.  Clients can then avoid constructing a Bidi object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Text in the Arabic Presentation Forms area of Unicode is presumed to already be shaped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * and ordered for display, and so will not cause this function to return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @param text the text containing the characters to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param start the start of the range of characters to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param limit the limit of the range of characters to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @return true if the range of characters requires bidi analysis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    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
   304
        return BidiBase.requiresBidi(text, start, limit);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Reorder the objects in the array into visual order based on their levels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * This is a utility function to use when you have a collection of objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * representing runs of text in logical order, each run containing text
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   311
     * at a single level.  The elements at {@code index} from
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   312
     * {@code objectStart} up to {@code objectStart + count}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * in the objects array will be reordered into visual order assuming
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * each run of text has the level indicated by the corresponding element
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 47216
diff changeset
   315
     * in the levels array (at {@code index - objectStart + levelStart}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @param levels an array representing the bidi level of each object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @param levelStart the start position in the levels array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @param objects the array of objects to be reordered into visual order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @param objectStart the start position in the objects array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @param count the number of objects to reorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    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
   324
        BidiBase.reorderVisually(levels, levelStart, objects, objectStart, count);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Display the bidi internal state, used in debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public String toString() {
2956
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   331
        return bidiBase.toString();
931f209e57a9 6850113: Bidi class needs to be updated to support Unicode 5.1
peytoia
parents: 2
diff changeset
   332
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
}