@papyrus-sdk/engine-native 0.1.0 → 0.1.2
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/build.gradle +40 -40
- package/android/src/main/AndroidManifest.xml +3 -3
- package/android/src/main/java/com/papyrus/engine/PapyrusEngineStore.java +71 -71
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +529 -529
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.kt +540 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusOutline.java +20 -20
- package/android/src/main/java/com/papyrus/engine/PapyrusOutlineItem.java +13 -13
- package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +24 -24
- package/android/src/main/java/com/papyrus/engine/PapyrusPageView.java +86 -86
- package/android/src/main/java/com/papyrus/engine/PapyrusPageViewManager.java +16 -16
- package/android/src/main/java/com/papyrus/engine/PapyrusPageViewModule.kt +12 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextHit.java +15 -15
- package/android/src/main/java/com/papyrus/engine/PapyrusTextSearch.java +20 -20
- package/android/src/main/java/com/papyrus/engine/PapyrusTextSelect.java +20 -20
- package/android/src/main/java/com/papyrus/engine/PapyrusTextSelection.java +11 -11
- package/dist/index.d.mts +95 -7
- package/dist/index.d.ts +95 -7
- package/dist/index.js +683 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +684 -13
- package/dist/index.mjs.map +1 -1
- package/ios/PapyrusNativeEngine.m +447 -372
- package/ios/PapyrusNativeEngine.podspec +15 -15
- package/ios/PapyrusPageView.h +19 -16
- package/ios/PapyrusPageView.m +63 -54
- package/ios/PapyrusPageViewManager.m +19 -19
- package/package.json +11 -7
- package/react-native.config.js +10 -10
- package/android/.cxx/Debug/6t29645j/arm64-v8a/.cmake/api/v1/query/client-agp/cache-v2 +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/.cmake/api/v1/query/client-agp/cmakeFiles-v1 +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/.cmake/api/v1/query/client-agp/codemodel-v2 +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/.cmake/api/v1/reply/cache-v2-55a2e41fcdfef7f23046.json +0 -1323
- package/android/.cxx/Debug/6t29645j/arm64-v8a/.cmake/api/v1/reply/cmakeFiles-v1-ce719ceafe10fdc060d9.json +0 -184
- package/android/.cxx/Debug/6t29645j/arm64-v8a/.cmake/api/v1/reply/codemodel-v2-ba59984c0779dea51592.json +0 -60
- package/android/.cxx/Debug/6t29645j/arm64-v8a/.cmake/api/v1/reply/directory-.-Debug-d0094a50bb2071803777.json +0 -14
- package/android/.cxx/Debug/6t29645j/arm64-v8a/.cmake/api/v1/reply/index-2025-12-22T13-33-34-0909.json +0 -92
- package/android/.cxx/Debug/6t29645j/arm64-v8a/.cmake/api/v1/reply/target-papyrus_text-Debug-29cd4996bc13fe24a65c.json +0 -168
- package/android/.cxx/Debug/6t29645j/arm64-v8a/.ninja_deps +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/.ninja_log +0 -20
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeCache.txt +0 -400
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/3.22.1-g37088a8-dirty/CMakeCCompiler.cmake +0 -72
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/3.22.1-g37088a8-dirty/CMakeCXXCompiler.cmake +0 -83
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/3.22.1-g37088a8-dirty/CMakeDetermineCompilerABI_C.bin +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/3.22.1-g37088a8-dirty/CMakeDetermineCompilerABI_CXX.bin +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/3.22.1-g37088a8-dirty/CMakeSystem.cmake +0 -15
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdC/CMakeCCompilerId.c +0 -803
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdC/CMakeCCompilerId.o +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdCXX/CMakeCXXCompilerId.cpp +0 -791
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdCXX/CMakeCXXCompilerId.o +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/CMakeOutput.log +0 -264
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/TargetDirectories.txt +0 -3
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/cmake.check_cache +0 -1
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/papyrus_text.dir/papyrus_outline.cpp.o +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/papyrus_text.dir/papyrus_text_search.cpp.o +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/CMakeFiles/rules.ninja +0 -64
- package/android/.cxx/Debug/6t29645j/arm64-v8a/additional_project_files.txt +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/android_gradle_build.json +0 -38
- package/android/.cxx/Debug/6t29645j/arm64-v8a/android_gradle_build_mini.json +0 -27
- package/android/.cxx/Debug/6t29645j/arm64-v8a/build.ninja +0 -158
- package/android/.cxx/Debug/6t29645j/arm64-v8a/build_file_index.txt +0 -1
- package/android/.cxx/Debug/6t29645j/arm64-v8a/cmake_install.cmake +0 -54
- package/android/.cxx/Debug/6t29645j/arm64-v8a/compile_commands.json +0 -12
- package/android/.cxx/Debug/6t29645j/arm64-v8a/compile_commands.json.bin +0 -0
- package/android/.cxx/Debug/6t29645j/arm64-v8a/configure_fingerprint.bin +0 -28
- package/android/.cxx/Debug/6t29645j/arm64-v8a/metadata_generation_command.txt +0 -19
- package/android/.cxx/Debug/6t29645j/arm64-v8a/prefab_config.json +0 -4
- package/android/.cxx/Debug/6t29645j/arm64-v8a/symbol_folder_index.txt +0 -1
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/.cmake/api/v1/query/client-agp/cache-v2 +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/.cmake/api/v1/query/client-agp/cmakeFiles-v1 +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/.cmake/api/v1/query/client-agp/codemodel-v2 +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/.cmake/api/v1/reply/cache-v2-7f933b968e76d6ce336c.json +0 -1323
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/.cmake/api/v1/reply/cmakeFiles-v1-439d2bc9e04bf2a43452.json +0 -184
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/.cmake/api/v1/reply/codemodel-v2-efc4cfee3dc3a5ec05be.json +0 -60
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/.cmake/api/v1/reply/directory-.-Debug-d0094a50bb2071803777.json +0 -14
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/.cmake/api/v1/reply/index-2025-12-22T13-33-36-0881.json +0 -92
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/.cmake/api/v1/reply/target-papyrus_text-Debug-e3f83458cbaf3644c279.json +0 -168
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/.ninja_deps +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/.ninja_log +0 -20
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeCache.txt +0 -400
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/3.22.1-g37088a8-dirty/CMakeCCompiler.cmake +0 -72
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/3.22.1-g37088a8-dirty/CMakeCXXCompiler.cmake +0 -83
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/3.22.1-g37088a8-dirty/CMakeDetermineCompilerABI_C.bin +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/3.22.1-g37088a8-dirty/CMakeDetermineCompilerABI_CXX.bin +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/3.22.1-g37088a8-dirty/CMakeSystem.cmake +0 -15
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdC/CMakeCCompilerId.c +0 -803
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdC/CMakeCCompilerId.o +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdCXX/CMakeCXXCompilerId.cpp +0 -791
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdCXX/CMakeCXXCompilerId.o +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/CMakeOutput.log +0 -268
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/TargetDirectories.txt +0 -3
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/cmake.check_cache +0 -1
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/papyrus_text.dir/papyrus_outline.cpp.o +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/papyrus_text.dir/papyrus_text_search.cpp.o +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/CMakeFiles/rules.ninja +0 -64
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/additional_project_files.txt +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/android_gradle_build.json +0 -38
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/android_gradle_build_mini.json +0 -27
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/build.ninja +0 -158
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/build_file_index.txt +0 -1
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/cmake_install.cmake +0 -54
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/compile_commands.json +0 -12
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/compile_commands.json.bin +0 -0
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/configure_fingerprint.bin +0 -28
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/metadata_generation_command.txt +0 -19
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/prefab_config.json +0 -4
- package/android/.cxx/Debug/6t29645j/armeabi-v7a/symbol_folder_index.txt +0 -1
- package/android/.cxx/Debug/6t29645j/hash_key.txt +0 -26
- package/android/.cxx/Debug/6t29645j/x86/.cmake/api/v1/query/client-agp/cache-v2 +0 -0
- package/android/.cxx/Debug/6t29645j/x86/.cmake/api/v1/query/client-agp/cmakeFiles-v1 +0 -0
- package/android/.cxx/Debug/6t29645j/x86/.cmake/api/v1/query/client-agp/codemodel-v2 +0 -0
- package/android/.cxx/Debug/6t29645j/x86/.cmake/api/v1/reply/cache-v2-921e99e188641cccb611.json +0 -1323
- package/android/.cxx/Debug/6t29645j/x86/.cmake/api/v1/reply/cmakeFiles-v1-842a746390c683135141.json +0 -184
- package/android/.cxx/Debug/6t29645j/x86/.cmake/api/v1/reply/codemodel-v2-5a1f9507fc5ae29259c9.json +0 -60
- package/android/.cxx/Debug/6t29645j/x86/.cmake/api/v1/reply/directory-.-Debug-d0094a50bb2071803777.json +0 -14
- package/android/.cxx/Debug/6t29645j/x86/.cmake/api/v1/reply/index-2025-12-22T13-33-37-0961.json +0 -92
- package/android/.cxx/Debug/6t29645j/x86/.cmake/api/v1/reply/target-papyrus_text-Debug-3cc07532ad82ada3b95c.json +0 -168
- package/android/.cxx/Debug/6t29645j/x86/.ninja_deps +0 -0
- package/android/.cxx/Debug/6t29645j/x86/.ninja_log +0 -20
- package/android/.cxx/Debug/6t29645j/x86/CMakeCache.txt +0 -400
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/3.22.1-g37088a8-dirty/CMakeCCompiler.cmake +0 -72
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/3.22.1-g37088a8-dirty/CMakeCXXCompiler.cmake +0 -83
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/3.22.1-g37088a8-dirty/CMakeDetermineCompilerABI_C.bin +0 -0
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/3.22.1-g37088a8-dirty/CMakeDetermineCompilerABI_CXX.bin +0 -0
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/3.22.1-g37088a8-dirty/CMakeSystem.cmake +0 -15
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdC/CMakeCCompilerId.c +0 -803
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdC/CMakeCCompilerId.o +0 -0
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdCXX/CMakeCXXCompilerId.cpp +0 -791
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdCXX/CMakeCXXCompilerId.o +0 -0
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/CMakeOutput.log +0 -258
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/TargetDirectories.txt +0 -3
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/cmake.check_cache +0 -1
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/papyrus_text.dir/papyrus_outline.cpp.o +0 -0
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/papyrus_text.dir/papyrus_text_search.cpp.o +0 -0
- package/android/.cxx/Debug/6t29645j/x86/CMakeFiles/rules.ninja +0 -64
- package/android/.cxx/Debug/6t29645j/x86/additional_project_files.txt +0 -0
- package/android/.cxx/Debug/6t29645j/x86/android_gradle_build.json +0 -38
- package/android/.cxx/Debug/6t29645j/x86/android_gradle_build_mini.json +0 -27
- package/android/.cxx/Debug/6t29645j/x86/build.ninja +0 -158
- package/android/.cxx/Debug/6t29645j/x86/build_file_index.txt +0 -1
- package/android/.cxx/Debug/6t29645j/x86/cmake_install.cmake +0 -54
- package/android/.cxx/Debug/6t29645j/x86/compile_commands.json +0 -12
- package/android/.cxx/Debug/6t29645j/x86/compile_commands.json.bin +0 -0
- package/android/.cxx/Debug/6t29645j/x86/configure_fingerprint.bin +0 -28
- package/android/.cxx/Debug/6t29645j/x86/metadata_generation_command.txt +0 -19
- package/android/.cxx/Debug/6t29645j/x86/prefab_config.json +0 -4
- package/android/.cxx/Debug/6t29645j/x86/symbol_folder_index.txt +0 -1
- package/android/.cxx/Debug/6t29645j/x86_64/.cmake/api/v1/query/client-agp/cache-v2 +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/.cmake/api/v1/query/client-agp/cmakeFiles-v1 +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/.cmake/api/v1/query/client-agp/codemodel-v2 +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/.cmake/api/v1/reply/cache-v2-de693df49d051882903b.json +0 -1323
- package/android/.cxx/Debug/6t29645j/x86_64/.cmake/api/v1/reply/cmakeFiles-v1-8206847cf10ce80b1459.json +0 -184
- package/android/.cxx/Debug/6t29645j/x86_64/.cmake/api/v1/reply/codemodel-v2-ad9301b1a16c83f532c2.json +0 -60
- package/android/.cxx/Debug/6t29645j/x86_64/.cmake/api/v1/reply/directory-.-Debug-d0094a50bb2071803777.json +0 -14
- package/android/.cxx/Debug/6t29645j/x86_64/.cmake/api/v1/reply/index-2025-12-22T13-33-39-0005.json +0 -92
- package/android/.cxx/Debug/6t29645j/x86_64/.cmake/api/v1/reply/target-papyrus_text-Debug-e1bb1d27c41dc820b379.json +0 -168
- package/android/.cxx/Debug/6t29645j/x86_64/.ninja_deps +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/.ninja_log +0 -20
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeCache.txt +0 -400
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/3.22.1-g37088a8-dirty/CMakeCCompiler.cmake +0 -72
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/3.22.1-g37088a8-dirty/CMakeCXXCompiler.cmake +0 -83
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/3.22.1-g37088a8-dirty/CMakeDetermineCompilerABI_C.bin +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/3.22.1-g37088a8-dirty/CMakeDetermineCompilerABI_CXX.bin +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/3.22.1-g37088a8-dirty/CMakeSystem.cmake +0 -15
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdC/CMakeCCompilerId.c +0 -803
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdC/CMakeCCompilerId.o +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdCXX/CMakeCXXCompilerId.cpp +0 -791
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/3.22.1-g37088a8-dirty/CompilerIdCXX/CMakeCXXCompilerId.o +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/CMakeOutput.log +0 -258
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/TargetDirectories.txt +0 -3
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/cmake.check_cache +0 -1
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/papyrus_text.dir/papyrus_outline.cpp.o +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/papyrus_text.dir/papyrus_text_search.cpp.o +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/CMakeFiles/rules.ninja +0 -64
- package/android/.cxx/Debug/6t29645j/x86_64/additional_project_files.txt +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/android_gradle_build.json +0 -38
- package/android/.cxx/Debug/6t29645j/x86_64/android_gradle_build_mini.json +0 -27
- package/android/.cxx/Debug/6t29645j/x86_64/build.ninja +0 -158
- package/android/.cxx/Debug/6t29645j/x86_64/build_file_index.txt +0 -1
- package/android/.cxx/Debug/6t29645j/x86_64/cmake_install.cmake +0 -54
- package/android/.cxx/Debug/6t29645j/x86_64/compile_commands.json +0 -12
- package/android/.cxx/Debug/6t29645j/x86_64/compile_commands.json.bin +0 -0
- package/android/.cxx/Debug/6t29645j/x86_64/configure_fingerprint.bin +0 -28
- package/android/.cxx/Debug/6t29645j/x86_64/metadata_generation_command.txt +0 -19
- package/android/.cxx/Debug/6t29645j/x86_64/prefab_config.json +0 -4
- package/android/.cxx/Debug/6t29645j/x86_64/symbol_folder_index.txt +0 -1
- package/android/.cxx/tools/debug/arm64-v8a/compile_commands.json +0 -12
- package/android/.cxx/tools/debug/armeabi-v7a/compile_commands.json +0 -12
- package/android/.cxx/tools/debug/x86/compile_commands.json +0 -12
- package/android/.cxx/tools/debug/x86_64/compile_commands.json +0 -12
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/results.bin +0 -1
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/android/support/v4/util/ArrayMap.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/BuildConfig.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusEngineStore$EngineState.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusEngineStore.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusNativeEngineModule$1.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusNativeEngineModule.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusOutline.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusOutlineItem.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusPackage.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusPageView.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusPageViewManager.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusTextHit.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusTextSearch.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusTextSelect.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/papyrus/engine/PapyrusTextSelection.dex +0 -0
- package/android/build/.transforms/2a70e7e4bf5a7ddacb39b95e5520ae88/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
- package/android/build/.transforms/b336bac6032a9c6be0544a913e5a030c/results.bin +0 -1
- package/android/build/.transforms/b336bac6032a9c6be0544a913e5a030c/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/generated/source/buildConfig/debug/com/papyrus/engine/BuildConfig.java +0 -10
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +0 -7
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output-metadata.json +0 -18
- package/android/build/intermediates/aar_metadata/debug/writeDebugAarMetadata/aar-metadata.properties +0 -6
- package/android/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug/annotationProcessors.json +0 -1
- package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/compile_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
- package/android/build/intermediates/compile_symbol_list/debug/generateDebugRFile/R.txt +0 -0
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/build_command_papyrus_text.bat +0 -5
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/build_model.json +0 -186
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/build_stderr_papyrus_text.txt +0 -0
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/build_stdout_papyrus_text.txt +0 -2
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/generate_cxx_metadata_157_timing.txt +0 -8
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/generate_cxx_metadata_167_timing.txt +0 -8
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/generate_cxx_metadata_168_timing.txt +0 -14
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/generate_cxx_metadata_172_timing.txt +0 -8
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/generate_cxx_metadata_2919_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/generate_cxx_metadata_3311_timing.txt +0 -3
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/generate_cxx_metadata_450_timing.txt +0 -3
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/arm64-v8a/metadata_generation_record.json +0 -41
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/build_command_papyrus_text.bat +0 -5
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/build_model.json +0 -186
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/build_stderr_papyrus_text.txt +0 -0
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/build_stdout_papyrus_text.txt +0 -2
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/generate_cxx_metadata_158_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/generate_cxx_metadata_160_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/generate_cxx_metadata_164_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/generate_cxx_metadata_168_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/generate_cxx_metadata_2922_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/generate_cxx_metadata_3311_timing.txt +0 -3
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/generate_cxx_metadata_450_timing.txt +0 -3
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/armeabi-v7a/metadata_generation_record.json +0 -41
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/build_command_papyrus_text.bat +0 -5
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/build_model.json +0 -186
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/build_stderr_papyrus_text.txt +0 -0
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/build_stdout_papyrus_text.txt +0 -2
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/generate_cxx_metadata_160_timing.txt +0 -5
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/generate_cxx_metadata_164_timing.txt +0 -3
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/generate_cxx_metadata_168_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/generate_cxx_metadata_170_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/generate_cxx_metadata_2907_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/generate_cxx_metadata_3311_timing.txt +0 -3
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/generate_cxx_metadata_450_timing.txt +0 -3
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86/metadata_generation_record.json +0 -41
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/build_command_papyrus_text.bat +0 -5
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/build_model.json +0 -186
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/build_stderr_papyrus_text.txt +0 -0
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/build_stdout_papyrus_text.txt +0 -2
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/generate_cxx_metadata_155_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/generate_cxx_metadata_160_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/generate_cxx_metadata_164_timing.txt +0 -3
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/generate_cxx_metadata_168_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/generate_cxx_metadata_2916_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/generate_cxx_metadata_3311_timing.txt +0 -5
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/generate_cxx_metadata_450_timing.txt +0 -6
- package/android/build/intermediates/cxx/Debug/6t29645j/logs/x86_64/metadata_generation_record.json +0 -41
- package/android/build/intermediates/cxx/Debug/6t29645j/obj/arm64-v8a/libpapyrus_text.so +0 -0
- package/android/build/intermediates/cxx/Debug/6t29645j/obj/armeabi-v7a/libpapyrus_text.so +0 -0
- package/android/build/intermediates/cxx/Debug/6t29645j/obj/x86/libpapyrus_text.so +0 -0
- package/android/build/intermediates/cxx/Debug/6t29645j/obj/x86_64/libpapyrus_text.so +0 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +0 -1
- package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +0 -2
- package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +0 -2
- package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +0 -2
- package/android/build/intermediates/incremental/packageDebugAssets/merger.xml +0 -2
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/android/support/v4/util/ArrayMap.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/BuildConfig.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusEngineStore$EngineState.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusEngineStore.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusNativeEngineModule$1.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusNativeEngineModule.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusOutline.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusOutlineItem.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusPackage.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusPageView.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusPageViewManager.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusTextHit.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusTextSearch.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusTextSelect.class +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/papyrus/engine/PapyrusTextSelection.class +0 -0
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/arm64-v8a/libpapyrus_text.so +0 -0
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/armeabi-v7a/libpapyrus_text.so +0 -0
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86/libpapyrus_text.so +0 -0
- package/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/x86_64/libpapyrus_text.so +0 -0
- package/android/build/intermediates/local_only_symbol_list/debug/parseDebugLocalResources/R-def.txt +0 -2
- package/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +0 -7
- package/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +0 -7
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/arm64-v8a/libpapyrus_text.so +0 -0
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/armeabi-v7a/libpapyrus_text.so +0 -0
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86/libpapyrus_text.so +0 -0
- package/android/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/x86_64/libpapyrus_text.so +0 -0
- package/android/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +0 -1
- package/android/build/intermediates/nested_resources_validation_report/debug/generateDebugResources/nestedResourcesValidationReport.txt +0 -1
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/android/support/v4/util/ArrayMap.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/BuildConfig.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusEngineStore$EngineState.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusEngineStore.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusNativeEngineModule$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusNativeEngineModule.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusOutline.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusOutlineItem.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusPackage.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusPageView.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusPageViewManager.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusTextHit.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusTextSearch.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusTextSelect.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/papyrus/engine/PapyrusTextSelection.class +0 -0
- package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/symbol_list_with_package_name/debug/generateDebugRFile/package-aware-r.txt +0 -1
- package/android/build/outputs/logs/manifest-merger-debug-report.txt +0 -17
- package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PapyrusNativeEngineModule$1.class.uniqueId2 +0 -0
- package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PapyrusNativeEngineModule.class.uniqueId1 +0 -0
- package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/PapyrusPackage.class.uniqueId0 +0 -0
- package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
|
@@ -1,529 +1,529 @@
|
|
|
1
|
-
package com.papyrus.engine;
|
|
2
|
-
|
|
3
|
-
import android.content.ContentResolver;
|
|
4
|
-
import android.content.Context;
|
|
5
|
-
import android.net.Uri;
|
|
6
|
-
import android.os.ParcelFileDescriptor;
|
|
7
|
-
import android.view.View;
|
|
8
|
-
|
|
9
|
-
import com.facebook.react.bridge.Arguments;
|
|
10
|
-
import com.facebook.react.bridge.Promise;
|
|
11
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
12
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
13
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
14
|
-
import com.facebook.react.bridge.ReadableArray;
|
|
15
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
16
|
-
import com.facebook.react.bridge.WritableArray;
|
|
17
|
-
import com.facebook.react.bridge.WritableMap;
|
|
18
|
-
import com.facebook.react.bridge.ReadableType;
|
|
19
|
-
import com.facebook.react.uimanager.UIBlock;
|
|
20
|
-
import com.facebook.react.uimanager.UIManagerModule;
|
|
21
|
-
|
|
22
|
-
import com.shockwave.pdfium.PdfDocument;
|
|
23
|
-
|
|
24
|
-
import java.io.File;
|
|
25
|
-
import java.io.FileOutputStream;
|
|
26
|
-
import java.io.IOException;
|
|
27
|
-
import java.io.InputStream;
|
|
28
|
-
import java.net.HttpURLConnection;
|
|
29
|
-
import java.net.URL;
|
|
30
|
-
import java.util.concurrent.ExecutorService;
|
|
31
|
-
import java.util.concurrent.Executors;
|
|
32
|
-
|
|
33
|
-
public class PapyrusNativeEngineModule extends ReactContextBaseJavaModule {
|
|
34
|
-
private final ReactApplicationContext reactContext;
|
|
35
|
-
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
36
|
-
|
|
37
|
-
public PapyrusNativeEngineModule(ReactApplicationContext reactContext) {
|
|
38
|
-
super(reactContext);
|
|
39
|
-
this.reactContext = reactContext;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@Override
|
|
43
|
-
public String getName() {
|
|
44
|
-
return "PapyrusNativeEngine";
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
48
|
-
public String createEngine() {
|
|
49
|
-
return PapyrusEngineStore.createEngine(reactContext);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@ReactMethod
|
|
53
|
-
public void destroyEngine(String engineId) {
|
|
54
|
-
PapyrusEngineStore.destroyEngine(engineId);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@ReactMethod
|
|
58
|
-
public void load(final String engineId, final ReadableMap source, final Promise promise) {
|
|
59
|
-
executor.execute(() -> {
|
|
60
|
-
try {
|
|
61
|
-
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
62
|
-
if (state == null) {
|
|
63
|
-
promise.reject("papyrus_no_engine", "Engine not found");
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
File file = materializeSource(source, reactContext);
|
|
68
|
-
if (file == null) {
|
|
69
|
-
promise.reject("papyrus_invalid_source", "Unsupported PDF source");
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
ParcelFileDescriptor fd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
|
|
74
|
-
PdfDocument document = state.pdfium.newDocument(fd);
|
|
75
|
-
PapyrusEngineStore.setDocument(state, document, fd, file.getAbsolutePath());
|
|
76
|
-
|
|
77
|
-
int pageCount = state.pdfium.getPageCount(document);
|
|
78
|
-
WritableMap result = Arguments.createMap();
|
|
79
|
-
result.putInt("pageCount", pageCount);
|
|
80
|
-
promise.resolve(result);
|
|
81
|
-
} catch (Throwable error) {
|
|
82
|
-
promise.reject("papyrus_load_failed", error);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
88
|
-
public int getPageCount(String engineId) {
|
|
89
|
-
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
90
|
-
if (state == null || state.document == null) return 0;
|
|
91
|
-
return state.pdfium.getPageCount(state.document);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
@ReactMethod
|
|
95
|
-
public void renderPage(final String engineId, final int pageIndex, final int target, final float scale, final float zoom, final int rotation) {
|
|
96
|
-
final PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
97
|
-
if (state == null) return;
|
|
98
|
-
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
|
99
|
-
if (uiManager == null) return;
|
|
100
|
-
|
|
101
|
-
uiManager.addUIBlock(new UIBlock() {
|
|
102
|
-
@Override
|
|
103
|
-
public void execute(com.facebook.react.uimanager.NativeViewHierarchyManager nativeViewHierarchyManager) {
|
|
104
|
-
View view = nativeViewHierarchyManager.resolveView(target);
|
|
105
|
-
if (view instanceof PapyrusPageView) {
|
|
106
|
-
((PapyrusPageView) view).render(state, pageIndex, scale, zoom, rotation);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@ReactMethod
|
|
113
|
-
public void renderTextLayer(String engineId, int pageIndex, int target, float scale, float zoom, int rotation) {
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
@ReactMethod
|
|
117
|
-
public void getTextContent(String engineId, int pageIndex, Promise promise) {
|
|
118
|
-
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
119
|
-
if (state == null || state.document == null) {
|
|
120
|
-
promise.resolve(Arguments.createArray());
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
String text;
|
|
124
|
-
synchronized (state.pdfiumLock) {
|
|
125
|
-
text = extractPageText(state, pageIndex);
|
|
126
|
-
}
|
|
127
|
-
WritableArray items = Arguments.createArray();
|
|
128
|
-
if (text != null && !text.isEmpty()) {
|
|
129
|
-
WritableMap item = Arguments.createMap();
|
|
130
|
-
item.putString("str", text);
|
|
131
|
-
item.putString("dir", "ltr");
|
|
132
|
-
item.putDouble("width", 0);
|
|
133
|
-
item.putDouble("height", 0);
|
|
134
|
-
WritableArray transform = Arguments.createArray();
|
|
135
|
-
transform.pushDouble(1);
|
|
136
|
-
transform.pushDouble(0);
|
|
137
|
-
transform.pushDouble(0);
|
|
138
|
-
transform.pushDouble(1);
|
|
139
|
-
transform.pushDouble(0);
|
|
140
|
-
transform.pushDouble(0);
|
|
141
|
-
item.putArray("transform", transform);
|
|
142
|
-
item.putString("fontName", "");
|
|
143
|
-
items.pushMap(item);
|
|
144
|
-
}
|
|
145
|
-
promise.resolve(items);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
@ReactMethod
|
|
149
|
-
public void getPageDimensions(String engineId, int pageIndex, Promise promise) {
|
|
150
|
-
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
151
|
-
if (state == null || state.document == null) {
|
|
152
|
-
WritableMap result = Arguments.createMap();
|
|
153
|
-
result.putInt("width", 0);
|
|
154
|
-
result.putInt("height", 0);
|
|
155
|
-
promise.resolve(result);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
int width;
|
|
159
|
-
int height;
|
|
160
|
-
synchronized (state.pdfiumLock) {
|
|
161
|
-
width = state.pdfium.getPageWidthPoint(state.document, pageIndex);
|
|
162
|
-
height = state.pdfium.getPageHeightPoint(state.document, pageIndex);
|
|
163
|
-
}
|
|
164
|
-
WritableMap result = Arguments.createMap();
|
|
165
|
-
result.putInt("width", width);
|
|
166
|
-
result.putInt("height", height);
|
|
167
|
-
promise.resolve(result);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
@ReactMethod
|
|
171
|
-
public void getOutline(String engineId, Promise promise) {
|
|
172
|
-
executor.execute(() -> {
|
|
173
|
-
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
174
|
-
if (state == null || state.document == null) {
|
|
175
|
-
promise.resolve(Arguments.createArray());
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
PapyrusOutlineItem[] items = null;
|
|
180
|
-
try {
|
|
181
|
-
if (PapyrusOutline.AVAILABLE) {
|
|
182
|
-
if (state.sourcePath != null && !state.sourcePath.isEmpty()) {
|
|
183
|
-
synchronized (state.pdfiumLock) {
|
|
184
|
-
items = PapyrusOutline.nativeGetOutlineFile(state.sourcePath);
|
|
185
|
-
}
|
|
186
|
-
} else {
|
|
187
|
-
long docPtr;
|
|
188
|
-
synchronized (state.pdfiumLock) {
|
|
189
|
-
docPtr = extractNativeDocPointer(state.document);
|
|
190
|
-
}
|
|
191
|
-
if (docPtr != 0) {
|
|
192
|
-
synchronized (state.pdfiumLock) {
|
|
193
|
-
items = PapyrusOutline.nativeGetOutline(docPtr);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
} catch (Throwable ignored) {
|
|
199
|
-
items = null;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
WritableArray result = Arguments.createArray();
|
|
203
|
-
if (items != null) {
|
|
204
|
-
for (PapyrusOutlineItem item : items) {
|
|
205
|
-
result.pushMap(serializeOutlineItem(item));
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
promise.resolve(result);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
@ReactMethod
|
|
213
|
-
public void getPageIndex(String engineId, Object dest, Promise promise) {
|
|
214
|
-
promise.resolve(null);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
@ReactMethod
|
|
218
|
-
public void searchText(String engineId, String query, Promise promise) {
|
|
219
|
-
executor.execute(() -> {
|
|
220
|
-
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
221
|
-
if (state == null || state.document == null || query == null || query.length() < 2) {
|
|
222
|
-
promise.resolve(Arguments.createArray());
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
int pageCount = state.pdfium.getPageCount(state.document);
|
|
227
|
-
state.isSearching = true;
|
|
228
|
-
try {
|
|
229
|
-
try {
|
|
230
|
-
if (PapyrusTextSearch.AVAILABLE) {
|
|
231
|
-
PapyrusTextHit[] hits = null;
|
|
232
|
-
if (state.sourcePath != null && !state.sourcePath.isEmpty()) {
|
|
233
|
-
synchronized (state.pdfiumLock) {
|
|
234
|
-
hits = PapyrusTextSearch.nativeSearchFile(state.sourcePath, query);
|
|
235
|
-
}
|
|
236
|
-
} else {
|
|
237
|
-
long docPtr;
|
|
238
|
-
synchronized (state.pdfiumLock) {
|
|
239
|
-
docPtr = extractNativeDocPointer(state.document);
|
|
240
|
-
}
|
|
241
|
-
if (docPtr != 0) {
|
|
242
|
-
synchronized (state.pdfiumLock) {
|
|
243
|
-
hits = PapyrusTextSearch.nativeSearch(docPtr, pageCount, query);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (hits != null && hits.length > 0) {
|
|
249
|
-
WritableArray results = Arguments.createArray();
|
|
250
|
-
for (PapyrusTextHit hit : hits) {
|
|
251
|
-
WritableMap result = Arguments.createMap();
|
|
252
|
-
result.putInt("pageIndex", hit.pageIndex);
|
|
253
|
-
result.putString("text", hit.text != null ? hit.text : query);
|
|
254
|
-
result.putInt("matchIndex", hit.matchIndex);
|
|
255
|
-
if (hit.rects != null && hit.rects.length >= 4) {
|
|
256
|
-
WritableArray rects = Arguments.createArray();
|
|
257
|
-
for (int i = 0; i + 3 < hit.rects.length; i += 4) {
|
|
258
|
-
WritableMap rect = Arguments.createMap();
|
|
259
|
-
rect.putDouble("x", hit.rects[i]);
|
|
260
|
-
rect.putDouble("y", hit.rects[i + 1]);
|
|
261
|
-
rect.putDouble("width", hit.rects[i + 2]);
|
|
262
|
-
rect.putDouble("height", hit.rects[i + 3]);
|
|
263
|
-
rects.pushMap(rect);
|
|
264
|
-
}
|
|
265
|
-
result.putArray("rects", rects);
|
|
266
|
-
}
|
|
267
|
-
results.pushMap(result);
|
|
268
|
-
}
|
|
269
|
-
promise.resolve(results);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
} catch (Throwable ignored) {
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
String normalizedQuery = query.toLowerCase();
|
|
277
|
-
WritableArray results = Arguments.createArray();
|
|
278
|
-
|
|
279
|
-
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
|
|
280
|
-
String text;
|
|
281
|
-
synchronized (state.pdfiumLock) {
|
|
282
|
-
text = extractPageText(state, pageIndex);
|
|
283
|
-
}
|
|
284
|
-
if (text == null || text.isEmpty()) continue;
|
|
285
|
-
|
|
286
|
-
String lower = text.toLowerCase();
|
|
287
|
-
int pos = lower.indexOf(normalizedQuery);
|
|
288
|
-
int matchIndex = 0;
|
|
289
|
-
while (pos != -1) {
|
|
290
|
-
int start = Math.max(0, pos - 20);
|
|
291
|
-
int end = Math.min(text.length(), pos + normalizedQuery.length() + 20);
|
|
292
|
-
String preview = text.substring(start, end);
|
|
293
|
-
|
|
294
|
-
WritableMap result = Arguments.createMap();
|
|
295
|
-
result.putInt("pageIndex", pageIndex);
|
|
296
|
-
result.putString("text", preview);
|
|
297
|
-
result.putInt("matchIndex", matchIndex++);
|
|
298
|
-
results.pushMap(result);
|
|
299
|
-
|
|
300
|
-
pos = lower.indexOf(normalizedQuery, pos + 1);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
promise.resolve(results);
|
|
305
|
-
} finally {
|
|
306
|
-
state.isSearching = false;
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
@ReactMethod
|
|
312
|
-
public void selectText(String engineId, int pageIndex, double x, double y, double width, double height, Promise promise) {
|
|
313
|
-
executor.execute(() -> {
|
|
314
|
-
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
315
|
-
if (state == null || state.document == null || pageIndex < 0) {
|
|
316
|
-
promise.resolve(null);
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
if (!PapyrusTextSelect.AVAILABLE) {
|
|
321
|
-
promise.resolve(null);
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
PapyrusTextSelection selection = null;
|
|
326
|
-
try {
|
|
327
|
-
if (state.sourcePath != null && !state.sourcePath.isEmpty()) {
|
|
328
|
-
synchronized (state.pdfiumLock) {
|
|
329
|
-
selection = PapyrusTextSelect.nativeSelectTextFile(state.sourcePath, pageIndex, (float) x, (float) y, (float) width, (float) height);
|
|
330
|
-
}
|
|
331
|
-
} else {
|
|
332
|
-
long docPtr;
|
|
333
|
-
synchronized (state.pdfiumLock) {
|
|
334
|
-
docPtr = extractNativeDocPointer(state.document);
|
|
335
|
-
}
|
|
336
|
-
if (docPtr != 0) {
|
|
337
|
-
synchronized (state.pdfiumLock) {
|
|
338
|
-
selection = PapyrusTextSelect.nativeSelectText(docPtr, pageIndex, (float) x, (float) y, (float) width, (float) height);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
} catch (Throwable ignored) {
|
|
343
|
-
selection = null;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (selection == null || selection.rects == null || selection.rects.length == 0) {
|
|
347
|
-
promise.resolve(null);
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
WritableMap result = Arguments.createMap();
|
|
352
|
-
result.putString("text", selection.text != null ? selection.text : "");
|
|
353
|
-
WritableArray rects = Arguments.createArray();
|
|
354
|
-
for (int i = 0; i + 3 < selection.rects.length; i += 4) {
|
|
355
|
-
WritableMap rect = Arguments.createMap();
|
|
356
|
-
rect.putDouble("x", selection.rects[i]);
|
|
357
|
-
rect.putDouble("y", selection.rects[i + 1]);
|
|
358
|
-
rect.putDouble("width", selection.rects[i + 2]);
|
|
359
|
-
rect.putDouble("height", selection.rects[i + 3]);
|
|
360
|
-
rects.pushMap(rect);
|
|
361
|
-
}
|
|
362
|
-
result.putArray("rects", rects);
|
|
363
|
-
promise.resolve(result);
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
private String extractPageText(PapyrusEngineStore.EngineState state, int pageIndex) {
|
|
368
|
-
try {
|
|
369
|
-
state.pdfium.openPage(state.document, pageIndex);
|
|
370
|
-
} catch (Throwable ignored) {
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
try {
|
|
374
|
-
java.lang.reflect.Method method = null;
|
|
375
|
-
try {
|
|
376
|
-
method = state.pdfium.getClass().getDeclaredMethod("getPageText", PdfDocument.class, int.class);
|
|
377
|
-
} catch (NoSuchMethodException ignored) {
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
if (method == null) {
|
|
381
|
-
try {
|
|
382
|
-
method = state.pdfium.getClass().getDeclaredMethod("nativeGetPageText", long.class, int.class);
|
|
383
|
-
} catch (NoSuchMethodException ignored) {
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (method != null) {
|
|
388
|
-
method.setAccessible(true);
|
|
389
|
-
Object result;
|
|
390
|
-
if (method.getParameterTypes().length == 2 && method.getParameterTypes()[0] == PdfDocument.class) {
|
|
391
|
-
result = method.invoke(state.pdfium, state.document, pageIndex);
|
|
392
|
-
} else if (method.getParameterTypes().length == 2 && method.getParameterTypes()[0] == long.class) {
|
|
393
|
-
long docPtr = extractNativeDocPointer(state.document);
|
|
394
|
-
result = method.invoke(state.pdfium, docPtr, pageIndex);
|
|
395
|
-
} else {
|
|
396
|
-
result = null;
|
|
397
|
-
}
|
|
398
|
-
return result != null ? result.toString() : "";
|
|
399
|
-
}
|
|
400
|
-
} catch (Throwable ignored) {
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
return "";
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
private long extractNativeDocPointer(PdfDocument document) {
|
|
407
|
-
try {
|
|
408
|
-
java.lang.reflect.Field field = PdfDocument.class.getDeclaredField("mNativeDocPtr");
|
|
409
|
-
field.setAccessible(true);
|
|
410
|
-
Object value = field.get(document);
|
|
411
|
-
if (value instanceof Long) {
|
|
412
|
-
return (Long) value;
|
|
413
|
-
}
|
|
414
|
-
} catch (Throwable ignored) {
|
|
415
|
-
}
|
|
416
|
-
return 0;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
private WritableMap serializeOutlineItem(PapyrusOutlineItem item) {
|
|
420
|
-
WritableMap map = Arguments.createMap();
|
|
421
|
-
map.putString("title", item.title != null ? item.title : "");
|
|
422
|
-
map.putInt("pageIndex", item.pageIndex);
|
|
423
|
-
if (item.children != null && item.children.length > 0) {
|
|
424
|
-
WritableArray children = Arguments.createArray();
|
|
425
|
-
for (PapyrusOutlineItem child : item.children) {
|
|
426
|
-
children.pushMap(serializeOutlineItem(child));
|
|
427
|
-
}
|
|
428
|
-
map.putArray("children", children);
|
|
429
|
-
}
|
|
430
|
-
return map;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
private static File materializeSource(ReadableMap source, Context context) throws IOException {
|
|
434
|
-
if (source.hasKey("uri") && source.getType("uri") == ReadableType.String) {
|
|
435
|
-
String uriString = source.getString("uri");
|
|
436
|
-
if (uriString == null) return null;
|
|
437
|
-
|
|
438
|
-
if (uriString.startsWith("http://") || uriString.startsWith("https://")) {
|
|
439
|
-
return downloadToCache(uriString, context);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
if (uriString.startsWith("asset:/")) {
|
|
443
|
-
return copyFromAsset(uriString.substring("asset:/".length()), context);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
if (uriString.startsWith("file:///android_asset/")) {
|
|
447
|
-
return copyFromAsset(uriString.substring("file:///android_asset/".length()), context);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if (uriString.startsWith("content://")) {
|
|
451
|
-
return copyFromContentUri(Uri.parse(uriString), context);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
if (uriString.startsWith("file://")) {
|
|
455
|
-
return new File(Uri.parse(uriString).getPath());
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
return new File(uriString);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if (source.hasKey("data") && source.getType("data") == ReadableType.Array) {
|
|
462
|
-
ReadableArray array = source.getArray("data");
|
|
463
|
-
if (array == null) return null;
|
|
464
|
-
byte[] bytes = new byte[array.size()];
|
|
465
|
-
for (int i = 0; i < array.size(); i++) {
|
|
466
|
-
bytes[i] = (byte) array.getInt(i);
|
|
467
|
-
}
|
|
468
|
-
return writeBytesToCache(bytes, context);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
return null;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
private static File downloadToCache(String uri, Context context) throws IOException {
|
|
475
|
-
URL url = new URL(uri);
|
|
476
|
-
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
477
|
-
connection.connect();
|
|
478
|
-
if (connection.getResponseCode() >= 400) {
|
|
479
|
-
throw new IOException("Failed to download PDF");
|
|
480
|
-
}
|
|
481
|
-
InputStream inputStream = connection.getInputStream();
|
|
482
|
-
File out = createTempFile(context);
|
|
483
|
-
writeStreamToFile(inputStream, out);
|
|
484
|
-
connection.disconnect();
|
|
485
|
-
return out;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
private static File copyFromContentUri(Uri uri, Context context) throws IOException {
|
|
489
|
-
ContentResolver resolver = context.getContentResolver();
|
|
490
|
-
InputStream inputStream = resolver.openInputStream(uri);
|
|
491
|
-
if (inputStream == null) throw new IOException("Unable to read content URI");
|
|
492
|
-
File out = createTempFile(context);
|
|
493
|
-
writeStreamToFile(inputStream, out);
|
|
494
|
-
return out;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
private static File copyFromAsset(String assetPath, Context context) throws IOException {
|
|
498
|
-
InputStream inputStream = context.getAssets().open(assetPath);
|
|
499
|
-
File out = createTempFile(context);
|
|
500
|
-
writeStreamToFile(inputStream, out);
|
|
501
|
-
return out;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
private static File writeBytesToCache(byte[] bytes, Context context) throws IOException {
|
|
505
|
-
File out = createTempFile(context);
|
|
506
|
-
FileOutputStream fos = new FileOutputStream(out);
|
|
507
|
-
fos.write(bytes);
|
|
508
|
-
fos.flush();
|
|
509
|
-
fos.close();
|
|
510
|
-
return out;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
private static File createTempFile(Context context) throws IOException {
|
|
514
|
-
File cacheDir = context.getCacheDir();
|
|
515
|
-
return File.createTempFile("papyrus", ".pdf", cacheDir);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
private static void writeStreamToFile(InputStream inputStream, File out) throws IOException {
|
|
519
|
-
FileOutputStream fos = new FileOutputStream(out);
|
|
520
|
-
byte[] buffer = new byte[8192];
|
|
521
|
-
int read;
|
|
522
|
-
while ((read = inputStream.read(buffer)) != -1) {
|
|
523
|
-
fos.write(buffer, 0, read);
|
|
524
|
-
}
|
|
525
|
-
fos.flush();
|
|
526
|
-
fos.close();
|
|
527
|
-
inputStream.close();
|
|
528
|
-
}
|
|
529
|
-
}
|
|
1
|
+
package com.papyrus.engine;
|
|
2
|
+
|
|
3
|
+
import android.content.ContentResolver;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.net.Uri;
|
|
6
|
+
import android.os.ParcelFileDescriptor;
|
|
7
|
+
import android.view.View;
|
|
8
|
+
|
|
9
|
+
import com.facebook.react.bridge.Arguments;
|
|
10
|
+
import com.facebook.react.bridge.Promise;
|
|
11
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
12
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
13
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
14
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
15
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
16
|
+
import com.facebook.react.bridge.WritableArray;
|
|
17
|
+
import com.facebook.react.bridge.WritableMap;
|
|
18
|
+
import com.facebook.react.bridge.ReadableType;
|
|
19
|
+
import com.facebook.react.uimanager.UIBlock;
|
|
20
|
+
import com.facebook.react.uimanager.UIManagerModule;
|
|
21
|
+
|
|
22
|
+
import com.shockwave.pdfium.PdfDocument;
|
|
23
|
+
|
|
24
|
+
import java.io.File;
|
|
25
|
+
import java.io.FileOutputStream;
|
|
26
|
+
import java.io.IOException;
|
|
27
|
+
import java.io.InputStream;
|
|
28
|
+
import java.net.HttpURLConnection;
|
|
29
|
+
import java.net.URL;
|
|
30
|
+
import java.util.concurrent.ExecutorService;
|
|
31
|
+
import java.util.concurrent.Executors;
|
|
32
|
+
|
|
33
|
+
public class PapyrusNativeEngineModule extends ReactContextBaseJavaModule {
|
|
34
|
+
private final ReactApplicationContext reactContext;
|
|
35
|
+
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
36
|
+
|
|
37
|
+
public PapyrusNativeEngineModule(ReactApplicationContext reactContext) {
|
|
38
|
+
super(reactContext);
|
|
39
|
+
this.reactContext = reactContext;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Override
|
|
43
|
+
public String getName() {
|
|
44
|
+
return "PapyrusNativeEngine";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
48
|
+
public String createEngine() {
|
|
49
|
+
return PapyrusEngineStore.createEngine(reactContext);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@ReactMethod
|
|
53
|
+
public void destroyEngine(String engineId) {
|
|
54
|
+
PapyrusEngineStore.destroyEngine(engineId);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@ReactMethod
|
|
58
|
+
public void load(final String engineId, final ReadableMap source, final Promise promise) {
|
|
59
|
+
executor.execute(() -> {
|
|
60
|
+
try {
|
|
61
|
+
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
62
|
+
if (state == null) {
|
|
63
|
+
promise.reject("papyrus_no_engine", "Engine not found");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
File file = materializeSource(source, reactContext);
|
|
68
|
+
if (file == null) {
|
|
69
|
+
promise.reject("papyrus_invalid_source", "Unsupported PDF source");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
ParcelFileDescriptor fd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
|
|
74
|
+
PdfDocument document = state.pdfium.newDocument(fd);
|
|
75
|
+
PapyrusEngineStore.setDocument(state, document, fd, file.getAbsolutePath());
|
|
76
|
+
|
|
77
|
+
int pageCount = state.pdfium.getPageCount(document);
|
|
78
|
+
WritableMap result = Arguments.createMap();
|
|
79
|
+
result.putInt("pageCount", pageCount);
|
|
80
|
+
promise.resolve(result);
|
|
81
|
+
} catch (Throwable error) {
|
|
82
|
+
promise.reject("papyrus_load_failed", error);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
88
|
+
public int getPageCount(String engineId) {
|
|
89
|
+
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
90
|
+
if (state == null || state.document == null) return 0;
|
|
91
|
+
return state.pdfium.getPageCount(state.document);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@ReactMethod
|
|
95
|
+
public void renderPage(final String engineId, final int pageIndex, final int target, final float scale, final float zoom, final int rotation) {
|
|
96
|
+
final PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
97
|
+
if (state == null) return;
|
|
98
|
+
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
|
99
|
+
if (uiManager == null) return;
|
|
100
|
+
|
|
101
|
+
uiManager.addUIBlock(new UIBlock() {
|
|
102
|
+
@Override
|
|
103
|
+
public void execute(com.facebook.react.uimanager.NativeViewHierarchyManager nativeViewHierarchyManager) {
|
|
104
|
+
View view = nativeViewHierarchyManager.resolveView(target);
|
|
105
|
+
if (view instanceof PapyrusPageView) {
|
|
106
|
+
((PapyrusPageView) view).render(state, pageIndex, scale, zoom, rotation);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@ReactMethod
|
|
113
|
+
public void renderTextLayer(String engineId, int pageIndex, int target, float scale, float zoom, int rotation) {
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@ReactMethod
|
|
117
|
+
public void getTextContent(String engineId, int pageIndex, Promise promise) {
|
|
118
|
+
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
119
|
+
if (state == null || state.document == null) {
|
|
120
|
+
promise.resolve(Arguments.createArray());
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
String text;
|
|
124
|
+
synchronized (state.pdfiumLock) {
|
|
125
|
+
text = extractPageText(state, pageIndex);
|
|
126
|
+
}
|
|
127
|
+
WritableArray items = Arguments.createArray();
|
|
128
|
+
if (text != null && !text.isEmpty()) {
|
|
129
|
+
WritableMap item = Arguments.createMap();
|
|
130
|
+
item.putString("str", text);
|
|
131
|
+
item.putString("dir", "ltr");
|
|
132
|
+
item.putDouble("width", 0);
|
|
133
|
+
item.putDouble("height", 0);
|
|
134
|
+
WritableArray transform = Arguments.createArray();
|
|
135
|
+
transform.pushDouble(1);
|
|
136
|
+
transform.pushDouble(0);
|
|
137
|
+
transform.pushDouble(0);
|
|
138
|
+
transform.pushDouble(1);
|
|
139
|
+
transform.pushDouble(0);
|
|
140
|
+
transform.pushDouble(0);
|
|
141
|
+
item.putArray("transform", transform);
|
|
142
|
+
item.putString("fontName", "");
|
|
143
|
+
items.pushMap(item);
|
|
144
|
+
}
|
|
145
|
+
promise.resolve(items);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@ReactMethod
|
|
149
|
+
public void getPageDimensions(String engineId, int pageIndex, Promise promise) {
|
|
150
|
+
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
151
|
+
if (state == null || state.document == null) {
|
|
152
|
+
WritableMap result = Arguments.createMap();
|
|
153
|
+
result.putInt("width", 0);
|
|
154
|
+
result.putInt("height", 0);
|
|
155
|
+
promise.resolve(result);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
int width;
|
|
159
|
+
int height;
|
|
160
|
+
synchronized (state.pdfiumLock) {
|
|
161
|
+
width = state.pdfium.getPageWidthPoint(state.document, pageIndex);
|
|
162
|
+
height = state.pdfium.getPageHeightPoint(state.document, pageIndex);
|
|
163
|
+
}
|
|
164
|
+
WritableMap result = Arguments.createMap();
|
|
165
|
+
result.putInt("width", width);
|
|
166
|
+
result.putInt("height", height);
|
|
167
|
+
promise.resolve(result);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@ReactMethod
|
|
171
|
+
public void getOutline(String engineId, Promise promise) {
|
|
172
|
+
executor.execute(() -> {
|
|
173
|
+
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
174
|
+
if (state == null || state.document == null) {
|
|
175
|
+
promise.resolve(Arguments.createArray());
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
PapyrusOutlineItem[] items = null;
|
|
180
|
+
try {
|
|
181
|
+
if (PapyrusOutline.AVAILABLE) {
|
|
182
|
+
if (state.sourcePath != null && !state.sourcePath.isEmpty()) {
|
|
183
|
+
synchronized (state.pdfiumLock) {
|
|
184
|
+
items = PapyrusOutline.nativeGetOutlineFile(state.sourcePath);
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
long docPtr;
|
|
188
|
+
synchronized (state.pdfiumLock) {
|
|
189
|
+
docPtr = extractNativeDocPointer(state.document);
|
|
190
|
+
}
|
|
191
|
+
if (docPtr != 0) {
|
|
192
|
+
synchronized (state.pdfiumLock) {
|
|
193
|
+
items = PapyrusOutline.nativeGetOutline(docPtr);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
} catch (Throwable ignored) {
|
|
199
|
+
items = null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
WritableArray result = Arguments.createArray();
|
|
203
|
+
if (items != null) {
|
|
204
|
+
for (PapyrusOutlineItem item : items) {
|
|
205
|
+
result.pushMap(serializeOutlineItem(item));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
promise.resolve(result);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@ReactMethod
|
|
213
|
+
public void getPageIndex(String engineId, Object dest, Promise promise) {
|
|
214
|
+
promise.resolve(null);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
@ReactMethod
|
|
218
|
+
public void searchText(String engineId, String query, Promise promise) {
|
|
219
|
+
executor.execute(() -> {
|
|
220
|
+
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
221
|
+
if (state == null || state.document == null || query == null || query.length() < 2) {
|
|
222
|
+
promise.resolve(Arguments.createArray());
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
int pageCount = state.pdfium.getPageCount(state.document);
|
|
227
|
+
state.isSearching = true;
|
|
228
|
+
try {
|
|
229
|
+
try {
|
|
230
|
+
if (PapyrusTextSearch.AVAILABLE) {
|
|
231
|
+
PapyrusTextHit[] hits = null;
|
|
232
|
+
if (state.sourcePath != null && !state.sourcePath.isEmpty()) {
|
|
233
|
+
synchronized (state.pdfiumLock) {
|
|
234
|
+
hits = PapyrusTextSearch.nativeSearchFile(state.sourcePath, query);
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
long docPtr;
|
|
238
|
+
synchronized (state.pdfiumLock) {
|
|
239
|
+
docPtr = extractNativeDocPointer(state.document);
|
|
240
|
+
}
|
|
241
|
+
if (docPtr != 0) {
|
|
242
|
+
synchronized (state.pdfiumLock) {
|
|
243
|
+
hits = PapyrusTextSearch.nativeSearch(docPtr, pageCount, query);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (hits != null && hits.length > 0) {
|
|
249
|
+
WritableArray results = Arguments.createArray();
|
|
250
|
+
for (PapyrusTextHit hit : hits) {
|
|
251
|
+
WritableMap result = Arguments.createMap();
|
|
252
|
+
result.putInt("pageIndex", hit.pageIndex);
|
|
253
|
+
result.putString("text", hit.text != null ? hit.text : query);
|
|
254
|
+
result.putInt("matchIndex", hit.matchIndex);
|
|
255
|
+
if (hit.rects != null && hit.rects.length >= 4) {
|
|
256
|
+
WritableArray rects = Arguments.createArray();
|
|
257
|
+
for (int i = 0; i + 3 < hit.rects.length; i += 4) {
|
|
258
|
+
WritableMap rect = Arguments.createMap();
|
|
259
|
+
rect.putDouble("x", hit.rects[i]);
|
|
260
|
+
rect.putDouble("y", hit.rects[i + 1]);
|
|
261
|
+
rect.putDouble("width", hit.rects[i + 2]);
|
|
262
|
+
rect.putDouble("height", hit.rects[i + 3]);
|
|
263
|
+
rects.pushMap(rect);
|
|
264
|
+
}
|
|
265
|
+
result.putArray("rects", rects);
|
|
266
|
+
}
|
|
267
|
+
results.pushMap(result);
|
|
268
|
+
}
|
|
269
|
+
promise.resolve(results);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} catch (Throwable ignored) {
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
String normalizedQuery = query.toLowerCase();
|
|
277
|
+
WritableArray results = Arguments.createArray();
|
|
278
|
+
|
|
279
|
+
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
|
|
280
|
+
String text;
|
|
281
|
+
synchronized (state.pdfiumLock) {
|
|
282
|
+
text = extractPageText(state, pageIndex);
|
|
283
|
+
}
|
|
284
|
+
if (text == null || text.isEmpty()) continue;
|
|
285
|
+
|
|
286
|
+
String lower = text.toLowerCase();
|
|
287
|
+
int pos = lower.indexOf(normalizedQuery);
|
|
288
|
+
int matchIndex = 0;
|
|
289
|
+
while (pos != -1) {
|
|
290
|
+
int start = Math.max(0, pos - 20);
|
|
291
|
+
int end = Math.min(text.length(), pos + normalizedQuery.length() + 20);
|
|
292
|
+
String preview = text.substring(start, end);
|
|
293
|
+
|
|
294
|
+
WritableMap result = Arguments.createMap();
|
|
295
|
+
result.putInt("pageIndex", pageIndex);
|
|
296
|
+
result.putString("text", preview);
|
|
297
|
+
result.putInt("matchIndex", matchIndex++);
|
|
298
|
+
results.pushMap(result);
|
|
299
|
+
|
|
300
|
+
pos = lower.indexOf(normalizedQuery, pos + 1);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
promise.resolve(results);
|
|
305
|
+
} finally {
|
|
306
|
+
state.isSearching = false;
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@ReactMethod
|
|
312
|
+
public void selectText(String engineId, int pageIndex, double x, double y, double width, double height, Promise promise) {
|
|
313
|
+
executor.execute(() -> {
|
|
314
|
+
PapyrusEngineStore.EngineState state = PapyrusEngineStore.getEngine(engineId);
|
|
315
|
+
if (state == null || state.document == null || pageIndex < 0) {
|
|
316
|
+
promise.resolve(null);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (!PapyrusTextSelect.AVAILABLE) {
|
|
321
|
+
promise.resolve(null);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
PapyrusTextSelection selection = null;
|
|
326
|
+
try {
|
|
327
|
+
if (state.sourcePath != null && !state.sourcePath.isEmpty()) {
|
|
328
|
+
synchronized (state.pdfiumLock) {
|
|
329
|
+
selection = PapyrusTextSelect.nativeSelectTextFile(state.sourcePath, pageIndex, (float) x, (float) y, (float) width, (float) height);
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
long docPtr;
|
|
333
|
+
synchronized (state.pdfiumLock) {
|
|
334
|
+
docPtr = extractNativeDocPointer(state.document);
|
|
335
|
+
}
|
|
336
|
+
if (docPtr != 0) {
|
|
337
|
+
synchronized (state.pdfiumLock) {
|
|
338
|
+
selection = PapyrusTextSelect.nativeSelectText(docPtr, pageIndex, (float) x, (float) y, (float) width, (float) height);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
} catch (Throwable ignored) {
|
|
343
|
+
selection = null;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (selection == null || selection.rects == null || selection.rects.length == 0) {
|
|
347
|
+
promise.resolve(null);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
WritableMap result = Arguments.createMap();
|
|
352
|
+
result.putString("text", selection.text != null ? selection.text : "");
|
|
353
|
+
WritableArray rects = Arguments.createArray();
|
|
354
|
+
for (int i = 0; i + 3 < selection.rects.length; i += 4) {
|
|
355
|
+
WritableMap rect = Arguments.createMap();
|
|
356
|
+
rect.putDouble("x", selection.rects[i]);
|
|
357
|
+
rect.putDouble("y", selection.rects[i + 1]);
|
|
358
|
+
rect.putDouble("width", selection.rects[i + 2]);
|
|
359
|
+
rect.putDouble("height", selection.rects[i + 3]);
|
|
360
|
+
rects.pushMap(rect);
|
|
361
|
+
}
|
|
362
|
+
result.putArray("rects", rects);
|
|
363
|
+
promise.resolve(result);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
private String extractPageText(PapyrusEngineStore.EngineState state, int pageIndex) {
|
|
368
|
+
try {
|
|
369
|
+
state.pdfium.openPage(state.document, pageIndex);
|
|
370
|
+
} catch (Throwable ignored) {
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
try {
|
|
374
|
+
java.lang.reflect.Method method = null;
|
|
375
|
+
try {
|
|
376
|
+
method = state.pdfium.getClass().getDeclaredMethod("getPageText", PdfDocument.class, int.class);
|
|
377
|
+
} catch (NoSuchMethodException ignored) {
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (method == null) {
|
|
381
|
+
try {
|
|
382
|
+
method = state.pdfium.getClass().getDeclaredMethod("nativeGetPageText", long.class, int.class);
|
|
383
|
+
} catch (NoSuchMethodException ignored) {
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (method != null) {
|
|
388
|
+
method.setAccessible(true);
|
|
389
|
+
Object result;
|
|
390
|
+
if (method.getParameterTypes().length == 2 && method.getParameterTypes()[0] == PdfDocument.class) {
|
|
391
|
+
result = method.invoke(state.pdfium, state.document, pageIndex);
|
|
392
|
+
} else if (method.getParameterTypes().length == 2 && method.getParameterTypes()[0] == long.class) {
|
|
393
|
+
long docPtr = extractNativeDocPointer(state.document);
|
|
394
|
+
result = method.invoke(state.pdfium, docPtr, pageIndex);
|
|
395
|
+
} else {
|
|
396
|
+
result = null;
|
|
397
|
+
}
|
|
398
|
+
return result != null ? result.toString() : "";
|
|
399
|
+
}
|
|
400
|
+
} catch (Throwable ignored) {
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return "";
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
private long extractNativeDocPointer(PdfDocument document) {
|
|
407
|
+
try {
|
|
408
|
+
java.lang.reflect.Field field = PdfDocument.class.getDeclaredField("mNativeDocPtr");
|
|
409
|
+
field.setAccessible(true);
|
|
410
|
+
Object value = field.get(document);
|
|
411
|
+
if (value instanceof Long) {
|
|
412
|
+
return (Long) value;
|
|
413
|
+
}
|
|
414
|
+
} catch (Throwable ignored) {
|
|
415
|
+
}
|
|
416
|
+
return 0;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private WritableMap serializeOutlineItem(PapyrusOutlineItem item) {
|
|
420
|
+
WritableMap map = Arguments.createMap();
|
|
421
|
+
map.putString("title", item.title != null ? item.title : "");
|
|
422
|
+
map.putInt("pageIndex", item.pageIndex);
|
|
423
|
+
if (item.children != null && item.children.length > 0) {
|
|
424
|
+
WritableArray children = Arguments.createArray();
|
|
425
|
+
for (PapyrusOutlineItem child : item.children) {
|
|
426
|
+
children.pushMap(serializeOutlineItem(child));
|
|
427
|
+
}
|
|
428
|
+
map.putArray("children", children);
|
|
429
|
+
}
|
|
430
|
+
return map;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
private static File materializeSource(ReadableMap source, Context context) throws IOException {
|
|
434
|
+
if (source.hasKey("uri") && source.getType("uri") == ReadableType.String) {
|
|
435
|
+
String uriString = source.getString("uri");
|
|
436
|
+
if (uriString == null) return null;
|
|
437
|
+
|
|
438
|
+
if (uriString.startsWith("http://") || uriString.startsWith("https://")) {
|
|
439
|
+
return downloadToCache(uriString, context);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (uriString.startsWith("asset:/")) {
|
|
443
|
+
return copyFromAsset(uriString.substring("asset:/".length()), context);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (uriString.startsWith("file:///android_asset/")) {
|
|
447
|
+
return copyFromAsset(uriString.substring("file:///android_asset/".length()), context);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (uriString.startsWith("content://")) {
|
|
451
|
+
return copyFromContentUri(Uri.parse(uriString), context);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (uriString.startsWith("file://")) {
|
|
455
|
+
return new File(Uri.parse(uriString).getPath());
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return new File(uriString);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (source.hasKey("data") && source.getType("data") == ReadableType.Array) {
|
|
462
|
+
ReadableArray array = source.getArray("data");
|
|
463
|
+
if (array == null) return null;
|
|
464
|
+
byte[] bytes = new byte[array.size()];
|
|
465
|
+
for (int i = 0; i < array.size(); i++) {
|
|
466
|
+
bytes[i] = (byte) array.getInt(i);
|
|
467
|
+
}
|
|
468
|
+
return writeBytesToCache(bytes, context);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
private static File downloadToCache(String uri, Context context) throws IOException {
|
|
475
|
+
URL url = new URL(uri);
|
|
476
|
+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
477
|
+
connection.connect();
|
|
478
|
+
if (connection.getResponseCode() >= 400) {
|
|
479
|
+
throw new IOException("Failed to download PDF");
|
|
480
|
+
}
|
|
481
|
+
InputStream inputStream = connection.getInputStream();
|
|
482
|
+
File out = createTempFile(context);
|
|
483
|
+
writeStreamToFile(inputStream, out);
|
|
484
|
+
connection.disconnect();
|
|
485
|
+
return out;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
private static File copyFromContentUri(Uri uri, Context context) throws IOException {
|
|
489
|
+
ContentResolver resolver = context.getContentResolver();
|
|
490
|
+
InputStream inputStream = resolver.openInputStream(uri);
|
|
491
|
+
if (inputStream == null) throw new IOException("Unable to read content URI");
|
|
492
|
+
File out = createTempFile(context);
|
|
493
|
+
writeStreamToFile(inputStream, out);
|
|
494
|
+
return out;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
private static File copyFromAsset(String assetPath, Context context) throws IOException {
|
|
498
|
+
InputStream inputStream = context.getAssets().open(assetPath);
|
|
499
|
+
File out = createTempFile(context);
|
|
500
|
+
writeStreamToFile(inputStream, out);
|
|
501
|
+
return out;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
private static File writeBytesToCache(byte[] bytes, Context context) throws IOException {
|
|
505
|
+
File out = createTempFile(context);
|
|
506
|
+
FileOutputStream fos = new FileOutputStream(out);
|
|
507
|
+
fos.write(bytes);
|
|
508
|
+
fos.flush();
|
|
509
|
+
fos.close();
|
|
510
|
+
return out;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
private static File createTempFile(Context context) throws IOException {
|
|
514
|
+
File cacheDir = context.getCacheDir();
|
|
515
|
+
return File.createTempFile("papyrus", ".pdf", cacheDir);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
private static void writeStreamToFile(InputStream inputStream, File out) throws IOException {
|
|
519
|
+
FileOutputStream fos = new FileOutputStream(out);
|
|
520
|
+
byte[] buffer = new byte[8192];
|
|
521
|
+
int read;
|
|
522
|
+
while ((read = inputStream.read(buffer)) != -1) {
|
|
523
|
+
fos.write(buffer, 0, read);
|
|
524
|
+
}
|
|
525
|
+
fos.flush();
|
|
526
|
+
fos.close();
|
|
527
|
+
inputStream.close();
|
|
528
|
+
}
|
|
529
|
+
}
|