diff options
Diffstat (limited to 'app/src/main/java/org/terst/feedreader/data/Settings.kt')
| -rw-r--r-- | app/src/main/java/org/terst/feedreader/data/Settings.kt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/src/main/java/org/terst/feedreader/data/Settings.kt b/app/src/main/java/org/terst/feedreader/data/Settings.kt index ebeba6c..18c5f9d 100644 --- a/app/src/main/java/org/terst/feedreader/data/Settings.kt +++ b/app/src/main/java/org/terst/feedreader/data/Settings.kt @@ -39,12 +39,30 @@ private const val READER_FONT_SIZE_MIN_PX = 14 private const val READER_FONT_SIZE_MAX_PX = 28 val READER_FONT_SIZE_RANGE_PX = READER_FONT_SIZE_MIN_PX..READER_FONT_SIZE_MAX_PX +/** WebView's textZoom baseline: 100% is "render the CSS font sizes exactly as written." */ +const val UNZOOMED_TEXT_ZOOM_PERCENT = 100 + // Pure so the pinch-to-zoom math is testable without a WebView/gesture detector in the loop -- // ReaderWebView.kt calls this once per gesture (at pinch-end, with the cumulative scale factor // accumulated across the whole gesture), not per touch-move frame. fun pinchZoomFontSizePx(basePx: Int, scaleFactor: Float): Int = (basePx * scaleFactor).roundToInt().coerceIn(READER_FONT_SIZE_RANGE_PX.first, READER_FONT_SIZE_RANGE_PX.last) +/** + * The WebView textZoom percentage that makes text laid out at [renderedPx] read as [targetPx]. + * + * This is what makes a pinch reflow live instead of scaling the whole page and snapping back: + * WebView's textZoom re-lays-out the text (and only the text -- images and padding stay put) + * the moment it changes, with no reload and no JavaScript. + * + * [renderedPx] is the size the currently-loaded HTML was actually written at, which isn't always + * the saved font size -- a second pinch can start before the reload from the first one has + * landed. Measuring against the saved size in that window would shrink the text back to the + * old layout for a frame before growing again. + */ +fun readerTextZoomPercent(renderedPx: Int, targetPx: Int): Int = + (targetPx * UNZOOMED_TEXT_ZOOM_PERCENT / renderedPx.coerceAtLeast(1).toFloat()).roundToInt() + /** Stash connection settings, configured on the Settings screen. Both blank until set. */ class Settings(private val context: Context) { val stashBaseUrl: Flow<String> = |
