List of usage examples for com.google.gwt.canvas.dom.client Context2d clearRect
public final native void clearRect(double x, double y, double w, double h) ;
From source file:org.rstudio.core.client.widget.FontDetector.java
License:Open Source License
public static boolean isFontSupported(String fontName) { SimplePanel panel = null;/*from w ww . ja v a 2 s. co m*/ try { // default font name as a reference point final String defaultFontName = "Arial"; if (defaultFontName.equals(fontName)) return true; // make sure canvas is supported if (!Canvas.isSupported()) return false; // add a temporary div to the dom panel = new SimplePanel(); panel.setHeight("200px"); panel.getElement().getStyle().setVisibility(Visibility.HIDDEN); panel.getElement().getStyle().setOverflow(Overflow.SCROLL); RootPanel.get().add(panel, -2000, -2000); // add a canvas element to the div and get the 2d drawing context final Canvas canvas = Canvas.createIfSupported(); 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(); String defaultHash = hashGenerator.getHash(defaultFontName); String fontHash = hashGenerator.getHash(fontName); return !defaultHash.equals(fontHash); } catch (Exception ex) { Debug.log(ex.toString()); return false; } finally { if (panel != null) RootPanel.get().remove(panel); } }
From source file:org.rstudio.core.client.widget.ProgressSpinner.java
License:Open Source License
private void redraw() { Context2d ctx = canvas_.getContext2d(); double center = COORD_SIZE / 2; // clear canvas (we draw with an alpha channel so otherwise would stack) ctx.clearRect(0, 0, COORD_SIZE, COORD_SIZE); for (int i = 0; i < NUM_BLADES; i++) { // compute angle for this blade double theta = ((2 * Math.PI) / NUM_BLADES) * i; double sin = Math.sin(theta); double cos = Math.cos(theta); // set line drawing context ctx.beginPath();/*from w ww .j ava 2 s.c o m*/ ctx.setLineWidth(BLADE_WIDTH); ctx.setLineCap(LineCap.ROUND); // compute transparency for this blade double alpha = 1.0 - (((double) ((i + frame_) % NUM_BLADES)) / ((double) NUM_BLADES)); ctx.setStrokeStyle("rgba(" + color_ + ", " + alpha + ")"); // draw the blade ctx.moveTo(center + sin * innerRadius_, center + cos * innerRadius_); ctx.lineTo(center + sin * outerRadius_, center + cos * outerRadius_); ctx.stroke(); } }
From source file:stroom.widget.htree.client.ShadowBox.java
License:Apache License
private void clear(final Context2d ctx, final Bounds bounds) { ctx.clearRect(bounds.getX() - 2, bounds.getY() - 2, bounds.getWidth() + 4, bounds.getHeight() + 4); }
From source file:web.diva.client.somclust.view.MaxTreeZoomImage.java
public void buffer(Context2d back, Context2d front) { front.beginPath();/*from w w w . java2 s .com*/ front.clearRect(0, 0, width, height); front.drawImage(back.getCanvas(), 0, 0); }