Java Code Examples for com.google.gwt.canvas.client.Canvas#setWidth()
The following examples show how to use
com.google.gwt.canvas.client.Canvas#setWidth() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataStore.java From djvu-html5 with GNU General Public License v2.0 | 5 votes |
public static CanvasElement createImage(int width, int height) { Canvas canvas = Canvas.createIfSupported(); canvas.setWidth(width + "px"); canvas.setCoordinateSpaceWidth(width); canvas.setHeight(height + "px"); canvas.setCoordinateSpaceHeight(height); return canvas.getCanvasElement(); }
Example 2
Source File: Util.java From openchemlib-js with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void scaleCanvas(Canvas canvas, int width, int height) { canvas.setWidth(width + "px"); canvas.setHeight(height + "px"); Context2d ctx = canvas.getContext2d(); double ratio = Util.getDevicePixelRatio(); canvas.setCoordinateSpaceWidth((int)(width * ratio)); canvas.setCoordinateSpaceHeight((int)(height * ratio)); ctx.scale(ratio, ratio); }
Example 3
Source File: TextMetricsCalculator.java From jetpad-projectional-open-source with Apache License 2.0 | 5 votes |
private static int measureHeight(Font font, String text) { Canvas canvas = canvas(); Context2d ctx = canvas.getContext2d(); ctx.setFont(getFontString(font)); ctx.setFillStyle("rgb(255, 0, 0)"); int width = (int) ctx.measureText(text).getWidth(); int canvasHeight = font.getSize() * 2; canvas.setHeight(canvasHeight + "px"); canvas.setHeight(font.getSize() * 2 + "px"); canvas.setWidth(width + "px"); ctx.fillText(text, 0, font.getSize()); ImageData data = ctx.getImageData(0, 0, width, canvasHeight); int firstY = canvasHeight - 1; int lastY = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < canvasHeight; y++) { int red = data.getRedAt(x, y); if (red != 0) { if (firstY > y) { firstY = y; } if (lastY < y) { lastY = y; } } } } return lastY - firstY; }