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
Text boxes: resize anchored at top-left with the handle tracking the finger, plus an exact size slider
chethan616c508e0e8c914
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.ktindex ea5cdc4..a974af1 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfContinuousPage.kt@@ -534,35 +534,51 @@ internal fun PdfContinuousPage(if (selForXf != null && selXfBounds != null) {val density2 = LocalDensity.currentval pad = 30f- val boxL = selXfBounds.left - pad- val boxT = selXfBounds.top - pad- val boxW = selXfBounds.width + pad * 2- val boxH = selXfBounds.height + pad * 2+ // The hit box is FROZEN for the whole gesture. It used to follow the markup every frame,+ // so each drag delta (measured in the box's own, moving coordinates) was skewed by the+ // box's own movement — the text "swam" under the finger and resizes overshot (#48).+ // The pointer stays captured by the box even when the finger leaves it, so a frozen+ // box loses nothing.+ var frozen by remember(page, selectedMarkupIndex) { mutableStateOf<Rect?>(null) }+ val hitBounds = frozen ?: selXfBounds+ val boxL = hitBounds.left - pad+ val boxT = hitBounds.top - pad+ val boxW = hitBounds.width + pad * 2+ val boxH = hitBounds.height + pad * 2Box(Modifier.offset { IntOffset(boxL.roundToInt(), boxT.roundToInt()) }.size(with(density2) { boxW.toDp() }, with(density2) { boxH.toDp() }).pointerInput(page, selectedMarkupIndex) {var mode = 0 // 1 = move, 2 = resize+ // Everything is computed from the gesture's START state plus the TOTAL drag,+ // never accumulated frame-to-frame, so the result can't drift.+ var startMarkup: PdfMarkup? = null+ var startBounds: Rect? = null+ var total = Offset.ZerodetectDragGestures(onDragStart = { local ->val cur = marks.getOrNull(selectedMarkupIndex)val bb = cur?.movableBounds()- // Convert the box-local touch back to page space.- val pPage = Offset(local.x + boxL, local.y + boxT)- mode = if (bb != null && cur.isResizable() && (pPage - bb.bottomRight).getDistance() <= 60f) 2 else 1+ startMarkup = cur+ startBounds = bb+ frozen = bb+ total = Offset.Zero+ val pPage = Offset(local.x + (bb?.left ?: 0f) - pad, local.y + (bb?.top ?: 0f) - pad)+ mode = if (bb != null && cur.isResizable() && (pPage - bb.bottomRight).getDistance() <= 64f) 2 else 1onInteraction()},onDrag = { ch, drag ->if (mode == 0) return@detectDragGesturesch.consume()- val cur = marks.getOrNull(selectedMarkupIndex) ?: return@detectDragGestures- val bb = cur.movableBounds() ?: return@detectDragGestures- marks[selectedMarkupIndex] = if (mode == 2) cur.resizedBy(drag, bb) else cur.translated(drag)+ val m0 = startMarkup ?: return@detectDragGestures+ val b0 = startBounds ?: return@detectDragGestures+ total += drag+ marks[selectedMarkupIndex] = if (mode == 2) m0.resizedFrom(b0, total) else m0.translated(total)onInteraction()},- onDragEnd = { mode = 0 },- onDragCancel = { mode = 0 }+ onDragEnd = { mode = 0; frozen = null },+ onDragCancel = { mode = 0; frozen = null })})diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerDialogs.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerDialogs.ktindex a924119..bcfab3c 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerDialogs.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerDialogs.kt@@ -249,10 +249,13 @@ internal fun AnnotationEditorDialog(backdrop: LayerBackdrop,onDismiss: () -> Unit,onDelete: () -> Unit,- onSave: (String, Color) -> Unit+ /** Text boxes only: the current size, adjustable with a slider (null hides it, e.g. notes). */+ initialFontSize: Float? = null,+ onSave: (String, Color, Float?) -> Unit) {var text by remember { mutableStateOf(initialText) }var color by remember { mutableStateOf(initialColor) }+ var fontSize by remember { mutableStateOf(initialFontSize) }val focus = remember { FocusRequester() }var shown by remember { mutableStateOf(false) }LaunchedEffect(Unit) { shown = true; delay(260); runCatching { focus.requestFocus() } }@@ -265,7 +268,7 @@ internal fun AnnotationEditorDialog(actions = {GlassDialogAction(stringResource(R.string.delete), onDelete, destructive = true)GlassDialogAction(stringResource(R.string.cancel), onDismiss)- GlassDialogAction(stringResource(R.string.anno_save), { onSave(text, color) }, primary = true)+ GlassDialogAction(stringResource(R.string.anno_save), { onSave(text, color, fontSize) }, primary = true)}) {GlassDialogField(@@ -275,8 +278,25 @@ internal fun AnnotationEditorDialog(placeholder = stringResource(R.string.anno_hint),singleLine = false,minHeight = 96.dp,- focusRequester = focus+ focusRequester = focus,+ textStyle = TextStyle(fontSize = 16.sp))+ fontSize?.let { size ->+ // Exact sizing without dragging the handle — the precise way to resize (#48).+ Spacer(Modifier.height(14.dp))+ Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {+ BasicText(stringResource(R.string.anno_text_size), style = TextStyle(glassDialogInkSoft(), 12.sp, FontWeight.Medium))+ BasicText(size.roundToInt().toString(), style = TextStyle(glassDialogInk(), 12.sp, FontWeight.SemiBold))+ }+ com.chethan616.clearpdf.ui.components.LiquidSlider(+ value = { size },+ onValueChange = { fontSize = it },+ valueRange = 10f..200f,+ visibilityThreshold = 0.5f,+ backdrop = backdrop,+ modifier = Modifier.fillMaxWidth()+ )+ }Spacer(Modifier.height(14.dp))AnnotationColorRow(selected = color, backdrop = backdrop, fgSoft = glassDialogInkSoft(), onPick = { color = it })}diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerInternals.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerInternals.ktindex 0555ca0..8fb5d8c 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerInternals.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/PdfViewerInternals.kt@@ -314,6 +314,26 @@ internal fun PdfMarkup.resizedBy(drag: Offset, bounds: Rect): PdfMarkup = when (else -> this}+/**+ * Absolute resize: this markup as it was when the gesture began ([startBounds]), with its+ * bottom-right corner moved by the gesture's TOTAL drag. The top-left stays put, so the markup+ * never moves while it is resized.+ *+ * Text scales uniformly by the drag projected onto the box diagonal: its width and height both+ * scale with the font size, so the handle stays exactly under the finger along the diagonal and+ * sideways jitter is ignored (#48: "the text moves while resizing").+ */+internal fun PdfMarkup.resizedFrom(startBounds: Rect, total: Offset): PdfMarkup = when (this) {+ is PdfMarkup.TextBoxMarkup -> {+ val d = startBounds.bottomRight - startBounds.topLeft+ val t = d + total+ val len2 = (d.x * d.x + d.y * d.y).coerceAtLeast(1f)+ val f = ((t.x * d.x + t.y * d.y) / len2).coerceIn(0.15f, 10f)+ copy(fontSize = (fontSize * f).coerceIn(8f, 480f))+ }+ else -> resizedBy(total, startBounds)+}+internal fun PdfMarkup.shapeColor(): Color = when (this) {is PdfMarkup.StrokeMarkup -> coloris PdfMarkup.RectMarkup -> colordiff --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 6d67ae2..1cca5a0 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@@ -1856,13 +1856,16 @@ fun PdfViewerScreen(getPageMarks(editingAnnoPage).removeAll { matches(it) }editingAnnoId = null},- onSave = { newText, newColor ->+ initialFontSize = getPageMarks(editingAnnoPage)+ .firstOrNull { it is PdfMarkup.TextBoxMarkup && it.id == annoId }+ ?.let { (it as PdfMarkup.TextBoxMarkup).fontSize },+ onSave = { newText, newColor, newSize ->val list = getPageMarks(editingAnnoPage)val idx = list.indexOfFirst { matches(it) }if (idx >= 0) {if (newText.isBlank() && list[idx] is PdfMarkup.TextBoxMarkup) list.removeAt(idx)else list[idx] = when (val m = list[idx]) {- is PdfMarkup.TextBoxMarkup -> m.copy(text = newText, color = newColor)+ is PdfMarkup.TextBoxMarkup -> m.copy(text = newText, color = newColor, fontSize = newSize ?: m.fontSize)is PdfMarkup.NoteMarkup -> m.copy(text = newText, color = newColor)else -> m}diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xmlindex cd56ad2..02a8637 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -321,6 +321,7 @@<string name="anno_text_title">Insert text</string><string name="anno_hint">Type here…</string><string name="anno_save">Save</string>+ <string name="anno_text_size">Size</string><string name="not_now">Not now</string><string name="dont_ask_again">Don\'t ask again</string><string name="settings_custom_directory">Custom Directory</string>