Java Code Examples for com.google.gwt.canvas.dom.client.Context2d#fillRect()
The following examples show how to use
com.google.gwt.canvas.dom.client.Context2d#fillRect() .
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 | 6 votes |
private CanvasElement prepareMissingTileImage() { int tileSize = DjvuContext.getTileSize(); CanvasElement canvas = createImage(tileSize, tileSize); Context2d context2d = canvas.getContext2d(); context2d.setFillStyle("white"); context2d.fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); Image image = new Image(); final ImageElement imageElement = image.getElement().cast(); imageElement.getStyle().setProperty("visibility", "hidden"); Event.setEventListener(imageElement, event -> { if (Event.ONLOAD == event.getTypeInt()) { missingTileImage.getContext2d().drawImage(imageElement, 0, 0); RootPanel.get().getElement().removeChild(imageElement); } }); RootPanel.get().getElement().appendChild(imageElement); image.setUrl(getBlankImageUrl()); return canvas; }
Example 2
Source File: DataStore.java From djvu-html5 with GNU General Public License v2.0 | 6 votes |
public void setTile(TileInfo tileInfo, GMap bufferGMap) { if (bufferImageData == null || bufferImageData.getWidth() != bufferGMap.getDataWidth() || bufferImageData.getHeight() != bufferGMap.getDataHeight()) { bufferImageData = bufferCanvas.getContext2d() .createImageData(bufferGMap.getDataWidth(), bufferGMap.getDataHeight()); } Uint8Array imageArray = bufferImageData.getData().cast(); imageArray.set(bufferGMap.getImageData()); bufferCanvas.getContext2d().putImageData(bufferImageData, -bufferGMap.getBorder(), 0); CanvasElement tile = tiles.get(tileInfo); if (tile == null) { tile = createImage(bufferGMap.getDataWidth() - bufferGMap.getBorder(), bufferGMap.getDataHeight()); tiles.put(new TileInfo(tileInfo), tile); } Context2d c = tile.getContext2d(); c.setFillStyle("white"); c.fillRect(0, 0, tileSize, tileSize); c.drawImage(bufferCanvas, 0, 0); for (Consumer<Integer> listener : tileListeners) listener.accept(tileInfo.page); }
Example 3
Source File: SinglePageLayout.java From djvu-html5 with GNU General Public License v2.0 | 5 votes |
public void redraw() { Context2d graphics2d = canvas.getContext2d(); int w = canvas.getCoordinateSpaceWidth(), h = canvas.getCoordinateSpaceHeight(); graphics2d.setFillStyle(background); graphics2d.fillRect(0, 0, w, h); if (pageInfo == null) return; int subsample = toSubsample(zoom); double scale = zoom / toZoom(subsample); graphics2d.save(); int startX = w / 2 - centerX, startY = h / 2 - centerY; graphics2d.translate(startX, startY); graphics2d.scale(scale, scale); graphics2d.translate(-startX, -startY); graphics2d.scale(1, -1); // DjVu images have y-axis inverted int tileSize = DjvuContext.getTileSize(); int pw = (int) (pageInfo.width * zoom), ph = (int) (pageInfo.height * zoom); range.xmin = (int) (Math.max(0, centerX - w * 0.5) / tileSize / scale); range.xmax = (int) Math.ceil(Math.min(pw, centerX + w * 0.5) / tileSize / scale); range.ymin = (int) (Math.max(0, centerY - h * 0.5) / tileSize / scale); range.ymax = (int) Math.ceil(Math.min(ph, centerY + h * 0.5) / tileSize / scale); imagesArray = dataStore.getTileImages(page, subsample, range , imagesArray); for (int y = range.ymin; y <= range.ymax; y++) { for (int x = range.xmin; x <= range.xmax; x++) { CanvasElement canvasElement = imagesArray[y - range.ymin][x - range.xmin]; for (int repeats = scale == 1 ? 1 : 3; repeats > 0; repeats--) { graphics2d.drawImage(canvasElement, startX + x * tileSize, -startY - y * tileSize - canvasElement.getHeight()); } } } graphics2d.restore(); // missing tile graphics may exceed the page boundary graphics2d.fillRect(startX + pw, 0, w, h); graphics2d.fillRect(0, startY + ph, w, h); DjvuContext.setTileRange(range, subsample); }
Example 4
Source File: DrawArea.java From openchemlib-js with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void drawBackground(Context2d context2d, int w, int h) { context2d.clearRect(0, 0, w, h); context2d.setFillStyle(WHITE); context2d.fillRect(0, 0, w, h); }