ComposeCanvas

class ComposeCanvas(drawScope: DrawScope, textMeasurer: TextMeasurer, hairlineWidthPx: Float = 1.0f, skipSystemFontText: Boolean = false) : KiteCanvas

KiteCanvas backed by a Compose Multiplatform DrawScope.

Three rendering paths:

  • Embedded outlines: when hasOutlines is true, each byte/CID becomes a Compose Path filled at the right position.

  • System-font fallback: when no outlines are available, decode to text and hand to Compose's TextMeasurer.

  • Transparency groups: open a saveLayer on the underlying Canvas when the renderer requests one; later restore composites the layer back with the requested blend mode + alpha.

Clipping uses Compose's clipPath inside a recursive scope; transparency groups use the lower-level Canvas.saveLayer so they can span multiple DrawScope operations.

Constructors

Link copied to clipboard
constructor(drawScope: DrawScope, textMeasurer: TextMeasurer, hairlineWidthPx: Float = 1.0f, skipSystemFontText: Boolean = false)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open override fun applySoftMask(kind: SoftMask.Kind, maskBBox: KiteRectangle, maskCtm: KiteMatrix, render: () -> Unit, renderMask: (KiteCanvas) -> Unit)

open override fun applySoftMask(kind: SoftMask.Kind, maskBBox: KiteRectangle, maskCtm: KiteMatrix, transfer: KiteMaskTransfer?, render: () -> Unit, renderMask: (KiteCanvas) -> Unit)

Soft-mask compositing (ISO 32000-1 §11.6.5). We open a saveLayer for the content, render it, then over-paint the mask group with ComposeBlendMode.DstIn so the mask's alpha clips the content.

Link copied to clipboard
open override fun beginPage(widthPt: Double, heightPt: Double, deviceCtm: KiteMatrix)
Link copied to clipboard
open override fun beginTransparencyGroup(bbox: KiteRectangle, ctm: KiteMatrix, isolated: Boolean, knockout: Boolean, alpha: Double, blendMode: KiteBlendMode)

Transparency groups: open a Compose saveLayer on the active Canvas with a Paint that carries the requested alpha + blend mode. Subsequent draws accumulate into the offscreen layer; matching endTransparencyGroup calls restore, which composites the layer onto the parent.

Link copied to clipboard
open override fun drawGlyphs(glyphs: List<TextGlyph>, fontSize: Double, unitsPerEm: Int, hasOutlines: Boolean, fontSpec: FontSpec, textToDevice: KiteMatrix, color: RgbColor, alpha: Double, blendMode: KiteBlendMode)
Link copied to clipboard
open override fun drawImage(image: KiteImageData, ctm: KiteMatrix, alpha: Double)
open override fun drawImage(image: KiteImageData, ctm: KiteMatrix, alpha: Double, blendMode: KiteBlendMode)
Link copied to clipboard
open override fun endPage()
Link copied to clipboard
open override fun endTransparencyGroup()
Link copied to clipboard
open override fun fillPath(path: KitePath, ctm: KiteMatrix, color: RgbColor, evenOdd: Boolean, alpha: Double, blendMode: KiteBlendMode)
Link copied to clipboard
open override fun fillShading(shading: KiteShading, ctm: KiteMatrix, clipPath: KitePath?, alpha: Double, blendMode: KiteBlendMode)
Link copied to clipboard
open override fun hostGlyphOutline(text: String, fontSpec: FontSpec): KitePath?

The outline of text in the host face drawGlyphs draws a font without embedded outlines in, at 1000 units per em with y up (#85). Off the main thread it only records the run, as the system-font path does, so the page renders again on Main.

Link copied to clipboard
open override fun popClip()
Link copied to clipboard
open override fun pushClip(path: KitePath, ctm: KiteMatrix, evenOdd: Boolean)
Link copied to clipboard
open override fun strokePath(path: KitePath, ctm: KiteMatrix, color: RgbColor, lineWidth: Double, alpha: Double, blendMode: KiteBlendMode, dashArray: List<Double>?, dashPhase: Double, lineCap: Int, lineJoin: Int, miterLimit: Double)