(options: RectangleOpsOptions)
| 119 | * Generate operators for drawing a rectangle. |
| 120 | */ |
| 121 | export function drawRectangleOps(options: RectangleOpsOptions): Operator[] { |
| 122 | const ops: Operator[] = [pushGraphicsState()]; |
| 123 | |
| 124 | // Apply graphics state for opacity if provided |
| 125 | if (options.graphicsStateName) { |
| 126 | ops.push(setGraphicsState(options.graphicsStateName)); |
| 127 | } |
| 128 | |
| 129 | // Apply rotation if specified |
| 130 | if (options.rotate) { |
| 131 | const { angle, originX, originY } = options.rotate; |
| 132 | const rad = (angle * Math.PI) / 180; |
| 133 | const cos = Math.cos(rad); |
| 134 | const sin = Math.sin(rad); |
| 135 | // Translate to origin, rotate, translate back |
| 136 | ops.push(concatMatrix(1, 0, 0, 1, originX, originY)); |
| 137 | ops.push(concatMatrix(cos, sin, -sin, cos, 0, 0)); |
| 138 | ops.push(concatMatrix(1, 0, 0, 1, -originX, -originY)); |
| 139 | } |
| 140 | |
| 141 | // Set stroke properties |
| 142 | if (options.strokeColor) { |
| 143 | ops.push(setStrokeColor(options.strokeColor)); |
| 144 | ops.push(setLineWidth(options.strokeWidth ?? 1)); |
| 145 | } else if (options.strokePatternName) { |
| 146 | ops.push(setStrokingColorSpace(ColorSpace.Pattern)); |
| 147 | ops.push(setStrokingColorN(options.strokePatternName)); |
| 148 | ops.push(setLineWidth(options.strokeWidth ?? 1)); |
| 149 | } |
| 150 | |
| 151 | if (options.dashArray && options.dashArray.length > 0) { |
| 152 | ops.push(setDash(options.dashArray, options.dashPhase ?? 0)); |
| 153 | } |
| 154 | |
| 155 | // Set fill color or pattern |
| 156 | if (options.fillColor) { |
| 157 | ops.push(setFillColor(options.fillColor)); |
| 158 | } else if (options.fillPatternName) { |
| 159 | ops.push(setNonStrokingColorSpace(ColorSpace.Pattern)); |
| 160 | ops.push(setNonStrokingColorN(options.fillPatternName)); |
| 161 | } |
| 162 | |
| 163 | // Draw the path |
| 164 | if (options.cornerRadius && options.cornerRadius > 0) { |
| 165 | ops.push( |
| 166 | ...roundedRectPathOps( |
| 167 | options.x, |
| 168 | options.y, |
| 169 | options.width, |
| 170 | options.height, |
| 171 | options.cornerRadius, |
| 172 | ), |
| 173 | ); |
| 174 | } else { |
| 175 | ops.push(...rectPathOps(options.x, options.y, options.width, options.height)); |
| 176 | } |
| 177 | |
| 178 | // Paint the path |
no test coverage detected