Ejemplo n.º 1
0
 @Override
 protected Integer parse(String argument) throws NumberFormatException, CmdLineException {
   int value = Integer.parseInt(argument);
   Range range = setter.asAnnotatedElement().getAnnotation(Range.class);
   if (range != null && value != Math.min(Math.max(value, range.min()), range.max())) {
     throw new NumberFormatException();
   }
   return value;
 }
 private void readNames(int base) {
   pos = base;
   int nextra = readInt(2);
   names = new String[nextra];
   //	safenames= new String[nextra];
   for (int i = 0; i < nextra; i++) {
     Range r = getIndexEntry(base, i);
     names[i] = new String(data, r.getStart(), r.getLen());
     System.out.println(
         "Read name: "
             + i
             + " from "
             + r.getStart()
             + " to "
             + r.getEnd()
             + ": "
             + safe(names[i]));
   }
 }
 private void readDict(Range r) {
   //	System.out.println("reading dictionary from "+r.getStart()+" to "+r.getEnd());
   pos = r.getStart();
   while (pos < r.getEnd()) {
     int cmd = readCommand(false);
     if (cmd == 1006) { // charstringtype, default=2
       charstringtype = (int) stack[0];
     } else if (cmd == 1007) { // fontmatrix
       if (stackptr == 4) {
         at =
             new AffineTransform(
                 (float) stack[0], (float) stack[1], (float) stack[2], (float) stack[3], 0, 0);
       } else {
         at =
             new AffineTransform(
                 (float) stack[0],
                 (float) stack[1],
                 (float) stack[2],
                 (float) stack[3],
                 (float) stack[4],
                 (float) stack[5]);
       }
     } else if (cmd == 15) { // charset
       charsetbase = (int) stack[0];
     } else if (cmd == 16) { // encoding
       encodingbase = (int) stack[0];
     } else if (cmd == 17) { // charstrings
       charstringbase = (int) stack[0];
     } else if (cmd == 18) { // private
       privatesize = (int) stack[0];
       privatebase = (int) stack[1];
     } else if (cmd == 19) { // subrs (in Private dict)
       lsubrbase = (int) stack[0];
       lsubrsoffset = calcoffset(lsubrbase);
     } else if (cmd == 20) { // defaultWidthX (in Private dict)
       defaultWidthX = (int) stack[0];
     } else if (cmd == 21) { // nominalWidthX (in Private dict)
       nominalWidthX = (int) stack[0];
     }
     stackptr = 0;
   }
 }
  public void parseGlyph(Range r, GlyphData gp, FlPoint pt) {
    pos = r.getStart();
    int i;
    float x1, y1, x2, y2, x3, y3, ybase;
    int hold;
    int stemhints = 0;
    gp.setAdvance(defaultWidthX);
    while (pos < r.getEnd()) {
      int cmd = readCommand(true);
      hold = 0;
      switch (cmd) {
        case 1: // hstem
        case 3: // vstem
          if ((stackptr & 1) == 1) {
            gp.setAdvance(nominalWidthX + stack[0]);
          }
          stackptr = 0;
          break;
        case 4: // vmoveto
          if (stackptr > 1) { // this is the first call, arg1 is width
            gp.setAdvance(nominalWidthX + stack[0]);
            stack[0] = stack[1];
          }
          pt.y += stack[0];
          if (pt.open) {
            gp.closePath();
          }
          pt.open = false;
          gp.moveTo(pt.x, pt.y);
          stackptr = 0;
          break;
        case 5: // rlineto
          for (i = 0; i < stackptr; ) {
            pt.x += stack[i++];
            pt.y += stack[i++];
            gp.lineTo(pt.x, pt.y);
          }
          pt.open = true;
          stackptr = 0;
          break;
        case 6: // hlineto
          for (i = 0; i < stackptr; ) {
            if ((i & 1) == 0) {
              pt.x += stack[i++];
            } else {
              pt.y += stack[i++];
            }
            gp.lineTo(pt.x, pt.y);
          }
          pt.open = true;
          stackptr = 0;
          break;
        case 7: // vlineto
          for (i = 0; i < stackptr; ) {
            if ((i & 1) == 0) {
              pt.y += stack[i++];
            } else {
              pt.x += stack[i++];
            }
            gp.lineTo(pt.x, pt.y);
          }
          pt.open = true;
          stackptr = 0;
          break;
        case 8: // rrcurveto
          for (i = 0; i < stackptr; ) {
            x1 = pt.x + stack[i++];
            y1 = pt.y + stack[i++];
            x2 = x1 + stack[i++];
            y2 = y1 + stack[i++];
            pt.x = x2 + stack[i++];
            pt.y = y2 + stack[i++];
            gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          }
          pt.open = true;
          stackptr = 0;
          break;
        case 10: // callsubr
          hold = pos;
          i = (int) stack[--stackptr] + lsubrsoffset;
          Range lsubr = getIndexEntry(lsubrbase, i);
          parseGlyph(lsubr, gp, pt);
          pos = hold;
          break;
        case 11: // return
          return;
        case 14: // endchar
          if (stackptr == 5) {
            buildAccentChar(stack[1], stack[2], stack[3], stack[4], gp);
          }

          if (pt.open) {
            gp.closePath();
          }
          pt.open = false;
          stackptr = 0;
          return;
        case 18: // hstemhm
          if ((stackptr & 1) == 1) {
            gp.setAdvance(nominalWidthX + stack[0]);
          }
          stemhints += stackptr / 2;
          stackptr = 0;
          break;
        case 19: // hintmask
        case 20: // cntrmask
          if ((stackptr & 1) == 1) {
            gp.setAdvance(nominalWidthX + stack[0]);
          }
          stemhints += stackptr / 2;
          System.out.println(
              "Added "
                  + stackptr
                  + " extra bits;  skipping "
                  + ((stemhints - 1) / 8 + 1)
                  + " from "
                  + stemhints);
          pos += (stemhints - 1) / 8 + 1;
          stackptr = 0;
          break;
        case 21: // rmoveto
          if (stackptr > 2) {
            gp.setAdvance(nominalWidthX + stack[0]);
            stack[0] = stack[1];
            stack[1] = stack[2];
          }
          pt.x += stack[0];
          pt.y += stack[1];
          if (pt.open) {
            gp.closePath();
          }
          gp.moveTo(pt.x, pt.y);
          pt.open = false;
          stackptr = 0;
          break;
        case 22: // hmoveto
          if (stackptr > 1) {
            gp.setAdvance(nominalWidthX + stack[0]);
            stack[0] = stack[1];
          }
          pt.x += stack[0];
          if (pt.open) {
            gp.closePath();
          }
          gp.moveTo(pt.x, pt.y);
          pt.open = false;
          stackptr = 0;
          break;
        case 23: // vstemhm
          if ((stackptr & 1) == 1) {
            gp.setAdvance(nominalWidthX + stack[0]);
          }
          stemhints += stackptr / 2;
          stackptr = 0;
          break;
        case 24: // rcurveline
          for (i = 0; i < stackptr - 2; ) {
            x1 = pt.x + stack[i++];
            y1 = pt.y + stack[i++];
            x2 = x1 + stack[i++];
            y2 = y1 + stack[i++];
            pt.x = x2 + stack[i++];
            pt.y = y2 + stack[i++];
            gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          }
          pt.x += stack[i++];
          pt.y += stack[i++];
          gp.lineTo(pt.x, pt.y);
          pt.open = true;
          stackptr = 0;
          break;
        case 25: // rlinecurve
          for (i = 0; i < stackptr - 6; ) {
            pt.x += stack[i++];
            pt.y += stack[i++];
            gp.lineTo(pt.x, pt.y);
          }
          x1 = pt.x + stack[i++];
          y1 = pt.y + stack[i++];
          x2 = x1 + stack[i++];
          y2 = y1 + stack[i++];
          pt.x = x2 + stack[i++];
          pt.y = y2 + stack[i++];
          gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          pt.open = true;
          stackptr = 0;
          break;
        case 26: // vvcurveto
          i = 0;
          if ((stackptr & 1) == 1) { // odd number of arguments
            pt.x += stack[i++];
          }
          while (i < stackptr) {
            x1 = pt.x;
            y1 = pt.y + stack[i++];
            x2 = x1 + stack[i++];
            y2 = y1 + stack[i++];
            pt.x = x2;
            pt.y = y2 + stack[i++];
            gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          }
          pt.open = true;
          stackptr = 0;
          break;
        case 27: // hhcurveto
          i = 0;
          if ((stackptr & 1) == 1) { // odd number of arguments
            pt.y += stack[i++];
          }
          while (i < stackptr) {
            x1 = pt.x + stack[i++];
            y1 = pt.y;
            x2 = x1 + stack[i++];
            y2 = y1 + stack[i++];
            pt.x = x2 + stack[i++];
            pt.y = y2;
            gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          }
          pt.open = true;
          stackptr = 0;
          break;
        case 29: // callgsubr
          hold = pos;
          i = (int) stack[--stackptr] + gsubrsoffset;
          Range gsubr = getIndexEntry(gsubrbase, i);
          parseGlyph(gsubr, gp, pt);
          pos = hold;
          break;
        case 30: // vhcurveto
          hold = 4;
        case 31: // hvcurveto
          for (i = 0; i < stackptr; ) {
            boolean hv = (((i + hold) & 4) == 0);
            x1 = pt.x + (hv ? stack[i++] : 0);
            y1 = pt.y + (hv ? 0 : stack[i++]);
            x2 = x1 + stack[i++];
            y2 = y1 + stack[i++];
            pt.x = x2 + (hv ? 0 : stack[i++]);
            pt.y = y2 + (hv ? stack[i++] : 0);
            if (i == stackptr - 1) {
              if (hv) {
                pt.x += stack[i++];
              } else {
                pt.y += stack[i++];
              }
            }
            gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          }
          pt.open = true;
          stackptr = 0;
          break;
        case 1003: // and
          x1 = stack[--stackptr];
          y1 = stack[--stackptr];
          stack[stackptr++] = ((x1 != 0) && (y1 != 0)) ? 1 : 0;
          break;
        case 1004: // or
          x1 = stack[--stackptr];
          y1 = stack[--stackptr];
          stack[stackptr++] = ((x1 != 0) || (y1 != 0)) ? 1 : 0;
          break;
        case 1005: // not
          x1 = stack[--stackptr];
          stack[stackptr++] = (x1 == 0) ? 1 : 0;
          break;
        case 1009: // abs
          stack[stackptr - 1] = Math.abs(stack[stackptr - 1]);
          break;
        case 1010: // add
          x1 = stack[--stackptr];
          y1 = stack[--stackptr];
          stack[stackptr++] = x1 + y1;
          break;
        case 1011: // sub
          x1 = stack[--stackptr];
          y1 = stack[--stackptr];
          stack[stackptr++] = y1 - x1;
          break;
        case 1012: // div
          x1 = stack[--stackptr];
          y1 = stack[--stackptr];
          stack[stackptr++] = y1 / x1;
          break;
        case 1014: // neg
          stack[stackptr - 1] = -stack[stackptr - 1];
          break;
        case 1015: // eq
          x1 = stack[--stackptr];
          y1 = stack[--stackptr];
          stack[stackptr++] = (x1 == y1) ? 1 : 0;
          break;
        case 1018: // drop
          stackptr--;
          break;
        case 1020: // put
          i = (int) stack[--stackptr];
          x1 = stack[--stackptr];
          temps[i] = x1;
          break;
        case 1021: // get
          i = (int) stack[--stackptr];
          stack[stackptr++] = temps[i];
          break;
        case 1022: // ifelse
          if (stack[stackptr - 2] > stack[stackptr - 1]) {
            stack[stackptr - 4] = stack[stackptr - 3];
          }
          stackptr -= 3;
          break;
        case 1023: // random
          stack[stackptr++] = (float) Math.random();
          break;
        case 1024: // mul
          x1 = stack[--stackptr];
          y1 = stack[--stackptr];
          stack[stackptr++] = y1 * x1;
          break;
        case 1026: // sqrt
          stack[stackptr - 1] = (float) Math.sqrt(stack[stackptr - 1]);
          break;
        case 1027: // dup
          x1 = stack[stackptr - 1];
          stack[stackptr++] = x1;
          break;
        case 1028: // exch
          x1 = stack[stackptr - 1];
          stack[stackptr - 1] = stack[stackptr - 2];
          stack[stackptr - 2] = x1;
          break;
        case 1029: // index
          i = (int) stack[stackptr - 1];
          if (i < 0) {
            i = 0;
          }
          stack[stackptr - 1] = stack[stackptr - 2 - i];
          break;
        case 1030: // roll
          i = (int) stack[--stackptr];
          int n = (int) stack[--stackptr];
          // roll n number by i (+ = upward)
          if (i > 0) {
            i = i % n;
          } else {
            i = n - (-i % n);
          }
          // x x x x i y y y -> y y y x x x x i (where i=3)
          if (i > 0) {
            float roll[] = new float[n];
            System.arraycopy(stack, stackptr - 1 - i, roll, 0, i);
            System.arraycopy(stack, stackptr - 1 - n, roll, i, n - i);
            System.arraycopy(roll, 0, stack, stackptr - 1 - n, n);
          }
          break;
        case 1034: // hflex
          x1 = pt.x + stack[0];
          y1 = ybase = pt.y;
          x2 = x1 + stack[1];
          y2 = y1 + stack[2];
          pt.x = x2 + stack[3];
          pt.y = y2;
          gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          x1 = pt.x + stack[4];
          y1 = pt.y;
          x2 = x1 + stack[5];
          y2 = ybase;
          pt.x = x2 + stack[6];
          pt.y = y2;
          gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          pt.open = true;
          stackptr = 0;
          break;
        case 1035: // flex
          x1 = pt.x + stack[0];
          y1 = pt.y + stack[1];
          x2 = x1 + stack[2];
          y2 = y1 + stack[3];
          pt.x = x2 + stack[4];
          pt.y = y2 + stack[5];
          gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          x1 = pt.x + stack[6];
          y1 = pt.y + stack[7];
          x2 = x1 + stack[8];
          y2 = y1 + stack[9];
          pt.x = x2 + stack[10];
          pt.y = y2 + stack[11];
          gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          pt.open = true;
          stackptr = 0;
          break;
        case 1036: // hflex1
          ybase = pt.y;
          x1 = pt.x + stack[0];
          y1 = pt.y + stack[1];
          x2 = x1 + stack[2];
          y2 = y1 + stack[3];
          pt.x = x2 + stack[4];
          pt.y = y2;
          gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          x1 = pt.x + stack[5];
          y1 = pt.y;
          x2 = x1 + stack[6];
          y2 = y1 + stack[7];
          pt.x = x2 + stack[8];
          pt.y = ybase;
          gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          pt.open = true;
          stackptr = 0;
          break;
        case 1037: // flex1
          ybase = pt.y;
          float xbase = pt.x;
          x1 = pt.x + stack[0];
          y1 = pt.y + stack[1];
          x2 = x1 + stack[2];
          y2 = y1 + stack[3];
          pt.x = x2 + stack[4];
          pt.y = y2 + stack[5];
          gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          x1 = pt.x + stack[6];
          y1 = pt.y + stack[7];
          x2 = x1 + stack[8];
          y2 = y1 + stack[9];
          if (Math.abs(x2 - xbase) > Math.abs(y2 - ybase)) {
            pt.x = x2 + stack[10];
            pt.y = ybase;
          } else {
            pt.x = xbase;
            pt.y = y2 + stack[10];
          }
          gp.curveTo(x1, y1, x2, y2, pt.x, pt.y);
          pt.open = true;
          stackptr = 0;
          break;
        default:
          System.out.println("ERROR! TYPE1C CHARSTRING CMD IS " + cmd);
          break;
      }
    }
  }
