Exemplo n.º 1
0
  public static void main(String[] args) {
    List<Range> schedules = new LinkedList<>();
    schedules.add(new Range(6, 7));
    schedules.add(new Range(9, 10));
    schedules.add(new Range(13, 14));
    schedules.add(new Range(8, 10));
    schedules.add(new Range(22, 24));
    schedules.add(new Range(12, 15));
    schedules.add(new Range(21, 23));
    schedules.add(new Range(8, 9));
    schedules.add(new Range(12, 13));
    schedules.add(new Range(9, 11));
    schedules.add(new Range(15, 17));
    schedules.add(new Range(15, 16));

    List<Range> mergeResults = new Schedule(schedules).mergeAndSort();

    System.out.println("Input:");
    List<Range> sorted = new MergeSort(schedules).sort();
    for (Range range : sorted) {
      System.out.println(range.getStart() + " " + range.getEnd());
    }
    System.out.println();

    System.out.println("Merge results:");
    for (Range range : mergeResults) {
      System.out.println(range.getStart() + " " + range.getEnd());
    }
  }
Exemplo n.º 2
0
 // returns an ArrayList of ranges for the indicated day,
 // as defined by the Calendar class
 // may return ranges which overlap (occurs when the previous
 // night's range is over 24 hours long)
 @SuppressWarnings("unchecked")
 public ArrayList<Range> getRanges(int calendarDay) {
   ArrayList<Range> ranges = (ArrayList<Range>) _openRanges.get(calendarDay - 1).clone();
   ArrayList<Range> yesterdayRanges = _openRanges.get((calendarDay - 2 + 7) % 7);
   if (!yesterdayRanges.isEmpty()) {
     Range lastYesterday = yesterdayRanges.get(yesterdayRanges.size() - 1);
     if (lastYesterday.overnight() && !lastYesterday.getEnd().equals(Time.beginning))
       ranges.add(0, new Range(Time.beginning, lastYesterday.getEnd()));
   }
   return ranges;
 }
Exemplo n.º 3
0
  @Test
  public void testSimpleCases() throws Exception {
    Range _r = new Range(0, 10);
    assertEquals(0, _r.getStart());
    assertEquals(9, _r.getEnd());
    assertEquals(10, _r.getBatchSize());
    assertEquals(10, _r.getSize());
    assertEquals(Integer.MAX_VALUE, _r.getTotal());
    assertTrue(_r.hasNext());
    assertFalse(_r.hasPrevious());
    assertEquals("1 to 10 of " + Integer.MAX_VALUE, _r.toString());

    _r = new Range(10, 10);
    assertEquals(10, _r.getStart());
    assertEquals(19, _r.getEnd());
    assertEquals(10, _r.getBatchSize());
    assertEquals(10, _r.getSize());
    assertEquals(Integer.MAX_VALUE, _r.getTotal());
    assertTrue(_r.hasNext());
    assertTrue(_r.hasPrevious());
    assertEquals("11 to 20 of " + Integer.MAX_VALUE, _r.toString());

    _r = new Range(0, 10, 34);
    assertEquals(0, _r.getStart());
    assertEquals(9, _r.getEnd());
    assertEquals(10, _r.getBatchSize());
    assertEquals(10, _r.getSize());
    assertEquals(34, _r.getTotal());
    assertTrue(_r.hasNext());
    assertFalse(_r.hasPrevious());
    assertEquals("1 to 10 of 34", _r.toString());

    _r = new Range(10, 10, 34);
    assertEquals(10, _r.getStart());
    assertEquals(19, _r.getEnd());
    assertEquals(10, _r.getBatchSize());
    assertEquals(10, _r.getSize());
    assertEquals(34, _r.getTotal());
    assertTrue(_r.hasNext());
    assertTrue(_r.hasPrevious());
    assertEquals("11 to 20 of 34", _r.toString());

    _r = new Range(10, 10, 16);
    assertEquals(10, _r.getStart());
    assertEquals(16, _r.getEnd());
    assertEquals(10, _r.getBatchSize());
    assertEquals(6, _r.getSize());
    assertEquals(16, _r.getTotal());
    assertFalse(_r.hasNext());
    assertTrue(_r.hasPrevious());
    assertEquals("11 to 16 of 16", _r.toString());
  }
