@papyrus-sdk/engine-native 0.2.22-beta.9.epub.2 → 0.2.22
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/PapyrusNativeEngine.podspec +45 -0
- package/android/build.gradle +1 -0
- package/android/src/main/cpp/CMakeLists.txt +137 -0
- package/android/src/main/cpp/PapyrusComicArchiveJni.cpp +68 -0
- package/android/src/main/cpp/PapyrusComicArchiveTest.cpp +55 -0
- package/android/src/main/cpp/papyrus_outline_loader_test.cpp +240 -0
- package/android/src/main/cpp/papyrus_text_word_test.cpp +72 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicArchiveNative.java +14 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +491 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentViewManager.java +32 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +38 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +305 -35
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeTextModel.java +195 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +3 -1
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +195 -5
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerViewManager.java +20 -1
- package/android/src/main/java/com/papyrus/engine/PapyrusSelectionMenuIcon.java +48 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextAnnotationModel.java +22 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +661 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +49 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextStore.java +43 -0
- package/dist/index.d.mts +614 -4
- package/dist/index.d.ts +614 -4
- package/dist/index.js +484 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +477 -7
- package/dist/index.mjs.map +1 -1
- package/ios/PapyrusComicDocumentView.h +21 -0
- package/ios/PapyrusComicDocumentView.m +554 -0
- package/ios/PapyrusComicDocumentViewManager.m +23 -0
- package/ios/PapyrusEngineStore.h +3 -0
- package/ios/PapyrusEngineStore.m +32 -6
- package/ios/PapyrusNativeEngine.m +684 -5
- package/ios/PapyrusPageRotationRegistry.h +29 -0
- package/ios/PapyrusPageRotationRegistry.m +179 -0
- package/ios/PapyrusPageView.m +38 -11
- package/ios/PapyrusPdfDocumentView.h +55 -0
- package/ios/PapyrusPdfDocumentView.m +2370 -0
- package/ios/PapyrusPdfDocumentViewManager.m +61 -0
- package/ios/PapyrusPdfPageTheme.h +15 -0
- package/ios/PapyrusPdfPageTheme.m +218 -0
- package/ios/PapyrusSelectionMenu.h +27 -0
- package/ios/PapyrusTextAnnotationRange.h +2 -0
- package/ios/PapyrusTextAnnotationRange.m +29 -0
- package/ios/PapyrusTextDocumentView.h +32 -0
- package/ios/PapyrusTextDocumentView.m +518 -0
- package/ios/PapyrusTextDocumentViewManager.m +34 -0
- package/ios/PapyrusTextStore.h +13 -0
- package/ios/PapyrusTextStore.m +73 -0
- package/package.json +10 -8
- package/react-native.config.js +1 -1
- package/third_party_licenses/BLAKE2-NOTICE.txt +11 -0
- package/third_party_licenses/libarchive-COPYING +65 -0
- package/vendor/libarchive/PapyrusComicArchive.cpp +376 -0
- package/vendor/libarchive/PapyrusComicArchive.h +30 -0
- package/vendor/libarchive/README.papyrus.md +15 -0
- package/vendor/libarchive/android.h +192 -0
- package/vendor/libarchive/config/PapyrusArchiveConfig.h +71 -0
- package/vendor/libarchive/libarchive/CMakeLists.txt +293 -0
- package/vendor/libarchive/libarchive/android_lf.h +36 -0
- package/vendor/libarchive/libarchive/archive.h +1266 -0
- package/vendor/libarchive/libarchive/archive_acl.c +2025 -0
- package/vendor/libarchive/libarchive/archive_acl_private.h +85 -0
- package/vendor/libarchive/libarchive/archive_blake2.h +197 -0
- package/vendor/libarchive/libarchive/archive_blake2_impl.h +161 -0
- package/vendor/libarchive/libarchive/archive_blake2s_ref.c +369 -0
- package/vendor/libarchive/libarchive/archive_blake2sp_ref.c +361 -0
- package/vendor/libarchive/libarchive/archive_check_magic.c +183 -0
- package/vendor/libarchive/libarchive/archive_cmdline.c +211 -0
- package/vendor/libarchive/libarchive/archive_cmdline_private.h +45 -0
- package/vendor/libarchive/libarchive/archive_crc32.h +123 -0
- package/vendor/libarchive/libarchive/archive_cryptor.c +534 -0
- package/vendor/libarchive/libarchive/archive_cryptor_private.h +199 -0
- package/vendor/libarchive/libarchive/archive_digest.c +1584 -0
- package/vendor/libarchive/libarchive/archive_digest_private.h +431 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_darwin.c +558 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_freebsd.c +712 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_linux.c +760 -0
- package/vendor/libarchive/libarchive/archive_disk_acl_sunos.c +824 -0
- package/vendor/libarchive/libarchive/archive_endian.h +234 -0
- package/vendor/libarchive/libarchive/archive_entry.3 +147 -0
- package/vendor/libarchive/libarchive/archive_entry.c +2297 -0
- package/vendor/libarchive/libarchive/archive_entry.h +763 -0
- package/vendor/libarchive/libarchive/archive_entry_acl.3 +458 -0
- package/vendor/libarchive/libarchive/archive_entry_copy_bhfi.c +55 -0
- package/vendor/libarchive/libarchive/archive_entry_copy_stat.c +82 -0
- package/vendor/libarchive/libarchive/archive_entry_link_resolver.c +472 -0
- package/vendor/libarchive/libarchive/archive_entry_linkify.3 +224 -0
- package/vendor/libarchive/libarchive/archive_entry_locale.h +90 -0
- package/vendor/libarchive/libarchive/archive_entry_misc.3 +63 -0
- package/vendor/libarchive/libarchive/archive_entry_paths.3 +153 -0
- package/vendor/libarchive/libarchive/archive_entry_perms.3 +210 -0
- package/vendor/libarchive/libarchive/archive_entry_private.h +205 -0
- package/vendor/libarchive/libarchive/archive_entry_sparse.c +156 -0
- package/vendor/libarchive/libarchive/archive_entry_stat.3 +274 -0
- package/vendor/libarchive/libarchive/archive_entry_stat.c +121 -0
- package/vendor/libarchive/libarchive/archive_entry_strmode.c +69 -0
- package/vendor/libarchive/libarchive/archive_entry_time.3 +127 -0
- package/vendor/libarchive/libarchive/archive_entry_xattr.c +155 -0
- package/vendor/libarchive/libarchive/archive_hmac.c +345 -0
- package/vendor/libarchive/libarchive/archive_hmac_private.h +119 -0
- package/vendor/libarchive/libarchive/archive_integer.h +267 -0
- package/vendor/libarchive/libarchive/archive_match.c +1869 -0
- package/vendor/libarchive/libarchive/archive_openssl_evp_private.h +54 -0
- package/vendor/libarchive/libarchive/archive_openssl_hmac_private.h +54 -0
- package/vendor/libarchive/libarchive/archive_options.c +219 -0
- package/vendor/libarchive/libarchive/archive_options_private.h +49 -0
- package/vendor/libarchive/libarchive/archive_pack_dev.c +330 -0
- package/vendor/libarchive/libarchive/archive_pack_dev.h +49 -0
- package/vendor/libarchive/libarchive/archive_parse_date.c +1173 -0
- package/vendor/libarchive/libarchive/archive_pathmatch.c +480 -0
- package/vendor/libarchive/libarchive/archive_pathmatch.h +50 -0
- package/vendor/libarchive/libarchive/archive_platform.h +213 -0
- package/vendor/libarchive/libarchive/archive_platform_acl.h +53 -0
- package/vendor/libarchive/libarchive/archive_platform_stat.h +45 -0
- package/vendor/libarchive/libarchive/archive_platform_xattr.h +45 -0
- package/vendor/libarchive/libarchive/archive_ppmd7.c +1173 -0
- package/vendor/libarchive/libarchive/archive_ppmd7_private.h +119 -0
- package/vendor/libarchive/libarchive/archive_ppmd8.c +1293 -0
- package/vendor/libarchive/libarchive/archive_ppmd8_private.h +123 -0
- package/vendor/libarchive/libarchive/archive_ppmd_private.h +159 -0
- package/vendor/libarchive/libarchive/archive_private.h +209 -0
- package/vendor/libarchive/libarchive/archive_random.c +274 -0
- package/vendor/libarchive/libarchive/archive_random_private.h +36 -0
- package/vendor/libarchive/libarchive/archive_rb.c +709 -0
- package/vendor/libarchive/libarchive/archive_rb.h +113 -0
- package/vendor/libarchive/libarchive/archive_read.3 +250 -0
- package/vendor/libarchive/libarchive/archive_read.c +1814 -0
- package/vendor/libarchive/libarchive/archive_read_add_passphrase.3 +72 -0
- package/vendor/libarchive/libarchive/archive_read_add_passphrase.c +189 -0
- package/vendor/libarchive/libarchive/archive_read_append_filter.c +209 -0
- package/vendor/libarchive/libarchive/archive_read_data.3 +128 -0
- package/vendor/libarchive/libarchive/archive_read_data_into_fd.c +207 -0
- package/vendor/libarchive/libarchive/archive_read_disk.3 +422 -0
- package/vendor/libarchive/libarchive/archive_read_disk_entry_from_file.c +1086 -0
- package/vendor/libarchive/libarchive/archive_read_disk_posix.c +2639 -0
- package/vendor/libarchive/libarchive/archive_read_disk_private.h +97 -0
- package/vendor/libarchive/libarchive/archive_read_disk_set_standard_lookup.c +315 -0
- package/vendor/libarchive/libarchive/archive_read_disk_windows.c +2603 -0
- package/vendor/libarchive/libarchive/archive_read_extract.3 +135 -0
- package/vendor/libarchive/libarchive/archive_read_extract.c +59 -0
- package/vendor/libarchive/libarchive/archive_read_extract2.c +154 -0
- package/vendor/libarchive/libarchive/archive_read_filter.3 +163 -0
- package/vendor/libarchive/libarchive/archive_read_format.3 +190 -0
- package/vendor/libarchive/libarchive/archive_read_free.3 +91 -0
- package/vendor/libarchive/libarchive/archive_read_header.3 +89 -0
- package/vendor/libarchive/libarchive/archive_read_new.3 +57 -0
- package/vendor/libarchive/libarchive/archive_read_open.3 +247 -0
- package/vendor/libarchive/libarchive/archive_read_open_fd.c +236 -0
- package/vendor/libarchive/libarchive/archive_read_open_file.c +257 -0
- package/vendor/libarchive/libarchive/archive_read_open_filename.c +652 -0
- package/vendor/libarchive/libarchive/archive_read_open_memory.c +188 -0
- package/vendor/libarchive/libarchive/archive_read_private.h +274 -0
- package/vendor/libarchive/libarchive/archive_read_set_format.c +116 -0
- package/vendor/libarchive/libarchive/archive_read_set_options.3 +290 -0
- package/vendor/libarchive/libarchive/archive_read_set_options.c +132 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_all.c +84 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_by_code.c +68 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_bzip2.c +360 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_compress.c +457 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_grzip.c +108 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_gzip.c +538 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_lrzip.c +119 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_lz4.c +829 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_lzop.c +493 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_none.c +51 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_program.c +497 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_rpm.c +249 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_uu.c +739 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_xz.c +792 -0
- package/vendor/libarchive/libarchive/archive_read_support_filter_zstd.c +356 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_7zip.c +4650 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_all.c +88 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_ar.c +597 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_by_code.c +76 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_cab.c +3410 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_cpio.c +1152 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_empty.c +95 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_iso9660.c +3516 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_lha.c +2931 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_mtree.c +2113 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_rar.c +3932 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_rar5.c +4501 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_raw.c +194 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_tar.c +3785 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_warc.c +875 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_xar.c +3770 -0
- package/vendor/libarchive/libarchive/archive_read_support_format_zip.c +4710 -0
- package/vendor/libarchive/libarchive/archive_string.c +4391 -0
- package/vendor/libarchive/libarchive/archive_string.h +244 -0
- package/vendor/libarchive/libarchive/archive_string_composition.h +2289 -0
- package/vendor/libarchive/libarchive/archive_string_sprintf.c +200 -0
- package/vendor/libarchive/libarchive/archive_time.c +168 -0
- package/vendor/libarchive/libarchive/archive_time_private.h +47 -0
- package/vendor/libarchive/libarchive/archive_util.3 +239 -0
- package/vendor/libarchive/libarchive/archive_util.c +668 -0
- package/vendor/libarchive/libarchive/archive_version_details.c +516 -0
- package/vendor/libarchive/libarchive/archive_virtual.c +162 -0
- package/vendor/libarchive/libarchive/archive_windows.c +1035 -0
- package/vendor/libarchive/libarchive/archive_windows.h +332 -0
- package/vendor/libarchive/libarchive/archive_write.3 +266 -0
- package/vendor/libarchive/libarchive/archive_write.c +896 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter.c +71 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_b64encode.c +329 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_by_name.c +76 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_bzip2.c +411 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_compress.c +459 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_grzip.c +143 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_gzip.c +493 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_lrzip.c +214 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_lz4.c +710 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_lzop.c +500 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_none.c +42 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_program.c +398 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_uuencode.c +320 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_xz.c +547 -0
- package/vendor/libarchive/libarchive/archive_write_add_filter_zstd.c +608 -0
- package/vendor/libarchive/libarchive/archive_write_blocksize.3 +112 -0
- package/vendor/libarchive/libarchive/archive_write_data.3 +88 -0
- package/vendor/libarchive/libarchive/archive_write_disk.3 +360 -0
- package/vendor/libarchive/libarchive/archive_write_disk_posix.c +4789 -0
- package/vendor/libarchive/libarchive/archive_write_disk_private.h +43 -0
- package/vendor/libarchive/libarchive/archive_write_disk_set_standard_lookup.c +265 -0
- package/vendor/libarchive/libarchive/archive_write_disk_windows.c +2952 -0
- package/vendor/libarchive/libarchive/archive_write_filter.3 +140 -0
- package/vendor/libarchive/libarchive/archive_write_finish_entry.3 +77 -0
- package/vendor/libarchive/libarchive/archive_write_format.3 +187 -0
- package/vendor/libarchive/libarchive/archive_write_free.3 +94 -0
- package/vendor/libarchive/libarchive/archive_write_header.3 +71 -0
- package/vendor/libarchive/libarchive/archive_write_new.3 +56 -0
- package/vendor/libarchive/libarchive/archive_write_open.3 +270 -0
- package/vendor/libarchive/libarchive/archive_write_open_fd.c +141 -0
- package/vendor/libarchive/libarchive/archive_write_open_file.c +102 -0
- package/vendor/libarchive/libarchive/archive_write_open_filename.c +272 -0
- package/vendor/libarchive/libarchive/archive_write_open_memory.c +110 -0
- package/vendor/libarchive/libarchive/archive_write_private.h +166 -0
- package/vendor/libarchive/libarchive/archive_write_set_format.c +124 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_7zip.c +2571 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_ar.c +540 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_by_name.c +93 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio.c +11 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio_binary.c +618 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio_newc.c +457 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_cpio_odc.c +508 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_filter_by_ext.c +141 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_gnutar.c +790 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_iso9660.c +8216 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_mtree.c +2307 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_pax.c +2249 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_private.h +40 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_raw.c +123 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_shar.c +650 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_ustar.c +768 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_v7tar.c +648 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_warc.c +491 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_xar.c +3799 -0
- package/vendor/libarchive/libarchive/archive_write_set_format_zip.c +2548 -0
- package/vendor/libarchive/libarchive/archive_write_set_options.3 +779 -0
- package/vendor/libarchive/libarchive/archive_write_set_options.c +129 -0
- package/vendor/libarchive/libarchive/archive_write_set_passphrase.3 +72 -0
- package/vendor/libarchive/libarchive/archive_write_set_passphrase.c +95 -0
- package/vendor/libarchive/libarchive/archive_xxhash.h +48 -0
- package/vendor/libarchive/libarchive/config_freebsd.h +275 -0
- package/vendor/libarchive/libarchive/cpio.5 +389 -0
- package/vendor/libarchive/libarchive/filter_fork.h +44 -0
- package/vendor/libarchive/libarchive/filter_fork_posix.c +269 -0
- package/vendor/libarchive/libarchive/filter_fork_windows.c +270 -0
- package/vendor/libarchive/libarchive/libarchive-formats.5 +478 -0
- package/vendor/libarchive/libarchive/libarchive.3 +297 -0
- package/vendor/libarchive/libarchive/libarchive_changes.3 +339 -0
- package/vendor/libarchive/libarchive/libarchive_internals.3 +363 -0
- package/vendor/libarchive/libarchive/module.modulemap +34 -0
- package/vendor/libarchive/libarchive/mtree.5 +323 -0
- package/vendor/libarchive/libarchive/tar.5 +947 -0
- package/vendor/libarchive/libarchive/xxhash.c +531 -0
- package/ios/PapyrusNativeEngine.podspec +0 -15
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
package com.papyrus.engine;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.graphics.Color;
|
|
5
|
+
import android.os.Build;
|
|
6
|
+
import android.os.SystemClock;
|
|
7
|
+
import android.text.Layout;
|
|
8
|
+
import android.text.Selection;
|
|
9
|
+
import android.text.Spannable;
|
|
10
|
+
import android.text.SpannableString;
|
|
11
|
+
import android.text.style.BackgroundColorSpan;
|
|
12
|
+
import android.text.style.CharacterStyle;
|
|
13
|
+
import android.text.style.UnderlineSpan;
|
|
14
|
+
import android.text.style.LineBackgroundSpan;
|
|
15
|
+
import android.text.TextPaint;
|
|
16
|
+
import android.graphics.Canvas;
|
|
17
|
+
import android.graphics.Paint;
|
|
18
|
+
import android.app.AlertDialog;
|
|
19
|
+
import com.facebook.react.bridge.ReadableType;
|
|
20
|
+
import java.util.HashMap;
|
|
21
|
+
import java.util.Map;
|
|
22
|
+
import android.widget.Button;
|
|
23
|
+
import android.util.TypedValue;
|
|
24
|
+
import android.view.ActionMode;
|
|
25
|
+
import android.view.GestureDetector;
|
|
26
|
+
import android.view.MotionEvent;
|
|
27
|
+
import android.view.Menu;
|
|
28
|
+
import android.view.MenuItem;
|
|
29
|
+
import android.view.View;
|
|
30
|
+
import android.widget.FrameLayout;
|
|
31
|
+
import android.widget.ScrollView;
|
|
32
|
+
import android.widget.TextView;
|
|
33
|
+
|
|
34
|
+
import com.facebook.react.bridge.Arguments;
|
|
35
|
+
import com.facebook.react.bridge.ReactContext;
|
|
36
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
37
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
38
|
+
import com.facebook.react.bridge.WritableMap;
|
|
39
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
40
|
+
|
|
41
|
+
import java.util.ArrayList;
|
|
42
|
+
import java.util.List;
|
|
43
|
+
import java.util.concurrent.ExecutorService;
|
|
44
|
+
import java.util.concurrent.Executors;
|
|
45
|
+
|
|
46
|
+
public final class PapyrusTextDocumentView extends FrameLayout {
|
|
47
|
+
private static final int EVENT_THROTTLE_MS = 100;
|
|
48
|
+
private static final int MAX_SEARCH_HIGHLIGHTS = 2000;
|
|
49
|
+
private static final int ACTION_DEFINE = 0x5041;
|
|
50
|
+
private static final int ACTION_ANNOTATE = 0x5050;
|
|
51
|
+
private static final String[] MARKUP_ACTIONS = {"highlight", "underline", "strikeout", "comment"};
|
|
52
|
+
private static final ExecutorService TEXT_LAYOUT_EXECUTOR = Executors.newSingleThreadExecutor();
|
|
53
|
+
|
|
54
|
+
private final ScrollView scrollView;
|
|
55
|
+
private final PapyrusSelectableTextView textView;
|
|
56
|
+
private final FrameLayout textContainer;
|
|
57
|
+
private final List<Button> noteButtons = new ArrayList<>();
|
|
58
|
+
private ReadableArray annotations;
|
|
59
|
+
private final Map<String, Range> resolvedAnnotationRanges = new HashMap<>();
|
|
60
|
+
private String resolvedAnnotationText = "";
|
|
61
|
+
private final Map<Button,List<String>> noteGroups = new HashMap<>();
|
|
62
|
+
private ReadableMap annotationLabels;
|
|
63
|
+
private String engineId;
|
|
64
|
+
private int documentGeneration;
|
|
65
|
+
private int expectedTextLength;
|
|
66
|
+
private int currentTextOffset;
|
|
67
|
+
private Integer scrollToTextOffsetSignal;
|
|
68
|
+
private String pageTheme = "normal";
|
|
69
|
+
private String uiTheme = "light";
|
|
70
|
+
private String defineLabel = "Define";
|
|
71
|
+
private String defineSelectionMode = "selection";
|
|
72
|
+
private float fontSize = 18f;
|
|
73
|
+
private float lineHeight = 28f;
|
|
74
|
+
private int pageMarginDp = 20;
|
|
75
|
+
private int activeSearchIndex = -1;
|
|
76
|
+
private List<Range> searchRanges = new ArrayList<>();
|
|
77
|
+
private long lastOffsetEventAt;
|
|
78
|
+
private int lastOffsetEventValue = -1;
|
|
79
|
+
private int loadToken;
|
|
80
|
+
private int lastReportedStart = -1;
|
|
81
|
+
private int lastReportedEnd = -1;
|
|
82
|
+
private boolean suppressSelectionEvents;
|
|
83
|
+
|
|
84
|
+
public PapyrusTextDocumentView(Context context) {
|
|
85
|
+
super(context);
|
|
86
|
+
setClipToPadding(false);
|
|
87
|
+
scrollView = new ScrollView(context);
|
|
88
|
+
scrollView.setFillViewport(false);
|
|
89
|
+
scrollView.setVerticalScrollBarEnabled(true);
|
|
90
|
+
textContainer = new FrameLayout(context);
|
|
91
|
+
textView = new PapyrusSelectableTextView(context);
|
|
92
|
+
textView.setTextIsSelectable(true);
|
|
93
|
+
if (Build.VERSION.SDK_INT >= 26) textView.setTextClassifier(android.view.textclassifier.TextClassifier.NO_OP);
|
|
94
|
+
textView.setFocusable(true);
|
|
95
|
+
textView.setFocusableInTouchMode(true);
|
|
96
|
+
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
|
|
97
|
+
textView.setPadding(dp(Math.max(44,pageMarginDp)), dp(pageMarginDp), dp(pageMarginDp), dp(pageMarginDp));
|
|
98
|
+
textView.setOnSelectionChangedListener(this::emitTextRangeSelected);
|
|
99
|
+
GestureDetector annotationTaps = new GestureDetector(context,new GestureDetector.SimpleOnGestureListener(){
|
|
100
|
+
@Override public boolean onSingleTapUp(MotionEvent event){return hitTestAnnotation(event);}
|
|
101
|
+
});
|
|
102
|
+
textView.setOnTouchListener((v,event)->annotationTaps.onTouchEvent(event));
|
|
103
|
+
textView.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
|
|
104
|
+
@Override public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
105
|
+
addSelectionActions(menu);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
@Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
109
|
+
addSelectionActions(menu);
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
@Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
113
|
+
if (item.getItemId() == ACTION_DEFINE) { emitDefineSelection(); }
|
|
114
|
+
else if (item.getItemId() >= ACTION_ANNOTATE && item.getItemId() < ACTION_ANNOTATE + MARKUP_ACTIONS.length) {
|
|
115
|
+
WritableMap payload = selectedPayload();
|
|
116
|
+
if (payload != null) {
|
|
117
|
+
payload.putString("style", MARKUP_ACTIONS[item.getItemId() - ACTION_ANNOTATE]);
|
|
118
|
+
emit("onAnnotateSelection", payload);
|
|
119
|
+
}
|
|
120
|
+
} else return false;
|
|
121
|
+
mode.finish();
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
@Override public void onDestroyActionMode(ActionMode mode) { }
|
|
125
|
+
});
|
|
126
|
+
textContainer.addView(textView, new FrameLayout.LayoutParams(
|
|
127
|
+
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT
|
|
128
|
+
));
|
|
129
|
+
textView.addOnLayoutChangeListener((v,l,t,r,b,ol,ot,or,ob) -> layoutNoteButtons());
|
|
130
|
+
scrollView.addView(textContainer, new ScrollView.LayoutParams(
|
|
131
|
+
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT
|
|
132
|
+
));
|
|
133
|
+
scrollView.addOnLayoutChangeListener((view, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
|
|
134
|
+
if (right - left != oldRight - oldLeft && textView.length() > 0) requestTextContentLayout();
|
|
135
|
+
});
|
|
136
|
+
addView(scrollView, new FrameLayout.LayoutParams(
|
|
137
|
+
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT
|
|
138
|
+
));
|
|
139
|
+
scrollView.getViewTreeObserver().addOnScrollChangedListener(this::emitTextOffsetFromScroll);
|
|
140
|
+
applyTheme();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
public void setEngineId(String value) {
|
|
144
|
+
if (value == null || value.equals(engineId)) return;
|
|
145
|
+
engineId = value;
|
|
146
|
+
expectedTextLength = 0;
|
|
147
|
+
loadToken++;
|
|
148
|
+
reloadText();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
public void setDocumentGeneration(int value) {
|
|
152
|
+
if (value == documentGeneration) return;
|
|
153
|
+
documentGeneration = value;
|
|
154
|
+
expectedTextLength = 0;
|
|
155
|
+
loadToken++;
|
|
156
|
+
reloadText();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public void setTextLength(int value) {
|
|
160
|
+
int next = Math.max(0, value);
|
|
161
|
+
if (next == expectedTextLength) return;
|
|
162
|
+
expectedTextLength = next;
|
|
163
|
+
int clampedOffset = PapyrusNativeTextModel.clampRequestedTextOffset(currentTextOffset, expectedTextLength);
|
|
164
|
+
if (clampedOffset != currentTextOffset) {
|
|
165
|
+
currentTextOffset = clampedOffset;
|
|
166
|
+
scrollToTextOffset(clampedOffset);
|
|
167
|
+
}
|
|
168
|
+
if (next > 0 && textView.length() != next) reloadText();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public void setCurrentTextOffset(int value) {
|
|
172
|
+
int next = PapyrusNativeTextModel.clampRequestedTextOffset(value, expectedTextLength);
|
|
173
|
+
boolean changed = next != currentTextOffset;
|
|
174
|
+
currentTextOffset = next;
|
|
175
|
+
if (changed) scrollToTextOffset(next);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
public void setScrollToTextOffsetSignal(Integer value) {
|
|
179
|
+
if (value == null || value.equals(scrollToTextOffsetSignal)) return;
|
|
180
|
+
scrollToTextOffsetSignal = value;
|
|
181
|
+
scrollToTextOffset(value);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public void setTextNavigationRequest(ReadableMap request) {
|
|
185
|
+
if(request!=null && request.hasKey("offset"))scrollToTextOffset(Math.max(0,request.getInt("offset")));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public void setSearchResults(ReadableArray results) {
|
|
189
|
+
searchRanges = new ArrayList<>();
|
|
190
|
+
if (results != null) {
|
|
191
|
+
for (int i = 0; i < results.size() && searchRanges.size() < MAX_SEARCH_HIGHLIGHTS; i++) {
|
|
192
|
+
ReadableMap item = results.getMap(i);
|
|
193
|
+
if (item == null || !item.hasKey("location") || item.isNull("location")) continue;
|
|
194
|
+
ReadableMap location = item.getMap("location");
|
|
195
|
+
if (location == null) continue;
|
|
196
|
+
int start = location.hasKey("start") ? location.getInt("start") : -1;
|
|
197
|
+
int end = location.hasKey("end") ? location.getInt("end") : -1;
|
|
198
|
+
if (start >= 0 && end > start) searchRanges.add(new Range(start, end));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
applySearchHighlights();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public void setActiveSearchIndex(int value) {
|
|
205
|
+
activeSearchIndex = value;
|
|
206
|
+
applySearchHighlights();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public void setPageTheme(String value) {
|
|
210
|
+
pageTheme = value == null ? "normal" : value;
|
|
211
|
+
applyTheme();
|
|
212
|
+
applySearchHighlights();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
public void setUiTheme(String value) {
|
|
216
|
+
uiTheme = value == null ? "light" : value;
|
|
217
|
+
applyTheme();
|
|
218
|
+
applySearchHighlights();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public void setFontSize(float value) {
|
|
222
|
+
fontSize = Math.max(10f, Math.min(48f, value));
|
|
223
|
+
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
|
|
224
|
+
textView.setLineSpacing(Math.max(0f,lineHeight-fontSize),1f);
|
|
225
|
+
applySearchHighlights();
|
|
226
|
+
requestTextContentLayout();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
public void setLineHeight(float value) {
|
|
230
|
+
lineHeight = Math.max(fontSize, Math.min(72f, value));
|
|
231
|
+
textView.setLineSpacing(Math.max(0f, lineHeight - fontSize), 1f);
|
|
232
|
+
applySearchHighlights();
|
|
233
|
+
requestTextContentLayout();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public void setPageMargin(float value) {
|
|
237
|
+
pageMarginDp = Math.round(Math.max(8f, Math.min(64f, value)));
|
|
238
|
+
textView.setPadding(dp(Math.max(44,pageMarginDp)), dp(pageMarginDp), dp(pageMarginDp), dp(pageMarginDp));
|
|
239
|
+
requestTextContentLayout();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
public void setDefineLabel(String value) {
|
|
243
|
+
defineLabel = value == null ? "Define" : value;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public void setDefineSelectionMode(String value) {
|
|
247
|
+
defineSelectionMode = value == null ? "selection" : value;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private void addSelectionActions(Menu menu) {
|
|
251
|
+
MenuItem copy = menu.findItem(android.R.id.copy);
|
|
252
|
+
if (copy != null && !labelFor("copy").isEmpty()) copy.setTitle(labelFor("copy"));
|
|
253
|
+
MenuItem selectAll = menu.findItem(android.R.id.selectAll);
|
|
254
|
+
if (selectAll != null && !labelFor("selectAll").isEmpty()) selectAll.setTitle(labelFor("selectAll"));
|
|
255
|
+
for (int i = 0; i < MARKUP_ACTIONS.length; i++) {
|
|
256
|
+
String label = labelFor(MARKUP_ACTIONS[i]);
|
|
257
|
+
if (selectedPayload() != null && !label.isEmpty() && menu.findItem(ACTION_ANNOTATE+i) == null) {
|
|
258
|
+
menu.add(Menu.NONE, ACTION_ANNOTATE+i, i, label).setIcon(new PapyrusSelectionMenuIcon(MARKUP_ACTIONS[i]));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (selectedPayload() == null || "single-word".equals(defineSelectionMode) && !isSingleWordSelection()) {
|
|
262
|
+
menu.removeItem(ACTION_DEFINE);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
MenuItem item = menu.findItem(ACTION_DEFINE);
|
|
266
|
+
if (item == null) {
|
|
267
|
+
item = menu.add(Menu.NONE, ACTION_DEFINE, Menu.NONE, defineLabel);
|
|
268
|
+
item.setIcon(new PapyrusSelectionMenuIcon("define"));
|
|
269
|
+
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
|
270
|
+
} else {
|
|
271
|
+
item.setTitle(defineLabel);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
private void reloadText() {
|
|
276
|
+
if (engineId == null || documentGeneration <= 0) return;
|
|
277
|
+
String text = PapyrusTextStore.getText(engineId, documentGeneration);
|
|
278
|
+
if (text == null) return;
|
|
279
|
+
int token = ++loadToken;
|
|
280
|
+
int initialOffset = currentTextOffset;
|
|
281
|
+
if (Build.VERSION.SDK_INT >= 28) {
|
|
282
|
+
android.text.PrecomputedText.Params params = textView.getTextMetricsParams();
|
|
283
|
+
TEXT_LAYOUT_EXECUTOR.execute(() -> {
|
|
284
|
+
android.text.PrecomputedText precomputed = android.text.PrecomputedText.create(text, params);
|
|
285
|
+
post(() -> {
|
|
286
|
+
if (token != loadToken || !text.equals(PapyrusTextStore.getText(engineId, documentGeneration))) return;
|
|
287
|
+
// Typography can change while the background layout is running.
|
|
288
|
+
// Recompute with current metrics instead of applying an incompatible result.
|
|
289
|
+
if (!textView.getTextMetricsParams().equals(params)) { reloadText(); return; }
|
|
290
|
+
textView.setText(precomputed, TextView.BufferType.SPANNABLE);
|
|
291
|
+
textView.setTextIsSelectable(true);
|
|
292
|
+
textView.setClickable(true);
|
|
293
|
+
textView.setLongClickable(true);
|
|
294
|
+
applySearchHighlights();
|
|
295
|
+
requestTextContentLayout();
|
|
296
|
+
textView.requestLayout();
|
|
297
|
+
scrollView.requestLayout();
|
|
298
|
+
requestLayout();
|
|
299
|
+
scrollToTextOffset(initialOffset);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
} else {
|
|
303
|
+
textView.post(() -> {
|
|
304
|
+
if (token != loadToken) return;
|
|
305
|
+
textView.setText(text, TextView.BufferType.SPANNABLE);
|
|
306
|
+
textView.setTextIsSelectable(true);
|
|
307
|
+
textView.setClickable(true);
|
|
308
|
+
textView.setLongClickable(true);
|
|
309
|
+
applySearchHighlights();
|
|
310
|
+
requestTextContentLayout();
|
|
311
|
+
textView.requestLayout();
|
|
312
|
+
scrollView.requestLayout();
|
|
313
|
+
requestLayout();
|
|
314
|
+
scrollToTextOffset(initialOffset);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private void requestTextContentLayout() {
|
|
320
|
+
textView.post(() -> {
|
|
321
|
+
int contentWidth = scrollView.getWidth();
|
|
322
|
+
if (contentWidth <= 0 || textView.length() == 0) return;
|
|
323
|
+
|
|
324
|
+
android.view.ViewGroup.LayoutParams params = textView.getLayoutParams();
|
|
325
|
+
if (params.height != LayoutParams.WRAP_CONTENT) {
|
|
326
|
+
params.height = LayoutParams.WRAP_CONTENT;
|
|
327
|
+
textView.setLayoutParams(params);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
int contentWidthSpec = View.MeasureSpec.makeMeasureSpec(contentWidth, View.MeasureSpec.EXACTLY);
|
|
331
|
+
int contentHeightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
|
|
332
|
+
textView.forceLayout();
|
|
333
|
+
textView.measure(contentWidthSpec, contentHeightSpec);
|
|
334
|
+
Layout layout = textView.getLayout();
|
|
335
|
+
if (layout == null) return;
|
|
336
|
+
|
|
337
|
+
int contentHeight = Math.max(
|
|
338
|
+
textView.getMeasuredHeight(),
|
|
339
|
+
layout.getHeight() + textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom()
|
|
340
|
+
);
|
|
341
|
+
params.height = contentHeight;
|
|
342
|
+
textView.setLayoutParams(params);
|
|
343
|
+
int exactHeightSpec = View.MeasureSpec.makeMeasureSpec(contentHeight, View.MeasureSpec.EXACTLY);
|
|
344
|
+
textView.measure(contentWidthSpec, exactHeightSpec);
|
|
345
|
+
textView.layout(
|
|
346
|
+
textView.getLeft(),
|
|
347
|
+
textView.getTop(),
|
|
348
|
+
textView.getLeft() + textView.getMeasuredWidth(),
|
|
349
|
+
textView.getTop() + textView.getMeasuredHeight()
|
|
350
|
+
);
|
|
351
|
+
// React Native can retain the parent's old wrap-content measurement after
|
|
352
|
+
// asynchronous PrecomputedText arrives. Resize the content container too,
|
|
353
|
+
// otherwise its clip bounds can hide every line after the first.
|
|
354
|
+
android.view.ViewGroup.LayoutParams containerParams = textContainer.getLayoutParams();
|
|
355
|
+
containerParams.height = contentHeight;
|
|
356
|
+
textContainer.setLayoutParams(containerParams);
|
|
357
|
+
textContainer.forceLayout();
|
|
358
|
+
textContainer.measure(contentWidthSpec, exactHeightSpec);
|
|
359
|
+
textContainer.layout(0, 0, contentWidth, contentHeight);
|
|
360
|
+
scrollView.requestLayout();
|
|
361
|
+
requestLayout();
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
private void applySearchHighlights() {
|
|
366
|
+
if (textView.length() == 0) return;
|
|
367
|
+
int selectionStart = textView.getSelectionStart();
|
|
368
|
+
int selectionEnd = textView.getSelectionEnd();
|
|
369
|
+
int oldScrollY = scrollView.getScrollY();
|
|
370
|
+
Spannable styled = textView.getText() instanceof Spannable
|
|
371
|
+
? (Spannable) textView.getText() : new SpannableString(textView.getText());
|
|
372
|
+
for (BackgroundColorSpan span : styled.getSpans(0, styled.length(), BackgroundColorSpan.class)) styled.removeSpan(span);
|
|
373
|
+
for (LineBackgroundSpan span : styled.getSpans(0, styled.length(), LineBackgroundSpan.class)) styled.removeSpan(span);
|
|
374
|
+
for (CharacterStyle span : styled.getSpans(0, styled.length(), CharacterStyle.class)) {
|
|
375
|
+
if (!(span instanceof BackgroundColorSpan)) styled.removeSpan(span);
|
|
376
|
+
}
|
|
377
|
+
applyAnnotationSpans(styled);
|
|
378
|
+
for (int i = 0; i < searchRanges.size(); i++) {
|
|
379
|
+
Range range = searchRanges.get(i);
|
|
380
|
+
int start = Math.max(0, Math.min(styled.length(), range.start));
|
|
381
|
+
int end = Math.max(start, Math.min(styled.length(), range.end));
|
|
382
|
+
if (end > start) {
|
|
383
|
+
int color = i == activeSearchIndex ? 0x8C1976D2 : 0x70FFC928;
|
|
384
|
+
styled.setSpan(new BackgroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
suppressSelectionEvents = true;
|
|
388
|
+
if (styled != textView.getText()) textView.setText(styled, TextView.BufferType.SPANNABLE);
|
|
389
|
+
textView.invalidate();
|
|
390
|
+
if (selectionStart >= 0 && selectionEnd >= selectionStart && selectionEnd <= textView.length()) {
|
|
391
|
+
Selection.setSelection((Spannable) textView.getText(), selectionStart, selectionEnd);
|
|
392
|
+
}
|
|
393
|
+
suppressSelectionEvents = false;
|
|
394
|
+
scrollView.scrollTo(scrollView.getScrollX(), oldScrollY);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
public void setAnnotations(ReadableArray value) {
|
|
398
|
+
annotations = value;
|
|
399
|
+
resolvedAnnotationRanges.clear();
|
|
400
|
+
applySearchHighlights();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
public void setAnnotationLabels(ReadableMap value) { annotationLabels = value; }
|
|
404
|
+
|
|
405
|
+
private String labelFor(String key) {
|
|
406
|
+
return annotationLabels != null && annotationLabels.hasKey(key) && !annotationLabels.isNull(key)
|
|
407
|
+
? annotationLabels.getString(key) : "";
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
private ReadableMap annotationRange(ReadableMap item) {
|
|
411
|
+
if (item.hasKey("anchor") && !item.isNull("anchor")) {
|
|
412
|
+
ReadableMap anchor = item.getMap("anchor");
|
|
413
|
+
if (anchor != null && anchor.hasKey("kind") && "text-range".equals(anchor.getString("kind"))) return anchor;
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
return item.hasKey("textRange") && !item.isNull("textRange") ? item.getMap("textRange") : null;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private Range checkedAnnotationRange(ReadableMap item) {
|
|
420
|
+
try {
|
|
421
|
+
String id=item.getString("id");
|
|
422
|
+
CharSequence source=textView.getText();
|
|
423
|
+
if(!resolvedAnnotationText.contentEquals(source)){resolvedAnnotationText=source.toString();resolvedAnnotationRanges.clear();}
|
|
424
|
+
if(resolvedAnnotationRanges.containsKey(id))return resolvedAnnotationRanges.get(id);
|
|
425
|
+
ReadableMap range=annotationRange(item);
|
|
426
|
+
if(range==null || !range.hasKey("start") || !range.hasKey("end") || range.getType("start")!=ReadableType.Number || range.getType("end")!=ReadableType.Number)return null;
|
|
427
|
+
int start=range.getInt("start"),end=range.getInt("end");
|
|
428
|
+
Range result=null;
|
|
429
|
+
if(range.hasKey("quote") && range.getType("quote")==ReadableType.String){
|
|
430
|
+
int[] resolved=PapyrusTextAnnotationModel.resolve(resolvedAnnotationText,start,end,range.getString("quote"),range.hasKey("prefix")&&range.getType("prefix")==ReadableType.String?range.getString("prefix"):null,range.hasKey("suffix")&&range.getType("suffix")==ReadableType.String?range.getString("suffix"):null);
|
|
431
|
+
if(resolved!=null)result=new Range(resolved[0],resolved[1]);
|
|
432
|
+
} else if(start>=0 && end>start && end<=source.length())result=new Range(start,end);
|
|
433
|
+
resolvedAnnotationRanges.put(id,result);return result;
|
|
434
|
+
} catch(RuntimeException malformed) {return null;}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
private void applyAnnotationSpans(Spannable styled) {
|
|
438
|
+
for (Button button : noteButtons) textContainer.removeView(button);
|
|
439
|
+
noteButtons.clear();
|
|
440
|
+
noteIds.clear();
|
|
441
|
+
if (annotations == null) return;
|
|
442
|
+
for (int i=0; i<annotations.size(); i++) {
|
|
443
|
+
ReadableMap item = annotations.getMap(i);
|
|
444
|
+
if (item == null || !item.hasKey("id")) continue;
|
|
445
|
+
Range range = checkedAnnotationRange(item);
|
|
446
|
+
if (range == null) continue;
|
|
447
|
+
String type = item.hasKey("type") ? item.getString("type") : "";
|
|
448
|
+
String style = item.hasKey("markupStyle") && !item.isNull("markupStyle") ? item.getString("markupStyle") : type;
|
|
449
|
+
int color = 0xFFFFC928;
|
|
450
|
+
try { if (item.hasKey("color")) color = Color.parseColor(item.getString("color")); } catch (IllegalArgumentException ignored) { }
|
|
451
|
+
final int spanColor=color;
|
|
452
|
+
if ("highlight".equals(style)) {
|
|
453
|
+
double opacity = item.hasKey("opacity") ? Math.max(0,Math.min(1,item.getDouble("opacity"))) : 0.35;
|
|
454
|
+
styled.setSpan(new BackgroundColorSpan((color & 0x00FFFFFF) | ((int)(opacity*255)<<24)),range.start,range.end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
455
|
+
} else if ("underline".equals(style)) {
|
|
456
|
+
styled.setSpan(new UnderlineSpan(){@Override public void updateDrawState(TextPaint paint){super.updateDrawState(paint);paint.underlineColor=spanColor;paint.underlineThickness=Math.max(1,paint.getTextSize()/18);}},range.start,range.end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
457
|
+
} else if ("strikeout".equals(style)) {
|
|
458
|
+
styled.setSpan((LineBackgroundSpan)(canvas,paint,left,right,top,baseline,bottom,text,start,end,lineNumber)->{
|
|
459
|
+
if(range.end<=start || range.start>=end)return;
|
|
460
|
+
float x=left+paint.measureText(text,start,Math.max(start,range.start));
|
|
461
|
+
float width=paint.measureText(text,Math.max(start,range.start),Math.min(end,range.end));
|
|
462
|
+
int old=paint.getColor();float oldWidth=paint.getStrokeWidth();paint.setColor(spanColor);paint.setStrokeWidth(Math.max(1,paint.getTextSize()/18));
|
|
463
|
+
canvas.drawLine(x,baseline+paint.ascent()*0.4f,x+width,baseline+paint.ascent()*0.4f,paint);paint.setColor(old);paint.setStrokeWidth(oldWidth);
|
|
464
|
+
},range.start,range.end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
465
|
+
}
|
|
466
|
+
if (item.hasKey("noteContent") || "comment".equals(type) || "text".equals(type)) {
|
|
467
|
+
final String id = item.getString("id");
|
|
468
|
+
Button button = new Button(getContext());
|
|
469
|
+
button.setText("●"); button.setTextColor(color); button.setContentDescription(labelFor("comment"));
|
|
470
|
+
button.setTag(range.start); button.setMinWidth(0); button.setMinimumWidth(0);
|
|
471
|
+
button.setPadding(0,0,0,0); button.setBackgroundColor(Color.TRANSPARENT);
|
|
472
|
+
button.setOnClickListener(v -> openAnnotationGroup(button,id));
|
|
473
|
+
noteIds.put(button,id);
|
|
474
|
+
noteButtons.add(button); textContainer.addView(button,new FrameLayout.LayoutParams(dp(44),dp(44)));
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
textView.post(this::layoutNoteButtons);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
private boolean hitTestAnnotation(MotionEvent event) {
|
|
481
|
+
if (annotations == null || textView.getLayout() == null || textView.getSelectionEnd() > textView.getSelectionStart()) return false;
|
|
482
|
+
Layout layout = textView.getLayout();
|
|
483
|
+
float x = event.getX()-textView.getPaddingLeft();
|
|
484
|
+
int y = (int)event.getY()-textView.getPaddingTop();
|
|
485
|
+
if(x<0 || y<0 || y>layout.getHeight())return false;
|
|
486
|
+
int line=layout.getLineForVertical(y);
|
|
487
|
+
if(x<layout.getLineLeft(line) || x>layout.getLineRight(line))return false;
|
|
488
|
+
int offset=layout.getOffsetForHorizontal(line,x);
|
|
489
|
+
for(int i=0;i<annotations.size();i++) {
|
|
490
|
+
ReadableMap annotation=annotations.getMap(i);if(annotation==null)continue;
|
|
491
|
+
Range range=checkedAnnotationRange(annotation);
|
|
492
|
+
if(range!=null && offset>=range.start && offset<range.end) {
|
|
493
|
+
WritableMap payload=Arguments.createMap();payload.putString("id",annotation.getString("id"));emit("onAnnotationTap",payload);return true;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
private void layoutNoteButtons() {
|
|
500
|
+
Layout layout = textView.getLayout();
|
|
501
|
+
if (layout == null) return;
|
|
502
|
+
noteGroups.clear();
|
|
503
|
+
Map<Integer,Button> leaders=new HashMap<>();
|
|
504
|
+
for (Button button : noteButtons) {
|
|
505
|
+
int start = Math.min(textView.length(),(Integer)button.getTag());
|
|
506
|
+
int line = layout.getLineForOffset(start);
|
|
507
|
+
int y=textView.getPaddingTop()+layout.getLineTop(line);
|
|
508
|
+
button.setTranslationY((y/dp(44))*dp(44));
|
|
509
|
+
int bucket=y/dp(44);Button leader=leaders.get(bucket);
|
|
510
|
+
button.setVisibility(leader==null?View.VISIBLE:View.INVISIBLE);
|
|
511
|
+
String id=(String)button.getContentDescription();
|
|
512
|
+
// Accessibility label stays localized; stable IDs live in a keyed map.
|
|
513
|
+
id=noteIds.get(button);
|
|
514
|
+
if(leader==null){leaders.put(bucket,button);leader=button;noteGroups.put(leader,new ArrayList<>());}
|
|
515
|
+
noteGroups.get(leader).add(id);
|
|
516
|
+
}
|
|
517
|
+
for(Map.Entry<Button,List<String>> entry:noteGroups.entrySet())entry.getKey().setText(entry.getValue().size()>1?String.valueOf(entry.getValue().size()):"●");
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
private final Map<Button,String> noteIds=new HashMap<>();
|
|
521
|
+
private void openAnnotationGroup(Button button,String fallback) {
|
|
522
|
+
List<String> ids=noteGroups.get(button);
|
|
523
|
+
if(ids==null || ids.size()<2){emitAnnotationTap(fallback);return;}
|
|
524
|
+
String[] titles=new String[ids.size()];
|
|
525
|
+
for(int i=0;i<ids.size();i++){
|
|
526
|
+
titles[i]=ids.get(i);
|
|
527
|
+
for(int j=0;j<annotations.size();j++){ReadableMap a=annotations.getMap(j);if(ids.get(i).equals(a.getString("id"))){titles[i]=a.hasKey("noteContent")&&!a.isNull("noteContent")?a.getString("noteContent"):a.hasKey("content")&&!a.isNull("content")?a.getString("content"):ids.get(i);break;}}
|
|
528
|
+
}
|
|
529
|
+
new AlertDialog.Builder(getContext()).setTitle(labelFor("comment")).setItems(titles,(dialog,index)->emitAnnotationTap(ids.get(index))).show();
|
|
530
|
+
}
|
|
531
|
+
private void emitAnnotationTap(String id){WritableMap event=Arguments.createMap();event.putString("id",id);emit("onAnnotationTap",event);}
|
|
532
|
+
|
|
533
|
+
private void applyTheme() {
|
|
534
|
+
int paper = Color.WHITE;
|
|
535
|
+
int foreground = Color.BLACK;
|
|
536
|
+
if ("sepia".equals(pageTheme)) {
|
|
537
|
+
paper = Color.rgb(244, 235, 215);
|
|
538
|
+
foreground = Color.rgb(51, 43, 31);
|
|
539
|
+
} else if ("dark".equals(pageTheme) || "dark".equals(uiTheme)) {
|
|
540
|
+
paper = Color.rgb(31, 31, 33);
|
|
541
|
+
foreground = Color.rgb(235, 235, 235);
|
|
542
|
+
} else if ("high-contrast".equals(pageTheme)) {
|
|
543
|
+
paper = Color.BLACK;
|
|
544
|
+
foreground = Color.WHITE;
|
|
545
|
+
}
|
|
546
|
+
scrollView.setBackgroundColor(paper);
|
|
547
|
+
textView.setBackgroundColor(paper);
|
|
548
|
+
textView.setTextColor(foreground);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
private void scrollToTextOffset(int offset) {
|
|
552
|
+
final int requestedOffset = Math.max(0, offset);
|
|
553
|
+
textView.post(() -> {
|
|
554
|
+
Layout layout = textView.getLayout();
|
|
555
|
+
if (layout == null || textView.length() == 0) return;
|
|
556
|
+
int safeOffset = Math.min(textView.length(), requestedOffset);
|
|
557
|
+
int line = layout.getLineForOffset(safeOffset);
|
|
558
|
+
scrollView.scrollTo(0, Math.max(0, layout.getLineTop(line) + textView.getTop()));
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
private void emitTextOffsetFromScroll() {
|
|
563
|
+
if (textView.getLayout() == null || textView.length() == 0) return;
|
|
564
|
+
long now = SystemClock.uptimeMillis();
|
|
565
|
+
if (now - lastOffsetEventAt < EVENT_THROTTLE_MS) return;
|
|
566
|
+
Layout layout = textView.getLayout();
|
|
567
|
+
int line = layout.getLineForVertical(Math.max(0, scrollView.getScrollY() - textView.getTop()));
|
|
568
|
+
int offset = Math.max(0, Math.min(textView.length(), layout.getLineStart(line)));
|
|
569
|
+
if (offset == lastOffsetEventValue) return;
|
|
570
|
+
lastOffsetEventAt = now;
|
|
571
|
+
lastOffsetEventValue = offset;
|
|
572
|
+
currentTextOffset = offset;
|
|
573
|
+
WritableMap event = Arguments.createMap();
|
|
574
|
+
event.putInt("offset", offset);
|
|
575
|
+
emit("onTextOffsetChange", event);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
private WritableMap selectedPayload() {
|
|
579
|
+
int start = Math.max(0, textView.getSelectionStart());
|
|
580
|
+
int end = Math.min(textView.length(), textView.getSelectionEnd());
|
|
581
|
+
if (end <= start) return null;
|
|
582
|
+
WritableMap event = Arguments.createMap();
|
|
583
|
+
event.putString("text", textView.getText().subSequence(start, end).toString());
|
|
584
|
+
event.putInt("start", start);
|
|
585
|
+
event.putInt("end", end);
|
|
586
|
+
int prefixStart = Math.max(0, start - 48);
|
|
587
|
+
int suffixEnd = Math.min(textView.length(), end + 48);
|
|
588
|
+
if (prefixStart > 0 && Character.isLowSurrogate(textView.getText().charAt(prefixStart))) prefixStart--;
|
|
589
|
+
if (suffixEnd < textView.length() && Character.isLowSurrogate(textView.getText().charAt(suffixEnd))) suffixEnd++;
|
|
590
|
+
event.putString("prefix", textView.getText().subSequence(prefixStart, start).toString());
|
|
591
|
+
event.putString("suffix", textView.getText().subSequence(end, suffixEnd).toString());
|
|
592
|
+
return event;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
private boolean isSingleWordSelection() {
|
|
596
|
+
WritableMap selection = selectedPayload();
|
|
597
|
+
if (selection == null) return false;
|
|
598
|
+
String selected = selection.getString("text");
|
|
599
|
+
return selected != null && selected.trim().matches("[^\\s]+") && selected.trim().length() <= 64;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
private void emitTextRangeSelected() {
|
|
603
|
+
if (suppressSelectionEvents) return;
|
|
604
|
+
WritableMap selection = selectedPayload();
|
|
605
|
+
if (selection == null) {
|
|
606
|
+
lastReportedStart = -1;
|
|
607
|
+
lastReportedEnd = -1;
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
int start = selection.getInt("start");
|
|
611
|
+
int end = selection.getInt("end");
|
|
612
|
+
if (start == lastReportedStart && end == lastReportedEnd) return;
|
|
613
|
+
lastReportedStart = start;
|
|
614
|
+
lastReportedEnd = end;
|
|
615
|
+
emit("onTextRangeSelected", selection);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
private void emitDefineSelection() {
|
|
619
|
+
WritableMap selection = selectedPayload();
|
|
620
|
+
if (selection != null && (!"single-word".equals(defineSelectionMode) || isSingleWordSelection())) emit("onDefineSelection", selection);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
private void emit(String name, WritableMap payload) {
|
|
624
|
+
if (!(getContext() instanceof ReactContext)) return;
|
|
625
|
+
((ReactContext) getContext()).getJSModule(RCTEventEmitter.class).receiveEvent(getId(), name, payload);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
private int dp(float value) {
|
|
629
|
+
return Math.round(value * getResources().getDisplayMetrics().density);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
private interface SelectionListener { void onSelectionChanged(); }
|
|
633
|
+
|
|
634
|
+
private static final class PapyrusSelectableTextView extends TextView {
|
|
635
|
+
private SelectionListener listener;
|
|
636
|
+
PapyrusSelectableTextView(Context context) { super(context); }
|
|
637
|
+
void setOnSelectionChangedListener(SelectionListener value) { listener = value; }
|
|
638
|
+
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
639
|
+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
640
|
+
Layout layout = getLayout();
|
|
641
|
+
if (layout == null || MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY) return;
|
|
642
|
+
int contentHeight = layout.getHeight() + getCompoundPaddingTop() + getCompoundPaddingBottom();
|
|
643
|
+
int desiredHeight = resolveSizeAndState(
|
|
644
|
+
Math.max(getSuggestedMinimumHeight(), contentHeight),
|
|
645
|
+
heightMeasureSpec,
|
|
646
|
+
0
|
|
647
|
+
);
|
|
648
|
+
setMeasuredDimension(getMeasuredWidth(), desiredHeight);
|
|
649
|
+
}
|
|
650
|
+
@Override protected void onSelectionChanged(int selectionStart, int selectionEnd) {
|
|
651
|
+
super.onSelectionChanged(selectionStart, selectionEnd);
|
|
652
|
+
if (listener != null) listener.onSelectionChanged();
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
private static final class Range {
|
|
657
|
+
final int start;
|
|
658
|
+
final int end;
|
|
659
|
+
Range(int start, int end) { this.start = start; this.end = end; }
|
|
660
|
+
}
|
|
661
|
+
}
|