diff --git a/CHANGELOG.md b/CHANGELOG.md index a085df2a..eb58c753 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## pdfkit changelog +### Unreleased + +- Fix index not counting when rendering ordered lists (#1517) + ### [v0.15.1] - 2024-10-30 - Fix browserify transform sRGB_IEC61966_2_1.icc file diff --git a/lib/mixins/text.js b/lib/mixins/text.js index d78f4465..ad4273d0 100644 --- a/lib/mixins/text.js +++ b/lib/mixins/text.js @@ -153,12 +153,11 @@ export default { } }; - const drawListItem = function(listItem) { + const drawListItem = function(listItem, i) { wrapper = new LineWrapper(this, options); wrapper.on('line', this._line); level = 1; - let i = 0; wrapper.once('firstLine', () => { let item, itemType, labelType, bodyType; if (options.structParent) { @@ -225,7 +224,7 @@ export default { for (let i = 0; i < items.length; i++) { - drawListItem.call(this, items[i]); + drawListItem.call(this, items[i], i); } return this; diff --git a/tests/visual/__image_snapshots__/text-spec-js-text-list-lettered-1-snap.png b/tests/visual/__image_snapshots__/text-spec-js-text-list-lettered-1-snap.png new file mode 100644 index 00000000..27deba7e Binary files /dev/null and b/tests/visual/__image_snapshots__/text-spec-js-text-list-lettered-1-snap.png differ diff --git a/tests/visual/__image_snapshots__/text-spec-js-text-list-numbered-1-snap.png b/tests/visual/__image_snapshots__/text-spec-js-text-list-numbered-1-snap.png new file mode 100644 index 00000000..3ad335ad Binary files /dev/null and b/tests/visual/__image_snapshots__/text-spec-js-text-list-numbered-1-snap.png differ diff --git a/tests/visual/__image_snapshots__/text-spec-js-text-list-with-sub-list-ordered-1-snap.png b/tests/visual/__image_snapshots__/text-spec-js-text-list-with-sub-list-ordered-1-snap.png new file mode 100644 index 00000000..eed6dea1 Binary files /dev/null and b/tests/visual/__image_snapshots__/text-spec-js-text-list-with-sub-list-ordered-1-snap.png differ diff --git a/tests/visual/__image_snapshots__/text-spec-js-text-list-with-sub-list-unordered-1-snap.png b/tests/visual/__image_snapshots__/text-spec-js-text-list-with-sub-list-unordered-1-snap.png new file mode 100644 index 00000000..f458f0d5 Binary files /dev/null and b/tests/visual/__image_snapshots__/text-spec-js-text-list-with-sub-list-unordered-1-snap.png differ diff --git a/tests/visual/text.spec.js b/tests/visual/text.spec.js index 4c504df0..b44d2cd2 100644 --- a/tests/visual/text.spec.js +++ b/tests/visual/text.spec.js @@ -62,6 +62,34 @@ describe('text', function() { return runDocTest(function(doc) { doc.font('tests/fonts/Roboto-Regular.ttf'); doc.list(['Foo\nBar', 'Foo\rBar', 'Foo\r\nBar'], [100, 150]); + }); + }); + + test('list (numbered)', function() { + return runDocTest(function(doc) { + doc.font('tests/fonts/Roboto-Regular.ttf'); + doc.fillColor('#000').list(['One', 'Two', 'Three'], 100, 150, {listType: 'numbered'}); + }); + }); + + test('list (lettered)', function() { + return runDocTest(function(doc) { + doc.font('tests/fonts/Roboto-Regular.ttf'); + doc.fillColor('#000').list(['One', 'Two', 'Three'], 100, 150, {listType: 'lettered'}); + }); + }); + + test('list with sub-list (unordered)', function() { + return runDocTest(function(doc) { + doc.font('tests/fonts/Roboto-Regular.ttf'); + doc.fillColor('#000').list(['One', ['One.One', 'One.Two'], 'Three'], 100, 150); + }) + }) + + test('list with sub-list (ordered)', function() { + return runDocTest(function(doc) { + doc.font('tests/fonts/Roboto-Regular.ttf'); + doc.fillColor('#000').list(['One', ['One.One', 'One.Two'], 'Three'], 100, 150, {listType: 'numbered'}); }) }) });