use CSS zooming until end of zoom gesture

This commit is contained in:
Daniel Micay 2020-04-04 12:14:38 -04:00
parent 69a6219634
commit f780734c9c
2 changed files with 22 additions and 16 deletions

View File

@ -4,7 +4,7 @@ const padding = document.getElementById("padding");
let pdfDoc = null;
let pageRendering = false;
let renderPending = false;
let renderPendingZoom = false;
let renderPendingZoom = 0;
const canvas = document.getElementById('content');
let orientationDegrees = 0;
let zoomRatio = 1;
@ -95,15 +95,7 @@ function renderPage(pageNumber, zoom, prerender, prerenderTrigger=0) {
return;
}
const newCanvas = document.createElement("canvas");
const viewport = page.getViewport({scale: newZoomRatio, rotation: orientationDegrees})
const ratio = window.devicePixelRatio;
newCanvas.height = viewport.height * ratio;
newCanvas.width = viewport.width * ratio;
newCanvas.style.height = viewport.height + "px";
newCanvas.style.width = viewport.width + "px";
const newContext = newCanvas.getContext("2d", { alpha: false });
newContext.scale(ratio, ratio);
if (useRender) {
if (newZoomRatio !== zoomRatio) {
@ -113,6 +105,20 @@ function renderPage(pageNumber, zoom, prerender, prerenderTrigger=0) {
zoomRatio = newZoomRatio;
}
if (zoom == 2) {
pageRendering = false;
return;
}
const newCanvas = document.createElement("canvas");
const ratio = window.devicePixelRatio;
newCanvas.height = viewport.height * ratio;
newCanvas.width = viewport.width * ratio;
newCanvas.style.height = viewport.height + "px";
newCanvas.style.width = viewport.width + "px";
const newContext = newCanvas.getContext("2d", { alpha: false });
newContext.scale(ratio, ratio);
task = page.render({
canvasContext: newContext,
viewport: viewport

View File

@ -330,8 +330,8 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
mWebView.loadUrl("https://localhost/viewer.html");
}
private void renderPage(final boolean zoom) {
mWebView.evaluateJavascript(zoom ? "onRenderPage(true)" : "onRenderPage(false)", null);
private void renderPage(final int zoom) {
mWebView.evaluateJavascript("onRenderPage(" + zoom + ")", null);
}
private void documentOrientationChanged(final int orientationDegreesOffset) {
@ -339,7 +339,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
if (mDocumentOrientationDegrees < 0) {
mDocumentOrientationDegrees += 360;
}
renderPage(false);
renderPage(0);
}
private void openDocument() {
@ -352,7 +352,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
private void zoomIn(float value) {
if (mZoomRatio < MAX_ZOOM_RATIO) {
mZoomRatio += value;
renderPage(true);
renderPage(2);
invalidateOptionsMenu();
}
}
@ -360,13 +360,13 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
private void zoomOut(float value) {
if (mZoomRatio > MIN_ZOOM_RATIO) {
mZoomRatio -= value;
renderPage(true);
renderPage(2);
invalidateOptionsMenu();
}
}
private void zoomEnd() {
renderPage(true);
renderPage(1);
}
private static void enableDisableMenuItem(MenuItem item, boolean enable) {
@ -384,7 +384,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
public void onJumpToPageInDocument(final int selected_page) {
if (selected_page >= 1 && selected_page <= mNumPages && mPage != selected_page) {
mPage = selected_page;
renderPage(false);
renderPage(0);
showPageNumber();
}
}