Пример #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
  public void toggleRounded() {
    if (!m_actives.hasActivePoint()) return;

    EContourPoint contourPoint = m_actives.getActivePoint();
    contourPoint.toggleRounded();

    m_history.record("toggleGridfit");
  }
Пример #3
0
  public void addPoint() {
    if (!m_actives.hasActivePoint()) {
      return;
    } // if

    EContourPoint contourPoint = m_actives.getActivePoint();
    m_actives.unselectAll();
    m_actives.addActive(contourPoint.add());

    m_history.record("addPoint");
  }
Пример #4
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);
  }
Пример #5
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
  }
Пример #6
0
  public void toggleOnOff() {
    if (!m_actives.hasSelected()) return;

    int i;
    for (i = 0; i < m_actives.size(); i++) {
      GlyphObject active = m_actives.get(i);
      if (!(active instanceof EContourPoint)) {
        continue;
      } // if

      EContourPoint point = (EContourPoint) active;
      point.toggleOnCurve();
    } // for i

    m_history.record("toggleOnOff");
  }
Пример #7
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);
  }
Пример #8
0
  public void addHint(int a_ppem) {
    if (!m_actives.hasActivePoint()) return;

    EContourPoint contourPoint = m_actives.getActivePoint();
    m_actives.unselectAll();
    m_actives.addActive(contourPoint.addHint(a_ppem));

    if (contourPoint.hasControlPoint1()) {
      EContourPoint p = (EContourPoint) contourPoint.getControlPoint1().getContourPoint();
      m_actives.addActive(p.addHint(a_ppem));
    } // if

    if (contourPoint.hasControlPoint2()) {
      EContourPoint p = (EContourPoint) contourPoint.getControlPoint2().getContourPoint();
      m_actives.addActive(p.addHint(a_ppem));
    } // if

    m_history.record("addHint");
  }
Пример #9
0
  public void buildPointHost() {
    m_pointHost = null;

    /*if (!GlyphAction.isPointVisible()) {
        return;
    } // if*/

    int i;
    for (i = 0; i < m_actives.size(); i++) {
      GlyphObject object = (GlyphObject) m_actives.get(i);
      PointAggregate host = null;

      if (object instanceof EContourPoint) {
        EContourPoint point = (EContourPoint) object;
        host = point.getParent();

        if (host instanceof EContourPoint) {
          EContourPoint hostPoint = (EContourPoint) host;
          host = hostPoint.getParent();
        } // if
      } else if (object instanceof EHint) {
        EHint hint = (EHint) object;
        host = hint.getPointHost();
      } // if-else

      if (host == null) {
        continue;
      } // if

      if (m_pointHost == null) {
        m_pointHost = host;
      } else {
        if (m_pointHost != host) {
          m_pointHost = null;
          return;
        } // if
      } // if
    } // while
  }