Use object-enumeration for pattern type.

This commit is contained in:
Kalervo Kujala 2011-12-05 00:38:45 +02:00
parent 7116ce0b53
commit cca0306789

View File

@ -3,8 +3,10 @@
'use strict'; 'use strict';
var AXIAL_PATTERN_TYPE = 2; var PatternType = {
var RADIAL_PATTERN_TYPE = 3; AXIAL: 2,
RADIAL: 3
};
var Pattern = (function patternPattern() { var Pattern = (function patternPattern() {
// Constructor should define this.getPattern // Constructor should define this.getPattern
@ -31,8 +33,8 @@ var Pattern = (function patternPattern() {
var type = dict.get('ShadingType'); var type = dict.get('ShadingType');
switch (type) { switch (type) {
case AXIAL_PATTERN_TYPE: case PatternType.AXIAL:
case RADIAL_PATTERN_TYPE: 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:
@ -120,9 +122,9 @@ Shadings.RadialAxial = (function radialAxialShading() {
} }
var grad; var grad;
if (type == AXIAL_PATTERN_TYPE) 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 == RADIAL_PATTERN_TYPE) 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) {
@ -136,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 == AXIAL_PATTERN_TYPE) { 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 == RADIAL_PATTERN_TYPE) { } 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];