pdfjs
Advanced tools
Comparing version 1.0.0-alpha.3 to 1.0.0-alpha.4
@@ -7,5 +7,5 @@ 'use strict' | ||
BaseElement.prototype.createNode = function(x, y, width) { | ||
BaseElement.prototype.createNode = function() { | ||
var node = new this.Node(this) | ||
return node | ||
} |
@@ -12,1 +12,10 @@ 'use strict' | ||
require('../pdf/utils').inherits(Box, require('./container')) | ||
Box.prototype.clone = function() { | ||
var clone = new Box() | ||
clone.style = this.style | ||
clone.children = this.children.map(function(child) { | ||
return child.clone() | ||
}) | ||
return clone | ||
} |
@@ -23,1 +23,10 @@ 'use strict' | ||
} | ||
Cell.prototype.clone = function() { | ||
var clone = new Cell() | ||
clone.style = this.style | ||
clone.children = this.children.map(function(child) { | ||
return child.clone() | ||
}) | ||
return clone | ||
} |
@@ -15,1 +15,7 @@ 'use strict' | ||
require('../pdf/utils').inherits(Image, require('./base')) | ||
Image.prototype.clone = function() { | ||
var clone = new Image(this.img) | ||
clone.style = this.style | ||
return clone | ||
} |
@@ -35,1 +35,5 @@ 'use strict' | ||
}) | ||
LineBreak.prototype.clone = function() { | ||
return new LineBreak(this.style) | ||
} |
@@ -17,2 +17,8 @@ 'use strict' | ||
} | ||
} | ||
} | ||
Operations.prototype.clone = function() { | ||
var clone = new Operations | ||
clone.ops = this.ops.slice() | ||
return clone | ||
} |
@@ -11,1 +11,5 @@ 'use strict' | ||
require('../pdf/utils').inherits(PageCount, Word) | ||
PageCount.prototype.clone = function() { | ||
return this | ||
} |
@@ -11,1 +11,10 @@ 'use strict' | ||
require('../pdf/utils').inherits(PageNumber, Word) | ||
PageNumber.prototype.clone = function() { | ||
var clone = new PageNumber(this.style) | ||
clone.style = this.style | ||
clone.children = [clone].concat(this.children.slice(1).map(function(child) { | ||
return child.clone() | ||
})) | ||
return clone | ||
} |
@@ -25,1 +25,10 @@ 'use strict' | ||
} | ||
Row.prototype.clone = function() { | ||
var clone = new Row() | ||
clone.style = this.style | ||
clone.children = this.children.map(function(child) { | ||
return child.clone() | ||
}) | ||
return clone | ||
} |
@@ -33,1 +33,13 @@ 'use strict' | ||
} | ||
Table.prototype.clone = function() { | ||
var clone = new Table() | ||
clone.style = this.style | ||
clone.children = this.children.map(function(child) { | ||
return child.clone() | ||
}) | ||
clone.beforeBreakChildren = this.beforeBreakChildren.map(function(child) { | ||
return child.clone() | ||
}) | ||
return clone | ||
} |
@@ -108,1 +108,10 @@ 'use strict' | ||
} | ||
Text.prototype.clone = function() { | ||
var clone = new Text() | ||
clone.style = this.style | ||
clone.children = this.children.map(function(child) { | ||
return child.clone() | ||
}) | ||
return clone | ||
} |
@@ -55,2 +55,11 @@ 'use strict' | ||
Word.prototype.clone = function() { | ||
var clone = new Word(this.word, this.style) | ||
clone.style = this.style | ||
clone.children = [clone].concat(this.children.slice(1).map(function(child) { | ||
return child.clone() | ||
})) | ||
return clone | ||
} | ||
Word.prototype.toString = function() { | ||
@@ -57,0 +66,0 @@ return this.children.map(function(word) { |
@@ -32,2 +32,3 @@ 'use strict' | ||
this.afterBreak.forEach(function(node) { | ||
cursor.x = node.x.val | ||
node.compute(cursor) | ||
@@ -81,3 +82,3 @@ this.top -= node.height | ||
this.pageBreaks = [] | ||
this.addPage() | ||
this.addPage(doc) | ||
@@ -172,3 +173,3 @@ this.nextPageBreakId = 1 | ||
var offset = self.offset | ||
var mustBreak = (node.y - node.height) + offset < self.bottom | ||
var mustBreak = (node.y.val - node.height) + offset < self.bottom | ||
if (!mustBreak) { | ||
@@ -218,10 +219,14 @@ return false | ||
CursorFactory.prototype.addPage = function() { | ||
CursorFactory.prototype.addPage = function(parent) { | ||
var page = new Page( | ||
this.currentPage, | ||
this.header && this.header.createNode(), | ||
this.footer && this.footer.createNode(), | ||
(this.afterBreak[this.afterBreak.length - 1] || []).map(function(child) { | ||
return child.clone() | ||
}) | ||
this.header && this.header.clone().createNode(), | ||
this.footer && this.footer.clone().createNode(), | ||
(this.afterBreak[this.afterBreak.length - 1] || []) | ||
.filter(function(child) { | ||
return child.valid(parent) | ||
}) | ||
.map(function(child) { | ||
return child.clone() | ||
}) | ||
) | ||
@@ -265,3 +270,3 @@ | ||
if (++this.currentPage > this.pages.length) { | ||
this.addPage() | ||
this.addPage(parent) | ||
} | ||
@@ -268,0 +273,0 @@ } else { |
'use strict' | ||
var debug = require('debug')('pdfjs:break') | ||
var Value = require('../value') | ||
@@ -13,2 +14,5 @@ var BaseNode = module.exports = function() { | ||
this.arranged = false | ||
this.x = new Value(undefined) | ||
this.y = new Value(undefined) | ||
} | ||
@@ -29,4 +33,4 @@ | ||
BaseNode.prototype._compute = function(cursor) { | ||
this.x = cursor.x | ||
this.y = cursor.y | ||
this.x.val = cursor.x | ||
this.y.val = cursor.y | ||
@@ -61,3 +65,3 @@ this.width = 0 | ||
BaseNode.prototype.shift = function(offset) { | ||
this.y -= offset | ||
this.y.val -= offset | ||
@@ -109,4 +113,2 @@ if (this.children) { | ||
child.offset -= child.height | ||
if (i === 0) { | ||
@@ -167,1 +169,5 @@ child.children.length = 0 | ||
} | ||
BaseNode.prototype.valid = function() { | ||
return true | ||
} |
@@ -69,3 +69,3 @@ 'use strict' | ||
cursor.x = this.xBefore | ||
cursor.y = this.y - this.height | ||
cursor.y = this.y.val - this.height | ||
@@ -76,8 +76,8 @@ return cursor | ||
BoxNode.prototype._compute = function(cursor) { | ||
this.x = this.style.x !== null ? this.style.x : cursor.x | ||
this.y = cursor.y = this.style.y !== null ? this.style.y : cursor.y | ||
this.x.val = this.style.x !== null ? this.style.x : cursor.x | ||
this.y.val = cursor.y = this.style.y !== null ? this.style.y : cursor.y | ||
var maxWidth = cursor.width | ||
if (this.x + maxWidth > cursor.right) { | ||
maxWidth = cursor.right - this.x | ||
if (this.x.val + maxWidth > cursor.right) { | ||
maxWidth = cursor.right - this.x.val | ||
} | ||
@@ -93,6 +93,6 @@ | ||
var width = this.style.getBorderLeftWidth() + this.style.paddingLeft + this.width + this.style.paddingRight + this.style.getBorderRightWidth() | ||
var left = this.x + (this.style.getBorderLeftWidth() / 2) | ||
var top = this.y - (this.style.getBorderTopWidth() / 2) | ||
var right = this.x + width - (this.style.getBorderRightWidth() / 2) | ||
var bottom = this.y - height + (this.style.getBorderBottomWidth() / 2) | ||
var left = this.x.val + (this.style.getBorderLeftWidth() / 2) | ||
var top = this.y.val - (this.style.getBorderTopWidth() / 2) | ||
var right = this.x.val + width - (this.style.getBorderRightWidth() / 2) | ||
var bottom = this.y.val - height + (this.style.getBorderBottomWidth() / 2) | ||
@@ -99,0 +99,0 @@ // backogrund color |
@@ -54,4 +54,4 @@ 'use strict' | ||
CellNode.prototype.beforeContent = function(cursor) { | ||
cursor.x = this.x | ||
cursor.y = this.y | ||
cursor.x = this.x.val | ||
cursor.y = this.y.val | ||
@@ -62,8 +62,2 @@ return BoxNode.prototype.beforeContent.call(this, cursor) | ||
CellNode.prototype._compute = function(cursor) { | ||
// this.x = cursor.x | ||
// this.y = cursor.y | ||
// this.width = resolveWidth(this.style.width, cursor.width) | ||
// - this.style.paddingLeft - this.style.getBorderLeftWidth() | ||
// - this.style.paddingRight - this.style.getBorderRightWidth() | ||
} |
@@ -13,4 +13,4 @@ 'use strict' | ||
this.children = this.doc.children.map(function(child) { | ||
return child.createNode(this) | ||
}, this) | ||
return child.createNode() | ||
}) | ||
@@ -30,3 +30,7 @@ this.headers = [] | ||
} | ||
} | ||
DocumentNode.prototype.end = function(doc, parent) { | ||
var currentPage = doc.pages.kids.length | ||
var afterBreak = this.afterBreaks[currentPage] | ||
@@ -38,5 +42,3 @@ if (afterBreak) { | ||
} | ||
} | ||
DocumentNode.prototype.end = function(doc, parent) { | ||
var currentPage = doc.pages.kids.length | ||
@@ -43,0 +45,0 @@ var footer = this.footers[currentPage] |
@@ -21,4 +21,4 @@ 'use strict' | ||
ImageNode.prototype._compute = function(cursor) { | ||
this.x = cursor.x | ||
this.y = cursor.y | ||
this.x.val = cursor.x | ||
this.y.val = cursor.y | ||
@@ -74,6 +74,6 @@ this.renderWidth = this.info.width | ||
case 'right': | ||
this.x += cursor.width - this.renderWidth | ||
this.x.val += cursor.width - this.renderWidth | ||
break | ||
case 'center': | ||
this.x += (cursor.width - this.renderWidth) / 2 | ||
this.x.val += (cursor.width - this.renderWidth) / 2 | ||
break | ||
@@ -121,4 +121,4 @@ case 'left': | ||
var x = this.x | ||
var y = this.y - this.renderHeight | ||
var x = this.x.val | ||
var y = this.y.val - this.renderHeight | ||
@@ -125,0 +125,0 @@ |
@@ -25,4 +25,4 @@ 'use strict' | ||
LineBreakNode.prototype._compute = function(cursor) { | ||
this.x = cursor.x | ||
this.y = cursor.y | ||
this.x.val = cursor.x | ||
this.y.val = cursor.y | ||
@@ -29,0 +29,0 @@ this.width = 0 |
@@ -54,2 +54,3 @@ 'use strict' | ||
clone.widths = this.widths | ||
clone.x = this.x | ||
clone.children = this.children.map(function(child) { | ||
@@ -72,4 +73,6 @@ return child.clone() | ||
RowNode.prototype._compute = function(cursor) { | ||
this.x = cursor.x | ||
this.y = cursor.y | ||
if (this.x.val === undefined) { | ||
this.x.val = cursor.x | ||
} | ||
this.y.val = cursor.y | ||
@@ -89,4 +92,4 @@ var offset = 0, index = 0 | ||
child.y = cursor.y | ||
child.x = cursor.x + offset | ||
child.y.val = cursor.y | ||
child.x.val = cursor.x + offset | ||
offset += child.width | ||
@@ -105,6 +108,4 @@ + child.style.paddingLeft + child.style.paddingRight | ||
cursor.x = this.x | ||
cursor.y = this.y - this.height | ||
return cursor | ||
cursor.x = this.x.val | ||
cursor.y = this.y.val - this.height | ||
} | ||
@@ -111,0 +112,0 @@ |
@@ -38,13 +38,8 @@ 'use strict' | ||
TablePageBreakNode.prototype._compute = function(cursor) { | ||
this.x = cursor.x | ||
this.y = cursor.y | ||
this.x.val = cursor.x | ||
this.y.val = cursor.y | ||
} | ||
TablePageBreakNode.prototype.beforeContent = function(cursor) { | ||
this.yBefore = cursor.y | ||
return cursor | ||
} | ||
TablePageBreakNode.prototype.afterContent = function(cursor) { | ||
cursor.y = this.yBefore | ||
cursor.y = this.y.val | ||
} |
@@ -5,2 +5,3 @@ 'use strict' | ||
var TablePageBreakNode = require('./table-pagebreak') | ||
var ConditionalNode = require('./conditional') | ||
var RowProxy = require('../proxy/row') | ||
@@ -29,3 +30,11 @@ | ||
this.afterBreak = this.children.slice(0, this.style.headerRows) | ||
this.afterBreak = [] | ||
if (this.style.headerRows > 0) { | ||
var self = this | ||
this.afterBreak.push(new ConditionalNode( | ||
this.children.slice(0, this.style.headerRows), | ||
function(parent) { return parent === self } | ||
)) | ||
} | ||
} | ||
@@ -56,4 +65,4 @@ | ||
TableNode.prototype._compute = function(cursor) { | ||
this.x = cursor.x | ||
this.y = cursor.y | ||
this.x.val = cursor.x | ||
this.y.val = cursor.y | ||
@@ -96,2 +105,3 @@ this.width = utils.resolveWidth(this.style.width, cursor.width) | ||
this.children.forEach(function(row, j) { | ||
row.x = this.x | ||
row.width = this.width | ||
@@ -173,2 +183,8 @@ row.widths = this.widths | ||
if (this.afterBreak.length) { | ||
this.afterBreak[0].children.forEach(function(row) { | ||
row.x = this.x | ||
}, this) | ||
} | ||
this.beforeBreakChildren.forEach(function(row, j) { | ||
@@ -175,0 +191,0 @@ row.width = this.width |
@@ -37,4 +37,4 @@ 'use strict' | ||
TextNode.prototype._compute = function(cursor) { | ||
this.x = cursor.x | ||
var y = this.y = cursor.y | ||
this.x.val = cursor.x | ||
var y = this.y.val = cursor.y | ||
this.width = cursor.width | ||
@@ -41,0 +41,0 @@ this.height = 0 |
@@ -41,8 +41,8 @@ 'use strict' | ||
WordNode.prototype._compute = function(cursor) { | ||
this.y = cursor.y | ||
this.y.val = cursor.y | ||
} | ||
WordNode.prototype.setBoundingBox = function(x, y, width, height) { | ||
this.x = x | ||
this.y = y | ||
this.x.val = x | ||
this.y.val = y | ||
@@ -82,3 +82,3 @@ this.width = width | ||
if (this.isFirst) { | ||
doc.Tm(1, 0, 0, 1, this.x, this.y - this.height) | ||
doc.Tm(1, 0, 0, 1, this.x.val, this.y.val - this.height) | ||
} | ||
@@ -85,0 +85,0 @@ |
@@ -27,9 +27,8 @@ var PDFName = require('./name') | ||
PDFDictionary.prototype.toString = function() { | ||
var self = this | ||
return '<<\n' + | ||
Object.keys(this.dictionary).map(function(key) { | ||
var value = self.dictionary[key] && self.dictionary[key].toString() || 'null' | ||
return key.toString() + ' ' + value | ||
}).join('\n').replace(/^/gm, '\t') + '\n' + | ||
'>>' | ||
Object.keys(this.dictionary).map(function(key) { | ||
var value = this.dictionary[key] !== null ? this.dictionary[key].toString() : 'null' | ||
return key.toString() + ' ' + value | ||
}, this).join('\n').replace(/^/gm, '\t') + '\n' + | ||
'>>' | ||
} | ||
@@ -36,0 +35,0 @@ |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "1.0.0-alpha.3", | ||
"version": "1.0.0-alpha.4", | ||
"homepage": "https://github.com/rkusa/pdfjs", | ||
@@ -10,0 +10,0 @@ "description": "A Portable Document Format (PDF) generation library targeting both the server- and client-side.", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
884800
71
11143