Merge pull request #871 from kkujala/constants

Use constants for radial and axial types.
This commit is contained in:
Julian Viereck 2011-12-05 09:24:06 -08:00
commit d5f4fd05c6

View File

@ -3,6 +3,11 @@
'use strict'; 'use strict';
var PatternType = {
AXIAL: 2,
RADIAL: 3
};
var Pattern = (function patternPattern() { var Pattern = (function patternPattern() {
// Constructor should define this.getPattern // Constructor should define this.getPattern
function constructor() { function constructor() {
@ -28,9 +33,9 @@ var Pattern = (function patternPattern() {
var type = dict.get('ShadingType'); var type = dict.get('ShadingType');
switch (type) { switch (type) {
case 2: case PatternType.AXIAL:
case 3: case PatternType.RADIAL:
// both radial and axial shadings are handled by RadialAxial shading // 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, ctx);
default: default:
return new Shadings.Dummy(); return new Shadings.Dummy();
@ -117,9 +122,9 @@ Shadings.RadialAxial = (function radialAxialShading() {
} }
var grad; var grad;
if (type == 2) if (type == PatternType.AXIAL)
grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]); grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
else if (type == 3) else if (type == PatternType.RADIAL)
grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1); grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
for (var i = 0, ii = colorStops.length; i < ii; ++i) { for (var i = 0, ii = colorStops.length; i < ii; ++i) {
@ -133,12 +138,12 @@ Shadings.RadialAxial = (function radialAxialShading() {
getIR: function radialAxialShadingGetIR() { getIR: function radialAxialShadingGetIR() {
var coordsArr = this.coordsArr; var coordsArr = this.coordsArr;
var type = this.shadingType; var type = this.shadingType;
if (type == 2) { if (type == PatternType.AXIAL) {
var p0 = [coordsArr[0], coordsArr[1]]; var p0 = [coordsArr[0], coordsArr[1]];
var p1 = [coordsArr[2], coordsArr[3]]; var p1 = [coordsArr[2], coordsArr[3]];
var r0 = null; var r0 = null;
var r1 = null; var r1 = null;
} else if (type == 3) { } else if (type == PatternType.RADIAL) {
var p0 = [coordsArr[0], coordsArr[1]]; var p0 = [coordsArr[0], coordsArr[1]];
var p1 = [coordsArr[3], coordsArr[4]]; var p1 = [coordsArr[3], coordsArr[4]];
var r0 = coordsArr[2]; var r0 = coordsArr[2];