Skip to content

Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.

Merge branch 'feat/office-engine' into feat/editor-overhaul

Chethan616e1513d9c7e44
diff --cc THIRD_PARTY_NOTICES.md
index be142f3,4a663db..f3b3685
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@@ -71,36 -71,24 +71,58 @@@ The app does not bundle GPL or LGPL com
- Notice practice: the upstream banner (including its pako attribution) is preserved verbatim at the
top of the vendored file, and the library is credited in Settings → Licenses.
+## ImageToolbox (adapted source)
+
+- Source: https://github.com/T8RIN/ImageToolbox — Copyright (c) 2026 T8RIN (Malik Mukhametzyanov)
+- License: Apache License 2.0
+- Use: the image editor's cropper (`imageeditor/thirdparty/cropper`, from `lib/cropper` minus
+ its widgets), gesture helpers (`thirdparty/gesture`), image-scope helpers (`thirdparty/image`),
+ the perspective cropper (`thirdparty/freecorners`, from `lib/opencv-tools/free_corners_crop`
+ with OpenCV's `warpPerspective` replaced by `Matrix.setPolyToPoly`), and draw-engine code
+ (`imageeditor/engine/draw`: shape/arrow geometry from `PathHelper.kt`, paint set-up from
+ `DrawUtils.kt`, `FloodFill.kt`). Adjustment/preset choices and the watermark placement model
+ follow `feature/filters` and `feature/watermarking`.
+- Notice practice: every adapted file keeps the upstream Apache-2.0 header with an added
+ "Modified by ClearPDF" line; attribution is also in `NOTICE` and Settings → Licenses.
+
+## GPUImage for Android
+
+- Artifact: `jp.co.cyberagent.android:gpuimage:2.1.0` (Maven Central; ~0.2 MB incl. a tiny native helper)
+- License: Apache License 2.0 (CyberAgent, Inc.)
+- Use: GL-accelerated adjustments (white balance, vibrance, gamma, sharpen, vignette) and
+ artistic presets in the image editor.
+
+## Google ML Kit Subject Segmentation
+
+- Artifact: `com.google.android.gms:play-services-mlkit-subject-segmentation:16.0.0-beta1`
+- License: Google APIs Terms of Service
+- Use: optional automatic background removal in the image editor. The model is delivered by
+ Google Play services; the call is gated at runtime (Android 7+, Play services present) behind
+ the `BackgroundRemover` interface so FOSS builds can swap or drop it.
+
+## Stack Blur
+
+- Algorithm by Mario Klingemann (public domain), re-implemented in `imageeditor/engine/BlurUtils.kt`
+ as the pre-Android-12 fallback for the blur brush.
++
+ ## LibreOffice (optional Office engine)
+
+ - What: "Office engine (powered by LibreOffice)" — a prebuilt LibreOfficeKit bundle for Android
+ (`liblo-native-code.so`, `libc++_shared.so` and the LibreOffice runtime tree). It is **not in the
+ APK**. It is installed only when the user asks for it in Settings: the `play` flavor gets it through
+ the on-demand Play Feature Delivery module `:office_engine`, and the `foss` flavor downloads it from
+ a pinned release, accepting it only if its size and SHA-256 match `OfficeEngineManifest.kt`.
+ - Binary source: https://github.com/vasuki-re/LibreOffice-Lite (release v2.0), a build of
+ LibreOffice core (https://git.libreoffice.org/core, mirror https://github.com/LibreOffice/core).
+ - License: Mozilla Public License 2.0 for LibreOffice itself; some bundled parts (fonts such as
+ Liberation, Carlito, Caladea and Gentium Basic, and other third-party libraries compiled into
+ LibreOffice) carry their own licences, listed at https://www.libreoffice.org/about-us/licenses/.
+ - Source availability (MPL-2.0 §3.2): the corresponding LibreOffice source is available from the
+ URLs above. Anyone redistributing a build that bundles or rehosts the engine must keep that source
+ available and should prefer a self-built bundle whose build recipe is published.
+ - ClearPDF's Kotlin JNI binding (`app/src/main/java/org/libreoffice/kit/`) is original code; only
+ its package, class and method names follow LibreOffice's Android binding, because the native
+ library resolves them by name.
+ - Trademark: "LibreOffice" is a trademark of The Document Foundation; ClearPDF uses it only to say
+ the optional engine is powered by LibreOffice and is not affiliated with or endorsed by TDF.
+ - Credited in Settings → Licenses and Settings → Office engine.
diff --cc app/build.gradle.kts
index 8e76dc7,16299de..a5e7e9b
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@@ -76,11 -76,22 +76,28 @@@ android
buildFeatures {
compose = true
}
+ testOptions {
+ // Plain JVM unit tests (the xlsx model/writer). Android stubs return defaults instead of
+ // throwing so incidental framework calls don't fail a pure-logic test.
+ unitTests.isReturnDefaultValues = true
+ }
++
+ // Two distributions of the same app (identical applicationId):
+ // - play: Google Play. The optional Office engine ships as the on-demand dynamic feature
- // module :office_engine (Play Feature Delivery), so the app still declares no INTERNET.
++ // module :office_engine (Play Feature Delivery); no native code is ever downloaded by the app.
+ // - foss: GitHub/F-Droid-style sideload builds. The Office engine is downloaded on request
+ // from a pinned, SHA-256 verified release; only this flavor declares INTERNET
+ // (see src/foss/AndroidManifest.xml).
+ flavorDimensions += "distribution"
+ productFlavors {
+ create("play") {
+ dimension = "distribution"
+ }
+ create("foss") {
+ dimension = "distribution"
+ }
+ }
+ dynamicFeatures += setOf(":office_engine")
// Bundling on-device OCR (bundled ML Kit + Tesseract4Android) added native .so libs for
// 4 CPU architectures; without splitting, every install carries all 4. This produces one
// APK per ABI (~1/4 the native-lib weight each) plus a universal fallback for sideloading.
@@@ -167,13 -177,8 +184,18 @@@ dependencies
implementation(libs.acccompanist.permissions)
implementation("androidx.documentfile:documentfile:1.0.1")
+ // Image editor: GPUImage (upstream 2.1.0, ~0.2 MB; the T8RIN 8.x fork needs compileSdk 37
+ // + desugaring and drags in androidx.core 1.19) for GL adjustments/filters, EXIF read/strip,
+ // and ML Kit subject segmentation for auto background removal (API 24+, gated at runtime;
+ // isolated behind BackgroundRemover so a FOSS flavor can swap it out).
+ implementation(libs.gpuimage)
+ implementation(libs.androidx.exifinterface)
+ implementation(libs.mlkit.subject.segmentation)
+ // A real XmlPullParser for JVM tests; android.jar only carries stubs of it.
+ testImplementation("net.sf.kxml:kxml2:2.3.0")
++
+ // Optional Office engine (powered by LibreOffice) — installer differs per distribution.
+ "playImplementation"(libs.play.feature.delivery.ktx)
+ "fossImplementation"(libs.androidx.work.runtime.ktx)
+ "fossImplementation"(libs.xz)
}
diff --cc app/src/main/AndroidManifest.xml
index 13f3e83,7b24e85..4f5ea65
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@@ -158,12 -148,21 +160,28 @@@
android:resource="@xml/file_paths" />
</provider>
+ <!-- Ask Google Play services to fetch the subject-segmentation model ahead of time so the
+ image editor's "Remove background" works on first use. The download is done by Play
+ services itself; the app declares no network permission. -->
+ <meta-data
+ android:name="com.google.mlkit.vision.DEPENDENCIES"
+ android:value="subject_segment" />
++
+ <!-- Optional Office engine (powered by LibreOffice), isolated in its own process so a
+ native crash or runaway document can never take down the app. -->
+ <service
+ android:name=".office.OfficeEngineService"
+ android:exported="false"
+ android:process=":office" />
+
+ <!-- WebViews only ever render local content; opt out of Safe Browsing lookups and
+ WebView usage metrics so nothing is sent even in builds that hold INTERNET. -->
+ <meta-data
+ android:name="android.webkit.WebView.EnableSafeBrowsing"
+ android:value="false" />
+ <meta-data
+ android:name="android.webkit.WebView.MetricsOptOut"
+ android:value="true" />
</application>
</manifest>
diff --cc app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
index 86d4878,d6773d5..28a9221
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
@@@ -820,21 -874,11 +874,26 @@@ private val OpenSourceCredits = listOf
"MIT License (used under MIT of its MIT/GPLv3 dual licence)",
"https://github.com/Stuk/jszip"
),
+ Credit(
+ "ImageToolbox", "T8RIN (Malik Mukhametzyanov)",
+ "Apache License 2.0 — image editor cropper, perspective crop and draw engine (adapted)",
+ "https://github.com/T8RIN/ImageToolbox"
+ ),
+ Credit(
+ "GPUImage for Android", "CyberAgent, Inc.",
+ "Apache License 2.0 — image editor adjustments and filters",
+ "https://github.com/cats-oss/android-gpuimage"
+ ),
+ Credit(
+ "ML Kit Subject Segmentation", "Google",
+ "Google APIs Terms — optional background removal via Play services",
+ "https://developers.google.com/ml-kit/vision/subject-segmentation"
+ ),
+ Credit(
+ "LibreOffice", "The Document Foundation",
+ "Mozilla Public License 2.0 — optional Office engine (downloaded on request, not bundled)",
+ "https://www.libreoffice.org/about-us/licenses/"
+ ),
Credit(
"Pdf_Tools", "Karna14314",
"PDF viewer zoom/pan reference",
diff --cc gradle/libs.versions.toml
index 89ef531,c3fa110..af7265f
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@@ -19,10 -19,10 +19,14 @@@ accompanist = "0.36.0
pdfbox = "2.0.27.0"
kotlinxCoroutines = "1.10.2"
tesseract4android = "4.9.0"
+gpuimage = "2.1.0"
+exifinterface = "1.3.7"
+mlkitSubjectSegmentation = "16.0.0-beta1"
+
+ playFeatureDelivery = "2.1.0"
+ work = "2.10.1"
+ xz = "1.10"
+
[libraries]
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "serialization" }
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core" }