Exemplo n.º 4
0
 public Rectangle getCursorBounds() {
   Range range = getSession().getSelection().getRange();
   Renderer renderer = widget_.getEditor().getRenderer();
   ScreenCoordinates start =
       renderer.textToScreenCoordinates(range.getStart().getRow(), range.getStart().getColumn());
   ScreenCoordinates end =
       renderer.textToScreenCoordinates(range.getEnd().getRow(), range.getEnd().getColumn());
   return new Rectangle(
       start.getPageX(),
       start.getPageY(),
       end.getPageX() - start.getPageX(),
       renderer.getLineHeight());
 }
Exemplo n.º 5
0
  /**
   * Merge another intersecting range with this range.
   *
   * @param range The other range to merge with.
   * @return The merged range.
   * @throws IllegalArgumentException Thrown if the provided range doesn't intersect.
   * @see #combinable(Range)
   */
  public Range combine(Range range) throws IllegalArgumentException {
    if (!range.combinable(this)) {
      throw new IllegalArgumentException("Ranges do not intersect. Can not merge.");
    }

    if (range.getStart() < start) {
      start = range.getStart();
    }

    if (range.getEnd() > end) {
      end = range.getEnd();
    }

    return this;
  }
Exemplo n.º 6
0
 // returns minutes to the next closing time for the restaurant, 1440 if open over 24 hours, -1 if
 // closed for the day
 public int minutesToClose() {
   Time now = new Time();
   Range current = getCurrentRange();
   if (current != null) {
     if (current.overnight()) {
       ArrayList<Range> tomorrow =
           getRangesToModify(
               (new GregorianCalendar().get(Calendar.DAY_OF_WEEK) + 1 - Calendar.SUNDAY) % 7
                   + Calendar.SUNDAY);
       if (!tomorrow.isEmpty()) {
         Range next = tomorrow.get(0);
         if (!next.after(current.getEnd())) {
           int min = current.minutesUntilEnd(now) + next.minutesUntilEnd(next.getStart());
           return min > 1440 ? 1440 : min;
         }
       }
     }
     if (current.getStart().equals(Time.beginning)) {
       ArrayList<Range> today = getTodayRanges();
       if (today.size() > 1) {
         Range next = today.get(1);
         if (!next.after(current)) { // they overlap
           int min = current.minutesUntilEnd(now) + next.minutesUntilEnd(next.getStart());
           return min > 1440 ? 1440 : min;
         }
       }
     }
     return current.minutesUntilEnd(now);
   }
   return -1;
 }
Exemplo n.º 7
0
  @Test
  public void testGetNextReturnsValidRange() throws Exception {
    Range _r = new Range(0, 10);
    Range _r2 = _r.next();
    assertEquals(10, _r2.getStart());
    assertEquals(19, _r2.getEnd());
    assertEquals(10, _r2.getBatchSize());
    assertEquals(10, _r2.getSize());

    _r = new Range(0, 10, 14);
    _r2 = _r.next();
    assertEquals(10, _r2.getStart());
    assertEquals(14, _r2.getEnd());
    assertEquals(10, _r2.getBatchSize());
    assertEquals(4, _r2.getSize());
  }
Exemplo n.º 8
0
  /** Test of getEnd method, of class Range. */
  @Test
  public void testGetEnd() {
    System.out.println(" getEnd");
    final int expResult = 10;

    Range instance = new Range("Range", 0, expResult);
    int result = instance.getEnd();

    assertEquals(expResult, result);
  }
Exemplo n.º 9
0
  @Override
  public boolean equals(Object obj) {
    if (!(obj instanceof Range)) return false;

    Range r = (Range) obj;

    if ((r.getStart() == start) && (r.getEnd() == end)) return true;

    return false;
  }
Exemplo n.º 10
0
  @Test
  public void testGetPreviousReturnsValidRange() throws Exception {
    Range _r = new Range(10, 10);
    Range _r2 = _r.previous();
    assertEquals(0, _r2.getStart());
    assertEquals(9, _r2.getEnd());
    assertEquals(10, _r2.getBatchSize());
    assertEquals(10, _r2.getSize());

    _r = new Range(0, 10, 14);
    _r2 = _r.previous();
    assertEquals(_r, _r2);

    _r = new Range(3, 10, 14);
    _r2 = _r.previous();
    assertEquals(0, _r2.getStart());
    assertEquals(9, _r2.getEnd());
    assertEquals(10, _r2.getBatchSize());
    assertEquals(10, _r2.getSize());
  }
