diff --git a/lib/mixins/text.js b/lib/mixins/text.js index 43903abd3..3999eb3b3 100644 --- a/lib/mixins/text.js +++ b/lib/mixins/text.js @@ -102,10 +102,6 @@ export default { const unit = Math.round((this._font.ascender / 1000) * this._fontSize); const midLine = unit / 2; const r = options.bulletRadius || unit / 3; - const indent = - options.textIndent || (listType === 'bullet' ? r * 5 : unit * 2); - const itemIndent = - options.bulletIndent || (listType === 'bullet' ? r * 8 : unit * 2); let level = 1; const items = []; @@ -143,6 +139,13 @@ export default { return `${text}.`; } }; + + const getIndent = function(level) { + return (typeof options.customTextIndent === "function" && options.customTextIndent(level)) || options.textIndent || (listType === 'bullet' ? r * 5 : unit * 2); + } + const getItemIndent = function(level) { + return (typeof options.customItemIndent === "function" && options.customItemIndent(level)) || options.bulletIndent || (listType === 'bullet' ? r * 8 : unit * 2); + } wrapper = new LineWrapper(this, options); wrapper.on('line', this._line); @@ -152,31 +155,35 @@ export default { wrapper.on('firstLine', () => { let l; if ((l = levels[i++]) !== level) { - const diff = itemIndent * (l - level); + const diff = getItemIndent(level) * (l - level); this.x += diff; wrapper.lineWidth -= diff; level = l; } + if (listType !== "bullet" && typeof options.customLabel === "function") { + return options.customLabel(numbers[i - 1], level); + } + switch (listType) { case 'bullet': - this.circle(this.x - indent + r, this.y + midLine, r); + this.circle(this.x - getIndent(level) + r, this.y + midLine, r); return this.fill(); case 'numbered': case 'lettered': var text = label(numbers[i - 1]); - return this._fragment(text, this.x - indent, this.y, options); + return this._fragment(text, this.x - getIndent(level), this.y, options); } }); wrapper.on('sectionStart', () => { - const pos = indent + itemIndent * (level - 1); + const pos = getIndent(level) + getItemIndent(level) * (level - 1); this.x += pos; return (wrapper.lineWidth -= pos); }); wrapper.on('sectionEnd', () => { - const pos = indent + itemIndent * (level - 1); + const pos = getIndent(level) + getItemIndent(level) * (level - 1); this.x -= pos; return (wrapper.lineWidth += pos); });