Skip to content

Commit

Permalink
#1517 Fix ordered lists (#1568)
Browse files Browse the repository at this point in the history
* adds test cases for ordered lists

* fixes broken labels for ordered lists (#1517)

* adds test for sub-lists (ordered and unordered)

* update changelog for fix of #1517

---------

Co-authored-by: David <filecage@users.noreply.github.com>
  • Loading branch information
filecage and filecage authored Dec 14, 2024
1 parent 4bad866 commit ffbbee5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/mixins/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions tests/visual/text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
})
})
});

0 comments on commit ffbbee5

Please sign in to comment.