suspend fun composePage()

in printing/src/main/java/com/zachklipp/richtext/ui/printing/ComposePdfRenderer.kt [45:82]


  suspend fun composePage(page: Page)
}

/**
 * Renders a composable function ([content]) to a [PrintedPdfDocument].
 *
 * Compose requires a [View] that is actually attached to a window to work, so this function creates
 * a temporary window to compose into, then draws the window's contents into the page's canvas.
 * Since this looks weird, the window is covered by another, identically-sized window that displays
 * [progressIndicator] to the user while the [Page] is being rendered.
 *
 * This is a suspend function, and must be called on the main dispatcher.
 *
 * @param activity The [ComponentActivity] that is used for [Context] and to own the windows.
 * @param pageDpi The density of the page in DPI. The default value makes the default Material font
 * size roughly 11pt.
 * @param minIndicatorMillis The minimum duration to show the progress indicator. Rendering can
 * actually be so fast that the indicator just flickers, which makes for a bad UX. This value
 * ensures that the indicator is displayed for a longer period of time so it looks like it's
 * actually doing something.
 * @param progressIndicator A composable that is used to cover the window used for rendering pages
 * with a more user-friendly UI. Note that this should normally be hidden completely behind the
 * print preview activity and only seen if the preview is cancelled and the app doesn't handle the
 * cancellation right away.
 * @param content The composable to render.
 * @param writer A function which calls [PdfComposeScope.composePage] for each page of composable
 * content that needs to be written. The composition is retained until this block returns, so the
 * block can do things like mutate `MutableState` objects to update the composable between pages.
 */
internal suspend fun composeToPdf(
  activity: ComponentActivity,
  pdfDocument: PrintedPdfDocument,
  pageDpi: Int,
  minIndicatorMillis: Long = 1000,
  progressIndicator: @Composable () -> Unit = { DefaultPdfRenderingProgress() },
  content: @Composable PrinterMetrics.() -> Unit,
  writer: suspend PdfComposeScope.() -> Unit
) {