@papyrus-sdk/engine-native 0.2.22-beta.5 → 0.2.22-beta.7

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.
Files changed (33) hide show
  1. package/{ios/PapyrusNativeEngine.podspec → PapyrusNativeEngine.podspec} +11 -7
  2. package/android/src/main/cpp/papyrus_outline_loader_test.cpp +240 -0
  3. package/android/src/main/cpp/papyrus_text_word_test.cpp +72 -0
  4. package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +164 -26
  5. package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +21 -0
  6. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +13 -1
  7. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +195 -5
  8. package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerViewManager.java +20 -1
  9. package/android/src/main/java/com/papyrus/engine/PapyrusSelectionMenuIcon.java +48 -0
  10. package/android/src/main/java/com/papyrus/engine/PapyrusTextAnnotationModel.java +22 -0
  11. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +239 -17
  12. package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +6 -0
  13. package/dist/index.d.mts +137 -1
  14. package/dist/index.d.ts +137 -1
  15. package/dist/index.js +37 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +37 -0
  18. package/dist/index.mjs.map +1 -1
  19. package/ios/PapyrusComicDocumentView.m +200 -27
  20. package/ios/PapyrusNativeEngine.m +21 -6
  21. package/ios/PapyrusPdfDocumentView.h +3 -0
  22. package/ios/PapyrusPdfDocumentView.m +96 -11
  23. package/ios/PapyrusPdfDocumentViewManager.m +3 -0
  24. package/ios/PapyrusSelectionMenu.h +27 -0
  25. package/ios/PapyrusTextAnnotationRange.h +2 -0
  26. package/ios/PapyrusTextAnnotationRange.m +29 -0
  27. package/ios/PapyrusTextDocumentView.h +5 -0
  28. package/ios/PapyrusTextDocumentView.m +233 -14
  29. package/ios/PapyrusTextDocumentViewManager.m +5 -0
  30. package/package.json +8 -8
  31. package/react-native.config.js +1 -1
  32. package/vendor/libarchive/README.papyrus.md +1 -1
  33. package/vendor/libarchive/config/PapyrusArchiveConfig.h +6 -0
@@ -1,6 +1,11 @@
1
1
  package com.papyrus.engine;
2
2
 
3
3
  import android.content.Context;
4
+ import android.content.ClipboardManager;
5
+ import android.content.ClipData;
6
+ import android.view.ActionMode;
7
+ import android.view.Menu;
8
+ import android.view.MenuItem;
4
9
  import android.graphics.Bitmap;
5
10
  import android.graphics.Canvas;
6
11
  import android.graphics.Color;
@@ -25,6 +30,7 @@ import android.view.ViewParent;
25
30
  import android.widget.OverScroller;
26
31
 
27
32
  import com.facebook.react.bridge.Arguments;
33
+ import com.facebook.react.bridge.ReadableMap;
28
34
  import com.facebook.react.bridge.ReactContext;
29
35
  import com.facebook.react.bridge.WritableArray;
30
36
  import com.facebook.react.bridge.WritableMap;