Ejemplo n.º 5
0
  public boolean performTest(String arg) {
    boolean passed = true;
    try {
      Writer writer = new Writer(false);
      DOMParser parser = new DOMParser();
      if (!arg.equals("delete2") && !arg.equals("insert2")) {
        if (fStdOut) System.out.println("\n*************** Test == " + arg + " ***************");
        for (int i = 0; i < tests.length; i++) {
          if (fStdOut) System.out.println("\n\nTest[" + i + "]");
          if (fStdOut) System.out.println("\nBefore " + arg + ": document=" + tests[i] + ":");
          parser.parse(new InputSource(new StringReader(tests[i])));
          DocumentImpl document = (DocumentImpl) parser.getDocument();
          Range range = document.createRange();
          Node root = document.getDocumentElement();
          boolean surround = false;
          Node surroundNode = document.createElement(SURROUND);
          if (arg.equals("surround")) {
            surround = true;
          }

          if (i == 0) {
            range.setStart(root.getFirstChild(), 1);
            range.setEndBefore(root.getLastChild());
            if (surround) range.setEnd(root.getLastChild(), 1);

          } else if (i == 1) {
            Node n1 = root.getFirstChild().getNextSibling().getFirstChild();
            range.setStart(n1, 1);
            range.setEnd(root.getLastChild(), 1);
            if (surround) range.setEnd(n1, 2);
          } else if (i == 2) {
            range.setStart(root.getFirstChild(), 1);
            Node n2 = root.getFirstChild().getNextSibling().getFirstChild();
            range.setEnd(n2, 1);
            if (surround) range.setEndBefore(root.getLastChild());
          } else if (i == 3) {
            Node n3 = root.getFirstChild().getFirstChild();
            range.setStart(n3, 1);
            range.setEnd(root.getLastChild().getFirstChild(), 1);
            if (surround) {
              range.selectNode(root.getFirstChild().getNextSibling());
            }
          } else if (i == 4) {
            Node n4 = root.getFirstChild().getFirstChild().getNextSibling().getFirstChild();
            range.setStartAfter(n4);
            range.setEndAfter(root.getLastChild().getFirstChild());
            if (surround) {
              range.selectNodeContents(root.getFirstChild().getNextSibling());
            }
          }

          if (fStdOut) System.out.println("range.toString=" + range.toString());
          DocumentFragment frag = null;

          if (arg.equals("surround")) {
            try {
              if (fStdOut) System.out.println("surroundNode=" + surroundNode);
              range.surroundContents(surroundNode);
            } catch (org.w3c.dom.ranges.RangeException e) {
              if (fStdOut) System.out.println(e);
            }
            String result = toString(document);
            if (fStdOut) System.out.println("After surround: document=" + result + ":");
            if (!result.equals(surroundResult[i])) {
              if (fStdOut) System.out.println("Should be: document=" + surroundResult[i] + ":");
              passed = false;
              if (fStdOut) System.out.println("Test FAILED!");
              if (fStdOut) System.out.println("*** Surround document Test[" + i + "] FAILED!");
            }
          }

          if (arg.equals("insert")) {
            range.insertNode(document.createTextNode(INSERT));
            String result = toString(document);
            if (fStdOut) System.out.println("After  insert: document=" + result + ":");
            if (!result.equals(insertResult[i])) {
              if (fStdOut) System.out.println("Should be: document=" + insertResult[i] + ":");
              passed = false;
              if (fStdOut) System.out.println("Test FAILED!");
              if (fStdOut) System.out.println("*** Insert document Test[" + i + "] FAILED!");
            }

          } else if (arg.equals("delete")) {
            range.deleteContents();
            String result = toString(document);
            if (fStdOut) System.out.println("After delete:" + result + ":");
            if (!result.equals(deleteResult[i])) {
              if (fStdOut) System.out.println("Should be: document=" + deleteResult[i] + ":");
              passed = false;
              if (fStdOut) System.out.println("Test FAILED!");
              if (fStdOut) System.out.println("*** Delete document Test[" + i + "] FAILED!");
            }
          } else if (arg.equals("extract")) {
            frag = range.extractContents();
            // range.insertNode(document.createTextNode("^"));
            String result = toString(document);
            if (fStdOut) System.out.println("After extract: document=" + result + ":");
            if (!result.equals(deleteResult[i])) {
              if (fStdOut) System.out.println("Should be: document=" + deleteResult[i] + ":");
              passed = false;
              if (fStdOut) System.out.println("*** Extract document Test[" + i + "] FAILED!");
            }
            String fragResult = toString(frag);
            if (fStdOut) System.out.println("After extract: fragment=" + fragResult + ":");
            if (!fragResult.equals(extractResult[i])) {
              if (fStdOut) System.out.println("Should be: fragment=" + extractResult[i] + ":");
              passed = false;
              if (fStdOut) System.out.println("*** Extract Fragment Test[" + i + "] FAILED!");
            }
          } else if (arg.equals("clone")) {
            frag = range.cloneContents();
            String fragResult = toString(frag);
            if (fStdOut) System.out.println("After clone: fragment=" + fragResult);
            if (!fragResult.equals(extractResult[i])) {
              if (fStdOut) System.out.println("Should be: fragment=" + extractResult[i] + ":");
              passed = false;
              if (fStdOut) System.out.println("*** Clone Fragment Test[" + i + "] FAILED!");
            }
          }
        }

      } else if (arg.equals("insert2")) {
        if (fStdOut) System.out.println("\n*************** Test == " + arg + " ***************");
        for (int i = 0; i < 4; i++) {

          if (fStdOut) System.out.println("\n\nTest[" + i + "]");
          if (fStdOut) System.out.println("\nBefore " + arg + ": document=" + INSERT2 + ":");
          parser.parse(new InputSource(new StringReader(INSERT2)));
          DocumentImpl document = (DocumentImpl) parser.getDocument();
          Node root = document.getDocumentElement();
          Range range = document.createRange();
          range.setStart(root.getFirstChild(), 11);
          range.setEnd(root.getFirstChild(), 18);
          Range rangei = document.createRange();
          if (i == 0) {
            rangei.setStart(root.getFirstChild(), 10);
            rangei.setEnd(root.getFirstChild(), 10);
          }
          if (i == 1) {
            rangei.setStart(root.getFirstChild(), 11);
            rangei.setEnd(root.getFirstChild(), 11);
          }
          if (i == 2) {
            rangei.setStart(root.getFirstChild(), 12);
            rangei.setEnd(root.getFirstChild(), 12);
          }
          if (i == 3) {
            rangei.setStart(root.getFirstChild(), 17);
            rangei.setEnd(root.getFirstChild(), 17);
          }
          // if (fStdOut) System.out.println("range: start1=="+range.getStartContainer());
          // root.insertBefore(document.createTextNode("YES!"), root.getFirstChild());
          // if (fStdOut) System.out.println("range: start2=="+range.getStartContainer());

          if (DEBUG)
            if (fStdOut) System.out.println("before insert start=" + range.getStartOffset());
          if (DEBUG) if (fStdOut) System.out.println("before insert end=" + range.getEndOffset());
          rangei.insertNode(document.createTextNode(INSERTED_TEXT));
          if (DEBUG)
            if (fStdOut) System.out.println("after insert start=" + range.getStartOffset());
          if (DEBUG) if (fStdOut) System.out.println("after insert end=" + range.getEndOffset());

          String result = toString(document);
          if (fStdOut) System.out.println("After insert2: document=" + result + ":");
          if (!result.equals(rangeInsertResult[i])) {
            if (fStdOut) System.out.println("Should be: document=" + rangeInsertResult[i] + ":");
            passed = false;
            if (fStdOut) System.out.println("Test FAILED!");
            if (fStdOut) System.out.println("*** Delete Ranges document Test[" + i + "] FAILED!");
          }
        }
      } else if (arg.equals("delete2")) {
        //
        // Range Deletion, acting upon another range.
        //

        if (fStdOut) System.out.println("\n*************** Test == " + arg + " ***************");
        for (int i = 0; i < rangeDelete.length; i++) {
          if (fStdOut) System.out.println("\n\nTest[" + i + "]");
          if (fStdOut) System.out.println("\nBefore " + arg + ": document=" + rangeDelete[i] + ":");
          parser.parse(new InputSource(new StringReader(rangeDelete[i])));
          DocumentImpl document = (DocumentImpl) parser.getDocument();
          Range range = document.createRange();
          Range ranged = document.createRange();
          Node root = document.getDocumentElement();
          boolean surround = false;
          Node surroundNode = document.createElement(SURROUND);
          if (arg.equals("surround")) {
            surround = true;
          }

          if (i == 0) {
            ranged.setStart(root.getFirstChild(), 5);
            ranged.setEnd(root.getFirstChild(), 14);

            range.setStart(root.getFirstChild(), 11);
            range.setEnd(root.getFirstChild(), 19);
          } else if (i == 1) {
            ranged.setStart(root.getFirstChild(), 5);
            ranged.setEnd(root.getFirstChild(), 22);

            range.setStart(root.getFirstChild(), 11);
            range.setEnd(root.getFirstChild(), 21);
          } else if (i == 2) {
            ranged.setStart(root.getFirstChild(), 5);
            ranged.setEnd(root.getFirstChild().getNextSibling().getFirstChild(), 1);

            range.setStart(root.getFirstChild(), 11);

            range.setEndAfter(root.getFirstChild().getNextSibling().getFirstChild());
          } else if (i == 3) {
            ranged.setStart(root.getFirstChild(), 5);
            ranged.setEnd(root.getFirstChild(), 11);

            range.setStart(root.getFirstChild(), 11);
            range.setEnd(root.getFirstChild(), 21);
          } else if (i == 4) {
            ranged.selectNode(root.getFirstChild().getNextSibling());

            range.setStart(root.getFirstChild().getNextSibling().getFirstChild(), 6);
            range.setEnd(root.getFirstChild().getNextSibling().getFirstChild(), 15);
          }

          DocumentFragment frag = null;

          if (arg.equals("delete2")) {
            if (DEBUG) {
              if (fStdOut) System.out.println("BEFORE deleteContents()");
              if (fStdOut) System.out.println("ranged: startc=" + ranged.getStartContainer());
              if (fStdOut) System.out.println("ranged: starto=" + ranged.getStartOffset());
              if (fStdOut) System.out.println("ranged:   endc=" + ranged.getEndContainer());
              if (fStdOut) System.out.println("ranged:   endo=" + ranged.getEndOffset());

              if (fStdOut) System.out.println("range: startc=" + range.getStartContainer());
              if (fStdOut) System.out.println("range: starto=" + range.getStartOffset());
              if (fStdOut) System.out.println("range:   endc=" + range.getEndContainer());
              if (fStdOut) System.out.println("range:   endo=" + range.getEndOffset());
            }
            ranged.deleteContents();
            String result = null;
            if (DEBUG) {
              if (fStdOut) System.out.println("AFTER deleteContents()");
              result = toString(document);
              if (fStdOut) System.out.println("ranged: startc=" + ranged.getStartContainer());
              if (fStdOut) System.out.println("ranged: starto=" + ranged.getStartOffset());
              if (fStdOut) System.out.println("ranged:   endc=" + ranged.getEndContainer());
              if (fStdOut) System.out.println("ranged:   endo=" + ranged.getEndOffset());

              if (fStdOut) System.out.println("range: startc=" + range.getStartContainer());
              if (fStdOut) System.out.println("range: starto=" + range.getStartOffset());
              if (fStdOut) System.out.println("range:   endc=" + range.getEndContainer());
              if (fStdOut) System.out.println("range:   endo=" + range.getEndOffset());
            }

            ranged.insertNode(document.createTextNode("^"));

            result = toString(document);
            if (fStdOut) System.out.println("After delete2: document=" + result + ":");
            if (!result.equals(rangeDeleteResult[i])) {
              if (fStdOut) System.out.println("Should be: document=" + rangeDeleteResult[i] + ":");
              passed = false;
              if (fStdOut) System.out.println("Test FAILED!");
              if (fStdOut) System.out.println("*** Delete Ranges document Test[" + i + "] FAILED!");
            }
          }
        }
      }

    } catch (org.xml.sax.SAXParseException spe) {
      passed = false;
    } catch (org.xml.sax.SAXException se) {
      if (se.getException() != null) se.getException().printStackTrace(System.err);
      else se.printStackTrace(System.err);
      passed = false;
    } catch (Exception e) {
      e.printStackTrace(System.err);
      passed = false;
    }
    if (!passed) if (fStdOut) System.out.println("*** The " + arg + " Test FAILED! ***");

    return passed;
  }