예제 #1
0
  public TTGlyph toSimpleGlyph() {
    // convert the file into array of contours
    XContour[] contours = toContours();
    if ((contours == null) && (!isRequiredGlyph())) {
      return null;
    } // if

    TTGlyph retval = new TTGlyph();
    retval.setSimple(true);
    retval.setAdvanceWidth(getAdvanceWidth());

    if (contours == null) {
      return retval;
    } // if

    ArrayList<EContourPoint> points = new ArrayList<>();
    for (int i = 0; i < contours.length; i++) {
      XContour contour = contours[i];
      XContourPoint[] contourPoints = contour.getContourPoint();
      for (int j = 0; j < contourPoints.length; j++) {
        points.add((EContourPoint) contourPoints[j]);
      } // for j
      retval.addEndPoint(points.size() - 1);
    } // for i

    for (EContourPoint point : points) {
      loadContourPoint(retval, point);
    } // for point

    boolean hasGridfit = false;
    // I need int i here.
    for (int i = 0; i < points.size(); i++) {
      EContourPoint point = points.get(i);

      if (!point.isRounded()) {
        continue;
      } // if

      hasGridfit = true;
      loadGridfit(retval, point, i);
    } // for i

    if (hasGridfit) {
      retval.addInstruction(TTGlyph.IUP1);
      retval.addInstruction(TTGlyph.IUP0);
    } // if

    // I need int i here.
    for (int i = 0; i < points.size(); i++) {
      EContourPoint point = points.get(i);
      if (point.getHint().length == 0) {
        continue;
      } // if

      loadHint(retval, point, i);
    } // for i

    return retval;
  }
예제 #2
0
  private void loadGridfit(TTGlyph a_glyph, EContourPoint a_point, int a_index) {
    if (!a_point.isRounded()) {
      return;
    } // if

    a_glyph.addInstruction(TTGlyph.PUSHB000);
    a_glyph.addInstruction(a_index);
    a_glyph.addInstruction(TTGlyph.MDAP1);
  }
예제 #3
0
  private void loadContourPoint(TTGlyph a_glyph, EContourPoint a_point) {
    double x = a_point.getX();
    double y = a_point.getY();
    Point p = new Point((int) x, (int) y);
    int flag = 0;
    if (a_point.isOn()) {
      flag = TTGlyph.k_onCurve;
    } // if

    a_glyph.addPoint(p);
    a_glyph.addFlag(flag);
  }
예제 #4
0
  private void loadHint(TTGlyph a_glyph, EContourPoint a_point, int a_index) {
    double x = a_point.getX();
    double y = a_point.getY();

    XHint[] hints = a_point.getHint();

    for (int i = 0; i < hints.length; i++) {
      EHint hint = (EHint) hints[i];
      double xHint = hint.getX();
      double yHint = hint.getY();

      if (x == xHint && y == yHint) {
        continue;
      } // if

      double xDelta = xHint - x;
      double yDelta = yHint - y;
      int instruction = TTGlyph.DELTAP1;
      double deltaStep = ((double) Engine.getEm()) / hint.getPpem() / 8;
      int xShift = (int) Math.round(xDelta / deltaStep);
      int yShift = (int) Math.round(yDelta / deltaStep);

      if (xShift == 0 && yShift == 0) {
        continue;
      } // if

      a_glyph.addInstruction(TTGlyph.PUSHB000);
      a_glyph.addInstruction((int) hint.getPpem());
      a_glyph.addInstruction(TTGlyph.SDB);

      if (xShift != 0) {
        a_glyph.addInstruction(TTGlyph.SVTCA1);
        a_glyph.addInstruction(TTGlyph.PUSHB010);
        a_glyph.addInstruction(TTGlyph.toDeltaArg(0, xShift));
        a_glyph.addInstruction(a_index);
        a_glyph.addInstruction(1);
        a_glyph.addInstruction(TTGlyph.DELTAP1);
      } // if

      if (yShift != 0) {
        a_glyph.addInstruction(TTGlyph.SVTCA0);
        a_glyph.addInstruction(TTGlyph.PUSHB010);
        a_glyph.addInstruction(TTGlyph.toDeltaArg(0, yShift));
        a_glyph.addInstruction(a_index);
        a_glyph.addInstruction(1);
        a_glyph.addInstruction(TTGlyph.DELTAP1);
      } // if
    } // for i
  }