1 /*
2 * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
29 * Corporation and others. All Rights Reserved.
30 *******************************************************************************
31 */
32
33 /* FOOD FOR THOUGHT: currently the reordering modes are a mixture of
34 * algorithm for direct BiDi, algorithm for inverse Bidi and the bizarre
35 * concept of RUNS_ONLY which is a double operation.
36 * It could be advantageous to divide this into 3 concepts:
37 * a) Operation: direct / inverse / RUNS_ONLY
38 * b) Direct algorithm: default / NUMBERS_SPECIAL / GROUP_NUMBERS_WITH_L
39 * c) Inverse algorithm: default / INVERSE_LIKE_DIRECT / NUMBERS_SPECIAL
40 * This would allow combinations not possible today like RUNS_ONLY with
41 * NUMBERS_SPECIAL.
42 * Also allow to set INSERT_MARKS for the direct step of RUNS_ONLY and
43 * REMOVE_CONTROLS for the inverse step.
44 * Not all combinations would be supported, and probably not all do make sense.
45 * This would need to document which ones are supported and what are the
46 * fallbacks for unsupported combinations.
47 */
48
49 package sun.text.bidi;
50
51 import java.lang.reflect.Array;
52 import java.text.AttributedCharacterIterator;
53 import java.text.Bidi;
54 import java.util.Arrays;
55 import jdk.internal.access.JavaAWTFontAccess;
56 import jdk.internal.access.SharedSecrets;
57 import sun.text.normalizer.UBiDiProps;
58 import sun.text.normalizer.UCharacter;
59 import sun.text.normalizer.UTF16;
60
61 /**
62 *
63 * <h2>Bidi algorithm for ICU</h2>
64 *
65 * This is an implementation of the Unicode Bidirectional Algorithm. The
66 * algorithm is defined in the <a
67 * href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>.
68 * <p>
69 *
70 * Note: Libraries that perform a bidirectional algorithm and reorder strings
71 * accordingly are sometimes called "Storage Layout Engines". ICU's Bidi and
72 * shaping (ArabicShaping) classes can be used at the core of such "Storage
73 * Layout Engines".
74 *
75 * <h3>General remarks about the API:</h3>
76 *
77 * The "limit" of a sequence of characters is the position just after
78 * their last character, i.e., one more than that position.
79 * <p>
515 * If the text is not mixed-directional, then the
516 * algorithm steps for the weak type resolution are not performed,
517 * and all levels are set to the paragraph level.
518 *
519 * If there are no explicit embedding codes, then the (Xn) steps
520 * are not performed.
521 *
522 * If embedding levels are supplied as a parameter, then all
523 * explicit embedding codes are ignored, and the (Xn) steps
524 * are not performed.
525 *
526 * White Space types could get the level of the run they belong to,
527 * and are checked with a test of (flags&MASK_EMBEDDING) to
528 * consider if the paragraph direction should be considered in
529 * the flags variable.
530 *
531 * If there are no White Space types in the paragraph, then
532 * (L1) is not necessary in adjustWSLevels().
533 */
534
535 public class BidiBase {
536
537 static class Point {
538 int pos; /* position in text */
539 int flag; /* flag for LRM/RLM, before/after */
540 }
541
542 static class InsertPoints {
543 int size;
544 int confirmed;
545 Point[] points = new Point[0];
546 }
547
548 static class Opening {
549 int position; /* position of opening bracket */
550 int match; /* matching char or -position of closing bracket */
551 int contextPos; /* position of last strong char found before opening */
552 short flags; /* bits for L or R/AL found within the pair */
553 byte contextDir; /* L or R according to last strong char before opening */
554 }
|
1 /*
2 * Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
29 * Corporation and others. All Rights Reserved.
30 *******************************************************************************
31 */
32
33 /* FOOD FOR THOUGHT: currently the reordering modes are a mixture of
34 * algorithm for direct BiDi, algorithm for inverse Bidi and the bizarre
35 * concept of RUNS_ONLY which is a double operation.
36 * It could be advantageous to divide this into 3 concepts:
37 * a) Operation: direct / inverse / RUNS_ONLY
38 * b) Direct algorithm: default / NUMBERS_SPECIAL / GROUP_NUMBERS_WITH_L
39 * c) Inverse algorithm: default / INVERSE_LIKE_DIRECT / NUMBERS_SPECIAL
40 * This would allow combinations not possible today like RUNS_ONLY with
41 * NUMBERS_SPECIAL.
42 * Also allow to set INSERT_MARKS for the direct step of RUNS_ONLY and
43 * REMOVE_CONTROLS for the inverse step.
44 * Not all combinations would be supported, and probably not all do make sense.
45 * This would need to document which ones are supported and what are the
46 * fallbacks for unsupported combinations.
47 */
48
49 package jdk.internal.icu.text;
50
51 import java.lang.reflect.Array;
52 import java.text.AttributedCharacterIterator;
53 import java.text.Bidi;
54 import java.util.Arrays;
55 import jdk.internal.access.JavaAWTFontAccess;
56 import jdk.internal.access.SharedSecrets;
57 import jdk.internal.icu.lang.UCharacter;
58 import jdk.internal.icu.impl.UBiDiProps;
59
60 /**
61 *
62 * <h2>Bidi algorithm for ICU</h2>
63 *
64 * This is an implementation of the Unicode Bidirectional Algorithm. The
65 * algorithm is defined in the <a
66 * href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>.
67 * <p>
68 *
69 * Note: Libraries that perform a bidirectional algorithm and reorder strings
70 * accordingly are sometimes called "Storage Layout Engines". ICU's Bidi and
71 * shaping (ArabicShaping) classes can be used at the core of such "Storage
72 * Layout Engines".
73 *
74 * <h3>General remarks about the API:</h3>
75 *
76 * The "limit" of a sequence of characters is the position just after
77 * their last character, i.e., one more than that position.
78 * <p>
514 * If the text is not mixed-directional, then the
515 * algorithm steps for the weak type resolution are not performed,
516 * and all levels are set to the paragraph level.
517 *
518 * If there are no explicit embedding codes, then the (Xn) steps
519 * are not performed.
520 *
521 * If embedding levels are supplied as a parameter, then all
522 * explicit embedding codes are ignored, and the (Xn) steps
523 * are not performed.
524 *
525 * White Space types could get the level of the run they belong to,
526 * and are checked with a test of (flags&MASK_EMBEDDING) to
527 * consider if the paragraph direction should be considered in
528 * the flags variable.
529 *
530 * If there are no White Space types in the paragraph, then
531 * (L1) is not necessary in adjustWSLevels().
532 */
533
534 // Original filename in ICU4J: Bidi.java
535 public class BidiBase {
536
537 static class Point {
538 int pos; /* position in text */
539 int flag; /* flag for LRM/RLM, before/after */
540 }
541
542 static class InsertPoints {
543 int size;
544 int confirmed;
545 Point[] points = new Point[0];
546 }
547
548 static class Opening {
549 int position; /* position of opening bracket */
550 int match; /* matching char or -position of closing bracket */
551 int contextPos; /* position of last strong char found before opening */
552 short flags; /* bits for L or R/AL found within the pair */
553 byte contextDir; /* L or R according to last strong char before opening */
554 }
|