Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.
Rust androiddocument-scannerdocximage-editorjetpack-composekotlinliquid-glassofflineopen-sourcepdfpdf-compressorpdf-editorpdf-mergerpdf-readerpdf-splitterpdf-toolspdf-viewerpptxspreadsheet-editorxlsx
Improve document rendering and sharing
Chethan61641b49895cee8
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.ktindex 582193d..27e4612 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerBottomToolbar.kt@@ -725,33 +725,40 @@ internal fun PdfViewerBottomToolbar()}}- // Reserve the circle's slot at the home-bar level so the pill never sits under the- // share button. (The tool panels above cover full width and only FADE on morph.)- Spacer(Modifier.size(52.dp))+ // Reserve both bottom-right actions: direct Share and the existing Open another PDF+ // morph control. Tool panels above cover full width and only fade during a morph.+ Spacer(Modifier.width(108.dp).height(52.dp))}}}- // ── Share capsule OVERLAY ──────────────────────────────────────────- // Sits over the reserved slot at the bottom-right. Because it's a sibling of the column- // (not inside it) and bottom-anchored, morphing it taller grows only this wrapper Box- // upward — the column (tool panels + pill) stays pinned to the base and never moves.+ // ── File actions OVERLAY ───────────────────────────────────────────+ // These sit over their reserved bottom-right slots. The explicit Share button makes the+ // common action discoverable; the morph capsule keeps the quick Open another PDF action.AnimatedVisibility(- // Sits in the pill row's reserved slot, so it rides the same `selectorGate` and fades out- // alongside the pill instead of popping away on its own.visible = selectorGate && !showFindBar && !showSignaturePad,enter = fadeIn(tween(180)),exit = fadeOut(tween(FaceHandoffMillis)),modifier = Modifier.align(Alignment.BottomEnd).zIndex(3f)) {- ShareMorphButton(- backdrop = backdrop,- glass = pillGlass,- fg = fg,- onOpen = onOpenAnotherPdf,- onShare = onShareDocument,- onShareModeChanged = { shareActive = it; onShareHoldChanged(it) }- )+ Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.Bottom) {+ LiquidIconButton(+ onClick = onShareDocument,+ backdrop = backdrop,+ modifier = Modifier.size(48.dp),+ surfaceColor = pillGlass+ ) {+ Icon(Icons.Rounded.IosShare, stringResource(R.string.viewer_share_document), Modifier.size(20.dp), fg)+ }+ ShareMorphButton(+ backdrop = backdrop,+ glass = pillGlass,+ fg = fg,+ onOpen = onOpenAnotherPdf,+ onShare = onShareDocument,+ onShareModeChanged = { shareActive = it; onShareHoldChanged(it) }+ )+ }}}}diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.ktindex 3a40103..f1f71b2 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerScreen.kt@@ -767,6 +767,23 @@ fun PdfViewerScreen() {val renderWidthPx = with(LocalDensity.current) { maxWidth.roundToPx() }.coerceAtLeast(720)+ // Re-render the focused page after zoom settles. Scaling a screen-sized bitmap makes PDF+ // text and fine diagrams soft; a bounded higher-resolution page keeps pinch zoom readable+ // without triggering a native render for every pointer frame.+ LaunchedEffect(state.document?.uri, currentPageIndex, renderWidthPx) {+ snapshotFlow { scale }+ .distinctUntilChanged()+ .debounce(220)+ .collect { zoom ->+ if (zoom < 1.18f) return@collect+ val desired = (renderWidthPx * zoom.coerceAtMost(2.5f))+ .roundToInt()+ .coerceAtMost(3072)+ .coerceAtLeast(renderWidthPx)+ if (desired > renderWidthPx) viewModel.renderPage(context, currentPageIndex, desired)+ }+ }+// Warms the pages just ahead of (and one behind) wherever scrolling currently is, so a page's// render has a head start instead of only beginning once it scrolls into view — undebounced// is fine here since `prefetchAround`/`renderPage` are no-ops for a page already rendered ordiff --git a/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.kt b/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.ktindex e0ecbc7..8e4dc3c 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/viewmodel/PdfViewerViewModel.kt@@ -182,6 +182,7 @@ class PdfViewerViewModel(private val openPdfUseCase: OpenPdfUseCase) : ViewModel}private val renderingPages = mutableSetOf<Pair<Uri, Int>>()+ private val pendingRenderWidths = mutableMapOf<Pair<Uri, Int>, Int>()private val renderedPageWidths = mutableMapOf<Int, Int>()private val textLoadingPages = mutableSetOf<Int>()@@ -215,6 +216,7 @@ class PdfViewerViewModel(private val openPdfUseCase: OpenPdfUseCase) : ViewModel_uiState.value.document?.let { openPdfUseCase.close(it) }recycleBitmaps(_uiState.value.pageBitmaps)renderingPages.clear()+ pendingRenderWidths.clear()renderedPageWidths.clear()textLoadingPages.clear()_uiState.value = _uiState.value.copy(@@ -411,7 +413,10 @@ class PdfViewerViewModel(private val openPdfUseCase: OpenPdfUseCase) : ViewModelval documentUri = doc.urival renderKey = documentUri to pageIndex- if (!renderingPages.add(renderKey)) return+ if (!renderingPages.add(renderKey)) {+ pendingRenderWidths[renderKey] = maxOf(pendingRenderWidths[renderKey] ?: 0, renderWidth)+ return+ }viewModelScope.launch {try {@@ -433,18 +438,26 @@ class PdfViewerViewModel(private val openPdfUseCase: OpenPdfUseCase) : ViewModel// through the viewport a frame later. That eviction is now solely `trimBitmapCache`// (below), which the caller in `PdfViewerScreen` debounces — this function's only job// is to place the bitmap it just rendered.- val bitmaps = currentState.pageBitmaps.toMutableList()- val previous = bitmaps[pageIndex]- if (previous != null && previous != bitmap && !previous.isRecycled) previous.recycle()- bitmaps[pageIndex] = bitmap- if (bitmap == null) renderedPageWidths.remove(pageIndex)- else renderedPageWidths[pageIndex] = renderWidth- _uiState.value = currentState.copy(pageBitmaps = bitmaps)+ if (bitmap != null) {+ val bitmaps = currentState.pageBitmaps.toMutableList()+ val previous = bitmaps[pageIndex]+ if (previous != null && previous != bitmap && !previous.isRecycled) previous.recycle()+ bitmaps[pageIndex] = bitmap+ renderedPageWidths[pageIndex] = renderWidth+ _uiState.value = currentState.copy(pageBitmaps = bitmaps)+ }// Load text for page if not already done (async, IO thread)loadTextPage(context, doc, pageIndex)} finally {renderingPages.remove(renderKey)+ val pendingWidth = pendingRenderWidths.remove(renderKey)+ val latest = _uiState.value+ if (pendingWidth != null && latest.document?.uri == documentUri &&+ (renderedPageWidths[pageIndex] ?: 0) < pendingWidth+ ) {+ renderPage(context, pageIndex, pendingWidth)+ }}}}diff --git a/app/src/main/java/com/chethan616/clearpdf/utils/PptxRenderer.kt b/app/src/main/java/com/chethan616/clearpdf/utils/PptxRenderer.ktindex 7dafdb5..20ed77a 100644--- a/app/src/main/java/com/chethan616/clearpdf/utils/PptxRenderer.kt+++ b/app/src/main/java/com/chethan616/clearpdf/utils/PptxRenderer.kt@@ -293,6 +293,14 @@ internal object PptxRenderer {/** Tables arrive wrapped in a graphic frame; charts and SmartArt also do, and are skipped. */private fun drawGraphicFrame(canvas: Canvas, frame: OoxmlNode, ctx: SlideContext, transform: Transform) {+ // Legacy Equation.3 objects carry a picture inside mc:Fallback. Android cannot open+ // the embedded OLE object, but its fallback is the exact equation artwork Office+ // displays; draw it through the same relationship/geometry path as ordinary pictures.+ if (frame.find("p:oleObj") != null) {+ frame.find("p:pic")?.let { drawPicture(canvas, it, ctx, transform) }+ return+ }+val box = frame.find("p:xfrm")?.let { boxOf(it) }?.let { transform.apply(it) } ?: returnval table = frame.find("a:tbl") ?: returnval grid = table.find("a:tblGrid")?.childrenNamed("a:gridCol").orEmpty()