< prev index next >

jdk/src/java.base/share/classes/sun/text/bidi/BidiLine.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -20,31 +20,27 @@
  *
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
 /*
- *******************************************************************************
- * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved         *
- *                                                                             *
- * The original version of this source code and documentation is copyrighted   *
- * and owned by IBM, These materials are provided under terms of a License     *
- * Agreement between IBM and Sun. This technology is protected by multiple     *
- * US and International patents. This notice and attribution to IBM may not    *
- * to removed.                                                                 *
- *******************************************************************************
- */
+*******************************************************************************
+*   Copyright (C) 2001-2014, International Business Machines
+*   Corporation and others.  All Rights Reserved.
+*******************************************************************************
+*/
 /* Written by Simon Montagu, Matitiahu Allouche
  * (ported from C code written by Markus W. Scherer)
  */
 
 package sun.text.bidi;
 
 import java.text.Bidi;
 import java.util.Arrays;
 
-public final class BidiLine {
+final class BidiLine {
 
     /*
      * General remarks about the functions in this file:
      *
      * These functions deal with the aspects of potentially mixed-directional

@@ -120,17 +116,17 @@
            are already set to paragraph level.
            Setting trailingWSStart to pBidi->length will avoid changing the
            level of B chars from 0 to paraLevel in getLevels when
            orderParagraphsLTR==TRUE
         */
-        if (BidiBase.NoContextRTL(dirProps[start - 1]) == BidiBase.B) {
+        if (dirProps[start - 1] == BidiBase.B) {
             bidiBase.trailingWSStart = start;   /* currently == bidiBase.length */
             return;
         }
         /* go backwards across all WS, BN, explicit codes */
         while (start > 0 &&
-                (BidiBase.DirPropFlagNC(dirProps[start - 1]) & BidiBase.MASK_WS) != 0) {
+                (BidiBase.DirPropFlag(dirProps[start - 1]) & BidiBase.MASK_WS) != 0) {
             --start;
         }
 
         /* if the WS run can be merged with the previous run then do so here */
         while (start > 0 && levels[start - 1] == paraLevel) {

@@ -138,17 +134,15 @@
         }
 
         bidiBase.trailingWSStart=start;
     }
 
-    public static Bidi setLine(Bidi bidi, BidiBase paraBidi,
-                               Bidi newBidi, BidiBase newBidiBase,
+    static Bidi setLine(BidiBase paraBidi,
+                              Bidi newBidi, BidiBase lineBidi,
                                int start, int limit) {
         int length;
 
-        BidiBase lineBidi = newBidiBase;
-
         /* set the values in lineBidi from its paraBidi parent */
         /* class members are already initialized to 0 */
         // lineBidi.paraBidi = null;        /* mark unfinished setLine */
         // lineBidi.flags = 0;
         // lineBidi.controlCount = 0;

@@ -159,10 +153,12 @@
         lineBidi.text = new char[length];
         System.arraycopy(paraBidi.text, start, lineBidi.text, 0, length);
         lineBidi.paraLevel = paraBidi.GetParaLevelAt(start);
         lineBidi.paraCount = paraBidi.paraCount;
         lineBidi.runs = new BidiRun[0];
+        lineBidi.reorderingMode = paraBidi.reorderingMode;
+        lineBidi.reorderingOptions = paraBidi.reorderingOptions;
         if (paraBidi.controlCount > 0) {
             int j;
             for (j = start; j < limit; j++) {
                 if (BidiBase.IsBidiControlChar(paraBidi.text[j])) {
                     lineBidi.controlCount++;

@@ -204,11 +200,11 @@
             byte level;
 
             setTrailingWSStart(lineBidi);
             trailingWSStart = lineBidi.trailingWSStart;
 
-            /* recalculate lineBidi.direction */
+            /* recalculate lineBidiBase.direction */
             if (trailingWSStart == 0) {
                 /* all levels are at paraLevel */
                 lineBidi.direction = (byte)(lineBidi.paraLevel & 1);
             } else {
                 /* get the level of the first character */

@@ -258,11 +254,12 @@
                 default:
                     break;
             }
         }
 
-        newBidiBase.paraBidi = paraBidi; /* mark successful setLine */
+        lineBidi.paraBidi = paraBidi;     /* mark successful setLine */
+
         return newBidi;
     }
 
     static byte getLevelAt(BidiBase bidiBase, int charIndex)
     {

@@ -301,34 +298,23 @@
             return levels;
         }
         return bidiBase.levels;
     }
 
-    static BidiRun getLogicalRun(BidiBase bidiBase, int logicalPosition)
-    {
-        /* this is done based on runs rather than on levels since levels have
-           a special interpretation when REORDER_RUNS_ONLY
-         */
-        BidiRun newRun = new BidiRun(), iRun;
-        getRuns(bidiBase);
-        int runCount = bidiBase.runCount;
-        int visualStart = 0, logicalLimit = 0;
-        iRun = bidiBase.runs[0];
-
-        for (int i = 0; i < runCount; i++) {
-            iRun = bidiBase.runs[i];
-            logicalLimit = iRun.start + iRun.limit - visualStart;
-            if ((logicalPosition >= iRun.start) &&
-                (logicalPosition < logicalLimit)) {
-                break;
-            }
-            visualStart = iRun.limit;
+    static BidiRun getVisualRun(BidiBase bidiBase, int runIndex) {
+        int start = bidiBase.runs[runIndex].start;
+        int limit;
+        byte level = bidiBase.runs[runIndex].level;
+
+        if (runIndex > 0) {
+            limit = start +
+                    bidiBase.runs[runIndex].limit -
+                    bidiBase.runs[runIndex - 1].limit;
+        } else {
+            limit = start + bidiBase.runs[0].limit;
         }
-        newRun.start = iRun.start;
-        newRun.limit = logicalLimit;
-        newRun.level = iRun.level;
-        return newRun;
+        return new BidiRun(start, limit, level);
     }
 
     /* in trivial cases there is only one trivial run; called by getRuns() */
     private static void getSingleRun(BidiBase bidiBase, byte level) {
         /* simple, single-run case */

@@ -500,11 +486,11 @@
         } else /* BidiBase.MIXED, length>0 */ {
             /* mixed directionality */
             int length = bidiBase.length, limit;
             byte[] levels = bidiBase.levels;
             int i, runCount;
-            byte level = BidiBase.INTERNAL_LEVEL_DEFAULT_LTR;   /* initialize with no valid level */
+            byte level = -1;    /* initialize with no valid level */
             /*
              * If there are WS characters at the end of the line
              * and the run preceding them has a level different from
              * paraLevel, then they will form their own run at paraLevel (L1).
              * Count them separately.

@@ -649,11 +635,11 @@
         /* determine minLevel and maxLevel */
         minLevel = BidiBase.MAX_EXPLICIT_LEVEL + 1;
         maxLevel = 0;
         for (start = levels.length; start>0; ) {
             level = levels[--start];
-            if (level > BidiBase.MAX_EXPLICIT_LEVEL + 1) {
+            if (level < 0 || level > (BidiBase.MAX_EXPLICIT_LEVEL + 1)) {
                 return null;
             }
             if (level < minLevel) {
                 minLevel = level;
             }
< prev index next >