Skip to content

Commit 1bb2cee

Browse files
committed
change property name and order to match css spec
1 parent 3050110 commit 1bb2cee

4 files changed

Lines changed: 23 additions & 26 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- Replace outdated jpeg-exif with minimal implementation
1616
- Replace outdated crypto-js with maintained small alternatives
1717
- Fix issue with indentation with `indentAllLines: true` when a new page is created
18-
- Extend cornerRadius param to accept an array of radii
18+
- Extend `roundedRect` with `borderRadius` as number for all corners or per-corner array (CSS order)
1919

2020
### [v0.17.2] - 2025-08-30
2121

docs/vector.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ PDFKit also includes some helpers that make defining common shapes much
5757
easier. Here is a list of the helpers.
5858

5959
* `rect(x, y, width, height)`
60-
* `roundedRect(x, y, width, height, cornerRadius)`
60+
* `roundedRect(x, y, width, height, borderRadius)`
6161
* `ellipse(centerX, centerY, radiusX, radiusY = radiusX)`
6262
* `circle(centerX, centerY, radius)`
6363
* `polygon(points...)`
6464

65-
`roundedRect` `cornerRadius` param accepts a single radius (number) or per-corner radii (array).
66-
If an array, the order is: `[topRight, bottomRight, bottomLeft, topLeft]`.
67-
For example, to round only the right side corners: `roundedRect(x, y, w, h, [20, 20, 0, 0])`.
65+
`roundedRect` `borderRadius` accepts a single radius (number) or per-corner radii (array).
66+
If an array with four values, the order matches CSS `border-radius`:
67+
`/* top-left | top-right | bottom-right | bottom-left */`
68+
For example, to round only the right-side corners: `roundedRect(x, y, w, h, [0, 20, 20, 0])`.
6869

6970
The last one, `polygon`, allows you to pass in a list of points (arrays of x,y
7071
pairs), and it will create the shape by moving to the first point, and then

lib/mixins/vector.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,27 @@ export default {
113113
},
114114

115115
/**
116-
* @param {number|number[]} cornerRadius - Corner radius (number) or per-corner radii (array).
117-
* If an array, order is: top-right, bottom-right, bottom-left, top-left.
116+
* @param {number|number[]} borderRadius - Radius (number) or per-corner radii (array).
117+
* If an array, order matches CSS `border-radius` with four values:
118+
* top-left, top-right, bottom-right, bottom-left.
118119
*/
119-
roundedRect(x, y, w, h, cornerRadius) {
120-
if (cornerRadius == null) {
121-
cornerRadius = 0;
120+
roundedRect(x, y, w, h, borderRadius) {
121+
if (borderRadius == null) {
122+
borderRadius = 0;
122123
}
123124

124125
let radii;
125-
if (Array.isArray(cornerRadius)) {
126-
radii = cornerRadius.slice(0, 4);
126+
if (Array.isArray(borderRadius)) {
127+
radii = borderRadius.slice(0, 4);
127128
} else {
128-
radii = [
129-
cornerRadius, // top-right
130-
cornerRadius, // bottom-right
131-
cornerRadius, // bottom-left
132-
cornerRadius, // top-left
133-
];
129+
radii = [borderRadius, borderRadius, borderRadius, borderRadius];
134130
}
135131

136132
const limit = Math.min(0.5 * w, 0.5 * h);
137-
const rTR = Math.max(0, Math.min(radii[0] || 0, limit));
138-
const rBR = Math.max(0, Math.min(radii[1] || 0, limit));
139-
const rBL = Math.max(0, Math.min(radii[2] || 0, limit));
140-
const rTL = Math.max(0, Math.min(radii[3] || 0, limit));
133+
const rTL = Math.max(0, Math.min(radii[0] || 0, limit));
134+
const rTR = Math.max(0, Math.min(radii[1] || 0, limit));
135+
const rBR = Math.max(0, Math.min(radii[2] || 0, limit));
136+
const rBL = Math.max(0, Math.min(radii[3] || 0, limit));
141137

142138
const cpTR = rTR * (1.0 - KAPPA);
143139
const cpBR = rBR * (1.0 - KAPPA);

tests/unit/vector.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe('Vector Graphics', () => {
178178
});
179179

180180
describe('roundedRect', () => {
181-
test('uses cornerRadius to draw rounded corners by default', () => {
181+
test('uses borderRadius to draw rounded corners by default', () => {
182182
const docData = logData(document);
183183

184184
document.roundedRect(50, 50, 100, 80, 20).stroke();
@@ -197,7 +197,7 @@ describe('Vector Graphics', () => {
197197
expect(streamString).toMatch(/\sc[\s\n]/);
198198
});
199199

200-
test('cornerRadius array can disable rounded corners', () => {
200+
test('borderRadius array can disable rounded corners', () => {
201201
const docData = logData(document);
202202

203203
document.roundedRect(50, 50, 100, 80, [0, 0, 0, 0]).stroke();
@@ -224,8 +224,8 @@ describe('Vector Graphics', () => {
224224
const w = 30;
225225
const r = 5;
226226

227-
// Only the top-right corner is rounded
228-
document.roundedRect(x, y, w, 40, [r, 0, 0, 0]).stroke();
227+
// Only the top-right corner is rounded (CSS order: TL, TR, BR, BL)
228+
document.roundedRect(x, y, w, 40, [0, r, 0, 0]).stroke();
229229
document.end();
230230

231231
const objects = getObjects(docData);

0 commit comments

Comments
 (0)