@@ -143,6 +149,105 @@ public class PapyrusPdfViewerView extends View {
143
149
  private static final float DOUBLE_TAP_MAX_DISTANCE_DP = 20;
144
150
  private final long doubleTapTimeoutMs;
145
151
  private Runnable pendingSingleTap;
152
+ private Runnable pendingLongPress;
153
+ private boolean longPressSelected;
154
+ private ActionMode selectionActionMode;
155
+ private ReadableMap selectionLabels;
156
+ private String defineLabel = "Define";
157
+ private String defineSelectionMode = "selection";
158
+ private boolean defineEnabled;
159
+ private static final String[] SELECTION_ACTIONS = {"copy", "define", "highlight", "underline", "strikeout", "comment"};
160
+
161
+ public void setAnnotationLabels(ReadableMap labels) { selectionLabels = labels; }
162
+ public void setDefineLabel(String label) { defineLabel = label == null ? "Define" : label; }
163
+ public void setDefineSelectionMode(String mode) { defineSelectionMode = mode; }
164
+ public void setDefineEnabled(boolean enabled) { defineEnabled = enabled; }
165
+
166
+ private String selectionLabel(String key) {
167
+ if ("define".equals(key)) return defineLabel;
168
+ return selectionLabels != null && selectionLabels.hasKey(key) && !selectionLabels.isNull(key)
169
+ ? selectionLabels.getString(key) : key;
170
+ }
171
+
172
+ private void cancelPendingLongPress() {
173
+ if (pendingLongPress != null) mainHandler.removeCallbacks(pendingLongPress);
174
+ pendingLongPress = null;
175
+ }
176
+
177
+ @Override protected void onDetachedFromWindow() {
178
+ cancelPendingLongPress();
179
+ if (pendingSingleTap != null) mainHandler.removeCallbacks(pendingSingleTap);
180
+ clearSelectionState();
181
+ super.onDetachedFromWindow();
182
+ }
183
+
184
+ private void showSelectionMenu() {
185
+ if (selectedText.trim().isEmpty() || selectedRects.isEmpty()) return;
186
+ if (selectionActionMode != null) { selectionActionMode.invalidate(); selectionActionMode.invalidateContentRect(); return; }
187
+ selectionActionMode = startActionMode(new ActionMode.Callback2() {
188
+ @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { fillSelectionMenu(menu); return true; }
189
+ @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { fillSelectionMenu(menu); return true; }
190
+ @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
191
+ int index = item.getItemId() - 0x5070;
192
+ if (index < 0 || index >= SELECTION_ACTIONS.length) return false;
193
+ String action = SELECTION_ACTIONS[index];
194
+ if ("copy".equals(action)) {
195
+ ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
196
+ if (clipboard != null) clipboard.setPrimaryClip(ClipData.newPlainText(selectionLabel("copy"), selectedText));
197
+ } else {
198
+ WritableMap event = selectionPayload();
199
+ if ("define".equals(action)) emitSelectionIntent("onDefineSelection", event);
200
+ else { event.putString("style", action); emitSelectionIntent("onAnnotateSelection", event); }
201
+ }
202
+ mode.finish();
203
+ return true;
204
+ }
205
+ @Override public void onDestroyActionMode(ActionMode mode) {
206
+ if (selectionActionMode != mode) return;
207
+ selectionActionMode = null;
208
+ clearSelectionState();
209
+ emitSelectionCleared();
210
+ }
211
+ @Override public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
212
+ PageFrame frame = findSelectFrame();
213
+ if (frame == null || selectedRects.isEmpty()) { outRect.set(0,0,1,1); return; }
214
+ RectF bounds = new RectF();
215
+ for (NormalizedRect r : selectedRects) bounds.union(frame.left-offsetX+r.x*frame.width,
216
+ frame.top-offsetY+r.y*frame.height,frame.left-offsetX+(r.x+r.width)*frame.width,
217
+ frame.top-offsetY+(r.y+r.height)*frame.height);
218
+ bounds.roundOut(outRect);
219
+ }
220
+ }, ActionMode.TYPE_FLOATING);
221
+ }
222
+
223
+ private void fillSelectionMenu(Menu menu) {
224
+ menu.clear();
225
+ for (int i=0; i<SELECTION_ACTIONS.length; i++) {
226
+ String key = SELECTION_ACTIONS[i];
227
+ if ("define".equals(key) && (!defineEnabled || "single-word".equals(defineSelectionMode) && selectedText.trim().matches("(?s).*\\s+.*"))) continue;
228
+ MenuItem item = menu.add(Menu.NONE, 0x5070+i, i, selectionLabel(key));
229
+ item.setIcon(new PapyrusSelectionMenuIcon(key));
230
+ item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
231
+ }
232
+ }
233
+
234
+ private WritableMap selectionPayload() {
235
+ WritableMap event = Arguments.createMap();
236
+ event.putString("text", selectedText);
237
+ event.putInt("pageIndex", selectPageIndex);
238
+ WritableArray rects = Arguments.createArray();
239
+ for (NormalizedRect rect : selectedRects) {
240
+ WritableMap r = Arguments.createMap();
241
+ r.putDouble("x",rect.x); r.putDouble("y",rect.y);
242
+ r.putDouble("width",rect.width); r.putDouble("height",rect.height); rects.pushMap(r);
243
+ }
244
+ event.putArray("rects",rects);
245
+ return event;
246
+ }
247
+
248
+ private void emitSelectionIntent(String name, WritableMap event) {
249
+ reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(getId(), name, event);
250
+ }
146
251
  private boolean suppressPageTapForGesture = false;
