KitePageRasterizer

@Stable
class KitePageRasterizer(density: Density, layoutDirection: LayoutDirection, textMeasurer: TextMeasurer, maxBitmapPixels: Long)(source)

Imperative page → ImageBitmap pipeline. This is the raster engine behind KiteDocView; it is public so apps with custom viewers (own pagers, thumbnail grids, PNG export jobs) don't have to re-implement the CTM/flip/hairline math themselves.

Obtain one inside composition with rememberKitePageRasterizer, or construct it directly off-composition when you already hold a TextMeasurer.

rasterize requires the platform UI thread and refuses other callers before drawing. On desktop JVM this is the AWT event dispatch thread, including headless exports. rasterizeOffMain is the suspend entry point for any calling thread; it moves the work to kitepdfRasterDispatcher (a background pool on JVM/Android/Apple, Main on JS/Wasm) so a complex page does not jank scrolling or pinch. KiteDocView uses that path. A page with text in a system font draws there too, since the platform's own text engine shapes that text on any thread (#131, #487).

Constructors

Link copied to clipboard
constructor(density: Density, layoutDirection: LayoutDirection, textMeasurer: TextMeasurer, maxBitmapPixels: Long)
constructor(density: Density, layoutDirection: LayoutDirection, textMeasurer: TextMeasurer)

Binary-compatible constructor using the default bitmap ceiling.

Functions

Link copied to clipboard
fun rasterize(page: KitePage, widthPx: Int, heightPx: Int, background: Color = Color.White, hairlineWidthPx: Float = 1.0f, theme: ReaderTheme? = null): ImageBitmap

Renders page into a fresh widthPx×heightPx bitmap.

fun rasterize(page: KitePage, widthPx: Int, heightPx: Int, background: Color = Color.White, hairlineWidthPx: Float = 1.0f, theme: ReaderTheme? = null, canvasDecorator: KiteCanvasDecorator?): ImageBitmap

rasterize with an application canvas wrapper. See KiteCanvasDecorator for ordering, repeatable paint passes and threading requirements.

fun rasterize(page: KitePage, widthPx: Int, heightPx: Int, formState: PdfFormState?, background: Color = Color.White, hairlineWidthPx: Float = 1.0f, theme: ReaderTheme? = null, canvasDecorator: KiteCanvasDecorator? = null): ImageBitmap

rasterize for an export of a form: a PDF page draws its fields with the values that formState holds, the ones the reader typed and the scripts wrote, as the viewer shows them. Other pages ignore formState.

Link copied to clipboard
suspend fun rasterizeOffMain(page: KitePage, widthPx: Int, heightPx: Int, background: Color = Color.White, hairlineWidthPx: Float = 1.0f, theme: ReaderTheme? = null): ImageBitmap

rasterize, off the main thread where the platform allows. Cancelling the calling coroutine stops a PDF page between operators and throws a CancellationException instead of returning a partial bitmap (#188).

suspend fun rasterizeOffMain(page: KitePage, widthPx: Int, heightPx: Int, background: Color = Color.White, hairlineWidthPx: Float = 1.0f, theme: ReaderTheme? = null, canvasDecorator: KiteCanvasDecorator?): ImageBitmap

rasterizeOffMain with an application canvas wrapper. See KiteCanvasDecorator for ordering, repeatable paint passes and threading requirements.

suspend fun rasterizeOffMain(page: KitePage, widthPx: Int, heightPx: Int, formState: PdfFormState?, background: Color = Color.White, hairlineWidthPx: Float = 1.0f, theme: ReaderTheme? = null, canvasDecorator: KiteCanvasDecorator? = null): ImageBitmap

Exports the accepted live values of formState from any coroutine dispatcher. The state is copied before waiting for a raster slot, so both paint passes use the same field values, choice selections and visibility (ISO 32000-1, 12.7). Later edits do not change an export already in progress. Other page types ignore the form state. Unlike the viewer's cached page bitmap, this includes widgets.