Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase zoom range #100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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