Skip to content

Commit

Permalink
ADD maxHeight option to text.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmihelac committed Jun 3, 2015
1 parent 70375eb commit 4148e43
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/layoutBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,16 @@ LayoutBuilder.prototype.processTable = function(tableNode) {
// leafs (texts)
LayoutBuilder.prototype.processLeaf = function(node) {
var line = this.buildNextLine(node);
var currentHeight = (line) ? line.getHeight() : 0;
var maxHeight = node.maxHeight || -1;

while (line) {
var positions = this.writer.addLine(line);
while (line && (maxHeight === -1 || currentHeight < maxHeight)) {
var positions = this.writer.addLine(line);
node.positions.push(positions);
line = this.buildNextLine(node);
line = this.buildNextLine(node);
if (line) {
currentHeight += line.getHeight();
}
}
};

Expand All @@ -539,6 +544,7 @@ LayoutBuilder.prototype.buildNextLine = function(textNode) {
}

line.lastLineInParagraph = textNode._inlines.length === 0;

return line;
};

Expand Down
10 changes: 10 additions & 0 deletions tests/layoutBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ describe('LayoutBuilder', function() {
assert.equal(pages[0].items.length, 6);
});

it('should respect maxHeight', function() {
var desc = [{
text: 'another paragraph, this time a little bit longer though, we want to force this line to be broken into several lines',
maxHeight: 15
}];
var pages = builder.layoutDocument(desc, sampleTestProvider);
assert.equal(pages.length, 1);
assert.equal(pages[0].items.length, 1);
});

it('should add new pages when theres not enough space left on current page', function() {
var desc = [
'first paragraph',
Expand Down

0 comments on commit 4148e43

Please sign in to comment.