Yokan / rebuild
Course 1 8624561

ImageSharing.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/screens/reader/ImageSharing.kt

implementation40 lines
1package eu.friedcutlet.yokan.ui.screens.reader23/** Opens the platform share UI for in-memory image data. */4expect fun shareImage(bytes: ByteArray, fileName: String, mimeType: String): Boolean56/**7 * Saves in-memory image data to the platform's user-visible picture library, inside a8 * [folder] (album on iOS) below Yokan's own location when one is given.9 */10expect suspend fun saveImageToGallery(bytes: ByteArray, fileName: String, mimeType: String, folder: String?): Boolean1112/** Places the image on the system clipboard. */13expect suspend fun copyImageToClipboard(bytes: ByteArray, fileName: String, mimeType: String): Boolean1415/**16 * Two decoded pages side by side at a common height, encoded as JPEG; null for animated,17 * undecodable or oversized inputs.18 */19internal expect suspend fun mergeSpreadImages(left: ByteArray, right: ByteArray): ByteArray?2021internal fun String.safeSharedFileName(): String =22    replace(Regex("[^A-Za-z0-9._-]+"), "_").trim('_').ifBlank { "yokan-cover.jpg" }2324/** A title as a single path segment: path separators and reserved characters are replaced. */25internal fun readerImageFolderName(title: String): String =26    title.replace(Regex("[\\\\/:*?\"<>|\\x00-\\x1F]+"), "_").trim().trim('.').take(100).trim().ifBlank { "Untitled" }2728/** Side-by-side pixel layout shared by every platform's spread merge. */29internal data class SpreadLayout(val width: Int, val height: Int, val leftWidth: Int, val rightWidth: Int)3031/** Scales both pages to the taller page's height; null when the result would exceed the decode budget. */32internal fun spreadLayout(leftWidth: Int, leftHeight: Int, rightWidth: Int, rightHeight: Int): SpreadLayout? {33    if (leftWidth <= 0 || leftHeight <= 0 || rightWidth <= 0 || rightHeight <= 0) return null34    val height = maxOf(leftHeight, rightHeight)35    val scaledLeft = (leftWidth.toLong() * height / leftHeight).toInt().coerceAtLeast(1)36    val scaledRight = (rightWidth.toLong() * height / rightHeight).toInt().coerceAtLeast(1)37    val width = scaledLeft.toLong() + scaledRight38    if (width * height > eu.friedcutlet.yokan.services.download.MaxSplitImagePixels) return null39    return SpreadLayout(width.toInt(), height, scaledLeft, scaledRight)40}41

Search chapters, reference and source filenames.