Skip to content

Commit

Permalink
Increase zoom range #84
Browse files Browse the repository at this point in the history
  • Loading branch information
MHShetty committed Aug 11, 2021
1 parent c1e2b20 commit 62d0ca0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
14 changes: 14 additions & 0 deletions app/src/main/assets/viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,17 @@ body, canvas, #padding {
.textLayer .endOfContent.active {
top: 0px;
}

html, body {
display: table;
height: 100%;
width: 100%;
text-align:center;
}

#content-wrapper {
display: flex;
justify-content: center; /* center horizontally */
align-items: center;
height: 100%;
}
5 changes: 3 additions & 2 deletions app/src/main/assets/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<script src="pdf.js"></script>
</head>
<body>
<div id="padding"></div>
<canvas id="content"></canvas>
<div id="content-wrapper">
<canvas id="content"></canvas>
</div>
<div id="text" class="textLayer"></div>
<script src="viewer.js"></script>
</body>
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/assets/viewer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict";

const padding = document.getElementById("padding");
let pdfDoc = null;
let pageRendering = false;
let renderPending = false;
Expand Down Expand Up @@ -54,7 +53,6 @@ function display(newCanvas, zoom) {
canvas.width = newCanvas.width;
canvas.style.height = newCanvas.style.height;
canvas.style.width = newCanvas.style.width;
padding.style.width = canvas.style.width;
canvas.getContext("2d", { alpha: false }).drawImage(newCanvas, 0, 0);
if (!zoom) {
scrollTo(0, 0);
Expand Down Expand Up @@ -95,7 +93,7 @@ function renderPage(pageNumber, zoom, prerender, prerenderTrigger=0) {
return;
}

const viewport = page.getViewport({scale: newZoomRatio, rotation: orientationDegrees})
const viewport = page.getViewport({scale: window.screen.width / page.getViewport({scale: 1}).width * newZoomRatio, rotation: orientationDegrees})

if (useRender) {
if (newZoomRatio !== zoomRatio) {
Expand Down Expand Up @@ -200,7 +198,9 @@ function isTextSelected() {

function updateInset() {
const windowInsetTop = channel.getWindowInsetTop() / window.devicePixelRatio + "px";
padding.style.paddingTop = windowInsetTop;
canvas.style.paddingTop = windowInsetTop;
// bottom insets was added to ensure that the PDF is in center
canvas.style.paddingBottom = windowInsetTop;
textLayerDiv.style.top = windowInsetTop;
}

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
"usb 'none'; " +
"vr 'none'";

private static final float MIN_ZOOM_RATIO = 0.5f;
private static final float MAX_ZOOM_RATIO = 1.5f;
private static final float MIN_ZOOM_RATIO = 0.9f;
private static final float MAX_ZOOM_RATIO = 3f;
private static final int ALPHA_LOW = 130;
private static final int ALPHA_HIGH = 255;
private static final int ACTION_OPEN_DOCUMENT_REQUEST_CODE = 1;
Expand All @@ -88,7 +88,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
private Uri mUri;
public int mPage;
public int mNumPages;
private float mZoomRatio = 1f;
private float mZoomRatio = MIN_ZOOM_RATIO;
private int mDocumentOrientationDegrees;
private int mDocumentState;
private int windowInsetTop;
Expand Down

0 comments on commit 62d0ca0

Please sign in to comment.