Exemplo n.º 11
0
  private void indentPastedRange(Range range) {
    if (fileType_ == null
        || !fileType_.canAutoIndent()
        || !RStudioGinjector.INSTANCE.getUIPrefs().reindentOnPaste().getValue()) {
      return;
    }

    String firstLinePrefix =
        getSession()
            .getTextRange(
                Range.fromPoints(Position.create(range.getStart().getRow(), 0), range.getStart()));

    if (firstLinePrefix.trim().length() != 0) {
      Position newStart = Position.create(range.getStart().getRow() + 1, 0);
      if (newStart.compareTo(range.getEnd()) >= 0) return;

      range = Range.fromPoints(newStart, range.getEnd());
    }

    getSession().reindent(range);
  }
Exemplo n.º 12
0
  /**
   * Determine if this range can merge with the provided range. A range is mergeable if the start of
   * the second range is between the start and end of the first range or the end of the second range
   * is between the start and end of the first range or start of one is one less than the end of the
   * other.
   *
   * @param range The range to test against this range.
   * @return <code>True</code> if the ranges intersect, <code>false</code> otherwise.
   */
  public boolean combinable(Range range) {
    long point;

    point = range.getStart();

    if ((point >= start) && (point <= end)) {
      return true;
    }

    point = range.getEnd();

    if ((point >= start) && (point <= end)) {
      return true;
    }

    if (((end + 1) == range.getStart()) || (range.getEnd() + 1 == start)) {
      return true;
    }

    return false;
  }
Exemplo n.º 13
0
  @Test
  public void testAlwaysMakesAValidRange() throws Exception {
    Range _r = new Range(-20, -6);
    assertEquals(0, _r.getStart());
    assertEquals(0, _r.getEnd());
    assertEquals(1, _r.getBatchSize());
    assertEquals(0, _r.getSize());
    assertTrue(_r.hasNext());
    assertFalse(_r.hasPrevious());
    assertEquals(_r, _r.previous());

    _r = new Range(-3, -3, -3);
    assertEquals(0, _r.getStart());
    assertEquals(0, _r.getEnd());
    assertEquals(1, _r.getBatchSize());
    assertEquals(0, _r.getSize());
    assertFalse(_r.hasNext());
    assertFalse(_r.hasPrevious());
    assertEquals(_r, _r.next());
    assertEquals(_r, _r.previous());
  }
Exemplo n.º 14
0
 // pre: restaurant is open, and returns null if open
 // more than 24 hours from now
 public Time getNextCloseTime() {
   Range current = getCurrentRange();
   if (current == null) throw new RuntimeException("Restaurant must be open");
   if (current.overnight()) {
     ArrayList<Range> tomorrow =
         getRangesToModify(
             (new GregorianCalendar().get(Calendar.DAY_OF_WEEK) + 1 - Calendar.SUNDAY) % 7
                 + Calendar.SUNDAY);
     if (!tomorrow.isEmpty()) {
       Range next = tomorrow.get(0);
       if (!next.after(current.getEnd())) {
         Time now = new Time();
         if (!next.overnight() && !next.getEnd().after(now)) return next.getEnd();
         else return null;
       }
     }
   }
   if (current.getStart().equals(Time.beginning)) {
     ArrayList<Range> today = getTodayRanges();
     if (today.size() > 1) {
       Range next = today.get(1);
       Time now = new Time();
       if (!next.after(current)) // they overlap
       if (!next.overnight() || !next.getEnd().after(now)) return next.getEnd();
         else return null;
     }
   }
   return current.getEnd();
   //		if (current != null)
   //			return current.getEnd();
   //		return null;
 }
Exemplo n.º 15
0
 @Override
 public Tuple getNext() throws IOException {
   try {
     if (!reader.nextKeyValue()) {
       return null;
     }
     Text value = (Text) reader.getCurrentValue();
     String line = value.toString();
     Tuple tuple = tupleFactory.newTuple(ranges.size());
     for (int i = 0; i < ranges.size(); i++) {
       Range range = ranges.get(i);
       if (range.getEnd() > line.length()) {
         LOG.warn(
             String.format(
                 "Range end (%s) is longer than line length (%s)", range.getEnd(), line.length()));
         continue;
       }
       tuple.set(i, new DataByteArray(range.getSubstring(line)));
     }
     return tuple;
   } catch (InterruptedException e) {
     throw new ExecException(e);
   }
 }
