Cleaned up code for tiling
This commit is contained in:
parent
4a5e1329c2
commit
4593fb3949
68
pdf.js
68
pdf.js
@ -1609,38 +1609,8 @@ var CanvasExtraState = (function() {
|
|||||||
// Start of text line (in text coordinates)
|
// Start of text line (in text coordinates)
|
||||||
this.lineX = 0.0;
|
this.lineX = 0.0;
|
||||||
this.lineY = 0.0;
|
this.lineY = 0.0;
|
||||||
|
|
||||||
this.transMatrix = IDENTITY_MATRIX;
|
|
||||||
}
|
}
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
applyTransform: function(point) {
|
|
||||||
var m = this.transMatrix
|
|
||||||
var x = point[0] * m[0] + point[1] * m[2] + m[4];
|
|
||||||
var y = point[0] * m[1] + point[1] * m[3] + m[5];
|
|
||||||
return [x,y];
|
|
||||||
},
|
|
||||||
concatTransform: function(m) {
|
|
||||||
var tm = this.transMatrix;
|
|
||||||
|
|
||||||
var a = m[0] * tm[0] + m[1] * tm[2];
|
|
||||||
var b = m[0] * tm[1] + m[1] * tm[3];
|
|
||||||
var c = m[2] * tm[0] + m[3] * tm[2];
|
|
||||||
var d = m[2] * tm[1] + m[3] * tm[3];
|
|
||||||
var e = m[4] * tm[0] + m[5] * tm[2] + tm[4];
|
|
||||||
var f = m[4] * tm[1] + m[5] * tm[3] + tm[5];
|
|
||||||
this.transMatrix = [a, b, c, d, e, f]
|
|
||||||
},
|
|
||||||
getInvTransform: function(matrix) {
|
|
||||||
var m = this.transMatrix;
|
|
||||||
var det = 1 / (m[0] * m[3] - m[1] * m[2]);
|
|
||||||
var a = m[3] * det;
|
|
||||||
var b = -m[1] * det;
|
|
||||||
var c = -m[2] * det;
|
|
||||||
var d = m[0] * det;
|
|
||||||
var e = (m[2] * m[5] - m[3] * m[4]) * det;
|
|
||||||
var f = (m[1] * m[4] - m[0] * m[5]) * det;
|
|
||||||
return [a, b, c, d, e, f]
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return constructor;
|
return constructor;
|
||||||
})();
|
})();
|
||||||
@ -1942,7 +1912,6 @@ var CanvasGraphics = (function() {
|
|||||||
},
|
},
|
||||||
transform: function(a, b, c, d, e, f) {
|
transform: function(a, b, c, d, e, f) {
|
||||||
this.ctx.transform(a, b, c, d, e, f);
|
this.ctx.transform(a, b, c, d, e, f);
|
||||||
this.current.concatTransform([a,b,c,d,e,f]);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Path
|
// Path
|
||||||
@ -2181,6 +2150,22 @@ var CanvasGraphics = (function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
tilingFill: function(pattern) {
|
tilingFill: function(pattern) {
|
||||||
|
function applyMatrix(point, m) {
|
||||||
|
var x = point[0] * m[0] + point[1] * m[2] + m[4];
|
||||||
|
var y = point[0] * m[1] + point[1] * m[3] + m[5];
|
||||||
|
return [x,y];
|
||||||
|
};
|
||||||
|
|
||||||
|
function multiply(m, tm) {
|
||||||
|
var a = m[0] * tm[0] + m[1] * tm[2];
|
||||||
|
var b = m[0] * tm[1] + m[1] * tm[3];
|
||||||
|
var c = m[2] * tm[0] + m[3] * tm[2];
|
||||||
|
var d = m[2] * tm[1] + m[3] * tm[3];
|
||||||
|
var e = m[4] * tm[0] + m[5] * tm[2] + tm[4];
|
||||||
|
var f = m[4] * tm[1] + m[5] * tm[3] + tm[5];
|
||||||
|
return [a, b, c, d, e, f]
|
||||||
|
};
|
||||||
|
|
||||||
this.save();
|
this.save();
|
||||||
var dict = pattern.dict;
|
var dict = pattern.dict;
|
||||||
|
|
||||||
@ -2196,10 +2181,9 @@ var CanvasGraphics = (function() {
|
|||||||
// not sure what to do with this
|
// not sure what to do with this
|
||||||
var tilingType = dict.get("TilingType");
|
var tilingType = dict.get("TilingType");
|
||||||
|
|
||||||
var tempExtra = new CanvasExtraState();
|
|
||||||
var matrix = dict.get("Matrix");
|
var matrix = dict.get("Matrix");
|
||||||
if (matrix && IsArray(matrix) && 6 == matrix.length)
|
if (!matrix)
|
||||||
tempExtra.transMatrix = matrix;
|
matrix = [1, 0, 0, 1, 0, 0];
|
||||||
|
|
||||||
var bbox = dict.get("BBox");
|
var bbox = dict.get("BBox");
|
||||||
var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
|
var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
|
||||||
@ -2208,9 +2192,9 @@ var CanvasGraphics = (function() {
|
|||||||
var ystep = dict.get("YStep");
|
var ystep = dict.get("YStep");
|
||||||
|
|
||||||
// top left corner should correspond to the top left of the bbox
|
// top left corner should correspond to the top left of the bbox
|
||||||
var topLeft = tempExtra.applyTransform([x0,y0]);
|
var topLeft = applyMatrix([x0,y0], matrix);
|
||||||
// we want the canvas to be as large as the step size
|
// we want the canvas to be as large as the step size
|
||||||
var botRight = tempExtra.applyTransform([x0 + xstep, y0 + ystep]);
|
var botRight = applyMatrix([x0 + xstep, y0 + ystep], matrix);
|
||||||
|
|
||||||
var tmpCanvas = document.createElement("canvas");
|
var tmpCanvas = document.createElement("canvas");
|
||||||
tmpCanvas.width = Math.ceil(botRight[0] - topLeft[0]);
|
tmpCanvas.width = Math.ceil(botRight[0] - topLeft[0]);
|
||||||
@ -2221,19 +2205,16 @@ var CanvasGraphics = (function() {
|
|||||||
var oldCtx = this.ctx;
|
var oldCtx = this.ctx;
|
||||||
this.ctx = tmpCtx;
|
this.ctx = tmpCtx;
|
||||||
|
|
||||||
// normalize matrix transform so each step
|
// normalize transform matrix so each step
|
||||||
// takes up the entire tmpCanvas
|
// takes up the entire tmpCanvas (no white borders)
|
||||||
if (matrix[1] === 0 && matrix[2] === 0) {
|
if (matrix[1] === 0 && matrix[2] === 0) {
|
||||||
matrix[0] = tmpCanvas.width / xstep;
|
matrix[0] = tmpCanvas.width / xstep;
|
||||||
matrix[3] = tmpCanvas.height / ystep;
|
matrix[3] = tmpCanvas.height / ystep;
|
||||||
tempExtra.transMatrix = matrix;
|
topLeft = applyMatrix([x0,y0], matrix);
|
||||||
topLeft = tempExtra.applyTransform([x0,y0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// move the top left corner of bounding box to [0,0]
|
// move the top left corner of bounding box to [0,0]
|
||||||
tempExtra.transMatrix = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
|
matrix = multiply(matrix, [1, 0, 0, 1, -topLeft[0], -topLeft[1]]);
|
||||||
tempExtra.concatTransform(matrix);
|
|
||||||
matrix = tempExtra.transMatrix;
|
|
||||||
|
|
||||||
this.transform.apply(this, matrix);
|
this.transform.apply(this, matrix);
|
||||||
|
|
||||||
@ -2253,6 +2234,7 @@ var CanvasGraphics = (function() {
|
|||||||
this.ctx = oldCtx;
|
this.ctx = oldCtx;
|
||||||
this.restore();
|
this.restore();
|
||||||
|
|
||||||
|
warn("Inverse pattern is painted");
|
||||||
var pattern = this.ctx.createPattern(tmpCanvas, "repeat");
|
var pattern = this.ctx.createPattern(tmpCanvas, "repeat");
|
||||||
this.ctx.fillStyle = pattern;
|
this.ctx.fillStyle = pattern;
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user