Create only one instance of each device colorspace.
This commit is contained in:
parent
f7d2a09bf8
commit
55d6ede1da
@ -358,9 +358,9 @@ var CanvasExtraState = (function CanvasExtraStateClosure() {
|
|||||||
this.textRenderingMode = TextRenderingMode.FILL;
|
this.textRenderingMode = TextRenderingMode.FILL;
|
||||||
this.textRise = 0;
|
this.textRise = 0;
|
||||||
// Color spaces
|
// Color spaces
|
||||||
this.fillColorSpace = new DeviceGrayCS();
|
this.fillColorSpace = ColorSpace.singletons.gray;
|
||||||
this.fillColorSpaceObj = null;
|
this.fillColorSpaceObj = null;
|
||||||
this.strokeColorSpace = new DeviceGrayCS();
|
this.strokeColorSpace = ColorSpace.singletons.gray;
|
||||||
this.strokeColorSpaceObj = null;
|
this.strokeColorSpaceObj = null;
|
||||||
this.fillColorObj = null;
|
this.fillColorObj = null;
|
||||||
this.strokeColorObj = null;
|
this.strokeColorObj = null;
|
||||||
@ -1357,8 +1357,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
setStrokeGray: function CanvasGraphics_setStrokeGray(gray) {
|
setStrokeGray: function CanvasGraphics_setStrokeGray(gray) {
|
||||||
if (!(this.current.strokeColorSpace instanceof DeviceGrayCS))
|
this.current.strokeColorSpace = ColorSpace.singletons.gray;
|
||||||
this.current.strokeColorSpace = new DeviceGrayCS();
|
|
||||||
|
|
||||||
var rgbColor = this.current.strokeColorSpace.getRgb(arguments, 0);
|
var rgbColor = this.current.strokeColorSpace.getRgb(arguments, 0);
|
||||||
var color = Util.makeCssRgb(rgbColor);
|
var color = Util.makeCssRgb(rgbColor);
|
||||||
@ -1366,8 +1365,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.current.strokeColor = color;
|
this.current.strokeColor = color;
|
||||||
},
|
},
|
||||||
setFillGray: function CanvasGraphics_setFillGray(gray) {
|
setFillGray: function CanvasGraphics_setFillGray(gray) {
|
||||||
if (!(this.current.fillColorSpace instanceof DeviceGrayCS))
|
this.current.fillColorSpace = ColorSpace.singletons.gray;
|
||||||
this.current.fillColorSpace = new DeviceGrayCS();
|
|
||||||
|
|
||||||
var rgbColor = this.current.fillColorSpace.getRgb(arguments, 0);
|
var rgbColor = this.current.fillColorSpace.getRgb(arguments, 0);
|
||||||
var color = Util.makeCssRgb(rgbColor);
|
var color = Util.makeCssRgb(rgbColor);
|
||||||
@ -1375,8 +1373,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.current.fillColor = color;
|
this.current.fillColor = color;
|
||||||
},
|
},
|
||||||
setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
|
setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
|
||||||
if (!(this.current.strokeColorSpace instanceof DeviceRgbCS))
|
this.current.strokeColorSpace = ColorSpace.singletons.rgb;
|
||||||
this.current.strokeColorSpace = new DeviceRgbCS();
|
|
||||||
|
|
||||||
var rgbColor = this.current.strokeColorSpace.getRgb(arguments, 0);
|
var rgbColor = this.current.strokeColorSpace.getRgb(arguments, 0);
|
||||||
var color = Util.makeCssRgb(rgbColor);
|
var color = Util.makeCssRgb(rgbColor);
|
||||||
@ -1384,8 +1381,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.current.strokeColor = color;
|
this.current.strokeColor = color;
|
||||||
},
|
},
|
||||||
setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
|
setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
|
||||||
if (!(this.current.fillColorSpace instanceof DeviceRgbCS))
|
this.current.fillColorSpace = ColorSpace.singletons.rgb;
|
||||||
this.current.fillColorSpace = new DeviceRgbCS();
|
|
||||||
|
|
||||||
var rgbColor = this.current.fillColorSpace.getRgb(arguments, 0);
|
var rgbColor = this.current.fillColorSpace.getRgb(arguments, 0);
|
||||||
var color = Util.makeCssRgb(rgbColor);
|
var color = Util.makeCssRgb(rgbColor);
|
||||||
@ -1393,16 +1389,14 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.current.fillColor = color;
|
this.current.fillColor = color;
|
||||||
},
|
},
|
||||||
setStrokeCMYKColor: function CanvasGraphics_setStrokeCMYKColor(c, m, y, k) {
|
setStrokeCMYKColor: function CanvasGraphics_setStrokeCMYKColor(c, m, y, k) {
|
||||||
if (!(this.current.strokeColorSpace instanceof DeviceCmykCS))
|
this.current.strokeColorSpace = ColorSpace.singletons.cmyk;
|
||||||
this.current.strokeColorSpace = new DeviceCmykCS();
|
|
||||||
|
|
||||||
var color = Util.makeCssCmyk(arguments);
|
var color = Util.makeCssCmyk(arguments);
|
||||||
this.ctx.strokeStyle = color;
|
this.ctx.strokeStyle = color;
|
||||||
this.current.strokeColor = color;
|
this.current.strokeColor = color;
|
||||||
},
|
},
|
||||||
setFillCMYKColor: function CanvasGraphics_setFillCMYKColor(c, m, y, k) {
|
setFillCMYKColor: function CanvasGraphics_setFillCMYKColor(c, m, y, k) {
|
||||||
if (!(this.current.fillColorSpace instanceof DeviceCmykCS))
|
this.current.fillColorSpace = ColorSpace.singletons.cmyk;
|
||||||
this.current.fillColorSpace = new DeviceCmykCS();
|
|
||||||
|
|
||||||
var color = Util.makeCssCmyk(arguments);
|
var color = Util.makeCssCmyk(arguments);
|
||||||
this.ctx.fillStyle = color;
|
this.ctx.fillStyle = color;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals error, info, input, isArray, isDict, isName, isStream, isString,
|
/* globals error, info, input, isArray, isDict, isName, isStream, isString,
|
||||||
PDFFunction, warn */
|
PDFFunction, warn, shadow */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -127,11 +127,11 @@ var ColorSpace = (function ColorSpaceClosure() {
|
|||||||
|
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'DeviceGrayCS':
|
case 'DeviceGrayCS':
|
||||||
return new DeviceGrayCS();
|
return this.singletons.gray;
|
||||||
case 'DeviceRgbCS':
|
case 'DeviceRgbCS':
|
||||||
return new DeviceRgbCS();
|
return this.singletons.rgb;
|
||||||
case 'DeviceCmykCS':
|
case 'DeviceCmykCS':
|
||||||
return new DeviceCmykCS();
|
return this.singletons.cmyk;
|
||||||
case 'PatternCS':
|
case 'PatternCS':
|
||||||
var basePatternCS = IR[1];
|
var basePatternCS = IR[1];
|
||||||
if (basePatternCS)
|
if (basePatternCS)
|
||||||
@ -281,6 +281,18 @@ var ColorSpace = (function ColorSpaceClosure() {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ColorSpace.singletons = {
|
||||||
|
get gray() {
|
||||||
|
return shadow(this, 'gray', new DeviceGrayCS());
|
||||||
|
},
|
||||||
|
get rgb() {
|
||||||
|
return shadow(this, 'rgb', new DeviceRgbCS());
|
||||||
|
},
|
||||||
|
get cmyk() {
|
||||||
|
return shadow(this, 'cmyk', new DeviceCmykCS());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return ColorSpace;
|
return ColorSpace;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@ var TilingPattern = (function TilingPatternClosure() {
|
|||||||
context.strokeStyle = ctx.strokeStyle;
|
context.strokeStyle = ctx.strokeStyle;
|
||||||
break;
|
break;
|
||||||
case PaintType.UNCOLORED:
|
case PaintType.UNCOLORED:
|
||||||
var rgbColor = new DeviceRgbCS().getRgb(color, 0);
|
var rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
|
||||||
var cssColor = Util.makeCssRgb(rgbColor);
|
var cssColor = Util.makeCssRgb(rgbColor);
|
||||||
context.fillStyle = cssColor;
|
context.fillStyle = cssColor;
|
||||||
context.strokeStyle = cssColor;
|
context.strokeStyle = cssColor;
|
||||||
|
10
src/util.js
10
src/util.js
@ -14,7 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals Cmd, DeviceCmykCS, Dict, globalScope, INFOS, MozBlobBuilder, Name,
|
/* globals Cmd, ColorSpace, Dict, globalScope, INFOS, MozBlobBuilder, Name,
|
||||||
PDFJS, Ref, WARNINGS, verbosity */
|
PDFJS, Ref, WARNINGS, verbosity */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -281,12 +281,8 @@ var Util = PDFJS.Util = (function UtilClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Util.makeCssCmyk = function Util_makeCssCmyk(cmyk) {
|
Util.makeCssCmyk = function Util_makeCssCmyk(cmyk) {
|
||||||
var cs = new DeviceCmykCS();
|
var rgb = ColorSpace.singletons.cmyk.getRgb(cmyk, 0);
|
||||||
Util.makeCssCmyk = function makeCssCmyk(cmyk) {
|
return Util.makeCssRgb(rgb);
|
||||||
var rgb = cs.getRgb(cmyk, 0);
|
|
||||||
return Util.makeCssRgb(rgb);
|
|
||||||
};
|
|
||||||
return Util.makeCssCmyk(cmyk);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Concatenates two transformation matrices together and returns the result.
|
// Concatenates two transformation matrices together and returns the result.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user