diff --git a/.github/config/ubuntu-22.04/conan/profiles/android-23-armv7 b/.github/config/ubuntu-22.04/conan/profiles/android-23-armv7
new file mode 100644
index 000000000000..e79b03eba947
--- /dev/null
+++ b/.github/config/ubuntu-22.04/conan/profiles/android-23-armv7
@@ -0,0 +1,35 @@
+{% set android_home = os.getenv("ANDROID_HOME") %}
+{% set ndk_version = "26.3.11579264" %}
+{% set api_level = "23" %}
+{% set arch = "armv7" %}
+{% set cc = {
+ "armv7": "armv7a-linux-androideabi" + api_level + "-clang",
+ "armv8": "aarch64-linux-android" + api_level + "-clang",
+ "x86": "i686-linux-android" + api_level + "-clang",
+ "x86_64": "x86_64-linux-android" + api_level + "-clang",
+}[arch] %}
+
+[settings]
+os=Android
+os.api_level={{api_level}}
+arch={{arch}}
+build_type=RelWithDebInfo
+compiler=clang
+compiler.version=17
+compiler.cppstd=20
+compiler.libcxx=c++_shared
+
+[conf]
+tools.android:ndk_path={{android_home}}/ndk/{{ndk_version}}
+
+[buildenv]
+# Cross compile toolchain evn vars are required to build
+# libffi, libgettext, libiconv, libxml2 and other autotools packages for Android
+# https://github.com/conan-io/conan/issues/16493
+AR={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
+AS={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-as
+RANLIB={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib
+CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/{{cc}}
+CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/{{cc}}++
+LD={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/ld
+STRIP={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
diff --git a/.github/config/ubuntu-22.04/conan/profiles/android-23-armv8 b/.github/config/ubuntu-22.04/conan/profiles/android-23-armv8
new file mode 100644
index 000000000000..f93c2b761bfc
--- /dev/null
+++ b/.github/config/ubuntu-22.04/conan/profiles/android-23-armv8
@@ -0,0 +1,35 @@
+{% set android_home = os.getenv("ANDROID_HOME") %}
+{% set ndk_version = "26.3.11579264" %}
+{% set api_level = "23" %}
+{% set arch = "armv8" %}
+{% set cc = {
+ "armv7": "armv7a-linux-androideabi" + api_level + "-clang",
+ "armv8": "aarch64-linux-android" + api_level + "-clang",
+ "x86": "i686-linux-android" + api_level + "-clang",
+ "x86_64": "x86_64-linux-android" + api_level + "-clang",
+}[arch] %}
+
+[settings]
+os=Android
+os.api_level={{api_level}}
+arch={{arch}}
+build_type=RelWithDebInfo
+compiler=clang
+compiler.version=17
+compiler.cppstd=20
+compiler.libcxx=c++_shared
+
+[conf]
+tools.android:ndk_path={{android_home}}/ndk/{{ndk_version}}
+
+[buildenv]
+# Cross compile toolchain evn vars are required to build
+# libffi, libgettext, libiconv, libxml2 and other autotools packages for Android
+# https://github.com/conan-io/conan/issues/16493
+AR={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
+AS={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-as
+RANLIB={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib
+CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/{{cc}}
+CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/{{cc}}++
+LD={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/ld
+STRIP={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
diff --git a/.github/config/ubuntu-22.04/conan/profiles/android-23-x86 b/.github/config/ubuntu-22.04/conan/profiles/android-23-x86
new file mode 100644
index 000000000000..e6fe7887b3fc
--- /dev/null
+++ b/.github/config/ubuntu-22.04/conan/profiles/android-23-x86
@@ -0,0 +1,35 @@
+{% set android_home = os.getenv("ANDROID_HOME") %}
+{% set ndk_version = "26.3.11579264" %}
+{% set api_level = "23" %}
+{% set arch = "x86" %}
+{% set cc = {
+ "armv7": "armv7a-linux-androideabi" + api_level + "-clang",
+ "armv8": "aarch64-linux-android" + api_level + "-clang",
+ "x86": "i686-linux-android" + api_level + "-clang",
+ "x86_64": "x86_64-linux-android" + api_level + "-clang",
+}[arch] %}
+
+[settings]
+os=Android
+os.api_level={{api_level}}
+arch={{arch}}
+build_type=RelWithDebInfo
+compiler=clang
+compiler.version=17
+compiler.cppstd=20
+compiler.libcxx=c++_shared
+
+[conf]
+tools.android:ndk_path={{android_home}}/ndk/{{ndk_version}}
+
+[buildenv]
+# Cross compile toolchain evn vars are required to build
+# libffi, libgettext, libiconv, libxml2 and other autotools packages for Android
+# https://github.com/conan-io/conan/issues/16493
+AR={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
+AS={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-as
+RANLIB={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib
+CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/{{cc}}
+CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/{{cc}}++
+LD={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/ld
+STRIP={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
diff --git a/.github/config/ubuntu-22.04/conan/profiles/android-23-x86_64 b/.github/config/ubuntu-22.04/conan/profiles/android-23-x86_64
new file mode 100644
index 000000000000..3a1e95bbd04c
--- /dev/null
+++ b/.github/config/ubuntu-22.04/conan/profiles/android-23-x86_64
@@ -0,0 +1,35 @@
+{% set android_home = os.getenv("ANDROID_HOME") %}
+{% set ndk_version = "26.3.11579264" %}
+{% set api_level = "23" %}
+{% set arch = "x86_64" %}
+{% set cc = {
+ "armv7": "armv7a-linux-androideabi" + api_level + "-clang",
+ "armv8": "aarch64-linux-android" + api_level + "-clang",
+ "x86": "i686-linux-android" + api_level + "-clang",
+ "x86_64": "x86_64-linux-android" + api_level + "-clang",
+}[arch] %}
+
+[settings]
+os=Android
+os.api_level={{api_level}}
+arch={{arch}}
+build_type=RelWithDebInfo
+compiler=clang
+compiler.version=17
+compiler.cppstd=20
+compiler.libcxx=c++_shared
+
+[conf]
+tools.android:ndk_path={{android_home}}/ndk/{{ndk_version}}
+
+[buildenv]
+# Cross compile toolchain evn vars are required to build
+# libffi, libgettext, libiconv, libxml2 and other autotools packages for Android
+# https://github.com/conan-io/conan/issues/16493
+AR={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
+AS={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-as
+RANLIB={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib
+CC={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/{{cc}}
+CXX={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/{{cc}}++
+LD={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/ld
+STRIP={{android_home}}/ndk/{{ndk_version}}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip
diff --git a/.github/config/ubuntu-22.04/conan/profiles/default b/.github/config/ubuntu-22.04/conan/profiles/default
new file mode 100644
index 000000000000..52cae59d6c82
--- /dev/null
+++ b/.github/config/ubuntu-22.04/conan/profiles/default
@@ -0,0 +1,11 @@
+[settings]
+os=Linux
+arch=x86_64
+build_type=Release
+compiler=gcc
+compiler.version=12
+compiler.cppstd=20
+compiler.libcxx=libstdc++11
+
+[conf]
+tools.build:compiler_executables={'c': 'gcc-12', 'cpp': 'g++-12'}
diff --git a/.github/config/ubuntu-22.04/conan/profiles/ubuntu b/.github/config/ubuntu-22.04/conan/profiles/ubuntu
new file mode 120000
index 000000000000..331d858ce9b1
--- /dev/null
+++ b/.github/config/ubuntu-22.04/conan/profiles/ubuntu
@@ -0,0 +1 @@
+default
\ No newline at end of file
diff --git a/.github/workflows/android_main.yml b/.github/workflows/android_main.yml
index 1f2a4a1dea61..e841ff0f7d60 100644
--- a/.github/workflows/android_main.yml
+++ b/.github/workflows/android_main.yml
@@ -43,8 +43,9 @@ jobs:
- name: conan remote
run: conan remote add odr https://artifactory.opendocument.app/artifactory/api/conan/conan
- - name: conan profile
- run: conan profile detect
+
+ - name: conan config
+ run: conan config install .github/config/ubuntu-22.04/conan
- name: gradle
run: ./gradlew assembleDebug lintProDebug lintLiteDebug --stacktrace
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index 700b05db2722..f1b7bbec25ec 100644
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.18.1)
-project(odr-droid CXX)
+project(odr-droid LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -13,3 +13,6 @@ target_include_directories(odr-core
PRIVATE src/main/cpp)
target_link_libraries(odr-core
PRIVATE odrcore::odrcore log)
+
+add_library(envvar SHARED src/main/cpp/EnvVar.c)
+set_target_properties(envvar PROPERTIES LINKER_LANGUAGE C)
diff --git a/app/build.gradle b/app/build.gradle
index 2b5d77c99308..852231ab24a1 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -1,5 +1,3 @@
-import org.apache.tools.ant.filters.ReplaceTokens
-
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
@@ -11,16 +9,9 @@ android {
ndkVersion "26.3.11579264"
}
-tasks.register('conanProfile', Copy) {
- from "conanprofile.txt"
- into project.layout.buildDirectory
- filter(ReplaceTokens, tokens: ["NDK_PATH": android.ndkDirectory.toString()])
-}
-
["armv8", "armv7", "x86", "x86_64"].each { architecture ->
tasks.named("conanInstall-" + architecture) {
- profile.set('build/conanprofile.txt')
- dependsOn(tasks.named('conanProfile'))
+ profile.set('../.github/config/ubuntu-22.04/conan/profiles/android-23-' + architecture)
}
}
@@ -40,13 +31,16 @@ android {
externalNativeBuild {
cmake {
- targets "odr-core"
+ targets "odr-core", "envvar"
arguments(
"-DCMAKE_TOOLCHAIN_FILE=build/conan/android_toolchain.cmake",
+ // We can migrate to static STL once all C++ deps are in conan and linked as one .so library
+ "-DANDROID_STL=c++_shared",
"-DCMAKE_BUILD_TYPE=RelWithDebInfo",
)
}
}
+ sourceSets.main.assets.srcDirs += "build/conan/armv8/assets"
}
flavorDimensions "default"
@@ -111,18 +105,25 @@ android {
lint {
abortOnError false
}
- packagingOptions {
- jniLibs {
- // No need to pickFirst libc++_shared.so if all files are identical.
- // They will be identical if NDK major version matches.
- // NDK runtime problems may occur if NDK version mismatches,
- // so comment this out, to get a compile error instead
- // pickFirsts += ['**/libc++_shared.so']
- }
- }
namespace 'at.tomtasche.reader'
}
+// Make sure the assets are installed when needed
+afterEvaluate {
+ tasks.named("generateProDebugAssets").configure {
+ dependsOn(tasks.named("conanInstall-armv8"))
+ }
+ tasks.named("generateProReleaseAssets").configure {
+ dependsOn(tasks.named("conanInstall-armv8"))
+ }
+ tasks.named("generateLiteDebugAssets").configure {
+ dependsOn(tasks.named("conanInstall-armv8"))
+ }
+ tasks.named("generateLiteReleaseAssets").configure {
+ dependsOn(tasks.named("conanInstall-armv8"))
+ }
+}
+
dependencies {
implementation platform('com.google.firebase:firebase-bom:33.1.1')
implementation 'com.google.firebase:firebase-storage'
@@ -140,8 +141,8 @@ dependencies {
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.webkit:webkit:1.11.0'
- implementation 'app.opendocument:pdf2htmlex-android:0.18.25'
- implementation 'com.viliussutkus89:wvware-android:1.2.9'
+ implementation 'com.viliussutkus89:fontconfig-android-translator:1.0.2'
+ implementation 'com.viliussutkus89:assetextractor-android:1.3.3'
implementation 'com.github.huzongyao:AndroidMagic:v1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
diff --git a/app/conanfile.py b/app/conanfile.py
new file mode 100644
index 000000000000..ce135298abc4
--- /dev/null
+++ b/app/conanfile.py
@@ -0,0 +1,30 @@
+import os
+
+from conan import ConanFile
+from conan.tools.cmake import CMakeToolchain, CMakeDeps
+
+required_conan_version = ">=2.0.6"
+
+
+class OdrDroidConan(ConanFile):
+ settings = "os", "compiler", "build_type", "arch"
+
+ def requirements(self):
+ self.requires("odrcore/4.1.0-pdf2htmlex-git", options={
+ "with_pdf2htmlEX": True,
+ "with_wvWare": True,
+ })
+
+ def generate(self):
+ deps = CMakeDeps(self)
+ deps.generate()
+
+ tc = CMakeToolchain(self)
+ tc.generate()
+
+ asset_dir = os.path.join(self.build_folder, 'assets')
+ os.mkdir(asset_dir)
+ os.symlink(self.dependencies['pdf2htmlex'].cpp_info.resdirs[0], os.path.join(asset_dir, 'pdf2htmlEX'))
+ os.symlink(self.dependencies['poppler-data'].cpp_info.resdirs[0], os.path.join(asset_dir, 'poppler-data'))
+ os.symlink(self.dependencies['fontconfig'].cpp_info.resdirs[0], os.path.join(asset_dir, 'fontconfig'))
+ os.symlink(self.dependencies['wvware'].cpp_info.resdirs[0], os.path.join(asset_dir, 'wv'))
diff --git a/app/conanfile.txt b/app/conanfile.txt
deleted file mode 100644
index cba437bbf759..000000000000
--- a/app/conanfile.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-[requires]
-odrcore/4.1.1@
-
-[generators]
-CMakeToolchain
-CMakeDeps
diff --git a/app/conanprofile.txt b/app/conanprofile.txt
deleted file mode 100644
index 4047180cb7b6..000000000000
--- a/app/conanprofile.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-include(default)
-
-[settings]
-os=Android
-os.api_level=23
-compiler=clang
-compiler.version=17
-compiler.cppstd=20
-compiler.libcxx=c++_shared
-build_type=RelWithDebInfo
-
-[conf]
-tools.android:ndk_path=@NDK_PATH@
-tools.build:skip_test=True
diff --git a/app/src/main/assets/etc/fonts/local.conf b/app/src/main/assets/etc/fonts/local.conf
new file mode 100644
index 000000000000..4c88aab7143b
--- /dev/null
+++ b/app/src/main/assets/etc/fonts/local.conf
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+ Load Android font files from /system/fonts
+ /system/fonts
+
+ system-etc-fonts-xml-translated.conf
+
+ ../../share/fonts
+
+
+ Symbol
+ Standard Symbols L
+
+
+
+ Zapf Dingbats
+ Dingbats
+
+
+
diff --git a/app/src/main/assets/share/fonts/COPYING b/app/src/main/assets/share/fonts/COPYING
new file mode 100644
index 000000000000..a43ea2126fb6
--- /dev/null
+++ b/app/src/main/assets/share/fonts/COPYING
@@ -0,0 +1,339 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 675 Mass Ave, Cambridge, MA 02139, USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ Appendix: How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C) 19yy
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) 19yy name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ , 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/app/src/main/assets/share/fonts/README b/app/src/main/assets/share/fonts/README
new file mode 100644
index 000000000000..0f94fd688f75
--- /dev/null
+++ b/app/src/main/assets/share/fonts/README
@@ -0,0 +1,10 @@
+This package contains two fonts:
+
+ s050000l.pfb -- Symbol
+ d050000l.pfb -- Zapf Dingbats
+
+These fonts are substitutes for the corresponding Base-14 fonts. They
+are part of the font set contributed to the ghostscript project by
+URW++ Design and Development Incorporated of Hamburg, Germany
+(http://www.urwpp.de/). They have been released under the GNU General
+Public License (GPL) v2 -- see the "COPYING" file.
diff --git a/app/src/main/assets/share/fonts/d050000l.pfb b/app/src/main/assets/share/fonts/d050000l.pfb
new file mode 100755
index 000000000000..4a3c386d292d
Binary files /dev/null and b/app/src/main/assets/share/fonts/d050000l.pfb differ
diff --git a/app/src/main/assets/share/fonts/s050000l.pfb b/app/src/main/assets/share/fonts/s050000l.pfb
new file mode 100644
index 000000000000..d0505e46cd55
Binary files /dev/null and b/app/src/main/assets/share/fonts/s050000l.pfb differ
diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp
index 80173c6ea84b..e25b1bf2be75 100644
--- a/app/src/main/cpp/CoreWrapper.cpp
+++ b/app/src/main/cpp/CoreWrapper.cpp
@@ -68,6 +68,12 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject
jfieldID txtField = env->GetFieldID(optionsClass, "txt", "Z");
jboolean txt = env->GetBooleanField(options, txtField);
+ jfieldID pdf2htmlEXField = env->GetFieldID(optionsClass, "pdf2htmlEX", "Z");
+ jboolean pdf2htmlEX = env->GetBooleanField(options, pdf2htmlEXField);
+
+ jfieldID wvWareField = env->GetFieldID(optionsClass, "wvWare", "Z");
+ jboolean wvWare = env->GetBooleanField(options, wvWareField);
+
jfieldID pagingField = env->GetFieldID(optionsClass, "paging", "Z");
jboolean paging = env->GetBooleanField(options, pagingField);
@@ -119,12 +125,20 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject
config.text_document_margin = true;
}
- html = odr::OpenDocumentReader::html(inputPathCpp, [&passwordCpp]() -> std::string {
- if (passwordCpp.has_value()) {
- return passwordCpp.value();
- }
- return "";
- }, outputPathCpp, config);
+ if (pdf2htmlEX) {
+ html = odr::OpenDocumentReader::pdf2htmlEX(inputPathCpp, outputPathCpp, config, passwordCpp);
+ }
+ else if (wvWare) {
+ html = odr::OpenDocumentReader::wvHtml(inputPathCpp, outputPathCpp, config, passwordCpp);
+ }
+ else {
+ html = odr::OpenDocumentReader::html(inputPathCpp, [&passwordCpp]() -> std::string {
+ if (passwordCpp.has_value()) {
+ return passwordCpp.value();
+ }
+ return "";
+ }, outputPathCpp, config);
+ }
{
const auto extensionCpp = odr::OpenDocumentReader::type_to_string(
diff --git a/app/src/main/cpp/EnvVar.c b/app/src/main/cpp/EnvVar.c
new file mode 100644
index 000000000000..c20e2c0527f9
--- /dev/null
+++ b/app/src/main/cpp/EnvVar.c
@@ -0,0 +1,12 @@
+#include
+#include
+
+JNIEXPORT void JNICALL
+Java_app_opendocument_android_pdf2htmlex_EnvVar_set(JNIEnv *env, __attribute__((unused)) jclass clazz,
+ jstring key, jstring value) {
+ const char *key_c = (*env)->GetStringUTFChars(env, key, JNI_FALSE);
+ const char *value_c = (*env)->GetStringUTFChars(env, value, JNI_FALSE);
+ setenv(key_c, value_c, 1);
+ (*env)->ReleaseStringUTFChars(env, value, value_c);
+ (*env)->ReleaseStringUTFChars(env, key, key_c);
+}
diff --git a/app/src/main/java/app/opendocument/android/pdf2htmlex/EnvVar.java b/app/src/main/java/app/opendocument/android/pdf2htmlex/EnvVar.java
new file mode 100644
index 000000000000..c060eb389dcd
--- /dev/null
+++ b/app/src/main/java/app/opendocument/android/pdf2htmlex/EnvVar.java
@@ -0,0 +1,8 @@
+package app.opendocument.android.pdf2htmlex;
+
+public final class EnvVar {
+ static {
+ System.loadLibrary("envvar");
+ }
+ public static native void set(String key, String value);
+}
diff --git a/app/src/main/java/app/opendocument/android/pdf2htmlex/FontconfigAndroid.java b/app/src/main/java/app/opendocument/android/pdf2htmlex/FontconfigAndroid.java
new file mode 100644
index 000000000000..861663ec80b0
--- /dev/null
+++ b/app/src/main/java/app/opendocument/android/pdf2htmlex/FontconfigAndroid.java
@@ -0,0 +1,34 @@
+package app.opendocument.android.pdf2htmlex;
+
+import android.content.res.AssetManager;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
+import com.viliussutkus89.android.assetextractor.AssetExtractor;
+import com.viliussutkus89.android.fontconfigtranslator.FontconfigTranslator;
+
+import java.io.File;
+
+
+public final class FontconfigAndroid {
+ public static void init(@NonNull AssetManager assetManager, @NonNull File cacheDir, @NonNull File filesDir) {
+ File xdgCache = new File(cacheDir, "xdg-cache");
+ xdgCache.mkdir();
+ EnvVar.set("XDG_CACHE_HOME", xdgCache.getAbsolutePath());
+
+ AssetExtractor ae = new AssetExtractor(assetManager).setNoOverwrite();
+ File fontsConfigDir = ae.extract(new File(filesDir, "etc"), "fontconfig/fontconfig/conf.avail");
+ ae.extract(fontsConfigDir, "etc/fonts/local.conf");
+ EnvVar.set("FONTCONFIG_PATH", fontsConfigDir.getAbsolutePath());
+
+ ae.extract(new File(filesDir, "share"), "share/fonts");
+
+ try {
+ File fontconfigGeneratedXml = new File(fontsConfigDir, "system-etc-fonts-xml-translated.conf");
+ FontconfigTranslator.translate(fontconfigGeneratedXml);
+ } catch (Exception e) {
+ Log.e("Fontconfig", "Fontconfig translator failed: ", e);
+ }
+ }
+}
diff --git a/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java b/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java
index eeceebe9bc0c..6297e156f147 100644
--- a/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java
+++ b/app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java
@@ -82,6 +82,8 @@ public static class CoreOptions {
public boolean ooxml;
public boolean txt;
+ public boolean pdf2htmlEX;
+ public boolean wvWare;
public boolean editable;
diff --git a/app/src/main/java/at/tomtasche/reader/background/DocLoader.java b/app/src/main/java/at/tomtasche/reader/background/DocLoader.java
index d66c7e5e0908..edd1566b59aa 100644
--- a/app/src/main/java/at/tomtasche/reader/background/DocLoader.java
+++ b/app/src/main/java/at/tomtasche/reader/background/DocLoader.java
@@ -2,13 +2,19 @@
import android.content.Context;
import android.net.Uri;
+import android.webkit.MimeTypeMap;
-import com.viliussutkus89.android.wvware.wvWare;
+import com.viliussutkus89.android.assetextractor.AssetExtractor;
import java.io.File;
+import app.opendocument.android.pdf2htmlex.EnvVar;
+
public class DocLoader extends FileLoader {
+ private CoreWrapper lastCore;
+ private CoreWrapper.CoreOptions lastCoreOptions;
+
public DocLoader(Context context) {
super(context, LoaderType.DOC);
}
@@ -18,43 +24,90 @@ public boolean isSupported(Options options) {
return options.fileType.startsWith("application/msword");
}
- @Override
public void loadSync(Options options) {
+ AssetExtractor ae = new AssetExtractor(context.getAssets()).setNoOverwrite();
+
+ // @TODO: use asset files without extracting
+ File wv_data_dir = ae.extract(context.getFilesDir(), "wv");
+ EnvVar.set("WVDATADIR", wv_data_dir.getAbsolutePath());
+
final Result result = new Result();
result.options = options;
result.loaderType = type;
try {
- File cacheFile = AndroidFileCache.getCacheFile(context, options.cacheUri);
- File cacheDirectory = AndroidFileCache.getCacheDirectory(cacheFile);
-
- wvWare docConverter = new wvWare(context).setInputDOC(cacheFile);
- if (options.password != null) {
- docConverter.setPassword(options.password);
+ translate(options, result);
+ callOnSuccess(result);
+ } catch (Throwable e) {
+ if (e instanceof CoreWrapper.CoreEncryptedException) {
+ e = new EncryptedDocumentException();
}
- File output = docConverter.convertToHTML();
+ callOnError(result, e);
+ }
+ }
- File htmlFile = new File(cacheDirectory, "doc.html");
- StreamUtil.copy(output, htmlFile);
+ private void translate(Options options, Result result) throws Exception {
+ File cachedFile = AndroidFileCache.getCacheFile(context, options.cacheUri);
- // library does not delete output files automatically
- output.delete();
+ if (lastCore != null) {
+ lastCore.close();
+ lastCore = null;
+ }
- Uri finalUri = Uri.fromFile(htmlFile);
+ CoreWrapper core = new CoreWrapper();
+ try {
+ core.initialize();
- options.fileType = "application/msword";
+ lastCore = core;
+ } catch (Throwable e) {
+ crashManager.log(e);
+ }
- result.partTitles.add(null);
- result.partUris.add(finalUri);
+ File cacheDirectory = AndroidFileCache.getCacheDirectory(cachedFile);
- callOnSuccess(result);
- } catch (Throwable e) {
- if (e instanceof wvWare.PasswordRequiredException || e instanceof wvWare.WrongPasswordException) {
- e = new EncryptedDocumentException();
+ CoreWrapper.CoreOptions coreOptions = new CoreWrapper.CoreOptions();
+ coreOptions.inputPath = cachedFile.getPath();
+ coreOptions.outputPath = cacheDirectory.getPath();
+ coreOptions.password = options.password;
+ coreOptions.editable = options.translatable;
+ coreOptions.ooxml = false;
+ coreOptions.wvWare = true;
+
+ lastCoreOptions = coreOptions;
+
+ CoreWrapper.CoreResult coreResult = lastCore.parse(coreOptions);
+
+ String coreExtension = coreResult.extension;
+ // "unnamed" refers to default of Meta::typeToString
+ if (coreExtension != null && !coreExtension.equals("unnamed")) {
+ options.fileExtension = coreExtension;
+
+ String fileType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(coreExtension);
+ if (fileType != null) {
+ options.fileType = fileType;
}
+ }
- callOnError(result, e);
+ if (coreResult.exception != null) {
+ throw coreResult.exception;
+ }
+
+ for (int i = 0; i < coreResult.pagePaths.size(); i++) {
+ File entryFile = new File(coreResult.pagePaths.get(i));
+
+ result.partTitles.add(coreResult.pageNames.get(i));
+ result.partUris.add(Uri.fromFile(entryFile));
+ }
+ }
+
+ @Override
+ public void close() {
+ super.close();
+
+ if (lastCore != null) {
+ lastCore.close();
+ lastCore = null;
}
}
}
diff --git a/app/src/main/java/at/tomtasche/reader/background/LoaderService.java b/app/src/main/java/at/tomtasche/reader/background/LoaderService.java
index 679be70f2835..f2abd53c4804 100644
--- a/app/src/main/java/at/tomtasche/reader/background/LoaderService.java
+++ b/app/src/main/java/at/tomtasche/reader/background/LoaderService.java
@@ -64,7 +64,7 @@ public synchronized void onCreate() {
odfLoader = new OdfLoader(context, configManager);
odfLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
- pdfLoader = new PdfLoader(context);
+ pdfLoader = new PdfLoader(context, configManager);
pdfLoader.initialize(this, mainHandler, backgroundHandler, analyticsManager, crashManager);
ooxmlLoader = new OoxmlLoader(context);
diff --git a/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java b/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java
index e3c931dd2a17..716932d83f73 100644
--- a/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java
+++ b/app/src/main/java/at/tomtasche/reader/background/OdfLoader.java
@@ -4,8 +4,12 @@
import android.net.Uri;
import android.webkit.MimeTypeMap;
+import com.viliussutkus89.android.assetextractor.AssetExtractor;
+
import java.io.File;
+import app.opendocument.android.pdf2htmlex.EnvVar;
+import app.opendocument.android.pdf2htmlex.FontconfigAndroid;
import at.tomtasche.reader.nonfree.ConfigManager;
public class OdfLoader extends FileLoader {
diff --git a/app/src/main/java/at/tomtasche/reader/background/PdfLoader.java b/app/src/main/java/at/tomtasche/reader/background/PdfLoader.java
index 26e7559b9ceb..8b2e884f5d08 100644
--- a/app/src/main/java/at/tomtasche/reader/background/PdfLoader.java
+++ b/app/src/main/java/at/tomtasche/reader/background/PdfLoader.java
@@ -2,82 +2,146 @@
import android.content.Context;
import android.net.Uri;
-import android.util.Log;
+import android.webkit.MimeTypeMap;
-import app.opendocument.android.pdf2htmlex.pdf2htmlEX;
-import com.viliussutkus89.android.wvware.wvWare;
+import com.viliussutkus89.android.assetextractor.AssetExtractor;
import java.io.File;
-import java.io.InputStream;
+
+import app.opendocument.android.pdf2htmlex.EnvVar;
+import app.opendocument.android.pdf2htmlex.FontconfigAndroid;
+import at.tomtasche.reader.nonfree.ConfigManager;
public class PdfLoader extends FileLoader {
- private static final String[] MIME_WHITELIST = {
- // pdf: https://filext.com/file-extension/PDF
- "application/pdf", "application/x-pdf", "application/acrobat", "applications/vnd.pdf", "text/pdf", "text/x-pdf",
- };
+ private final ConfigManager configManager;
+
+ private CoreWrapper lastCore;
+ private CoreWrapper.CoreOptions lastCoreOptions;
- public PdfLoader(Context context) {
+ public PdfLoader(Context context, ConfigManager configManager) {
super(context, LoaderType.PDF);
+
+ this.configManager = configManager;
}
@Override
public boolean isSupported(Options options) {
- String fileType = options.fileType;
-
- for (String mime : MIME_WHITELIST) {
- if (!fileType.startsWith(mime)) {
- continue;
- }
-
- return true;
- }
-
- return false;
+ // pdf: https://filext.com/file-extension/PDF
+ return options.fileType.startsWith("application/pdf") || options.fileType.startsWith("application/x-pdf") || options.fileType.startsWith("application/acrobat") || options.fileType.startsWith("applications/vnd.pdf") || options.fileType.startsWith("text/pdf") || options.fileType.startsWith("text/x-pdf");
}
@Override
public void loadSync(Options options) {
+ AssetExtractor ae = new AssetExtractor(context.getAssets()).setNoOverwrite();
+
+ File cacheDir = new File(context.getCacheDir(), "pdf2htmlEX");
+ cacheDir.mkdir();
+
+ File envTMPDIR = new File(cacheDir, "tmp");
+ envTMPDIR.mkdir();
+ EnvVar.set("TMPDIR", envTMPDIR.getAbsolutePath());
+
+ File fontforgeHome = new File(cacheDir, "FontforgeHome");
+ fontforgeHome.mkdir();
+ EnvVar.set("HOME", fontforgeHome.getAbsolutePath());
+
+ File shareDir = new File(context.getFilesDir(), "share");
+ // @TODO: https://github.com/ViliusSutkus89/pdf2htmlEX-Android/issues/9
+ File pdf2htmlEX_dataDir = ae.extract(shareDir, "pdf2htmlEX");
+ EnvVar.set("PDF2HTMLEX_DATA_DIR", pdf2htmlEX_dataDir.getAbsolutePath());
+
+ // @TODO: https://github.com/ViliusSutkus89/pdf2htmlEX-Android/issues/10
+ File poppler_dataDir = ae.extract(shareDir, "poppler-data");
+ EnvVar.set("POPPLER_DATA_DIR", poppler_dataDir.getAbsolutePath());
+
+ FontconfigAndroid.init(context.getAssets(), context.getCacheDir(), context.getFilesDir());
+
+ EnvVar.set("USER", android.os.Build.MODEL);
+
final Result result = new Result();
result.options = options;
result.loaderType = type;
try {
- File cacheFile = AndroidFileCache.getCacheFile(context, options.cacheUri);
- File cacheDirectory = AndroidFileCache.getCacheDirectory(cacheFile);
-
- pdf2htmlEX pdfConverter = new pdf2htmlEX(context).setInputPDF(cacheFile);
- pdfConverter.setProcessOutline(false);
- pdfConverter.setBackgroundImageFormat(pdf2htmlEX.BackgroundImageFormat.JPG);
- pdfConverter.setDRM(false);
- pdfConverter.setProcessAnnotation(true);
- if (options.password != null) {
- pdfConverter.setOwnerPassword(options.password).setUserPassword(options.password);
- pdfConverter.setEmbedExternalFont(false).setEmbedFont(false);
+ translate(options, result);
+
+ callOnSuccess(result);
+ } catch (Throwable e) {
+ if (e instanceof CoreWrapper.CoreEncryptedException) {
+ e = new EncryptedDocumentException();
}
- File output = pdfConverter.convert();
+ callOnError(result, e);
+ }
+ }
+
+ private void translate(Options options, Result result) throws Exception {
+ File cachedFile = AndroidFileCache.getCacheFile(context, options.cacheUri);
- File htmlFile = new File(cacheDirectory, "pdf.html");
- StreamUtil.copy(output, htmlFile);
+ if (lastCore != null) {
+ lastCore.close();
+ lastCore = null;
+ }
- // pdf2htmlEX does not delete output files automatically
- output.delete();
+ CoreWrapper core = new CoreWrapper();
+ try {
+ core.initialize();
- Uri finalUri = Uri.fromFile(htmlFile);
+ lastCore = core;
+ } catch (Throwable e) {
+ crashManager.log(e);
+ }
- options.fileType = "application/pdf";
+ File cacheDirectory = AndroidFileCache.getCacheDirectory(cachedFile);
- result.partTitles.add(null);
- result.partUris.add(finalUri);
+ CoreWrapper.CoreOptions coreOptions = new CoreWrapper.CoreOptions();
+ coreOptions.inputPath = cachedFile.getPath();
+ coreOptions.outputPath = cacheDirectory.getPath();
+ coreOptions.password = options.password;
+ coreOptions.editable = options.translatable;
+ coreOptions.ooxml = false;
+ coreOptions.pdf2htmlEX = true;
- callOnSuccess(result);
- } catch (Throwable e) {
- if (e instanceof pdf2htmlEX.PasswordRequiredException || e instanceof pdf2htmlEX.WrongPasswordException) {
- e = new EncryptedDocumentException();
+ Boolean usePaging = configManager.getBooleanConfig("use_paging");
+ if (usePaging == null || usePaging) {
+ coreOptions.paging = true;
+ }
+
+ lastCoreOptions = coreOptions;
+
+ CoreWrapper.CoreResult coreResult = lastCore.parse(coreOptions);
+
+ String coreExtension = coreResult.extension;
+ // "unnamed" refers to default of Meta::typeToString
+ if (coreExtension != null && !coreExtension.equals("unnamed")) {
+ options.fileExtension = coreExtension;
+
+ String fileType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(coreExtension);
+ if (fileType != null) {
+ options.fileType = fileType;
}
+ }
- callOnError(result, e);
+ if (coreResult.exception != null) {
+ throw coreResult.exception;
+ }
+
+ for (int i = 0; i < coreResult.pagePaths.size(); i++) {
+ File entryFile = new File(coreResult.pagePaths.get(i));
+
+ result.partTitles.add(coreResult.pageNames.get(i));
+ result.partUris.add(Uri.fromFile(entryFile));
+ }
+ }
+
+ @Override
+ public void close() {
+ super.close();
+
+ if (lastCore != null) {
+ lastCore.close();
+ lastCore = null;
}
}
}