Fixed tiling patterns
This commit is contained in:
parent
9dcac17a3e
commit
dc77e076c2
72
pdf.js
72
pdf.js
@ -2969,7 +2969,6 @@ var Page = (function() {
|
|||||||
var fonts = [ ];
|
var fonts = [ ];
|
||||||
|
|
||||||
this.compile(gfx, fonts);
|
this.compile(gfx, fonts);
|
||||||
fonts = []
|
|
||||||
stats.compile = Date.now();
|
stats.compile = Date.now();
|
||||||
|
|
||||||
FontLoader.bind(
|
FontLoader.bind(
|
||||||
@ -4017,9 +4016,13 @@ var CanvasGraphics = (function() {
|
|||||||
var fillColor = this.current.fillColor;
|
var fillColor = this.current.fillColor;
|
||||||
|
|
||||||
if (fillColor.type === "Pattern") {
|
if (fillColor.type === "Pattern") {
|
||||||
|
this.ctx.save();
|
||||||
ctx.fillStyle = fillColor.getPattern(ctx);
|
ctx.fillStyle = fillColor.getPattern(ctx);
|
||||||
|
ctx.fill();
|
||||||
|
this.ctx.restore();
|
||||||
|
} else {
|
||||||
|
ctx.fill();
|
||||||
}
|
}
|
||||||
ctx.fill();
|
|
||||||
|
|
||||||
this.consumePath();
|
this.consumePath();
|
||||||
},
|
},
|
||||||
@ -4246,12 +4249,6 @@ var CanvasGraphics = (function() {
|
|||||||
this.setFillColor.apply(this, arguments);
|
this.setFillColor.apply(this, arguments);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getShadingPattern: function(pattern, dict) {
|
|
||||||
// TODO('store transform so it can be applied before every fill');
|
|
||||||
// return shading;
|
|
||||||
},
|
|
||||||
getTilingPattern: function(pattern, dict, color) {
|
|
||||||
},
|
|
||||||
setStrokeGray: function(gray) {
|
setStrokeGray: function(gray) {
|
||||||
this.setStrokeRGBColor(gray, gray, gray);
|
this.setStrokeRGBColor(gray, gray, gray);
|
||||||
},
|
},
|
||||||
@ -4906,9 +4903,8 @@ var Pattern = (function() {
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 2:
|
case 2:
|
||||||
return new SimpleShading(dict, matrix, xref, res, ctx);
|
|
||||||
break;
|
|
||||||
case 3:
|
case 3:
|
||||||
|
// both radial and axial shadings are handled by simple shading
|
||||||
return new SimpleShading(dict, matrix, xref, res, ctx);
|
return new SimpleShading(dict, matrix, xref, res, ctx);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -4928,7 +4924,6 @@ var SimpleShading = (function() {
|
|||||||
|
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.curMatrix = ctx.mozCurrentTransform;
|
this.curMatrix = ctx.mozCurrentTransform;
|
||||||
console.log(ctx.mozCurrentTransform);
|
|
||||||
|
|
||||||
var cs = dict.get('ColorSpace', 'CS');
|
var cs = dict.get('ColorSpace', 'CS');
|
||||||
cs = ColorSpace.parse(cs, xref, res);
|
cs = ColorSpace.parse(cs, xref, res);
|
||||||
@ -5001,17 +4996,12 @@ var SimpleShading = (function() {
|
|||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
if (curMatrix) {
|
if (curMatrix) {
|
||||||
var userMatrix = ctx.mozCurrentTransformInverse;
|
var userMatrix = ctx.mozCurrentTransformInverse;
|
||||||
console.log(p0 + ',' + p1);
|
|
||||||
console.log(curMatrix);
|
|
||||||
console.log(userMatrix);
|
|
||||||
|
|
||||||
p0 = this.applyTransform(p0, curMatrix);
|
p0 = this.applyTransform(p0, curMatrix);
|
||||||
p0 = this.applyTransform(p0, userMatrix);
|
p0 = this.applyTransform(p0, userMatrix);
|
||||||
console.log(p0);
|
|
||||||
|
|
||||||
p1 = this.applyTransform(p1, curMatrix);
|
p1 = this.applyTransform(p1, curMatrix);
|
||||||
p1 = this.applyTransform(p1, userMatrix);
|
p1 = this.applyTransform(p1, userMatrix);
|
||||||
console.log(p0 + ',' + p1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var colorStops = this.colorStops;
|
var colorStops = this.colorStops;
|
||||||
@ -5042,7 +5032,7 @@ var SimpleShading = (function() {
|
|||||||
var TilingPattern = (function() {
|
var TilingPattern = (function() {
|
||||||
var PAINT_TYPE_COLORED = 1, PAINT_TYPE_UNCOLORED = 2;
|
var PAINT_TYPE_COLORED = 1, PAINT_TYPE_UNCOLORED = 2;
|
||||||
|
|
||||||
function constructor(pattern, dict, color, patMatrix, xref, ctx) {
|
function constructor(pattern, dict, color, xref, ctx) {
|
||||||
function multiply(m, tm) {
|
function multiply(m, tm) {
|
||||||
var a = m[0] * tm[0] + m[1] * tm[2];
|
var a = m[0] * tm[0] + m[1] * tm[2];
|
||||||
var b = m[0] * tm[1] + m[1] * tm[3];
|
var b = m[0] * tm[1] + m[1] * tm[3];
|
||||||
@ -5053,10 +5043,12 @@ var TilingPattern = (function() {
|
|||||||
return [a, b, c, d, e, f];
|
return [a, b, c, d, e, f];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TODO('TilingType');
|
TODO('TilingType');
|
||||||
|
|
||||||
this.patMatrix = patMatrix;
|
this.matrix = dict.get("Matrix");
|
||||||
|
this.curMatrix = ctx.mozCurrentTransform;
|
||||||
|
this.invMatrix = ctx.mozCurrentTransformInverse;
|
||||||
|
this.ctx = ctx;
|
||||||
|
|
||||||
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];
|
||||||
@ -5072,9 +5064,9 @@ var TilingPattern = (function() {
|
|||||||
var height = botRight[1] - topLeft[1];
|
var height = botRight[1] - topLeft[1];
|
||||||
|
|
||||||
// TODO: hack to avoid OOM, remove then pattern code is fixed
|
// TODO: hack to avoid OOM, remove then pattern code is fixed
|
||||||
while (Math.abs(width) > 8192 || Math.abs(height) > 8192) {
|
while (Math.abs(width) > 512 || Math.abs(height) > 512) {
|
||||||
width /= 2;
|
width = 512;
|
||||||
height /= 2;
|
height = 512;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tmpCanvas = new ScratchCanvas(width, height);
|
var tmpCanvas = new ScratchCanvas(width, height);
|
||||||
@ -5098,9 +5090,14 @@ var TilingPattern = (function() {
|
|||||||
error('Unsupported paint type');
|
error('Unsupported paint type');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var scale = [width / xstep, height / ystep];
|
||||||
|
this.scale = scale;
|
||||||
|
|
||||||
// transform coordinates to pattern space
|
// transform coordinates to pattern space
|
||||||
var tmpTransform = [width / xstep, 0, 0, height / ystep, -topLeft[0], -topLeft[1]];
|
var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
|
||||||
graphics.transform.apply(graphics, matrix);
|
var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
|
||||||
|
graphics.transform.apply(graphics, tmpScale);
|
||||||
|
graphics.transform.apply(graphics, tmpTranslate);
|
||||||
|
|
||||||
if (bbox && IsArray(bbox) && 4 == bbox.length) {
|
if (bbox && IsArray(bbox) && 4 == bbox.length) {
|
||||||
graphics.rectangle.apply(graphics, bbox);
|
graphics.rectangle.apply(graphics, bbox);
|
||||||
@ -5118,27 +5115,18 @@ var TilingPattern = (function() {
|
|||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
getPattern: function tiling_getPattern(ctx) {
|
getPattern: function tiling_getPattern(ctx) {
|
||||||
var patternMatrix = this.patternMatrix;
|
var matrix = this.matrix;
|
||||||
if (patternMatrix) {
|
var curMatrix = this.curMatrix;
|
||||||
var userMatrix = ctx.mozCurrentTransformInverse;
|
|
||||||
|
|
||||||
var p = this.applyTransform(x0, y0, patternMatrix);
|
if (curMatrix)
|
||||||
p = this.applyTransform(p[0], p[1], userMatrix);
|
ctx.setTransform.apply(ctx, curMatrix);
|
||||||
x0 = p[0];
|
|
||||||
y0 = p[1];
|
|
||||||
|
|
||||||
var p = this.applyTransform(x1, y1, patternMatrix);
|
if (matrix)
|
||||||
p = this.applyTransform(p[0], p[1], userMatrix);
|
ctx.transform.apply(ctx, matrix);
|
||||||
x1 = p[0];
|
|
||||||
y1 = p[1];
|
var scale = this.scale;
|
||||||
}
|
ctx.scale(1 / scale[0], 1 / scale[1]);
|
||||||
|
|
||||||
var colorStops = this.colorStops;
|
|
||||||
var gradient =
|
|
||||||
ctx.createRadialGradient(x0, y0, r0, x1, y1, r1);
|
|
||||||
for (var i = 0, ii = colorStops.length; i < ii; ++i)
|
|
||||||
var c = colorStops[i];
|
|
||||||
ctx.transform.apply
|
|
||||||
return ctx.createPattern(this.canvas, 'repeat');
|
return ctx.createPattern(this.canvas, 'repeat');
|
||||||
},
|
},
|
||||||
applyTransform: function(x0, y0, m) {
|
applyTransform: function(x0, y0, m) {
|
||||||
|
Loading…
Reference in New Issue
Block a user