AwtCanvas

KiteCanvas backed by java.awt.Graphics2D. Pure JRE: no Skia, no Compose, no native binaries.

The right choice when:

  • you're rendering a PDF inside an AWT / Swing / JavaFX (via SwingNode) component

  • you want PNG/JPEG output via javax.imageio.ImageIO without pulling in Skia's native libs

  • server-side rendering where the JVM is already there

Pair with AwtPdfRasterizer for the common "give me a BufferedImage" use case.

Caveats: Java2D supports a subset of PDF's 16 blend modes natively. The common ones (Normal, SrcOver) are mapped to AlphaComposite. The rest (Multiply, Screen, …) require a custom java.awt.Composite. We ship a pixel-level PdfBlendComposite that implements all 16 modes for fidelity.

Constructors

Link copied to clipboard
constructor(g: Graphics2D)

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 (ISO 32000-1, 11.6.5): the content paints into its own transparent layer, the mask scales that layer's alpha, and the layer then composites onto the page once. The backdrop is never read or masked (#78), the layer has alpha whatever the destination type (#80), and the mask group's colours never reach the page (#79). Skia and Compose use the same layer model.

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)

ISO 32000-1, 11.4.5: a group's constant alpha and blend mode apply once, when the group composites onto its backdrop. So a group that has them paints into a transparent layer first (#77). The layer is isolated, and knockout is not honoured (#125).

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 logical font drawGlyphs draws a font without embedded outlines in, at 1000 units per em with y up (#85).

Link copied to clipboard
open override fun popClip()
Link copied to clipboard
open override fun pushClip(path: KitePath, ctm: KiteMatrix, evenOdd: Boolean)

Java2D clips by pixel centre and never anti-aliases a clip, so a clip is applied as MuPDF applies it (#285). A rectangle clips to the whole pixels it touches. Any other shape opens a SoftClip: the paints inside go to a layer, which composites onto the page through the anti-aliased coverage of the shape when the clip pops.

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)