Exemplo n.º 16
0
  /**
   * Indicates whether some other object is "equal to" this one.
   *
   * @param obj the reference object with which to compare.
   * @return <code>true</code> if this object is the same as the <code>obj</code> argument; <code>
   *     false</code> otherwise.
   */
  public boolean equals(Object obj) {
    Range r;

    if (!(obj instanceof Range)) {
      return false;
    }

    r = (Range) obj;

    if (r.getStart() == start) {
      if (r.getEnd() == end) {
        return true;
      }
    }

    return false;
  }
Exemplo n.º 17
0
  /** Test of getStart method, of class Range. */
  @Test
  public void testConstructor() {
    System.out.println(" Range constructor");

    int expStart = -100;
    int expEnd = 1000;
    String expName = "Range Name";
    Range instance = new Range(expName, expStart, expEnd);

    String resultName = instance.getName();
    int resultStart = instance.getStart();
    int resultEnd = instance.getEnd();

    assertEquals(expName, resultName);
    assertEquals(expStart, resultStart);
    assertEquals(expEnd, resultEnd);
  }
 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;
   }
 }
Exemplo n.º 20
0
  @Override
  public InputEditorSelection search(
      String needle,
      boolean backwards,
      boolean wrap,
      boolean caseSensitive,
      boolean wholeWord,
      Position start,
      Range range,
      boolean regexpMode) {
    Search search =
        Search.create(needle, backwards, wrap, caseSensitive, wholeWord, start, range, regexpMode);

    Range resultRange = search.find(getSession());
    if (resultRange != null) {
      return createSelection(resultRange.getStart(), resultRange.getEnd());
    } else {
      return null;
    }
  }
Exemplo n.º 21
0
  public void fitSelectionToLines(boolean expand) {
    Range range = getSession().getSelection().getRange();
    Position start = range.getStart();
    Position newStart = start;

    if (start.getColumn() > 0) {
      if (expand) {
        newStart = Position.create(start.getRow(), 0);
      } else {
        String firstLine = getSession().getLine(start.getRow());
        if (firstLine.substring(0, start.getColumn()).trim().length() == 0)
          newStart = Position.create(start.getRow(), 0);
      }
    }

    Position end = range.getEnd();
    Position newEnd = end;
    if (expand) {
      int endRow = end.getRow();
      if (endRow == newStart.getRow() || end.getColumn() > 0) {
        // If selection ends at the start of a line, keep the selection
        // there--unless that means less than one line will be selected
        // in total.
        newEnd = Position.create(endRow, getSession().getLine(endRow).length());
      }
    } else {
      while (newEnd.getRow() != newStart.getRow()) {
        String line = getSession().getLine(newEnd.getRow());
        if (line.substring(0, newEnd.getColumn()).trim().length() != 0) break;

        int prevRow = newEnd.getRow() - 1;
        int len = getSession().getLine(prevRow).length();
        newEnd = Position.create(prevRow, len);
      }
    }

    getSession().getSelection().setSelectionRange(Range.fromPoints(newStart, newEnd));
  }
Exemplo n.º 22
0
 public int getSelectionOffset(boolean start) {
   Range range = getSession().getSelection().getRange();
   if (start) return range.getStart().getColumn();
   else return range.getEnd().getColumn();
 }
Exemplo n.º 23
0
 public void collapseSelection(boolean collapseToStart) {
   Selection selection = getSession().getSelection();
   Range rng = selection.getRange();
   Position pos = collapseToStart ? rng.getStart() : rng.getEnd();
   selection.setSelectionRange(Range.fromPoints(pos, pos));
 }
Exemplo n.º 24
0
 public InputEditorSelection getSelection() {
   Range selection = getSession().getSelection().getRange();
   return new InputEditorSelection(
       new AceInputEditorPosition(getSession(), selection.getStart()),
       new AceInputEditorPosition(getSession(), selection.getEnd()));
 }
  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;
      }
    }
  }