Ejemplo n.º 1
0
  public final void clear() {
    Context2D context = getContext();

    if (null != context) {
      context.clearRect(0, 0, m_wide, m_high);
    }
  }
Ejemplo n.º 2
0
  private final String getTextBestFit(final Context2D context, final String text, final int wide) {
    double pt = LienzoCore.get().getDefaultFontSize();

    String st = LienzoCore.get().getDefaultFontStyle();

    String fm = LienzoCore.get().getDefaultFontFamily();

    String tf = Text.getFontString(pt, TextUnit.PT, st, fm);

    context.save();

    context.setToIdentityTransform();

    while (true) {
      context.setTextFont(tf);

      final TextMetrics tm = context.measureText(text);

      if (tm.getWidth() < wide) {
        break;
      }
      pt = pt - 2;

      if (pt < 6) {
        break;
      }
      tf = Text.getFontString(pt, TextUnit.PT, st, fm);
    }
    context.restore();

    return tf;
  }
Ejemplo n.º 3
0
  /**
   * Draws this ellipse.
   *
   * @param context the {@link Context2D} used to draw this ellipse.
   */
  @Override
  protected boolean prepare(final Context2D context, final Attributes attr, final double alpha) {
    final double w = attr.getWidth();

    final double h = attr.getHeight();

    if ((w > 0) && (h > 0)) {
      final double x = -(w / 2);

      final double y = -(h / 2);

      final double ox = (w / 2) * KAPPA; // control point offset horizontal

      final double oy = (h / 2) * KAPPA; // control point offset vertical

      final double xe = x + w; // x-end

      final double ye = y + h; // y-end

      final double xm = x + w / 2; // x-middle

      final double ym = y + h / 2; // y-middle

      context.beginPath();

      context.moveTo(x, ym);

      context.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);

      context.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);

      context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);

      context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);

      context.closePath();

      return true;
    }
    return false;
  }
Ejemplo n.º 4
0
  /**
   * Draws the frames of the video. If looping has been set, frames are drawn continuously in a
   * loop.
   *
   * @param context
   */
  @Override
  protected boolean prepare(final Context2D context, final Attributes attr, final double alpha) {
    if (m_inits) {
      init();

      if ((null == m_error) && (isAutoPlay())) {
        play();
      }
    }
    int wide = getWidth();

    int high = getHeight();

    if (null != m_error) {
      if (false == context.isSelection()) {
        if (wide < 1) {
          wide = MOVIE_ERROR_WIDE;
        }
        if (high < 1) {
          high = MOVIE_ERROR_HIGH;
        }
        context.save();

        context.setFillColor(ColorName.BLACK);

        context.rect(0, 0, wide, high);

        context.fill();

        context.setTextAlign(TextAlign.CENTER);

        context.setTextBaseline(TextBaseLine.MIDDLE);

        context.setTextFont(getTextBestFit(context, m_error, wide));

        context.setFillColor(ColorName.WHITE);

        context.rect(0, 0, wide, high);

        context.clip();

        context.fillText(m_error, wide / 2, high / 2);

        context.restore();
      }
    } else {
      if ((wide < 1) || (high < 1)) {
        return false;
      }
      if (context.isSelection()) {
        final String color = getColorKey();

        if (null != color) {
          context.save();

          context.setFillColor(color);

          context.fillRect(0, 0, wide, high);

          context.restore();
        }
        return false;
      }
      if (isEnded()) {
        if (null != m_postr) {
          context.save();

          context.setGlobalAlpha(alpha);

          context.drawImage(m_postr, 0, 0, wide, high);

          context.restore();
        } else {
          String fill = getFillColor();

          if (null != fill) {
            context.save();

            context.setGlobalAlpha(alpha);

            context.setFillColor(fill);

            context.fillRect(0, 0, wide, high);

            context.restore();
          }
        }
        return false;
      }
      context.save();

      context.setGlobalAlpha(alpha);

      if ((false == m_xorig) && (m_filters.isActive())) {
        try {
          m_canvas.getContext().drawImage(m_video.getElement(), 0, 0, wide, high);

          m_canvas
              .getContext()
              .putImageData(
                  m_filters.filter(m_canvas.getContext().getImageData(0, 0, wide, high), false),
                  0,
                  0);

          context.drawImage(m_canvas.getElement(), 0, 0, wide, high);
        } catch (Exception e) {
          // We should only get an exception here if the URL is cross-origin, and getImageData() is
          // basically a security exception.
          // ...or other unknown bad things, either way, turn off filtering. DSJ 7/18/2014

          context.drawImage(m_video.getElement(), 0, 0, wide, high);

          m_xorig = true;

          LienzoCore.get()
              .error("ERROR: In Movie filtering " + m_video.getSrc() + " " + e.getMessage());
        }
      } else {
        context.drawImage(m_video.getElement(), 0, 0, wide, high);
      }
      context.restore();
    }
    return false;
  }