/**
   * build an accented character out of two pre-defined glyphs.
   *
   * @param x the x offset of the accent
   * @param y the y offset of the accent
   * @param b the index of the base glyph
   * @param a the index of the accent glyph
   * @param gp the GeneralPath into which the combined glyph will be written.
   */
  private void buildAccentChar(float x, float y, char b, char a, Path gp) {
    // get the outline of the accent
    Path pathA = getOutline(a, getWidth(a, null));

    // undo the effect of the transform applied in read
    Matrix xformA = new Matrix();
    xformA.setTranslate(x, y);
    Matrix tmp = new Matrix(at);
    if (at.invert(tmp)) {
      xformA.preConcat(tmp);
    } else {
      // oh well ...
    }
    pathA.transform(xformA);

    Path pathB = getOutline(b, getWidth(b, null));

    Matrix xformB = new Matrix();
    if (at.invert(xformB)) {
      pathB.transform(xformB);
    } else {
      // ignore
    }

    gp.addPath(pathB);
    gp.addPath(pathA);
  }
Exemple #2
0
  // 0 <= value <= 1
  public void addValue(double value) {
    if (startTime == -1) startTime = System.nanoTime();
    if (value < 0) value = 0;
    else if (value > 1) value = 1;
    final long relTime = System.nanoTime() - startTime;
    if (relTime >= maxNsecs) return;

    if (values == 0) {
      pathStroke.moveTo(0, (float) (height * (1 - value)));
      values++;
    } else {
      final float x = nsecWidth * relTime;
      pathStroke.lineTo(x, (float) (height * (1 - value)));

      pathFill.rewind();
      pathFill.addPath(pathStroke);
      pathFill.lineTo(x, height);
      pathFill.lineTo(0, height);
    }
  }
  @Override
  public void drawGraph(Canvas canvas, float animatedValue) {
    float prevDx = 0f;
    float prevDy = 0f;
    float curDx = 0f;
    float curDy = 0f;

    PointF prevPrev = curveData.getValue().get(0);
    PointF prev = prevPrev;
    PointF cur = prev;
    PointF next = curveData.getValue().get(1);

    pointList.clear();
    cubicPath.moveTo(
        (cur.x - xAxisData.getMinimum()) * xAxisData.getAxisScale(),
        -(cur.y - yAxisData.getMinimum()) * yAxisData.getAxisScale() * animatedValue);
    /** 保存 */
    pointList.add(
        new PointF(
            (cur.x - xAxisData.getMinimum()) * xAxisData.getAxisScale(),
            -(cur.y - yAxisData.getMinimum()) * yAxisData.getAxisScale() * animatedValue));

    for (int j = 1; j < curveData.getValue().size(); j++) {
      prevPrev = curveData.getValue().get(j == 1 ? 0 : j - 2);
      prev = curveData.getValue().get(j - 1);
      cur = curveData.getValue().get(j);
      next = curveData.getValue().size() > j + 1 ? curveData.getValue().get(j + 1) : cur;

      prevDx = (cur.x - prevPrev.x) * intensity * xAxisData.getAxisScale();
      prevDy = (cur.y - prevPrev.y) * intensity * yAxisData.getAxisScale();
      curDx = (next.x - prev.x) * intensity * xAxisData.getAxisScale();
      curDy = (next.y - prev.y) * intensity * yAxisData.getAxisScale();

      cubicPath.cubicTo(
          (prev.x - xAxisData.getMinimum()) * xAxisData.getAxisScale() + prevDx,
          -(((prev.y - yAxisData.getMinimum()) * yAxisData.getAxisScale() + prevDy)
              * animatedValue),
          ((cur.x - xAxisData.getMinimum()) * xAxisData.getAxisScale() - curDx),
          -(((cur.y - yAxisData.getMinimum()) * yAxisData.getAxisScale() - curDy) * animatedValue),
          ((cur.x - xAxisData.getMinimum()) * xAxisData.getAxisScale()),
          -(((cur.y - yAxisData.getMinimum()) * yAxisData.getAxisScale()) * animatedValue));
      /** 保存 */
      pointList.add(
          new PointF(
              (cur.x - xAxisData.getMinimum()) * xAxisData.getAxisScale(),
              -((cur.y - yAxisData.getMinimum()) * yAxisData.getAxisScale()) * animatedValue));
    }

    canvas.save();
    canvas.translate(offset, 0);
    cubicPaint.setColor(curveData.getColor());
    canvas.drawPath(cubicPath, cubicPaint);
    cubicFillPath.addPath(cubicPath);
    cubicPath.rewind();

    /** 填充曲线图 */
    if (curveData.getDrawable() != null) {
      // 填充颜色
      cubicFillPath.lineTo(
          (curveData.getValue().get(curveData.getValue().size() - 1).x - xAxisData.getMinimum())
              * xAxisData.getAxisScale(),
          0);
      cubicFillPath.lineTo(
          (curveData.getValue().get(0).x - xAxisData.getMinimum()) * xAxisData.getAxisScale(), 0);
      cubicFillPath.close();

      canvas.save();
      canvas.clipPath(cubicFillPath);
      curveData
          .getDrawable()
          .setBounds(
              -canvas.getWidth() + (int) xAxisData.getAxisLength(),
              -(int) yAxisData.getAxisLength(),
              (int) xAxisData.getAxisLength(),
              canvas.getHeight() - (int) yAxisData.getAxisLength());
      curveData.getDrawable().draw(canvas);
      canvas.restore();
      cubicFillPath.rewind();
    }

    /** 点绘制 */
    outpointPaint.setColor(curveData.getColor());
    inPointPaint.setColor(Color.WHITE);
    ((IPointData) curveData).setInPaint(inPointPaint);
    ((IPointData) curveData).setOutPaint(outpointPaint);
    if (((IPointData) curveData).getInRadius() == IPointData.NOSETING)
      ((IPointData) curveData).setInRadius(xAxisData.getAxisLength() / 100);
    if (((IPointData) curveData).getOutRadius() == IPointData.NOSETING)
      ((IPointData) curveData).setOutRadius(xAxisData.getAxisLength() / 70);
    for (int j = 0; j < pointList.size(); j++) {
      mPointRender.drawCirclePoint(
          canvas,
          pointList.get(j),
          curveData.getValue().get(j),
          (IPointData) curveData,
          curveData.getTextSize(),
          curveData.getIsTextSize(),
          yAxisData.getDecimalPlaces());
    }
    canvas.restore();
  }