147
252
  private boolean insideSelectionAtDown = false;
148
253
 
@@ -327,6 +432,30 @@ public class PapyrusPdfViewerView extends View {
327
432
  invalidate();
328
433
  }
329
434
 
435
+ private long annotationNavigationGeneration = 0;
436
+
437
+ public void setAnnotationNavigationRequest(ReadableMap request) {
438
+ long generation = ++annotationNavigationGeneration;
439
+ if (request == null) return;
440
+ final String requestedEngine = engineId;
441
+ final int pageIndex = request.getInt("pageIndex");
442
+ final ReadableMap rect = request.getMap("rect");
443
+ if (rect == null) return;
444
+ final float x = (float) rect.getDouble("x");
445
+ final float y = (float) rect.getDouble("y");
446
+ post(() -> {
447
+ if (generation != annotationNavigationGeneration || requestedEngine == null || !requestedEngine.equals(engineId)) return;
448
+ ensureLayout();
449
+ if (pageIndex < 0 || pageIndex >= pageFrames.size()) return;
450
+ flingScroller.forceFinished(true);
451
+ PageFrame frame = pageFrames.get(pageIndex);
452
+ offsetY = frame.top + frame.height * clamp(y, 0f, 1f) - getHeight() * 0.15f;
453
+ offsetX = frame.left + frame.width * clamp(x, 0f, 1f) - getWidth() * 0.15f;
454
+ clampOffsets();
455
+ invalidate();
456
+ });
457
+ }
458
+
330
459
  public void setCurrentPage(int page) {
331
460
  if (page <= 0 || engineId == null) return;
332
461
  ensureLayout();
@@ -356,6 +485,7 @@ public class PapyrusPdfViewerView extends View {
356
485
  @Override
357
486
  public boolean onTouchEvent(MotionEvent event) {
358
487
  int action = event.getActionMasked();
488
+ if (event.getPointerCount() > 1 || action == MotionEvent.ACTION_CANCEL) cancelPendingLongPress();
359
489
  if (action == MotionEvent.ACTION_DOWN && event.getPointerCount() == 1) {
360
490
  requestDisallowParentInterception(true);
361
491
  } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
@@ -561,6 +691,8 @@ public class PapyrusPdfViewerView extends View {
561
691
  if (event.getPointerCount() > 1) {
562
692
  return true; // Multi-touch: ignore, let pinch zoom handle it
563
693
  }
694
+ cancelPendingLongPress();
695
+ longPressSelected = false;
564
696
  touchDownTime = System.currentTimeMillis();
565
697
  touchDownX = event.getX();
566
698
  touchDownY = event.getY();
@@ -593,6 +725,18 @@ public class PapyrusPdfViewerView extends View {
593
725
  }
594
726
  }
595
727
 
728
+ if (!insideSelectionAtDown) {
729
+ final float x = event.getX(), y = event.getY();
730
+ pendingLongPress = () -> {
731
+ pendingLongPress = null;
732
+ longPressSelected = true;
733
+ lastTapTime = 0;
734
+ if (pendingSingleTap != null) mainHandler.removeCallbacks(pendingSingleTap);
735
+ pendingSingleTap = null;
736
+ beginWordSelection(x, y);
737
+ };
738
+ mainHandler.postDelayed(pendingLongPress, ViewConfiguration.getLongPressTimeout());
739
+ }
596
740
  if (velocityTracker == null) {
597
741
  velocityTracker = VelocityTracker.obtain();
598
742
  } else {
@@ -614,6 +758,7 @@ public class PapyrusPdfViewerView extends View {
614
758
  float moveDx = event.getX() - touchDownX;
615
759
  float moveDy = event.getY() - touchDownY;
616
760
  float moveDistance = (float) Math.hypot(moveDx, moveDy);
761
+ if (moveDistance > ViewConfiguration.get(getContext()).getScaledTouchSlop()) cancelPendingLongPress();
617
762
 
618
763
  if (draggedHandle != 0 && isSelectingText && selectPageIndex >= 0) {
619
764
  ensureLayout();
@@ -663,6 +808,12 @@ public class PapyrusPdfViewerView extends View {
663
808
 
664
809
  case MotionEvent.ACTION_UP:
665
810
  case MotionEvent.ACTION_CANCEL: {
811
+ cancelPendingLongPress();
812
+ if (longPressSelected) {
813
+ longPressSelected = false;
814
+ if (velocityTracker != null) { velocityTracker.recycle(); velocityTracker = null; }
815
+ return true;
816
+ }
666
817
  boolean wasHandleDrag = draggedHandle != 0;
667
818
  draggedHandle = 0;
668
819
  insideSelectionAtDown = false;
@@ -788,6 +939,10 @@ public class PapyrusPdfViewerView extends View {
788
939
  }
789
940
 
790
941
  private void clearSelectionState() {
942
+ cancelPendingLongPress();
943
+ ActionMode menu = selectionActionMode;
944
+ selectionActionMode = null;
945
+ if (menu != null) menu.finish();
791
946
  isSelectingText = false;
792
947
  selectPageIndex = -1;
793
948
  selectedRects.clear();
@@ -988,7 +1143,8 @@ public class PapyrusPdfViewerView extends View {
988
1143
  invalidate();
989
1144
  if (emit) {
990
1145
  emitTextSelected();
991
- }
1146
+ showSelectionMenu();
1147
+ } else if (selectionActionMode != null) selectionActionMode.invalidateContentRect();
992
1148
  }
993
1149
 
994
1150
  private void emitTextSelected() {
@@ -1345,6 +1501,11 @@ public class PapyrusPdfViewerView extends View {
1345
1501
  for (Annotation annotation : annotations) {
1346
1502
  if (annotation.pageIndex != pageIndex) continue;
1347
1503
  if (annotation.rects == null || annotation.rects.isEmpty()) continue;
1504
+ if(annotation.hasNote){
1505
+ NormalizedRect last=annotation.rects.get(annotation.rects.size()-1);
1506
+ float cx=Math.min(0.99f,last.x+last.width+0.012f), cy=last.y+0.012f;
1507
+ if(Math.abs(nx-cx)<0.035f && Math.abs(ny-cy)<0.035f)return annotation;
1508
+ }
1348
1509
  for (NormalizedRect rect : annotation.rects) {
1349
1510
  if (nx >= rect.x && nx <= rect.x + rect.width &&
1350
1511
  ny >= rect.y && ny <= rect.y + rect.height) {
@@ -1873,8 +2034,20 @@ public class PapyrusPdfViewerView extends View {
1873
2034
  invalidate();
1874
2035
  }
1875
2036
 
2037
+ private final Map<String, Integer> noteGroupCounts = new HashMap<>();
2038
+ private final java.util.Set<String> hiddenNoteMarkers = new java.util.HashSet<>();
1876
2039
  public void setAnnotations(List<Annotation> items) {
1877
2040
  annotations = items != null ? items : new ArrayList<>();
2041
+ noteGroupCounts.clear(); hiddenNoteMarkers.clear();
2042
+ Map<String, String> leaders = new HashMap<>();
2043
+ for (Annotation annotation : annotations) {
2044
+ if (!annotation.hasNote || annotation.rects.isEmpty()) continue;
2045
+ NormalizedRect rect = annotation.rects.get(annotation.rects.size()-1);
2046
+ String key=annotation.pageIndex+":"+(int)Math.floor((rect.x+rect.width)/0.035f)+":"+(int)Math.floor(rect.y/0.035f);
2047
+ String leader=leaders.get(key);
2048
+ if (leader==null) {leaders.put(key,annotation.id);noteGroupCounts.put(annotation.id,1);}
2049
+ else {hiddenNoteMarkers.add(annotation.id);noteGroupCounts.put(leader,noteGroupCounts.get(leader)+1);}
2050
+ }
1878
2051
  invalidate();
1879
2052
  }
1880
2053
 
@@ -1949,26 +2122,39 @@ public class PapyrusPdfViewerView extends View {
1949
2122
  overlayPaint.setStyle(Paint.Style.FILL);
1950
2123
  continue;
1951
2124
  }
1952
- overlayPaint.setColor(Color.argb(140, Color.red(color), Color.green(color), Color.blue(color)));
2125
+ overlayPaint.setColor(Color.argb(Math.round(annotation.opacity*255), Color.red(color), Color.green(color), Color.blue(color)));
1953
2126
  for (NormalizedRect rect : annotation.rects) {
1954
2127
  float rLeft = left + rect.x * scaleX;
1955
2128
  float rTop = top + rect.y * scaleY;
1956
2129
  float rRight = rLeft + rect.width * scaleX;
1957
2130
  float rBottom = rTop + rect.height * scaleY;
1958
- if ("underline".equals(annotation.type)) {
2131
+ if ("underline".equals(annotation.markupStyle)) {
1959
2132
  overlayPaint.setStyle(Paint.Style.STROKE);
1960
2133
  overlayPaint.setStrokeWidth(Math.max(2f, scaleY * 0.008f));
1961
2134
  canvas.drawLine(rLeft, rBottom - 2, rRight, rBottom - 2, overlayPaint);
1962
2135
  overlayPaint.setStyle(Paint.Style.FILL);
1963
- } else if ("strikeout".equals(annotation.type)) {
2136
+ } else if ("strikeout".equals(annotation.markupStyle)) {
1964
2137
  overlayPaint.setStyle(Paint.Style.STROKE);
1965
2138
  overlayPaint.setStrokeWidth(Math.max(2f, scaleY * 0.008f));
1966
2139
  canvas.drawLine(rLeft, (rTop + rBottom) / 2f, rRight, (rTop + rBottom) / 2f, overlayPaint);
1967
2140
  overlayPaint.setStyle(Paint.Style.FILL);
1968
- } else {
2141
+ } else if ("squiggly".equals(annotation.markupStyle)) {
2142
+ overlayPaint.setStyle(Paint.Style.STROKE);overlayPaint.setStrokeWidth(2);
2143
+ Path wave=new Path();wave.moveTo(rLeft,rBottom-2);
2144
+ for(float x=rLeft+3;x<=rRight;x+=3)wave.lineTo(x,rBottom-2+(((int)((x-rLeft)/3))%2==0?-2:2));
2145
+ canvas.drawPath(wave,overlayPaint);overlayPaint.setStyle(Paint.Style.FILL);
2146
+ } else if ("highlight".equals(annotation.markupStyle)) {
1969
2147
  canvas.drawRect(rLeft, rTop, rRight, rBottom, overlayPaint);
1970
2148
  }
1971
2149
  }
2150
+ if (annotation.hasNote && !annotation.rects.isEmpty() && !hiddenNoteMarkers.contains(annotation.id)) {
2151
+ NormalizedRect last=annotation.rects.get(annotation.rects.size()-1);
2152
+ float cx=Math.min(left+scaleX-9,left+(last.x+last.width)*scaleX+9);
2153
+ float cy=top+last.y*scaleY+9;
2154
+ overlayPaint.setColor(color);overlayPaint.setAlpha(255);canvas.drawCircle(cx,cy,8,overlayPaint);
2155
+ int count=noteGroupCounts.getOrDefault(annotation.id,1);
2156
+ if(count>1){overlayPaint.setColor(Color.WHITE);overlayPaint.setTextSize(11);overlayPaint.setTextAlign(Paint.Align.CENTER);canvas.drawText(String.valueOf(count),cx,cy+4,overlayPaint);overlayPaint.setTextAlign(Paint.Align.LEFT);}
2157
+ }
1972
2158
  }
1973
2159
 
1974
2160
  if (isDrawingInk && inkStrokePageIndex == frame.index && inkStrokePoints.size() >= 2) {
@@ -2025,6 +2211,8 @@ public class PapyrusPdfViewerView extends View {
2025
2211
  final String id;
2026
2212
  final int pageIndex;
2027
2213
  final String type;
2214
+ String markupStyle;
2215
+ boolean hasNote;
2028
2216
  final String color;
2029
2217
  final List<NormalizedRect> rects;
2030
2218
  final List<NormalizedPoint> path;
@@ -2037,6 +2225,8 @@ public class PapyrusPdfViewerView extends View {
2037
2225
  this.id = id;
2038
2226
  this.pageIndex = pageIndex;
2039
2227
  this.type = type;
2228
+ this.markupStyle = type;
2229
+ this.hasNote = "comment".equals(type)||"text".equals(type);
2040
2230
  this.color = color;
2041
2231
  this.rects = rects;
2042
2232
  this.path = path;
@@ -14,6 +14,11 @@ import java.util.List;
14
14
  import java.util.Map;
15
15
 
16
16
  public class PapyrusPdfViewerViewManager extends SimpleViewManager<PapyrusPdfViewerView> {
17
+ @ReactProp(name = "annotationNavigationRequest")
18
+ public void setAnnotationNavigationRequest(PapyrusPdfViewerView view, @Nullable ReadableMap request) {
19
+ view.setAnnotationNavigationRequest(request);
20
+ }
21
+
17
22
  @NonNull
18
23
  @Override
19
24
  public String getName() {
@@ -93,6 +98,8 @@ public class PapyrusPdfViewerViewManager extends SimpleViewManager<PapyrusPdfVie
93
98
  com.facebook.react.common.MapBuilder.of("bubbled", "onTextSelected")
94
99
  )
95
100
  )
101
+ .put("onDefineSelection", com.facebook.react.common.MapBuilder.of("phasedRegistrationNames", com.facebook.react.common.MapBuilder.of("bubbled", "onDefineSelection")))
102
+ .put("onAnnotateSelection", com.facebook.react.common.MapBuilder.of("phasedRegistrationNames", com.facebook.react.common.MapBuilder.of("bubbled", "onAnnotateSelection")))
96
103
  .build();
97
104
  }
98
105
 
@@ -105,6 +112,15 @@ public class PapyrusPdfViewerViewManager extends SimpleViewManager<PapyrusPdfVie
105
112
  );
106
113
  }
107
114
 
115
+ @ReactProp(name = "annotationLabels")
116
+ public void setAnnotationLabels(PapyrusPdfViewerView view, @Nullable ReadableMap labels) { view.setAnnotationLabels(labels); }
117
+ @ReactProp(name = "defineLabel")
118
+ public void setDefineLabel(PapyrusPdfViewerView view, String label) { view.setDefineLabel(label); }
119
+ @ReactProp(name = "defineSelectionMode")
120
+ public void setDefineSelectionMode(PapyrusPdfViewerView view, String mode) { view.setDefineSelectionMode(mode); }
121
+ @ReactProp(name = "defineEnabled")
122
+ public void setDefineEnabled(PapyrusPdfViewerView view, boolean enabled) { view.setDefineEnabled(enabled); }
123
+
108
124
  @ReactProp(name = "engineId")
109
125
  public void setEngineId(PapyrusPdfViewerView view, String engineId) {
110
126
  view.setEngineId(engineId);
@@ -239,7 +255,10 @@ public class PapyrusPdfViewerViewManager extends SimpleViewManager<PapyrusPdfVie
239
255
  }
240
256
  float strokeWidth = item.hasKey("strokeWidth") ? (float) item.getDouble("strokeWidth") : 0.006f;
241
257
  float opacity = item.hasKey("opacity") ? (float) item.getDouble("opacity") : 0.85f;
242
- items.add(new PapyrusPdfViewerView.Annotation(id, pageIndex, type, color, rects, path, strokeWidth, opacity));
258
+ PapyrusPdfViewerView.Annotation annotation=new PapyrusPdfViewerView.Annotation(id,pageIndex,type,color,rects,path,strokeWidth,opacity);
259
+ annotation.markupStyle=item.hasKey("markupStyle") && !item.isNull("markupStyle") ? item.getString("markupStyle") : ("comment".equals(type)||"text".equals(type)?"none":type);
260
+ annotation.hasNote=item.hasKey("noteContent") || "comment".equals(type) || "text".equals(type);
261
+ items.add(annotation);
243
262
  }
244
263
  }
245
264
  view.setAnnotations(items);
@@ -0,0 +1,48 @@
1
+ package com.papyrus.engine;
2
+
3
+ import android.graphics.Canvas;
4
+ import android.graphics.Color;
5
+ import android.graphics.ColorFilter;
6
+ import android.graphics.Paint;
7
+ import android.graphics.PixelFormat;
8
+ import android.graphics.drawable.Drawable;
9
+
10
+ /** Small vector glyphs for public Android selection-menu APIs. */
11
+ final class PapyrusSelectionMenuIcon extends Drawable {
12
+ private final String action;
13
+ private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
14
+ PapyrusSelectionMenuIcon(String action) {
15
+ this.action = action;
16
+ paint.setColor(Color.BLACK);
17
+ paint.setStrokeWidth(2);
18
+ paint.setStyle(Paint.Style.STROKE);
19
+ }
20
+ @Override public void draw(Canvas canvas) {
21
+ canvas.save();
22
+ canvas.translate(getBounds().left,getBounds().top);
23
+ canvas.scale(getBounds().width()/24f,getBounds().height()/24f);
24
+ if ("copy".equals(action)) {
25
+ canvas.drawRoundRect(8,7,20,21,2,2,paint);
26
+ canvas.drawLine(4,17,4,3,paint); canvas.drawLine(4,3,16,3,paint);
27
+ } else if ("comment".equals(action)) {
28
+ canvas.drawRoundRect(3,3,21,17,2,2,paint);
29
+ canvas.drawLine(7,17,7,22,paint); canvas.drawLine(7,22,12,17,paint);
30
+ canvas.drawLine(7,8,17,8,paint); canvas.drawLine(7,12,15,12,paint);
31
+ } else if ("define".equals(action)) {
32
+ canvas.drawCircle(10,10,6,paint); canvas.drawLine(15,15,21,21,paint);
33
+ } else if ("highlight".equals(action)) {
34
+ canvas.drawLine(5,17,17,5,paint);canvas.drawLine(8,20,20,8,paint);
35
+ canvas.drawLine(17,5,20,8,paint);canvas.drawLine(4,21,12,21,paint);
36
+ } else {
37
+ canvas.drawLine(6,4,6,14,paint); canvas.drawLine(18,4,18,14,paint);
38
+ canvas.drawArc(6,8,18,20,0,180,false,paint);
39
+ canvas.drawLine(3,"underline".equals(action)?22:12,21,"underline".equals(action)?22:12,paint);
40
+ }
41
+ canvas.restore();
42
+ }
43
+ @Override public int getIntrinsicWidth() { return 24; }
44
+ @Override public int getIntrinsicHeight() { return 24; }
45
+ @Override public void setAlpha(int alpha) { paint.setAlpha(alpha); invalidateSelf(); }
46
+ @Override public void setColorFilter(ColorFilter filter) { paint.setColorFilter(filter); invalidateSelf(); }
47
+ @Override public int getOpacity() { return PixelFormat.TRANSLUCENT; }
48
+ }
@@ -0,0 +1,22 @@
1
+ package com.papyrus.engine;
2
+
3
+ /** Source UTF16 offsets; never normalizes CRLF, combining marks or surrogate pairs. */
4
+ public final class PapyrusTextAnnotationModel {
5
+ private PapyrusTextAnnotationModel() {}
6
+ private static boolean boundary(String text,int offset) {
7
+ return offset>=0 && offset<=text.length() && !(offset>0 && offset<text.length() && Character.isHighSurrogate(text.charAt(offset-1)) && Character.isLowSurrogate(text.charAt(offset)));
8
+ }
9
+ public static int[] resolve(String text,int start,int end,String quote,String prefix,String suffix) {
10
+ if(text==null || quote==null || quote.isEmpty())return null;
11
+ if(start>=0 && end>start && end<=text.length() && boundary(text,start) && boundary(text,end) && text.substring(start,end).equals(quote))return new int[]{start,end};
12
+ int[] match=null;
13
+ for(int offset=text.indexOf(quote);offset>=0;offset=text.indexOf(quote,offset+1)) {
14
+ int finish=offset+quote.length();
15
+ if(!boundary(text,offset) || !boundary(text,finish))continue;
16
+ if(prefix!=null && !prefix.isEmpty() && !text.substring(Math.max(0,offset-prefix.length()),offset).equals(prefix))continue;
17
+ if(suffix!=null && !suffix.isEmpty() && !text.substring(finish,Math.min(text.length(),finish+suffix.length())).equals(suffix))continue;
18
+ if(match!=null)return null;match=new int[]{offset,finish};
19
+ }
20
+ return match;
21
+ }
22
+ }