ContentStreamBuilder

Builds a page content stream (ISO 32000-1 §8–§9) from typed drawing operations, emitting the raw operator bytes. Each PDF operator takes its operands first, then the operator keyword: r g b rg, x y m, (str) Tj.

Coordinates are in the default user space (origin bottom-left, points). Numbers are formatted without scientific notation (via PdfObjectWriter); names and strings are escaped the same way the serializer escapes them.

Fonts and images are referenced through fontResolver / imageResolver, which map a StandardFont / PdfImage to the resource name the owning PdfBuilder will register in /Resources.

Functions

Link copied to clipboard
Link copied to clipboard

Intersect the clipping path with the current path using the nonzero winding rule (W). Per the spec, a path-painting operator must follow. Call endPath to clip without also painting the path, e.g. rectangle(...); clip(); endPath().

Link copied to clipboard

Like clip, but with the even-odd rule (W*).

Link copied to clipboard
Link copied to clipboard
fun drawImage(image: PdfImage, x: Double, y: Double, width: Double, height: Double): ContentStreamBuilder

Draw image into the rectangle (x, y) → (x+width, y+height) in user space (x, y is the bottom-left corner). Wrapped in its own q … Q so the image transform doesn't leak into later drawing.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Escape hatch: append literal content-stream source, followed by a newline. A Tf, q or Q in it is outside what the builder tracks, so showText keeps encoding for the font it set.

Link copied to clipboard
Link copied to clipboard

Q, back to the font that the matching save saw; with no matching save, the font stays.

Link copied to clipboard

q. The text font is graphics state, which q saves and Q restores (ISO 32000-1, 8.4.2 and 9.3.1), so the font that showText encodes for is saved with it (#733). A font that raw content sets is outside what the builder tracks.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Select an embedded custom font at size. Subsequent showText calls encode their text as Identity-H 2-byte glyph codes for this font, one glyph per character through the font's cmap, in the order of the string. The builder does not shape text: no GSUB substitution, no mark positioning and no bidi reordering, so Arabic letters do not join, marks of Devanagari or Thai do not move into place, and right-to-left text runs left to right. Scripts without those needs, CJK among them, render as written (#750). The font is registered with the owning PdfBuilder on first use.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Tj in the current font: WinAnsi bytes for a standard font, one glyph a character for an embedded one, unshaped (see setFont).

Link copied to clipboard
Link copied to clipboard
fun text(font: EmbeddedFont, size: Double, x: Double, y: Double, text: String): ContentStreamBuilder

As text, but with an embedded custom font (Identity-H encoded), with no shaping: see setFont.

fun text(font: StandardFont, size: Double, x: Double, y: Double, text: String): ContentStreamBuilder

Convenience: draw a single line of text in font at size, with its baseline at (x, y). Wraps BT/Tf/Td/Tj/ET.

Link copied to clipboard

Concatenate a b c d e f onto the current transformation matrix (cm).