code: private void adjustWSLevels() {
          int i;
  
          if ((flags & MASK_WS) != 0) {
              int flag;
              i = trailingWSStart;
              while (i > 0) {
                  /* reset a sequence of WS/BN before eop and B/S to the paragraph paraLevel */
                  while (i > 0 && ((flag = DirPropFlag(dirProps[--i])) & MASK_WS) != 0) {
                      if (orderParagraphsLTR && (flag & DirPropFlag(B)) != 0) {
                          levels[i] = 0;
                      } else {
                          levels[i] = GetParaLevelAt(i);
                      }
                  }
  
                  /* reset BN to the next character's paraLevel until B/S, which restarts above loop */
                  /* here, i+1 is guaranteed to be <length */
                  while (i > 0) {
                      flag = DirPropFlag(dirProps[--i]);
                      if ((flag & MASK_BN_EXPLICIT) != 0) {
                          levels[i] = levels[i + 1];
                      } else if (orderParagraphsLTR && (flag & DirPropFlag(B)) != 0) {
                          levels[i] = 0;
                          break;
                      } else if ((flag & MASK_B_S) != 0){
                          levels[i] = GetParaLevelAt(i);
                          break;
                      }
                  }
              }
          }
      }
docs: /*
  Reset the embedding levels for some non-graphic characters (L1).
  This method also sets appropriate levels for BN, and
  explicit embedding types that are supposed to have been removed
  from the paragraph in (X9).