Create only one instance of each device colorspace.

This commit is contained in:
Brendan Dahl 2013-07-30 15:35:35 -07:00
parent f7d2a09bf8
commit 55d6ede1da
4 changed files with 28 additions and 26 deletions

View file

@ -358,9 +358,9 @@ var CanvasExtraState = (function CanvasExtraStateClosure() {
this.textRenderingMode = TextRenderingMode.FILL;
this.textRise = 0;
// Color spaces
this.fillColorSpace = new DeviceGrayCS();
this.fillColorSpace = ColorSpace.singletons.gray;
this.fillColorSpaceObj = null;
this.strokeColorSpace = new DeviceGrayCS();
this.strokeColorSpace = ColorSpace.singletons.gray;
this.strokeColorSpaceObj = null;
this.fillColorObj = null;
this.strokeColorObj = null;
@ -1357,8 +1357,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}
},
setStrokeGray: function CanvasGraphics_setStrokeGray(gray) {
if (!(this.current.strokeColorSpace instanceof DeviceGrayCS))
this.current.strokeColorSpace = new DeviceGrayCS();
this.current.strokeColorSpace = ColorSpace.singletons.gray;
var rgbColor = this.current.strokeColorSpace.getRgb(arguments, 0);
var color = Util.makeCssRgb(rgbColor);
@ -1366,8 +1365,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.current.strokeColor = color;
},
setFillGray: function CanvasGraphics_setFillGray(gray) {
if (!(this.current.fillColorSpace instanceof DeviceGrayCS))
this.current.fillColorSpace = new DeviceGrayCS();
this.current.fillColorSpace = ColorSpace.singletons.gray;
var rgbColor = this.current.fillColorSpace.getRgb(arguments, 0);
var color = Util.makeCssRgb(rgbColor);
@ -1375,8 +1373,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.current.fillColor = color;
},
setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
if (!(this.current.strokeColorSpace instanceof DeviceRgbCS))
this.current.strokeColorSpace = new DeviceRgbCS();
this.current.strokeColorSpace = ColorSpace.singletons.rgb;
var rgbColor = this.current.strokeColorSpace.getRgb(arguments, 0);
var color = Util.makeCssRgb(rgbColor);
@ -1384,8 +1381,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.current.strokeColor = color;
},
setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
if (!(this.current.fillColorSpace instanceof DeviceRgbCS))
this.current.fillColorSpace = new DeviceRgbCS();
this.current.fillColorSpace = ColorSpace.singletons.rgb;
var rgbColor = this.current.fillColorSpace.getRgb(arguments, 0);
var color = Util.makeCssRgb(rgbColor);
@ -1393,16 +1389,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.current.fillColor = color;
},
setStrokeCMYKColor: function CanvasGraphics_setStrokeCMYKColor(c, m, y, k) {
if (!(this.current.strokeColorSpace instanceof DeviceCmykCS))
this.current.strokeColorSpace = new DeviceCmykCS();
this.current.strokeColorSpace = ColorSpace.singletons.cmyk;
var color = Util.makeCssCmyk(arguments);
this.ctx.strokeStyle = color;
this.current.strokeColor = color;
},
setFillCMYKColor: function CanvasGraphics_setFillCMYKColor(c, m, y, k) {
if (!(this.current.fillColorSpace instanceof DeviceCmykCS))
this.current.fillColorSpace = new DeviceCmykCS();
this.current.fillColorSpace = ColorSpace.singletons.cmyk;
var color = Util.makeCssCmyk(arguments);
this.ctx.fillStyle = color;