}
};
+ var IDENTITY_MATRIX = [ 1, 0, 0, 1, 0, 0 ];
+
+ // <canvas> contexts store most of the state we need natively.
+ // However, PDF needs a bit more state, which we store here.
+ var CanvasExtraState = (function() {
+ function constructor() {
+ // Are soft masks and alpha values shapes or opacities?
+ this.alphaIsShape = false;
+ this.fontSize = 0;
+ this.textMatrix = IDENTITY_MATRIX;
+ this.leading = 0;
+ this.colorSpace = null;
+ // Current point (in user coordinates)
+ this.x = 0;
+ this.y = 0;
+ // Start of text line (in text coordinates)
+ this.lineX = 0;
+ this.lineY = 0;
+ // Character and word spacing
+ this.charSpace = 0;
+ this.wordSpace = 0;
+ this.textHScale = 100;
++ // Color spaces
++ this.fillColorSpace = null;
++ this.strokeColorSpace = null;
+ }
+ constructor.prototype = {
+ };
+ return constructor;
+ })();
+
+ function ScratchCanvas(width, height) {
+ var canvas = document.createElement("canvas");
+ canvas.width = width;
+ canvas.height = height;
+ return canvas;
+ }
+
var CanvasGraphics = (function() {
- function constructor(canvasCtx) {
+ function constructor(canvasCtx, imageCanvas) {
this.ctx = canvasCtx;
this.current = new CanvasExtraState();
this.stateStack = [ ];
var ri = (255 * r) | 0, gi = (255 * g) | 0, bi = (255 * b) | 0;
return "rgb("+ ri +","+ gi +","+ bi +")";
},
- }
-
+ makeCssCmyk: function(c, m, y, k) {
+ // while waiting on CSS's cmyk()... http://www.ilkeratalay.com/colorspacesfaq.php#rgb
+ var ri = (255 * (1 - Math.min(1, c * (1 - k) + k))) | 0;
+ var gi = (255 * (1 - Math.min(1, m * (1 - k) + k))) | 0;
+ var bi = (255 * (1 - Math.min(1, y * (1 - k) + k))) | 0;
+ return "rgb("+ ri +","+ gi +","+ bi +")";
+ },
+ getColorSpaceObj(colorSpace) {
+ if (IsName(colorSpace)) {
+ var name = colorSpace.name;
+ } else if (IsArray(colorSpace)) {
+ var name = colorSpace[0];
+ }
+ },
// We generally keep the canvas context set for
// nonzero-winding, and just set evenodd for the operations
// that need them.