From ef58ccd284634e83e8ea82ec2af2773a27a5fe49 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Tue, 15 Nov 2011 18:23:45 -0600 Subject: [PATCH 1/2] Issue #644: bypassing identity cmap translation loading; resetting color space when stroke/fill color set --- src/canvas.js | 18 ++++++++++++++++++ src/evaluator.js | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/canvas.js b/src/canvas.js index 9759a8deb..a7c0cc93b 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -594,27 +594,45 @@ var CanvasGraphics = (function canvasGraphics() { } }, setStrokeGray: function canvasGraphicsSetStrokeGray(gray) { + if (!(this.current.strokeColorSpace instanceof DeviceGrayCS)) + this.current.strokeColorSpace = new DeviceGrayCS(); + this.setStrokeRGBColor(gray, gray, gray); }, setFillGray: function canvasGraphicsSetFillGray(gray) { + if (!(this.current.fillColorSpace instanceof DeviceGrayCS)) + this.current.fillColorSpace = new DeviceGrayCS(); + this.setFillRGBColor(gray, gray, gray); }, setStrokeRGBColor: function canvasGraphicsSetStrokeRGBColor(r, g, b) { + if (!(this.current.strokeColorSpace instanceof DeviceRgbCS)) + this.current.strokeColorSpace = new DeviceRgbCS(); + var color = Util.makeCssRgb(r, g, b); this.ctx.strokeStyle = color; this.current.strokeColor = color; }, setFillRGBColor: function canvasGraphicsSetFillRGBColor(r, g, b) { + if (!(this.current.fillColorSpace instanceof DeviceRgbCS)) + this.current.fillColorSpace = new DeviceRgbCS(); + var color = Util.makeCssRgb(r, g, b); this.ctx.fillStyle = color; this.current.fillColor = color; }, setStrokeCMYKColor: function canvasGraphicsSetStrokeCMYKColor(c, m, y, k) { + if (!(this.current.strokeColorSpace instanceof DeviceCmykCS)) + this.current.strokeColorSpace = new DeviceCmykCS(); + var color = Util.makeCssCmyk(c, m, y, k); this.ctx.strokeStyle = color; this.current.strokeColor = color; }, setFillCMYKColor: function canvasGraphicsSetFillCMYKColor(c, m, y, k) { + if (!(this.current.fillColorSpace instanceof DeviceCmykCS)) + this.current.fillColorSpace = new DeviceCmykCS(); + var color = Util.makeCssCmyk(c, m, y, k); this.ctx.fillStyle = color; this.current.fillColor = color; diff --git a/src/evaluator.js b/src/evaluator.js index 619a633b2..1cb8fe39f 100644 --- a/src/evaluator.js +++ b/src/evaluator.js @@ -522,7 +522,9 @@ var PartialEvaluator = (function partialEvaluator() { var cmapObj = xref.fetchIfRef(toUnicode); var charToUnicode = []; if (isName(cmapObj)) { - error('ToUnicode file cmap translation not implemented'); + var isIdentityMap = cmapObj.name.substr(0, 9) == 'Identity-'; + if (!isIdentityMap) + error('ToUnicode file cmap translation not implemented'); } else if (isStream(cmapObj)) { var tokens = []; var token = ''; From 7a2301dc951c56da91b863796d76e67070be4bc3 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Tue, 15 Nov 2011 20:16:22 -0600 Subject: [PATCH 2/2] Inline setXXXRGBColor calls --- src/canvas.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/canvas.js b/src/canvas.js index a7c0cc93b..9b3ed0ba9 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -546,7 +546,9 @@ var CanvasGraphics = (function canvasGraphics() { setStrokeColor: function canvasGraphicsSetStrokeColor(/*...*/) { var cs = this.current.strokeColorSpace; var color = cs.getRgb(arguments); - this.setStrokeRGBColor.apply(this, color); + var color = Util.makeCssRgb.apply(null, cs.getRgb(arguments)); + this.ctx.strokeStyle = color; + this.current.strokeColor = color; }, getColorN_IR_Pattern: function canvasGraphicsGetColorN_IR_Pattern(IR, cs) { if (IR[0] == 'TilingPattern') { @@ -581,8 +583,9 @@ var CanvasGraphics = (function canvasGraphics() { }, setFillColor: function canvasGraphicsSetFillColor(/*...*/) { var cs = this.current.fillColorSpace; - var color = cs.getRgb(arguments); - this.setFillRGBColor.apply(this, color); + var color = Util.makeCssRgb.apply(null, cs.getRgb(arguments)); + this.ctx.fillStyle = color; + this.current.fillColor = color; }, setFillColorN_IR: function canvasGraphicsSetFillColorN(/*...*/) { var cs = this.current.fillColorSpace; @@ -597,13 +600,17 @@ var CanvasGraphics = (function canvasGraphics() { if (!(this.current.strokeColorSpace instanceof DeviceGrayCS)) this.current.strokeColorSpace = new DeviceGrayCS(); - this.setStrokeRGBColor(gray, gray, gray); + var color = Util.makeCssRgb(gray, gray, gray); + this.ctx.strokeStyle = color; + this.current.strokeColor = color; }, setFillGray: function canvasGraphicsSetFillGray(gray) { if (!(this.current.fillColorSpace instanceof DeviceGrayCS)) this.current.fillColorSpace = new DeviceGrayCS(); - this.setFillRGBColor(gray, gray, gray); + var color = Util.makeCssRgb(gray, gray, gray); + this.ctx.fillStyle = color; + this.current.fillColor = color; }, setStrokeRGBColor: function canvasGraphicsSetStrokeRGBColor(r, g, b) { if (!(this.current.strokeColorSpace instanceof DeviceRgbCS))