Fix gradients for fill and stroke.

This commit is contained in:
Brendan Dahl 2012-03-29 08:53:51 -07:00
parent e641dabd2c
commit 7008d07fde
6 changed files with 42 additions and 31 deletions

View File

@ -924,7 +924,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}
var pattern = new TilingPattern(IR, color, this.ctx, this.objs);
} else if (IR[0] == 'RadialAxial' || IR[0] == 'Dummy') {
var pattern = Pattern.shadingFromIR(this.ctx, IR);
var pattern = Pattern.shadingFromIR(IR);
} else {
error('Unkown IR type ' + IR[0]);
}
@ -1008,7 +1008,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
var ctx = this.ctx;
this.save();
ctx.fillStyle = Pattern.shadingFromIR(ctx, patternIR);
var pattern = Pattern.shadingFromIR(patternIR);
ctx.fillStyle = pattern.getPattern(ctx);
var inv = ctx.mozCurrentTransformInverse;
if (inv) {

View File

@ -305,8 +305,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
else if (typeNum == SHADING_PATTERN) {
var shading = xref.fetchIfRef(dict.get('Shading'));
var matrix = dict.get('Matrix');
var pattern = Pattern.parseShading(shading, matrix, xref, res,
null /*ctx*/);
var pattern = Pattern.parseShading(shading, matrix, xref,
res);
args = pattern.getIR();
} else {
error('Unkown PatternType ' + typeNum);
@ -377,8 +377,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (!shading)
error('No shading object found');
var shadingFill = Pattern.parseShading(shading, null, xref, res,
null);
var shadingFill = Pattern.parseShading(shading, null, xref, res);
var patternIR = shadingFill.getIR();
args = [patternIR];
fn = 'shadingFill';

View File

@ -22,12 +22,11 @@ var Pattern = (function PatternClosure() {
}
};
Pattern.shadingFromIR = function pattern_shadingFromIR(ctx, raw) {
return Shadings[raw[0]].fromIR(ctx, raw);
Pattern.shadingFromIR = function pattern_shadingFromIR(raw) {
return Shadings[raw[0]].fromIR(raw);
};
Pattern.parseShading = function pattern_shading(shading, matrix, xref,
res, ctx) {
Pattern.parseShading = function pattern_shading(shading, matrix, xref, res) {
var dict = isStream(shading) ? shading.dict : shading;
var type = dict.get('ShadingType');
@ -36,7 +35,7 @@ var Pattern = (function PatternClosure() {
case PatternType.AXIAL:
case PatternType.RADIAL:
// Both radial and axial shadings are handled by RadialAxial shading.
return new Shadings.RadialAxial(dict, matrix, xref, res, ctx);
return new Shadings.RadialAxial(dict, matrix, xref, res);
default:
return new Shadings.Dummy();
}
@ -102,36 +101,40 @@ Shadings.RadialAxial = (function RadialAxialClosure() {
this.colorStops = colorStops;
}
RadialAxial.fromIR = function radialAxialShadingGetIR(ctx, raw) {
RadialAxial.fromIR = function radialAxialShadingGetIR(raw) {
var type = raw[1];
var colorStops = raw[2];
var p0 = raw[3];
var p1 = raw[4];
var r0 = raw[5];
var r1 = raw[6];
return {
type: 'Pattern',
getPattern: function(ctx) {
var curMatrix = ctx.mozCurrentTransform;
if (curMatrix) {
var userMatrix = ctx.mozCurrentTransformInverse;
var curMatrix = ctx.mozCurrentTransform;
if (curMatrix) {
var userMatrix = ctx.mozCurrentTransformInverse;
p0 = Util.applyTransform(p0, curMatrix);
p0 = Util.applyTransform(p0, userMatrix);
p0 = Util.applyTransform(p0, curMatrix);
p0 = Util.applyTransform(p0, userMatrix);
p1 = Util.applyTransform(p1, curMatrix);
p1 = Util.applyTransform(p1, userMatrix);
}
p1 = Util.applyTransform(p1, curMatrix);
p1 = Util.applyTransform(p1, userMatrix);
}
var grad;
if (type == PatternType.AXIAL)
grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
else if (type == PatternType.RADIAL)
grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
var grad;
if (type == PatternType.AXIAL)
grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
else if (type == PatternType.RADIAL)
grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
for (var i = 0, ii = colorStops.length; i < ii; ++i) {
var c = colorStops[i];
grad.addColorStop(c[0], c[1]);
}
return grad;
for (var i = 0, ii = colorStops.length; i < ii; ++i) {
var c = colorStops[i];
grad.addColorStop(c[0], c[1]);
}
return grad;
}
};
};
RadialAxial.prototype = {

View File

@ -30,3 +30,5 @@
!zerowidthline.pdf
!issue1002.pdf
!issue925.pdf
!gradientfill.pdf

BIN
test/pdfs/gradientfill.pdf Normal file

Binary file not shown.

View File

@ -558,5 +558,11 @@
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "gradientfill",
"file": "pdfs/gradientfill.pdf",
"md5": "cbc1988e4803f647fa83467a85f0e231",
"rounds": 1,
"type": "eq"
}
]