Package com.google.gwt.canvas.dom.client

Examples of com.google.gwt.canvas.dom.client.Context2d


      return imageData;
  }
  public  static ImageData fillImage(Image image, double cw,double ch) {
       Canvas canvasTmp = Canvas.createIfSupported();
        Context2d context = canvasTmp.getContext2d();

        //double ch = (image.getHeight() * scaleToRatioh) + 100;
        //double cw = (image.getWidth() * scaleToRatiow) + 100;

        canvasTmp.setCoordinateSpaceHeight((int) ch);
        canvasTmp.setCoordinateSpaceWidth((int) cw);
       
        ImageElement imageElement = ImageElement.as(image.getElement());
      
        // s = source
        // d = destination
        double sx = 0;
        double sy = 0;
        double sw = imageElement.getWidth();
        double sh = imageElement.getHeight();
       
        double dx = 0;
        double dy = 0;
        double dw = imageElement.getWidth();
        double dh = imageElement.getHeight();
       
        // tell it to scale image
        //context.scale(scaleToRatioh, scaleToRatiow);
       
        // draw image to canvas
        context.drawImage(imageElement, sx, sy, sw, sh, dx, dy, cw, ch);
       
        // get image data
        //double w = dw * scaleToRatioh;
        //double h = dh * scaleToRatiow;
        ImageData imageData = context.getImageData(0, 0, cw, ch);

        return imageData;
   
  }
View Full Code Here


    canvas1.setWidth("61px");
    assertEquals(41, canvas1.getOffsetHeight());
    assertEquals(61, canvas1.getOffsetWidth());

    // add 2d context, resize internal size, should have no effect
    Context2d context = canvas1.getContext2d();
    canvas1.setCoordinateSpaceHeight(140);
    canvas1.setCoordinateSpaceWidth(160);
    context.fillRect(2, 2, 300, 300);

    assertEquals(41, canvas1.getOffsetHeight());
    assertEquals(61, canvas1.getOffsetWidth());
  }
View Full Code Here

         canvas.setWidth("512px");
         canvas.setHeight("64px");
         canvas.getElement().getStyle().setLeft(400, Unit.PX);
         canvas.getElement().getStyle().setBackgroundColor("#ffe");
         panel.add(canvas);
         final Context2d ctx = canvas.getContext2d();
         ctx.setFillStyle("#000000");
        
         // closure to generate a hash for a font
         class HashGenerator {
            public String getHash(String fontName)
            {
               ctx.setFont("57px " + fontName + ", " + defaultFontName);
               int width = canvas.getOffsetWidth();
               int height = canvas.getOffsetHeight();
               ctx.clearRect(0, 0, width, height);
               ctx.fillText("TheQuickBrownFox", 2, 50);
               return canvas.toDataUrl();
            }};
        
         // get hashes and compare them
         HashGenerator hashGenerator = new HashGenerator();
View Full Code Here

    fCenter = center;
  }

  @Override
  public void draw(Surface surface) {
    Context2d context = surface.getContext();
    context.beginPath();
    context.arc(fCenter.x, fCenter.y, fRadius, 0, MathHelper.TWO_PI, true);
    context.closePath();
  }
View Full Code Here

   * Represents a custom shape.
   */
  public final class CustomShape extends Shape {
    @Override
    public final void draw(Surface surface) {
      Context2d context = surface.getContext();
      context.beginPath();
      for (ShapeVisitor shape : shapes) {
        shape.visit(surface);
      }
      context.closePath();
    }
View Full Code Here

        controlPoint2.getX(), controlPoint2.getY(),
        endPoint.getX(), endPoint.getY());
  }
 
  public void visit(Surface surface) {
    Context2d context = surface.getContext();
    context.moveTo(startPointX, startPointY);
    context.bezierCurveTo(controlPoint1X, controlPoint1Y,
        controlPoint2X, controlPoint2Y,
        endPointX, endPointY);
  }
View Full Code Here

    this(ellipse.getX(), ellipse.getY(), ellipse.getWidth(), ellipse.getHeight());
  }
 
  @Override
  public void visit(Surface surface) {
    Context2d context = surface.getContext();
    context.save();
    context.translate(x + width / 2, y + height / 2);
    context.scale(width / 2, height / 2);
    context.arc(0, 0, 1, 0, MathHelper.TWO_PI, true);
    context.restore();
  }
View Full Code Here

    this.height = height;
  }
 
  @Override
  public void visit(Surface surface) {
    Context2d context = surface.getContext();
    context.moveTo(x, y);
    context.lineTo(x + width, y);
    context.lineTo(x + width, y + height);
    context.lineTo(x, y + height);
    context.lineTo(x, y);
  }
View Full Code Here

    this(circle.getCenterX(), circle.getCenterY(), circle.getRadius());
  }
 
  @Override
  public void visit(Surface surface) {
    Context2d context = surface.getContext();
    context.arc(x, y, radius, 0, MathHelper.TWO_PI, true);
  }
View Full Code Here

    this.toY = toY;
  }
 
  @Override
  public void visit(Surface surface) {
    Context2d context = surface.getContext();
    context.moveTo(fromX, fromY);
    context.lineTo(toX, toY);
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.canvas.dom.client.Context2d

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.