Exemple #1
0
 public void setSize(int width, int height) {
   rootElement.getStyle().setWidth(width, Unit.PX);
   rootElement.getStyle().setHeight(height, Unit.PX);
   canvas.setWidth(scale().scaledCeil(width));
   canvas.setHeight(scale().scaledCeil(height));
   canvas.getStyle().setWidth(width, Style.Unit.PX);
   canvas.getStyle().setHeight(height, Style.Unit.PX);
   viewportChanged(scale(), canvas.getWidth(), canvas.getHeight());
 }
  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 = tileCache.tileSize;
    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 = tileCache.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];
        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);
  }
Exemple #3
0
 @Override
 public int getHeight() {
   return canvas.getHeight();
 }