import { PDFString } from '../core/pdf-string.ts'; import type { PDFFont, ShapedGlyph } from '../font/pdf-font.ts'; import type { Color } from './colors.ts'; import type { ExtGState } from './ext-gstate.ts'; import type { PDFImage } from './pdf-image.ts'; import { PDFInstruction } from './pdf-instruction.ts'; export declare const LineCapStyle: { /** Butt cap */ readonly Butt: 0; /** Round cap */ readonly Round: 1; /** Projecting square cap */ readonly ProjectingSquare: 2; }; export type LineCapStyle = (typeof LineCapStyle)[keyof typeof LineCapStyle]; export declare const LineJoinStyle: { /** Miter join */ readonly Miter: 0; /** Round join */ readonly Round: 1; /** Bevel join */ readonly Bevel: 2; }; export type LineJoinStyle = (typeof LineJoinStyle)[keyof typeof LineJoinStyle]; export declare const TextRenderingMode: { /** Fill text */ readonly Fill: 0; /** Stroke text */ readonly Stroke: 1; /** Fill, then stroke text */ readonly FillThenStroke: 2; /** Neither fill nor stroke text (invisible) */ readonly Invisible: 3; /** Fill text and add to clipping path */ readonly FillAndClip: 4; /** Stroke text and add to clipping path */ readonly StrokeAndClip: 5; /** Fill, then stroke text and add to clipping path */ readonly FillThenStrokeAndClip: 6; /** Add text to clipping path */ readonly Clip: 7; }; export type TextRenderingMode = (typeof TextRenderingMode)[keyof typeof TextRenderingMode]; /** * Represents a PDF content stream, which is a sequence of PDF * instructions that describe the graphical and textual content of a PDF * page or form XObject. */ export declare class ContentStream { private _instructions; private _currentFont; private _currentFontSize; private _graphicsStateStack; private _inTextObject; private _textObjectGraphicsStateDepth; /** * The raw PDF instructions in this content stream. */ get instructions(): readonly PDFInstruction[]; /** * Adds a raw PDF instruction to the content stream. * * @param instruction The PDF instruction to add. */ addInstruction(instruction: PDFInstruction): this; /** * Saves the current graphics state on the stack. * * Operator: `q` */ saveGraphicsState(): this; /** * Restores the most recently saved graphics state. * * Operator: `Q` */ restoreGraphicsState(): this; /** * Multiplies the current transformation matrix by the given matrix, * specified as six numbers that represent the following 3x3 matrix: * ``` * | a b 0 | * | c d 0 | * | e f 1 | * ``` * * Operator: `cm` */ applyTransformMatrix(a: number, b: number, c: number, d: number, e: number, f: number): this; /** * Translates the user coordinate system by the specified offsets, * multiplying the current transformation matrix. * * This is a shorthand for `applyTransformMatrix(1, 0, 0, 1, tx, ty)`. * @param tx The x-offset to translate by. * @param ty The y-offset to translate by. */ translate(tx: number, ty: number): this; /** * Scales the user coordinate system by the specified factors, * multiplying the current transformation matrix. * * This is a shorthand for `applyTransformMatrix(sx, 0, 0, sy, 0, 0)`. * @param sx The x-scale factor. * @param sy The y-scale factor. */ scale(sx: number, sy: number): this; /** * Rotates the user coordinate system by the specified angle, * multiplying the current transformation matrix. Rotation is * counterclockwise in user space. * * This is a shorthand for `applyTransformMatrix(cos(angle), sin(angle), * -sin(angle), cos(angle), 0, 0)`. * @param angle The angle to rotate by, in degrees. */ rotate(angle: number): this; /** * Skews the user coordinate system by the specified angles, * multiplying the current transformation matrix. * * This is a shorthand for `applyTransformMatrix(1, tan(angleY), * tan(angleX), 1, 0, 0)`. * @param angleX The angle to skew by along the x-axis, in degrees. * @param angleY The angle to skew by along the y-axis, in degrees. */ skew(angleX: number, angleY: number): this; /** * Sets the stroke line width in user space units. * * Operator: `w` * @param width The line width to set, in user space units. */ setLineWidth(width: number): this; /** * Sets the line cap style for stroke endpoints. * * Operator: `J` * @param cap The line cap style to set. */ setLineCap(cap: LineCapStyle): this; /** * Sets the line join style for stroke corners. * * Operator: `j` * @param join The line join style to set. */ setLineJoin(join: LineJoinStyle): this; /** * Sets the miter limit for joined stroke segments. * * Operator: `M` * @param limit The miter limit to set. */ setMiterLimit(limit: number): this; /** * Sets the dash pattern for stroked paths. * * Operator: `d` * @param pattern An array of dash lengths, in user space units. * @param phase The phase to start the dash pattern at, in user space units. */ setDashPattern(pattern: number[], phase: number): this; /** * Applies extended graphics state parameters such as opacity or blend mode. * * Operator: `gs` */ setGraphicsState(graphicsState: ExtGState): this; /** * Sets the stroke color in DeviceRGB. * This is a shorthand for `setStrokeColor({ colorSpace: 'DeviceRGB', components: [r, g, b] })`. * * Operator: `RG` */ setStrokeRGB(r: number, g: number, b: number): this; /** * Sets the fill color in DeviceRGB. * This is a shorthand for `setFillColor({ colorSpace: 'DeviceRGB', components: [r, g, b] })`. * * Operator: `rg` */ setFillRGB(r: number, g: number, b: number): this; /** * Sets the stroke color in DeviceGray. * This is a shorthand for `setStrokeColor({ colorSpace: 'DeviceGray', components: [gray] })`. * * Operator: `G` */ setStrokeGray(gray: number): this; /** * Sets the fill color in DeviceGray. * This is a shorthand for `setFillColor({ colorSpace: 'DeviceGray', components: [gray] })`. * Operator: `g` */ setFillGray(gray: number): this; /** * Sets the stroke color in DeviceCMYK. * This is a shorthand for `setStrokeColor({ colorSpace: 'DeviceCMYK', components: [c, m, y, k] })`. * * Operator: `K` */ setStrokeCMYK(c: number, m: number, y: number, k: number): this; /** * Sets the fill color in DeviceCMYK. * This is a shorthand for `setFillColor({ colorSpace: 'DeviceCMYK', components: [c, m, y, k] })`. * * Operator: `k` */ setFillCMYK(c: number, m: number, y: number, k: number): this; /** * Sets the stroke color using a `Color` object. * * Operator: `RG` for DeviceRGB, `G` for DeviceGray, `K` for * DeviceCMYK. For ICC-based color spaces, `CS` + `SC`, skipping `CS` * if the color space is unchanged. * * @param color The color to use. */ setStrokeColor(color: Color): this; /** * Sets the fill color using a `Color` object. * * Operator: `rg` for DeviceRGB, `g` for DeviceGray, `k` for * DeviceCMYK. For ICC-based color spaces, `cs` + `sc`, skipping `cs` * if the color space is unchanged. * * @param color The color to use. */ setFillColor(color: Color): this; /** * Moves the current point to a new position. * * Operator: `m` * @param x The x-coordinate of the new position. * @param y The y-coordinate of the new position. */ moveTo(x: number, y: number): this; /** * Adds a straight line segment to the current path. * * Operator: `l` * @param x The x-coordinate of the end point of the line. * @param y The y-coordinate of the end point of the line. */ lineTo(x: number, y: number): this; /** * Adds a cubic Bézier curve segment, extending from the current point * to the end point x3,y3 using the control points x1,y1 and x2,y2. * * Operator: `c` * @param x1 The x-coordinate of the first control point. * @param y1 The y-coordinate of the first control point. * @param x2 The x-coordinate of the second control point. * @param y2 The y-coordinate of the second control point. * @param x3 The x-coordinate of the end point of the curve. * @param y3 The y-coordinate of the end point of the curve. */ curveTo(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): this; /** * Adds a cubic Bézier curve using the current point as first control * point. * * Operator: `v` * @param x2 The x-coordinate of the second control point. * @param y2 The y-coordinate of the second control point. * @param x3 The x-coordinate of the end point of the curve. * @param y3 The y-coordinate of the end point of the curve. */ smoothCurveToFinal(x2: number, y2: number, x3: number, y3: number): this; /** * Adds a cubic Bézier curve using the endpoint as second control point. * * Operator: `y` * @param x1 The x-coordinate of the first control point. * @param y1 The y-coordinate of the first control point. * @param x3 The x-coordinate of the end point of the curve. * @param y3 The y-coordinate of the end point of the curve. */ smoothCurveToInitial(x1: number, y1: number, x3: number, y3: number): this; /** * Closes the current subpath. * * Operator: `h` */ closePath(): this; /** * Appends a rectangle to the current path. * * Operator: `re` * @param x The x-coordinate of the lower-left corner of the rectangle. * @param y The y-coordinate of the lower-left corner of the rectangle. * @param width The width of the rectangle. * @param height The height of the rectangle. */ rect(x: number, y: number, width: number, height: number): this; /** * Strokes the current path. * * Operator: `S` */ stroke(): this; /** * Closes and strokes the current path. * * Operator: `s` */ closeAndStroke(): this; /** * Fills the current path using the nonzero winding rule. * * Operator: `f` */ fill(): this; /** * Fills the current path using the even-odd rule. * * Operator: `f*` */ fillEvenOdd(): this; /** * Fills and strokes using the nonzero rule. * * Operator: `B` */ fillAndStroke(): this; /** * Fills and strokes using the even-odd rule. * * Operator: `B*` */ fillAndStrokeEvenOdd(): this; /** * Ends the current path without painting it. * * Operator: `n` */ endPath(): this; /** * Modifies the clipping path by intersecting it with the current path * using the nonzero rule. * * Operator: `W` */ clip(): this; /** * Modifies the clipping path by intersecting it with the current path * using the even-odd rule. * * Operator: `W*` */ clipEvenOdd(): this; /** * Begins a text object, initializing the text matrix and text line * matrix. Note that text objects cannot be nested. * * Operator: `BT` */ beginText(): this; /** * Ends a text object, discarding the text matrix and text line matrix. * * Operator: `ET` */ endText(): this; /** * Sets spacing between characters. * * Operator: `Tc` * @param charSpace The character spacing to set, in text space units. */ setCharacterSpacing(charSpace: number): this; /** * Sets spacing between words. * * Operator: `Tw` * @param wordSpace The word spacing to set, in text space units. */ setWordSpacing(wordSpace: number): this; /** * Sets horizontal text scaling, expressed as a percentage of normal * spacing. * * Operator: `Tz` * @param scale The horizontal scaling to set, as a percentage (e.g., * 100 for normal size). */ setHorizontalScaling(scale: number): this; /** * Set the text leading, i.e., the distance between baselines of * consecutive lines of text. * * Operator: `TL` * @param leading The text leading to set, in text space units. */ setTextLeading(leading: number): this; /** * Sets the text font and size. The font will be added to the page's * resources if not already present. * * Operator: `Tf` * @param font The font to set. * @param fontSize The font size to set. */ setFontAndSize(font: PDFFont, fontSize: number): this; /** * Sets how text is rendered or clipped. * * Operator: `Tr` * @param mode The text rendering mode to set. */ setTextRenderingMode(mode: TextRenderingMode): this; /** * Sets vertical text displacement. Positive values move text up in text * space. * * Operator: `Ts` * @param rise The text rise to set, in text space units. */ setTextRise(rise: number): this; /** * Moves the text position to the specified offset, relative to the * start of the current line. * * Operator: `Td` * @param tx The x-offset to move to, in text space units. * @param ty The y-offset to move to, in text space units. */ moveTextPosition(tx: number, ty: number): this; /** * Moves the text position to the specified offset, relative to the * start of the current line, and updates the text leading. * * Operator: `TD` * @param tx The x-offset to move to, in text space units. * @param ty The y-offset to move to, in text space units. */ moveTextPositionAndSetLeading(tx: number, ty: number): this; /** * Replaces the current text matrix and text line matrix with the specified matrix (Tm). * The matrix is specified as six numbers representing the following 3x3 matrix: * ``` * | a b 0 | * | c d 0 | * | e f 1 | * ``` * * Operator: `Tm` */ setTextMatrix(a: number, b: number, c: number, d: number, e: number, f: number): this; /** * Moves to the next text line using current text leading. * * Operator: `T*` */ nextLine(): this; /** * Shows a text string at the current text position. * Requires a font to be set via `setFontAndSize` first. * * Operator: `Tj` * @param text The text string to show. */ showText(text: string | PDFString): this; /** * Shows text with per-glyph positioning adjustments at the current text * position. Requires a font to be set via `setFontAndSize` first. * * Operator: `TJ` * @param glyphRun The glyph run to show with positioning adjustments. */ showPositionedText(glyphRun: ShapedGlyph[]): this; /** * Validates the content stream state. Throws if there are * unterminated text objects or unbalanced graphics state saves. */ validate(): void; private get _currentGState(); private requireTextObject; private requireCurrentFont; /** * Draws an image at the current position. The image resource will be * added to the page's resources if not already present. * * Operator: `Do` * @param image The image to draw. */ drawImage(image: PDFImage): this; /** * Draws an image at the specified position and size. This is a * convenience function that wraps the image drawing in a graphics * state, applies the necessary transformation matrix, and paints the * image. * * @param image The image to draw. * @param x The x-coordinate of the lower-left corner where the image * will be placed. * @param y The y-coordinate of the lower-left corner where the image * will be placed. * @param width The width to draw the image at, in user space units. * @param height The height to draw the image at, in user space units. */ drawImageAt(image: PDFImage, x: number, y: number, width: number, height: number): this; }