@papyrus-sdk/engine-native 0.2.18 → 0.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/papyrus/engine/PapyrusBitmapOwnership.java +9 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusEngineStore.java +12 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +66 -6
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.kt +14 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeRenderTelemetry.java +118 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusPageView.java +260 -47
- package/android/src/main/java/com/papyrus/engine/PapyrusPageViewManager.java +6 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +99 -213
- package/android/src/main/java/com/papyrus/engine/PapyrusRenderCompletion.java +33 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusRenderMath.java +13 -2
- package/android/src/main/java/com/papyrus/engine/PapyrusTextSelectionGesture.java +23 -0
- package/dist/index.d.mts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.js +100 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +100 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ import android.view.MotionEvent;
|
|
|
19
19
|
import android.view.ScaleGestureDetector;
|
|
20
20
|
import android.view.VelocityTracker;
|
|
21
21
|
import android.view.View;
|
|
22
|
+
import android.view.ViewParent;
|
|
22
23
|
import android.widget.OverScroller;
|
|
23
24
|
|
|
24
25
|
import com.facebook.react.bridge.Arguments;
|
|
@@ -138,11 +139,6 @@ public class PapyrusPdfViewerView extends View {
|
|
|
138
139
|
private static final float DOUBLE_TAP_MAX_DISTANCE_DP = 20;
|
|
139
140
|
private Runnable pendingSingleTap;
|
|
140
141
|
|
|
141
|
-
// Long-press detection
|
|
142
|
-
private static final long LONG_PRESS_MS = 450;
|
|
143
|
-
private Runnable pendingLongPress;
|
|
144
|
-
private boolean longPressFired = false;
|
|
145
|
-
|
|
146
142
|
// Selection handles
|
|
147
143
|
private static final float HANDLE_RADIUS_DP = 10;
|
|
148
144
|
private static final int HANDLE_COLOR = Color.parseColor("#4285F4");
|
|
@@ -329,16 +325,15 @@ public class PapyrusPdfViewerView extends View {
|
|
|
329
325
|
|
|
330
326
|
@Override
|
|
331
327
|
public boolean onTouchEvent(MotionEvent event) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
mainHandler.removeCallbacks(pendingLongPress);
|
|
338
|
-
pendingLongPress = null;
|
|
339
|
-
}
|
|
328
|
+
int action = event.getActionMasked();
|
|
329
|
+
if (action == MotionEvent.ACTION_DOWN && event.getPointerCount() == 1) {
|
|
330
|
+
requestDisallowParentInterception(true);
|
|
331
|
+
} else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
|
|
332
|
+
requestDisallowParentInterception(false);
|
|
340
333
|
}
|
|
341
334
|
|
|
335
|
+
scaleDetector.onTouchEvent(event);
|
|
336
|
+
|
|
342
337
|
if ("ink".equals(activeTool) && event.getPointerCount() == 1) {
|
|
343
338
|
return handleInkTouch(event);
|
|
344
339
|
}
|
|
@@ -539,7 +534,6 @@ public class PapyrusPdfViewerView extends View {
|
|
|
539
534
|
touchDownTime = System.currentTimeMillis();
|
|
540
535
|
touchDownX = event.getX();
|
|
541
536
|
touchDownY = event.getY();
|
|
542
|
-
longPressFired = false;
|
|
543
537
|
draggedHandle = 0;
|
|
544
538
|
|
|
545
539
|
// Check if touching a selection handle
|
|
@@ -553,10 +547,14 @@ public class PapyrusPdfViewerView extends View {
|
|
|
553
547
|
}
|
|
554
548
|
return true;
|
|
555
549
|
}
|
|
556
|
-
//
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
550
|
+
// Any new touch that is not on a selection handle starts normal
|
|
551
|
+
// scrolling. Keeping the selection body "active" here made a
|
|
552
|
+
// regular finger drag look like a stuck scroll after double-tap.
|
|
553
|
+
if (PapyrusTextSelectionGesture.shouldContinueAfterSelectionTouch(handleHit != 0)) {
|
|
554
|
+
isSelectingText = false;
|
|
555
|
+
selectPageIndex = -1;
|
|
556
|
+
selectedRects.clear();
|
|
557
|
+
selectedText = "";
|
|
560
558
|
}
|
|
561
559
|
}
|
|
562
560
|
|
|
@@ -571,41 +569,9 @@ public class PapyrusPdfViewerView extends View {
|
|
|
571
569
|
lastTouchX = event.getX();
|
|
572
570
|
lastTouchY = event.getY();
|
|
573
571
|
|
|
574
|
-
// Start long-press timer
|
|
575
|
-
pendingLongPress = () -> {
|
|
576
|
-
pendingLongPress = null;
|
|
577
|
-
longPressFired = true;
|
|
578
|
-
// Long press: select word at this point
|
|
579
|
-
ensureLayout();
|
|
580
|
-
float docX = touchDownX + offsetX;
|
|
581
|
-
float docY = touchDownY + offsetY;
|
|
582
|
-
int pageIdx = findPageIndexAt(docX, docY);
|
|
583
|
-
if (pageIdx >= 0) {
|
|
584
|
-
PageFrame frame = pageFrames.get(pageIdx);
|
|
585
|
-
float nx = clamp01((docX - frame.left) / frame.width);
|
|
586
|
-
float ny = clamp01((docY - frame.top) / frame.height);
|
|
587
|
-
isSelectingText = true;
|
|
588
|
-
selectPageIndex = pageIdx;
|
|
589
|
-
selectStartX = nx;
|
|
590
|
-
selectStartY = ny;
|
|
591
|
-
selectEndX = nx;
|
|
592
|
-
selectEndY = ny;
|
|
593
|
-
performWordSelection();
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
mainHandler.postDelayed(pendingLongPress, LONG_PRESS_MS);
|
|
597
572
|
return true;
|
|
598
573
|
|
|
599
574
|
case MotionEvent.ACTION_MOVE:
|
|
600
|
-
if (pendingLongPress != null) {
|
|
601
|
-
float cancelDx = event.getX() - touchDownX;
|
|
602
|
-
float cancelDy = event.getY() - touchDownY;
|
|
603
|
-
if (Math.hypot(cancelDx, cancelDy) > TAP_MAX_DISTANCE_DP * density) {
|
|
604
|
-
mainHandler.removeCallbacks(pendingLongPress);
|
|
605
|
-
pendingLongPress = null;
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
|
|
609
575
|
if (draggedHandle != 0 && isSelectingText && selectPageIndex >= 0) {
|
|
610
576
|
ensureLayout();
|
|
611
577
|
float moveDocX = event.getX() + offsetX;
|
|
@@ -620,24 +586,14 @@ public class PapyrusPdfViewerView extends View {
|
|
|
620
586
|
if (moveFrame != null) {
|
|
621
587
|
float nx = clamp01((moveDocX - moveFrame.left) / moveFrame.width);
|
|
622
588
|
float ny = clamp01((moveDocY - moveFrame.top) / moveFrame.height);
|
|
623
|
-
// Line-based selection: when dragging vertically across lines,
|
|
624
|
-
// snap X to page edge so the entire line gets selected
|
|
625
|
-
float lineHeight = 0.025f;
|
|
626
589
|
if (draggedHandle < 0) {
|
|
627
|
-
//
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
} else {
|
|
631
|
-
selectStartX = nx;
|
|
632
|
-
}
|
|
590
|
+
// Preserve the actual horizontal position instead of expanding
|
|
591
|
+
// the selection to the whole line when crossing line breaks.
|
|
592
|
+
selectStartX = PapyrusTextSelectionGesture.resolveSelectionEndpoint(nx);
|
|
633
593
|
selectStartY = ny;
|
|
634
594
|
} else {
|
|
635
|
-
//
|
|
636
|
-
|
|
637
|
-
selectEndX = 1f;
|
|
638
|
-
} else {
|
|
639
|
-
selectEndX = nx;
|
|
640
|
-
}
|
|
595
|
+
// Preserve the actual horizontal position for the end handle too.
|
|
596
|
+
selectEndX = PapyrusTextSelectionGesture.resolveSelectionEndpoint(nx);
|
|
641
597
|
selectEndY = ny;
|
|
642
598
|
}
|
|
643
599
|
performTextSelection();
|
|
@@ -677,13 +633,8 @@ public class PapyrusPdfViewerView extends View {
|
|
|
677
633
|
if (moveFrame != null) {
|
|
678
634
|
float nx = clamp01((moveDocX - moveFrame.left) / moveFrame.width);
|
|
679
635
|
float ny = clamp01((moveDocY - moveFrame.top) / moveFrame.height);
|
|
680
|
-
//
|
|
681
|
-
|
|
682
|
-
if (Math.abs(ny - selectStartY) > lineHeight * 0.6f) {
|
|
683
|
-
selectEndX = 1f;
|
|
684
|
-
} else {
|
|
685
|
-
selectEndX = nx;
|
|
686
|
-
}
|
|
636
|
+
// Keep the endpoint under the finger while dragging across lines.
|
|
637
|
+
selectEndX = PapyrusTextSelectionGesture.resolveSelectionEndpoint(nx);
|
|
687
638
|
selectEndY = ny;
|
|
688
639
|
performTextSelection();
|
|
689
640
|
}
|
|
@@ -694,11 +645,6 @@ public class PapyrusPdfViewerView extends View {
|
|
|
694
645
|
|
|
695
646
|
case MotionEvent.ACTION_UP:
|
|
696
647
|
case MotionEvent.ACTION_CANCEL:
|
|
697
|
-
if (pendingLongPress != null) {
|
|
698
|
-
mainHandler.removeCallbacks(pendingLongPress);
|
|
699
|
-
pendingLongPress = null;
|
|
700
|
-
}
|
|
701
|
-
|
|
702
648
|
draggedHandle = 0;
|
|
703
649
|
|
|
704
650
|
if (!scaleDetector.isInProgress() && velocityTracker != null) {
|
|
@@ -744,8 +690,8 @@ public class PapyrusPdfViewerView extends View {
|
|
|
744
690
|
float upDy = event.getY() - touchDownY;
|
|
745
691
|
float upDistance = (float) Math.hypot(upDx, upDy);
|
|
746
692
|
|
|
747
|
-
if (
|
|
748
|
-
if (isSelectingText
|
|
693
|
+
if (duration > TAP_MAX_DURATION_MS || upDistance > TAP_MAX_DISTANCE_DP * density) {
|
|
694
|
+
if (isSelectingText) {
|
|
749
695
|
emitTextSelected();
|
|
750
696
|
}
|
|
751
697
|
return true;
|
|
@@ -762,7 +708,38 @@ public class PapyrusPdfViewerView extends View {
|
|
|
762
708
|
pendingSingleTap = null;
|
|
763
709
|
}
|
|
764
710
|
|
|
765
|
-
if (isDoubleTap) {
|
|
711
|
+
if (PapyrusTextSelectionGesture.shouldEmitPageTap(isDoubleTap)) {
|
|
712
|
+
lastTapTime = now;
|
|
713
|
+
lastTapX = event.getX();
|
|
714
|
+
lastTapY = event.getY();
|
|
715
|
+
final float tapX = event.getX();
|
|
716
|
+
final float tapY = event.getY();
|
|
717
|
+
pendingSingleTap = () -> {
|
|
718
|
+
pendingSingleTap = null;
|
|
719
|
+
if (isSelectingText) {
|
|
720
|
+
isSelectingText = false;
|
|
721
|
+
selectPageIndex = -1;
|
|
722
|
+
selectedRects.clear();
|
|
723
|
+
selectedText = "";
|
|
724
|
+
invalidate();
|
|
725
|
+
}
|
|
726
|
+
ensureLayout();
|
|
727
|
+
float docX = tapX + offsetX;
|
|
728
|
+
float docY = tapY + offsetY;
|
|
729
|
+
int pageIdx = findPageIndexAt(docX, docY);
|
|
730
|
+
if (pageIdx < 0) return;
|
|
731
|
+
PageFrame frame = pageFrames.get(pageIdx);
|
|
732
|
+
float nx = (docX - frame.left) / frame.width;
|
|
733
|
+
float ny = (docY - frame.top) / frame.height;
|
|
734
|
+
Annotation hit = findAnnotationAt(pageIdx, nx, ny);
|
|
735
|
+
if (hit != null) {
|
|
736
|
+
emitAnnotationTap(hit);
|
|
737
|
+
} else {
|
|
738
|
+
emitTap(pageIdx, clamp01(nx), clamp01(ny));
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
mainHandler.postDelayed(pendingSingleTap, DOUBLE_TAP_MAX_DELTA_MS + 50);
|
|
742
|
+
} else {
|
|
766
743
|
lastTapTime = 0;
|
|
767
744
|
ensureLayout();
|
|
768
745
|
float docX = event.getX() + offsetX;
|
|
@@ -780,21 +757,6 @@ public class PapyrusPdfViewerView extends View {
|
|
|
780
757
|
selectEndY = ny;
|
|
781
758
|
performTextSelection();
|
|
782
759
|
}
|
|
783
|
-
} else {
|
|
784
|
-
lastTapTime = now;
|
|
785
|
-
lastTapX = event.getX();
|
|
786
|
-
lastTapY = event.getY();
|
|
787
|
-
pendingSingleTap = () -> {
|
|
788
|
-
pendingSingleTap = null;
|
|
789
|
-
if (isSelectingText) {
|
|
790
|
-
isSelectingText = false;
|
|
791
|
-
selectPageIndex = -1;
|
|
792
|
-
selectedRects.clear();
|
|
793
|
-
selectedText = "";
|
|
794
|
-
invalidate();
|
|
795
|
-
}
|
|
796
|
-
};
|
|
797
|
-
mainHandler.postDelayed(pendingSingleTap, DOUBLE_TAP_MAX_DELTA_MS + 50);
|
|
798
760
|
}
|
|
799
761
|
return true;
|
|
800
762
|
default:
|
|
@@ -802,30 +764,6 @@ public class PapyrusPdfViewerView extends View {
|
|
|
802
764
|
}
|
|
803
765
|
}
|
|
804
766
|
|
|
805
|
-
private boolean hitTestSelection(float screenX, float screenY) {
|
|
806
|
-
if (!isSelectingText || selectPageIndex < 0 || selectedRects.isEmpty()) return false;
|
|
807
|
-
PageFrame frame = null;
|
|
808
|
-
for (PageFrame f : pageFrames) {
|
|
809
|
-
if (f.index == selectPageIndex) {
|
|
810
|
-
frame = f;
|
|
811
|
-
break;
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
if (frame == null) return false;
|
|
815
|
-
|
|
816
|
-
float nx = clamp01((screenX + offsetX - frame.left) / frame.width);
|
|
817
|
-
float ny = clamp01((screenY + offsetY - frame.top) / frame.height);
|
|
818
|
-
|
|
819
|
-
// Check if point is inside any selected rect
|
|
820
|
-
for (NormalizedRect rect : selectedRects) {
|
|
821
|
-
if (nx >= rect.x && nx <= rect.x + rect.width &&
|
|
822
|
-
ny >= rect.y && ny <= rect.y + rect.height) {
|
|
823
|
-
return true;
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
return false;
|
|
827
|
-
}
|
|
828
|
-
|
|
829
767
|
private int hitTestHandle(float screenX, float screenY, float density) {
|
|
830
768
|
if (selectedRects.isEmpty() || selectPageIndex < 0) return 0;
|
|
831
769
|
PageFrame frame = null;
|
|
@@ -854,81 +792,6 @@ public class PapyrusPdfViewerView extends View {
|
|
|
854
792
|
return 0;
|
|
855
793
|
}
|
|
856
794
|
|
|
857
|
-
private void performWordSelection() {
|
|
858
|
-
if (selectPageIndex < 0) return;
|
|
859
|
-
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
860
|
-
if (state == null || state.document == null) return;
|
|
861
|
-
if (!PapyrusTextSelect.AVAILABLE) return;
|
|
862
|
-
|
|
863
|
-
// Use a larger rect to capture the whole word
|
|
864
|
-
float wordW = 0.05f;
|
|
865
|
-
float wordH = 0.03f;
|
|
866
|
-
float minX = Math.max(0f, selectStartX - wordW / 2f);
|
|
867
|
-
float minY = Math.max(0f, selectStartY - wordH / 2f);
|
|
868
|
-
float maxX = Math.min(1f, selectStartX + wordW / 2f);
|
|
869
|
-
float maxY = Math.min(1f, selectStartY + wordH / 2f);
|
|
870
|
-
|
|
871
|
-
final int pageIdx = selectPageIndex;
|
|
872
|
-
final float selX = minX;
|
|
873
|
-
final float selY = minY;
|
|
874
|
-
final float selW = Math.max(0.001f, maxX - minX);
|
|
875
|
-
final float selH = Math.max(0.001f, maxY - minY);
|
|
876
|
-
|
|
877
|
-
final String sourcePath = state.sourcePath;
|
|
878
|
-
SELECT_EXECUTOR.execute(() -> {
|
|
879
|
-
PapyrusTextSelection selection = null;
|
|
880
|
-
try {
|
|
881
|
-
if (sourcePath != null && !sourcePath.isEmpty()) {
|
|
882
|
-
synchronized (state.pdfiumLock) {
|
|
883
|
-
selection = PapyrusTextSelect.nativeSelectTextFile(sourcePath, pageIdx, selX, selY, selW, selH);
|
|
884
|
-
}
|
|
885
|
-
} else {
|
|
886
|
-
long docPtr;
|
|
887
|
-
synchronized (state.pdfiumLock) {
|
|
888
|
-
docPtr = extractNativeDocPointer(state.document);
|
|
889
|
-
}
|
|
890
|
-
if (docPtr != 0) {
|
|
891
|
-
synchronized (state.pdfiumLock) {
|
|
892
|
-
selection = PapyrusTextSelect.nativeSelectText(docPtr, pageIdx, selX, selY, selW, selH);
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
} catch (Throwable ignored) {
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
final PapyrusTextSelection finalSelection = selection;
|
|
900
|
-
mainHandler.post(() -> {
|
|
901
|
-
if (!isSelectingText && selectPageIndex != pageIdx) return;
|
|
902
|
-
selectedRects.clear();
|
|
903
|
-
if (finalSelection != null && finalSelection.rects != null && finalSelection.rects.length >= 4) {
|
|
904
|
-
selectedText = finalSelection.text != null ? finalSelection.text : "";
|
|
905
|
-
for (int i = 0; i + 3 < finalSelection.rects.length; i += 4) {
|
|
906
|
-
selectedRects.add(new NormalizedRect(
|
|
907
|
-
finalSelection.rects[i],
|
|
908
|
-
finalSelection.rects[i + 1],
|
|
909
|
-
finalSelection.rects[i + 2],
|
|
910
|
-
finalSelection.rects[i + 3]
|
|
911
|
-
));
|
|
912
|
-
}
|
|
913
|
-
// Set selection bounds to cover the word
|
|
914
|
-
if (!selectedRects.isEmpty()) {
|
|
915
|
-
float sx = selectedRects.get(0).x;
|
|
916
|
-
float sy = selectedRects.get(0).y;
|
|
917
|
-
float ex = selectedRects.get(selectedRects.size() - 1).x + selectedRects.get(selectedRects.size() - 1).width;
|
|
918
|
-
float ey = selectedRects.get(selectedRects.size() - 1).y + selectedRects.get(selectedRects.size() - 1).height;
|
|
919
|
-
selectStartX = sx;
|
|
920
|
-
selectStartY = sy;
|
|
921
|
-
selectEndX = ex;
|
|
922
|
-
selectEndY = ey;
|
|
923
|
-
}
|
|
924
|
-
} else {
|
|
925
|
-
selectedText = "";
|
|
926
|
-
}
|
|
927
|
-
invalidate();
|
|
928
|
-
});
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
|
|
932
795
|
private void performTextSelection() {
|
|
933
796
|
if (selectPageIndex < 0) return;
|
|
934
797
|
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
@@ -1053,6 +916,13 @@ public class PapyrusPdfViewerView extends View {
|
|
|
1053
916
|
canvas.drawColor(resolveBackgroundColor(pageTheme));
|
|
1054
917
|
if (pageFrames.isEmpty()) return;
|
|
1055
918
|
|
|
919
|
+
if (isPinching) {
|
|
920
|
+
canvas.save();
|
|
921
|
+
canvas.translate(pinchFocusX, pinchFocusY);
|
|
922
|
+
canvas.scale(pinchScale, pinchScale);
|
|
923
|
+
canvas.translate(-pinchFocusX, -pinchFocusY);
|
|
924
|
+
}
|
|
925
|
+
|
|
1056
926
|
boolean inGap = isViewportCenterInsidePageGap();
|
|
1057
927
|
int visibleCount = 0;
|
|
1058
928
|
|
|
@@ -1124,6 +994,9 @@ public class PapyrusPdfViewerView extends View {
|
|
|
1124
994
|
if (DEBUG_RENDER_GAP) {
|
|
1125
995
|
Log.d(TAG, "onDraw: visibleCount=" + visibleCount + " inGap=" + inGap + " zoom=" + zoom + " offsetY=" + offsetY + " lastStablePage=" + lastStablePage);
|
|
1126
996
|
}
|
|
997
|
+
if (isPinching) {
|
|
998
|
+
canvas.restore();
|
|
999
|
+
}
|
|
1127
1000
|
}
|
|
1128
1001
|
|
|
1129
1002
|
private boolean isViewportCenterInsidePageGap() {
|
|
@@ -1335,6 +1208,7 @@ public class PapyrusPdfViewerView extends View {
|
|
|
1335
1208
|
@Override
|
|
1336
1209
|
public boolean onScaleBegin(ScaleGestureDetector detector) {
|
|
1337
1210
|
isPinching = true;
|
|
1211
|
+
pinchScale = 1.0f;
|
|
1338
1212
|
pinchStartZoom = zoom;
|
|
1339
1213
|
pinchStartOffsetX = offsetX;
|
|
1340
1214
|
pinchStartOffsetY = offsetY;
|
|
@@ -1349,21 +1223,11 @@ public class PapyrusPdfViewerView extends View {
|
|
|
1349
1223
|
float focusX = detector.getFocusX();
|
|
1350
1224
|
float focusY = detector.getFocusY();
|
|
1351
1225
|
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
pinchFocusY = focusY;
|
|
1358
|
-
return true;
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
ViewportAnchor anchor = captureViewportAnchor(focusX, focusY);
|
|
1362
|
-
|
|
1363
|
-
zoom = newZoom;
|
|
1364
|
-
ensureLayoutLight();
|
|
1365
|
-
restoreViewportAnchor(anchor);
|
|
1366
|
-
|
|
1226
|
+
pinchScale = clamp(
|
|
1227
|
+
pinchScale * scaleFactor,
|
|
1228
|
+
0.5f / Math.max(pinchStartZoom, 0.5f),
|
|
1229
|
+
5.0f / Math.max(pinchStartZoom, 0.5f)
|
|
1230
|
+
);
|
|
1367
1231
|
pinchFocusX = focusX;
|
|
1368
1232
|
pinchFocusY = focusY;
|
|
1369
1233
|
invalidate();
|
|
@@ -1373,8 +1237,12 @@ public class PapyrusPdfViewerView extends View {
|
|
|
1373
1237
|
@Override
|
|
1374
1238
|
public void onScaleEnd(ScaleGestureDetector detector) {
|
|
1375
1239
|
ViewportAnchor anchor = captureViewportAnchor(pinchFocusX, pinchFocusY);
|
|
1240
|
+
float finalZoom = clamp(pinchStartZoom * pinchScale, 0.5f, 5.0f);
|
|
1376
1241
|
|
|
1377
1242
|
isPinching = false;
|
|
1243
|
+
pinchScale = 1.0f;
|
|
1244
|
+
zoom = finalZoom;
|
|
1245
|
+
renderGeneration += 1;
|
|
1378
1246
|
layoutDirty = true;
|
|
1379
1247
|
ensureLayout();
|
|
1380
1248
|
restoreViewportAnchor(anchor);
|
|
@@ -1581,6 +1449,12 @@ public class PapyrusPdfViewerView extends View {
|
|
|
1581
1449
|
Bitmap finalRendered = rendered;
|
|
1582
1450
|
post(() -> {
|
|
1583
1451
|
loadingKeys.remove(key);
|
|
1452
|
+
if (generationAtStart != renderGeneration) {
|
|
1453
|
+
if (finalRendered != null && !finalRendered.isRecycled()) {
|
|
1454
|
+
finalRendered.recycle();
|
|
1455
|
+
}
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1584
1458
|
if (finalRendered != null && !finalRendered.isRecycled()) {
|
|
1585
1459
|
RENDER_CACHE.put(key, finalRendered);
|
|
1586
1460
|
lastPageBitmap.put(frame.index, finalRendered);
|
|
@@ -1588,11 +1462,16 @@ public class PapyrusPdfViewerView extends View {
|
|
|
1588
1462
|
Log.d(TAG, "requestRender: complete page=" + frame.index + " key=" + key + " cacheSize=" + RENDER_CACHE.size());
|
|
1589
1463
|
}
|
|
1590
1464
|
}
|
|
1591
|
-
|
|
1592
|
-
invalidate();
|
|
1593
|
-
}
|
|
1465
|
+
invalidate();
|
|
1594
1466
|
});
|
|
1595
|
-
} catch (
|
|
1467
|
+
} catch (OutOfMemoryError error) {
|
|
1468
|
+
Bitmap failed = rendered;
|
|
1469
|
+
post(() -> {
|
|
1470
|
+
loadingKeys.remove(key);
|
|
1471
|
+
if (failed != null && !failed.isRecycled()) failed.recycle();
|
|
1472
|
+
Log.e(TAG, "Unable to allocate bitmap for dedicated PDF page; keeping previous surface", error);
|
|
1473
|
+
});
|
|
1474
|
+
} catch (RuntimeException error) {
|
|
1596
1475
|
Bitmap failed = rendered;
|
|
1597
1476
|
post(() -> {
|
|
1598
1477
|
loadingKeys.remove(key);
|
|
@@ -1663,6 +1542,13 @@ public class PapyrusPdfViewerView extends View {
|
|
|
1663
1542
|
}
|
|
1664
1543
|
}
|
|
1665
1544
|
|
|
1545
|
+
private void requestDisallowParentInterception(boolean disallow) {
|
|
1546
|
+
ViewParent parent = getParent();
|
|
1547
|
+
if (parent != null) {
|
|
1548
|
+
parent.requestDisallowInterceptTouchEvent(disallow);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1666
1552
|
private void emitVisiblePagesChanged() {
|
|
1667
1553
|
if (ISOLATE_RENDER_TEST) return;
|
|
1668
1554
|
if (isPinching) return;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package com.papyrus.engine;
|
|
2
|
+
|
|
3
|
+
import java.util.concurrent.atomic.AtomicBoolean;
|
|
4
|
+
import java.util.function.Consumer;
|
|
5
|
+
|
|
6
|
+
final class PapyrusRenderCompletion {
|
|
7
|
+
enum Status { READY, STALE, CANCELLED }
|
|
8
|
+
|
|
9
|
+
private final AtomicBoolean completed = new AtomicBoolean(false);
|
|
10
|
+
private final Consumer<Status> listener;
|
|
11
|
+
private final Consumer<Throwable> errorListener;
|
|
12
|
+
|
|
13
|
+
PapyrusRenderCompletion(Consumer<Status> listener) {
|
|
14
|
+
this(listener, error -> { });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
PapyrusRenderCompletion(Consumer<Status> listener, Consumer<Throwable> errorListener) {
|
|
18
|
+
this.listener = listener;
|
|
19
|
+
this.errorListener = errorListener;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
boolean complete(Status status) {
|
|
23
|
+
if (!completed.compareAndSet(false, true)) return false;
|
|
24
|
+
listener.accept(status);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
boolean error(Throwable error) {
|
|
29
|
+
if (!completed.compareAndSet(false, true)) return false;
|
|
30
|
+
errorListener.accept(error);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -3,19 +3,30 @@ package com.papyrus.engine;
|
|
|
3
3
|
final class PapyrusRenderMath {
|
|
4
4
|
static final long MAX_RENDER_PIXELS = 8L * 1024L * 1024L;
|
|
5
5
|
static final int MAX_RENDER_EDGE = 4096;
|
|
6
|
+
// Pdfium's compat surface becomes blank on the tested Android API when a
|
|
7
|
+
// single page exceeds this edge during a configuration change.
|
|
8
|
+
static final int COMPAT_MAX_RENDER_EDGE = 2048;
|
|
6
9
|
|
|
7
10
|
private PapyrusRenderMath() {
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
static int[] constrainRenderSize(int requestedWidth, int requestedHeight) {
|
|
14
|
+
return constrainRenderSize(requestedWidth, requestedHeight, MAX_RENDER_EDGE);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static int[] constrainCompatRenderSize(int requestedWidth, int requestedHeight) {
|
|
18
|
+
return constrainRenderSize(requestedWidth, requestedHeight, COMPAT_MAX_RENDER_EDGE);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private static int[] constrainRenderSize(int requestedWidth, int requestedHeight, int maxEdge) {
|
|
11
22
|
int width = Math.max(1, requestedWidth);
|
|
12
23
|
int height = Math.max(1, requestedHeight);
|
|
13
24
|
double scale = 1.0d;
|
|
14
25
|
|
|
15
|
-
if (width >
|
|
26
|
+
if (width > maxEdge || height > maxEdge) {
|
|
16
27
|
scale = Math.min(
|
|
17
28
|
scale,
|
|
18
|
-
Math.min((double)
|
|
29
|
+
Math.min((double) maxEdge / width, (double) maxEdge / height)
|
|
19
30
|
);
|
|
20
31
|
}
|
|
21
32
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.papyrus.engine;
|
|
2
|
+
|
|
3
|
+
/** Small, platform-independent rules for the PDF text-selection gesture. */
|
|
4
|
+
final class PapyrusTextSelectionGesture {
|
|
5
|
+
private PapyrusTextSelectionGesture() {}
|
|
6
|
+
|
|
7
|
+
static boolean shouldActivate(boolean isDoubleTap) {
|
|
8
|
+
return isDoubleTap;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static boolean shouldEmitPageTap(boolean isDoubleTap) {
|
|
12
|
+
return !isDoubleTap;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static boolean shouldContinueAfterSelectionTouch(boolean hitHandle) {
|
|
16
|
+
return !hitHandle;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Keep the selection endpoint where the user's finger actually landed. */
|
|
20
|
+
static float resolveSelectionEndpoint(float normalizedX) {
|
|
21
|
+
return Math.max(0f, Math.min(1f, normalizedX));
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComponentType, RefAttributes } from 'react';
|
|
2
2
|
import { ViewProps, View } from 'react-native';
|
|
3
3
|
import { BaseDocumentEngine } from '@papyrus-sdk/core';
|
|
4
|
-
import { RenderTargetType, DocumentLoadInput, TextItem, SearchResult, TextSelection, OutlineItem, PageDestination, PageTheme, Annotation, PdfVisiblePage } from '@papyrus-sdk/types';
|
|
4
|
+
import { RenderTargetType, DocumentLoadInput, RenderPageTelemetryContext, TextItem, SearchResult, TextSelection, OutlineItem, PageDestination, RenderPageResult, PageTheme, Annotation, PdfVisiblePage } from '@papyrus-sdk/types';
|
|
5
5
|
|
|
6
6
|
type PapyrusPageViewProps = ViewProps & {
|
|
7
7
|
engineId?: string;
|
|
@@ -93,9 +93,11 @@ declare class NativeDocumentEngine extends BaseDocumentEngine {
|
|
|
93
93
|
private currentPage;
|
|
94
94
|
private zoom;
|
|
95
95
|
private rotation;
|
|
96
|
+
private renderRequestCounter;
|
|
96
97
|
constructor();
|
|
97
98
|
load(input: DocumentLoadInput): Promise<void>;
|
|
98
99
|
getPageCount(): number;
|
|
100
|
+
getLifecycleStats(): Record<string, number>;
|
|
99
101
|
getCurrentPage(): number;
|
|
100
102
|
goToPage(page: number): void;
|
|
101
103
|
setZoom(zoom: number): void;
|
|
@@ -103,7 +105,7 @@ declare class NativeDocumentEngine extends BaseDocumentEngine {
|
|
|
103
105
|
rotate(direction: "clockwise" | "counterclockwise"): void;
|
|
104
106
|
getRotation(): number;
|
|
105
107
|
getNativeEngineId(): string;
|
|
106
|
-
renderPage(pageIndex: number, target: any, scale: number): Promise<void>;
|
|
108
|
+
renderPage(pageIndex: number, target: any, scale: number, telemetry?: RenderPageTelemetryContext): Promise<void | RenderPageResult>;
|
|
107
109
|
renderTextLayer(pageIndex: number, target: any, scale: number): Promise<void>;
|
|
108
110
|
getTextContent(pageIndex: number): Promise<TextItem[]>;
|
|
109
111
|
getPageDimensions(pageIndex: number): Promise<{
|
|
@@ -157,7 +159,9 @@ declare class WebViewDocumentEngine extends BaseDocumentEngine {
|
|
|
157
159
|
getWebViewRuntimeSource(): WebViewRuntimeSource | undefined;
|
|
158
160
|
getWebViewRuntimeConfig(): WebViewRuntimeConfig | undefined;
|
|
159
161
|
getRenderTargetType(): "webview";
|
|
162
|
+
getLifecycleStats(): Record<string, number>;
|
|
160
163
|
attachBridge(bridge: WebViewBridge): void;
|
|
164
|
+
detachBridge(): void;
|
|
161
165
|
handleMessage(raw: string): void;
|
|
162
166
|
private handleAssetRequest;
|
|
163
167
|
private handleFileChunkRequest;
|
|
@@ -169,7 +173,7 @@ declare class WebViewDocumentEngine extends BaseDocumentEngine {
|
|
|
169
173
|
getZoom(): number;
|
|
170
174
|
rotate(direction: "clockwise" | "counterclockwise"): void;
|
|
171
175
|
getRotation(): number;
|
|
172
|
-
renderPage(pageIndex: number, target: any, scale: number): Promise<void>;
|
|
176
|
+
renderPage(pageIndex: number, target: any, scale: number, _telemetry?: RenderPageTelemetryContext): Promise<void>;
|
|
173
177
|
renderTextLayer(pageIndex: number, container: any, scale: number): Promise<void>;
|
|
174
178
|
getTextContent(pageIndex: number): Promise<TextItem[]>;
|
|
175
179
|
getPageDimensions(pageIndex: number): Promise<{
|
|
@@ -207,7 +211,9 @@ declare class MobileDocumentEngine extends BaseDocumentEngine {
|
|
|
207
211
|
getWebViewRuntimeConfig(): WebViewRuntimeConfig | undefined;
|
|
208
212
|
getRenderTargetType(): RenderTargetType;
|
|
209
213
|
getNativeEngineId(): string | null;
|
|
214
|
+
getLifecycleStats(): Record<string, number>;
|
|
210
215
|
attachWebView(bridge: WebViewBridge): void;
|
|
216
|
+
detachWebView(): void;
|
|
211
217
|
handleWebViewMessage(data: string): void;
|
|
212
218
|
load(input: DocumentLoadInput): Promise<void>;
|
|
213
219
|
getPageCount(): number;
|
|
@@ -217,7 +223,7 @@ declare class MobileDocumentEngine extends BaseDocumentEngine {
|
|
|
217
223
|
getZoom(): number;
|
|
218
224
|
rotate(direction: "clockwise" | "counterclockwise"): void;
|
|
219
225
|
getRotation(): number;
|
|
220
|
-
renderPage(pageIndex: number, target: any, scale: number): Promise<void>;
|
|
226
|
+
renderPage(pageIndex: number, target: any, scale: number, telemetry?: RenderPageTelemetryContext): Promise<void>;
|
|
221
227
|
renderTextLayer(pageIndex: number, container: any, scale: number): Promise<void>;
|
|
222
228
|
getTextContent(pageIndex: number): Promise<TextItem[]>;
|
|
223
229
|
getPageDimensions(pageIndex: number): Promise<{
|