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

Pdfjs 4.7+fixes #404

Open
wants to merge 6 commits 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
27 changes: 3 additions & 24 deletions app/src/main/java/app/grapheneos/pdfviewer/GestureHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
class GestureHelper {
public interface GestureListener {
boolean onTapUp();
// Can be replaced with ratio when supported
void onZoomIn(float value);
void onZoomOut(float value);
void onZoom(float scaleFactor, float focusX, float focusY);
void onZoomEnd();
}

Expand All @@ -33,29 +31,10 @@ public boolean onSingleTapUp(MotionEvent motionEvent) {

final ScaleGestureDetector scaleDetector = new ScaleGestureDetector(context,
new ScaleGestureDetector.SimpleOnScaleGestureListener() {
final float SPAN_RATIO = 600;
float initialSpan;
float prevNbStep;

@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
initialSpan = detector.getCurrentSpan();
prevNbStep = 0;
return true;
}

@Override
public boolean onScale(ScaleGestureDetector detector) {
float spanDiff = initialSpan - detector.getCurrentSpan();
float curNbStep = spanDiff / SPAN_RATIO;

float stepDiff = curNbStep - prevNbStep;
if (stepDiff > 0) {
listener.onZoomOut(stepDiff);
} else {
listener.onZoomIn(Math.abs(stepDiff));
}
prevNbStep = curNbStep;
listener.onZoom(detector.getScaleFactor(), detector.getFocusX(),
detector.getFocusY());

return true;
}
Expand Down
41 changes: 20 additions & 21 deletions app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
public int mPage;
public int mNumPages;
private float mZoomRatio = 1f;
private float mZoomFocusX = 0f;
private float mZoomFocusY = 0f;
private int mDocumentOrientationDegrees;
private int mDocumentState;
private String mEncryptedDocumentPassword;
Expand Down Expand Up @@ -177,6 +179,16 @@ public void setZoomRatio(final float ratio) {
mZoomRatio = Math.max(Math.min(ratio, MAX_ZOOM_RATIO), MIN_ZOOM_RATIO);
}

@JavascriptInterface
public float getZoomFocusX() {
return mZoomFocusX;
}

@JavascriptInterface
public float getZoomFocusY() {
return mZoomFocusY;
}

@JavascriptInterface
public float getMinZoomRatio() {
return MIN_ZOOM_RATIO;
Expand Down Expand Up @@ -363,13 +375,8 @@ public boolean onTapUp() {
}

@Override
public void onZoomIn(float value) {
zoomIn(value, false);
}

@Override
public void onZoomOut(float value) {
zoomOut(value, false);
public void onZoom(float scaleFactor, float focusX, float focusY) {
zoom(scaleFactor, focusX, focusY, false);
}

@Override
Expand Down Expand Up @@ -559,20 +566,12 @@ private void shareDocument() {
}
}

private void zoomIn(float value, boolean end) {
if (mZoomRatio < MAX_ZOOM_RATIO) {
mZoomRatio = Math.min(mZoomRatio + value, MAX_ZOOM_RATIO);
renderPage(end ? 1 : 2);
invalidateOptionsMenu();
}
}

private void zoomOut(float value, boolean end) {
if (mZoomRatio > MIN_ZOOM_RATIO) {
mZoomRatio = Math.max(mZoomRatio - value, MIN_ZOOM_RATIO);
renderPage(end ? 1 : 2);
invalidateOptionsMenu();
}
private void zoom(float scaleFactor, float focusX, float focusY, boolean end) {
mZoomRatio = Math.min(Math.max(mZoomRatio * scaleFactor, MIN_ZOOM_RATIO), MAX_ZOOM_RATIO);
mZoomFocusX = focusX;
mZoomFocusY = focusY;
renderPage(end ? 1 : 2);
invalidateOptionsMenu();
}

private void zoomEnd() {
Expand Down
Loading