import { _PdfContentStream, _PdfRecord, PdfPage, Point } from '@syncfusion/ej2-pdf'; import { _TextProcessingMode } from '../enum'; import { PdfRedactor } from './pdf-redactor'; /** * Parses path drawing operators and rewrites shapes that intersect redaction regions. * * @private */ export declare class _PdfShapeParser { private _currentLocation; private _pathAccumulator; private _clearPathAccumulator; /** * Finds and emits path records for a redacted shape starting from index `i`. * * @private * @param {_PdfRecord[]} recordCollection The full record collection of the content stream. * @param {number} i The starting record index to scan from. * @param {PdfPage} page The page hosting the content. * @param {PdfRedactor} redaction The redactor owning state and helpers. * @param {_TextProcessingMode} mode Active processing mode. * @param {_PdfContentStream} stream Destination stream to receive rewritten commands. * @returns {number} The last processed record index or `-1` if nothing was emitted. */ _findRedactPath(recordCollection: _PdfRecord[], i: number, page: PdfPage, redaction: PdfRedactor, mode: _TextProcessingMode, stream: _PdfContentStream): number; /** * Flattens curve segments to line segments when needed. * * @private * @param {_PdfPathCommand[]} shapePaths Path commands to inspect. * @returns {_PdfPathCommand[]} Flattened path commands if curves were present; otherwise unchanged. */ private _flattenIfNeeded; /** * Clips the given shape point rings against all non-text redaction regions on the page. * * @private * @param {Point[][]} shapePoints Input shape rings. * @param {PdfRedactionRegion[]} redactions Redaction regions for the page. * @param {PdfPage} page Page providing size/transform hints. * @returns {{updatedShapePoints: Point[][], intersectionsPoints: Point[], isInSide: boolean, isOutSide: boolean, inSideRects: _PdfPathCommand[][], totalRedactionPoints: Point[][]}} * Clipped shape rings and classification context. */ private _clipAgainstRedactions; /** * Adjusts redaction bounds to the shape coordinate space. * * @private * @param {Rectangle} bounds Redaction bounds (page space). * @param {number} y Sample Y from current shape ring. * @param {PdfPage} page The page used for Y inversion. * @returns {Rectangle} Adjusted rectangle. */ private _adjustRedactionBounds; /** * Determines whether rendering should be skipped for a shape that remains unchanged and not inside a redaction. * * @private * @param {Point} shapePoints The possibly modified shape points. * @param {_PdfPathCommand} originalPoints The original path commands. * @param {boolean} isInSide Whether shape is fully inside a redaction region. * @returns {boolean} `true` to skip rendering; otherwise, `false`. */ private _shouldSkipRendering; /** * Builds drawing records `_PdfRecord[]` from clipped shape rings for the operator. * * @private * @param {string} value The drawing operator (`S`, `s`, `f`, `f*`, `B`, etc). * @param {Point} shapePoints The shape rings to emit. * @param {Point} intersectionsPoints Intersections collected during clip. * @param {boolean} isInSide If shape was fully inside a redaction. * @param {boolean} isOutSide If shape was fully outside a redaction. * @param {_PdfPathCommand | undefined} inSideRects Paths for inside rectangles (when applicable). * @param {Point} totalRedactionPoints Accumulated redaction polygon points. * @returns {_PdfRecord} Records to write to the content stream. */ private _buildRenderingRecords; /** * Converts a parsed `_PdfPathFigure` into the flat path command list. * * @private * @param {_PdfPathFigure} figure The path figure with segments. * @returns {_PdfPathCommand[]} Accumulated path commands. */ private _getGeometry; /** * Validates that a rect operator is followed by drawable operators (not `n`). * * @private * @param {_PdfRecord[]} recordCollection Record list. * @param {number} i Index of the `re` equivalent sequence. * @returns {boolean} `true` if the rectangle is valid to emit; otherwise, `false`. */ private _isValidRectangle; /** * Emits path commands for a rectangle sequence, if valid. * * @private * @param {_PdfRecord[]} recordCollection Record list. * @param {number} i Index of the rectangle start. * @param {string[]} element Rectangle operands `[x, y, w, h]` as strings. * @returns {_PdfRecord[]} The generated path records; empty if not valid. */ _processRectangle(recordCollection: _PdfRecord[], i: number, element: string[]): _PdfRecord[]; /** * Converts rectangle operands into a sequence of move/line/close commands. * * @private * @param {_PdfRecord[]} recordCollection Record list (for lookahead). * @param {number} i Index at which the rect started. * @param {string[]} element Rectangle operands `[x, y, w, h]` as strings. * @returns {_PdfRecord[]} The path commands representing the rectangle. */ private _generateRectanglePath; /** * Builds a rectangular path as a list of path commands. * * @private * @param {Rectangle} rect The rectangle specification. * @returns {_PdfPathCommand[]} Path commands for the rectangle. */ private _rectToPathCommands; /** * Extracts a flat list of points from a sequence of path commands. * * @private * @param {_PdfPathCommand[]} commands Command list. * @returns {Point[]} Flattened points. */ private _extractPoints; /** * Returns whether a point matches any intersection point, exactly. * * @private * @param {Point} pt The point to check. * @param {Point[]} [polygonIntersections] Known intersection list. * @returns {boolean} `true` if the point is an intersection; otherwise, `false`. */ private _isIntersecting; /** * Converts a set of point-rings to move/line path commands, optionally splitting at intersections. * * @private * @param {Point} input Rings to convert. * @param {Point} [polygonIntersections] Intersection points along the rings. * @returns {_PdfPathCommand[]} Path commands representing the rings. */ private _convertPointsToPath; /** * Flattens a cubic Bézier curve to a list of `segments` line points. * * @private * @param {Point} p0 Start point. * @param {Point} p1 First control point. * @param {Point} p2 Second control point. * @param {Point} p3 End point. * @param {number} [segments=8] Number of line segments to generate. * @returns {Point[]} The interpolated points on the curve. */ private _flattenBezierCurve; /** * Flattens all cubic curve commands in a path into straight line segments. * * @private * @param {_PdfPathCommand[]} commands Path commands (with `m/l/c/h`). * @param {number} [segmentsPerCurve=8] Line segments per curve. * @returns {_PdfPathCommand[]} The flattened command list. */ private _flattenPdfPathCommands; /** * Deep-equality test for two point arrays. * * @private * @param {Point[]} a Left array. * @param {Point[]} b Right array. * @returns {boolean} `true` if the arrays are same length and equal point-wise. */ private _pointsArraysEqual; /** * Removes duplicate points within each ring while preserving the first occurrence. * * @private * @param {Point} pointsArrays Rings to process. * @returns {Point} Rings without duplicates. */ private _removeDuplicatePoints; /** * Removes points that belong to redaction rectangles to avoid retracing them. * * @private * @param {Point} nonRedactedPointsArray Rings to filter. * @param {Point} redactionPointsArray Redaction polygon rings. * @returns {Point} Filtered rings without redaction points. */ private _removeRedactionPoints; /** * Builds `_PdfRecord[]` from a list of path commands. * * @private * @param {_PdfPathCommand[]} commands Path commands to convert. * @returns {_PdfRecord[]} Content stream records. */ private _buildRecords; } /** * A lightweight path command representation used by `_PdfShapeParser`. * * @private */ export declare type _PdfPathCommand = { operator: string; points: Point[]; };