use CSS zooming until end of zoom gesture
This commit is contained in:
parent
69a6219634
commit
f780734c9c
@ -4,7 +4,7 @@ const padding = document.getElementById("padding");
|
|||||||
let pdfDoc = null;
|
let pdfDoc = null;
|
||||||
let pageRendering = false;
|
let pageRendering = false;
|
||||||
let renderPending = false;
|
let renderPending = false;
|
||||||
let renderPendingZoom = false;
|
let renderPendingZoom = 0;
|
||||||
const canvas = document.getElementById('content');
|
const canvas = document.getElementById('content');
|
||||||
let orientationDegrees = 0;
|
let orientationDegrees = 0;
|
||||||
let zoomRatio = 1;
|
let zoomRatio = 1;
|
||||||
@ -95,15 +95,7 @@ function renderPage(pageNumber, zoom, prerender, prerenderTrigger=0) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newCanvas = document.createElement("canvas");
|
|
||||||
const viewport = page.getViewport({scale: newZoomRatio, rotation: orientationDegrees})
|
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 (useRender) {
|
||||||
if (newZoomRatio !== zoomRatio) {
|
if (newZoomRatio !== zoomRatio) {
|
||||||
@ -113,6 +105,20 @@ function renderPage(pageNumber, zoom, prerender, prerenderTrigger=0) {
|
|||||||
zoomRatio = newZoomRatio;
|
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({
|
task = page.render({
|
||||||
canvasContext: newContext,
|
canvasContext: newContext,
|
||||||
viewport: viewport
|
viewport: viewport
|
||||||
|
@ -330,8 +330,8 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||||||
mWebView.loadUrl("https://localhost/viewer.html");
|
mWebView.loadUrl("https://localhost/viewer.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderPage(final boolean zoom) {
|
private void renderPage(final int zoom) {
|
||||||
mWebView.evaluateJavascript(zoom ? "onRenderPage(true)" : "onRenderPage(false)", null);
|
mWebView.evaluateJavascript("onRenderPage(" + zoom + ")", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void documentOrientationChanged(final int orientationDegreesOffset) {
|
private void documentOrientationChanged(final int orientationDegreesOffset) {
|
||||||
@ -339,7 +339,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||||||
if (mDocumentOrientationDegrees < 0) {
|
if (mDocumentOrientationDegrees < 0) {
|
||||||
mDocumentOrientationDegrees += 360;
|
mDocumentOrientationDegrees += 360;
|
||||||
}
|
}
|
||||||
renderPage(false);
|
renderPage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openDocument() {
|
private void openDocument() {
|
||||||
@ -352,7 +352,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||||||
private void zoomIn(float value) {
|
private void zoomIn(float value) {
|
||||||
if (mZoomRatio < MAX_ZOOM_RATIO) {
|
if (mZoomRatio < MAX_ZOOM_RATIO) {
|
||||||
mZoomRatio += value;
|
mZoomRatio += value;
|
||||||
renderPage(true);
|
renderPage(2);
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -360,13 +360,13 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
|
|||||||
private void zoomOut(float value) {
|
private void zoomOut(float value) {
|
||||||
if (mZoomRatio > MIN_ZOOM_RATIO) {
|
if (mZoomRatio > MIN_ZOOM_RATIO) {
|
||||||
mZoomRatio -= value;
|
mZoomRatio -= value;
|
||||||
renderPage(true);
|
renderPage(2);
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void zoomEnd() {
|
private void zoomEnd() {
|
||||||
renderPage(true);
|
renderPage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void enableDisableMenuItem(MenuItem item, boolean enable) {
|
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) {
|
public void onJumpToPageInDocument(final int selected_page) {
|
||||||
if (selected_page >= 1 && selected_page <= mNumPages && mPage != selected_page) {
|
if (selected_page >= 1 && selected_page <= mNumPages && mPage != selected_page) {
|
||||||
mPage = selected_page;
|
mPage = selected_page;
|
||||||
renderPage(false);
|
renderPage(0);
|
||||||
showPageNumber();
|
showPageNumber();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user