|
|
@ -24,13 +24,18 @@ var CanvasExtraState = (function canvasExtraState() { |
|
|
|
this.wordSpacing = 0; |
|
|
|
this.wordSpacing = 0; |
|
|
|
this.textHScale = 1; |
|
|
|
this.textHScale = 1; |
|
|
|
// Color spaces
|
|
|
|
// Color spaces
|
|
|
|
|
|
|
|
this.fillColorSpace = new DeviceGrayCS; |
|
|
|
this.fillColorSpaceObj = null; |
|
|
|
this.fillColorSpaceObj = null; |
|
|
|
|
|
|
|
this.strokeColorSpace = new DeviceGrayCS; |
|
|
|
this.strokeColorSpaceObj = null; |
|
|
|
this.strokeColorSpaceObj = null; |
|
|
|
this.fillColorObj = null; |
|
|
|
this.fillColorObj = null; |
|
|
|
this.strokeColorObj = null; |
|
|
|
this.strokeColorObj = null; |
|
|
|
// Default fore and background colors
|
|
|
|
// Default fore and background colors
|
|
|
|
this.fillColor = '#000000'; |
|
|
|
this.fillColor = '#000000'; |
|
|
|
this.strokeColor = '#000000'; |
|
|
|
this.strokeColor = '#000000'; |
|
|
|
|
|
|
|
// Note: fill alpha applies to all non-stroking operations
|
|
|
|
|
|
|
|
this.fillAlpha = 1; |
|
|
|
|
|
|
|
this.strokeAlpha = 1; |
|
|
|
|
|
|
|
|
|
|
|
this.old = old; |
|
|
|
this.old = old; |
|
|
|
} |
|
|
|
} |
|
|
@ -209,6 +214,13 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
case 'Font': |
|
|
|
case 'Font': |
|
|
|
this.setFont(state[1], state[2]); |
|
|
|
this.setFont(state[1], state[2]); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case 'CA': |
|
|
|
|
|
|
|
this.current.strokeAlpha = state[1]; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'ca': |
|
|
|
|
|
|
|
this.current.fillAlpha = state[1]; |
|
|
|
|
|
|
|
this.ctx.globalAlpha = state[1]; |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
@ -257,9 +269,13 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
rectangle: function canvasGraphicsRectangle(x, y, width, height) { |
|
|
|
rectangle: function canvasGraphicsRectangle(x, y, width, height) { |
|
|
|
this.ctx.rect(x, y, width, height); |
|
|
|
this.ctx.rect(x, y, width, height); |
|
|
|
}, |
|
|
|
}, |
|
|
|
stroke: function canvasGraphicsStroke() { |
|
|
|
stroke: function canvasGraphicsStroke(consumePath) { |
|
|
|
|
|
|
|
consumePath = typeof consumePath !== 'undefined' ? consumePath : true; |
|
|
|
var ctx = this.ctx; |
|
|
|
var ctx = this.ctx; |
|
|
|
var strokeColor = this.current.strokeColor; |
|
|
|
var strokeColor = this.current.strokeColor; |
|
|
|
|
|
|
|
// For stroke we want to temporarily change the global alpha to the
|
|
|
|
|
|
|
|
// stroking alpha.
|
|
|
|
|
|
|
|
ctx.globalAlpha = this.current.strokeAlpha; |
|
|
|
if (strokeColor && strokeColor.hasOwnProperty('type') && |
|
|
|
if (strokeColor && strokeColor.hasOwnProperty('type') && |
|
|
|
strokeColor.type === 'Pattern') { |
|
|
|
strokeColor.type === 'Pattern') { |
|
|
|
// for patterns, we transform to pattern space, calculate
|
|
|
|
// for patterns, we transform to pattern space, calculate
|
|
|
@ -271,14 +287,17 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ctx.stroke(); |
|
|
|
ctx.stroke(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (consumePath) |
|
|
|
this.consumePath(); |
|
|
|
this.consumePath(); |
|
|
|
|
|
|
|
// Restore the global alpha to the fill alpha
|
|
|
|
|
|
|
|
ctx.globalAlpha = this.current.fillAlpha; |
|
|
|
}, |
|
|
|
}, |
|
|
|
closeStroke: function canvasGraphicsCloseStroke() { |
|
|
|
closeStroke: function canvasGraphicsCloseStroke() { |
|
|
|
this.closePath(); |
|
|
|
this.closePath(); |
|
|
|
this.stroke(); |
|
|
|
this.stroke(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
fill: function canvasGraphicsFill() { |
|
|
|
fill: function canvasGraphicsFill(consumePath) { |
|
|
|
|
|
|
|
consumePath = typeof consumePath !== 'undefined' ? consumePath : true; |
|
|
|
var ctx = this.ctx; |
|
|
|
var ctx = this.ctx; |
|
|
|
var fillColor = this.current.fillColor; |
|
|
|
var fillColor = this.current.fillColor; |
|
|
|
|
|
|
|
|
|
|
@ -291,7 +310,7 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ctx.fill(); |
|
|
|
ctx.fill(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (consumePath) |
|
|
|
this.consumePath(); |
|
|
|
this.consumePath(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
eoFill: function canvasGraphicsEoFill() { |
|
|
|
eoFill: function canvasGraphicsEoFill() { |
|
|
@ -300,29 +319,8 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
this.restoreFillRule(savedFillRule); |
|
|
|
this.restoreFillRule(savedFillRule); |
|
|
|
}, |
|
|
|
}, |
|
|
|
fillStroke: function canvasGraphicsFillStroke() { |
|
|
|
fillStroke: function canvasGraphicsFillStroke() { |
|
|
|
var ctx = this.ctx; |
|
|
|
this.fill(false); |
|
|
|
|
|
|
|
this.stroke(false); |
|
|
|
var fillColor = this.current.fillColor; |
|
|
|
|
|
|
|
if (fillColor && fillColor.hasOwnProperty('type') && |
|
|
|
|
|
|
|
fillColor.type === 'Pattern') { |
|
|
|
|
|
|
|
ctx.save(); |
|
|
|
|
|
|
|
ctx.fillStyle = fillColor.getPattern(ctx); |
|
|
|
|
|
|
|
ctx.fill(); |
|
|
|
|
|
|
|
ctx.restore(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ctx.fill(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var strokeColor = this.current.strokeColor; |
|
|
|
|
|
|
|
if (strokeColor && strokeColor.hasOwnProperty('type') && |
|
|
|
|
|
|
|
strokeColor.type === 'Pattern') { |
|
|
|
|
|
|
|
ctx.save(); |
|
|
|
|
|
|
|
ctx.strokeStyle = strokeColor.getPattern(ctx); |
|
|
|
|
|
|
|
ctx.stroke(); |
|
|
|
|
|
|
|
ctx.restore(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ctx.stroke(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.consumePath(); |
|
|
|
this.consumePath(); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -332,10 +330,12 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
this.restoreFillRule(savedFillRule); |
|
|
|
this.restoreFillRule(savedFillRule); |
|
|
|
}, |
|
|
|
}, |
|
|
|
closeFillStroke: function canvasGraphicsCloseFillStroke() { |
|
|
|
closeFillStroke: function canvasGraphicsCloseFillStroke() { |
|
|
|
return this.fillStroke(); |
|
|
|
this.closePath(); |
|
|
|
|
|
|
|
this.fillStroke(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
closeEOFillStroke: function canvasGraphicsCloseEOFillStroke() { |
|
|
|
closeEOFillStroke: function canvasGraphicsCloseEOFillStroke() { |
|
|
|
var savedFillRule = this.setEOFillRule(); |
|
|
|
var savedFillRule = this.setEOFillRule(); |
|
|
|
|
|
|
|
this.closePath(); |
|
|
|
this.fillStroke(); |
|
|
|
this.fillStroke(); |
|
|
|
this.restoreFillRule(savedFillRule); |
|
|
|
this.restoreFillRule(savedFillRule); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -537,8 +537,7 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// Color
|
|
|
|
// Color
|
|
|
|
setStrokeColorSpace: |
|
|
|
setStrokeColorSpace: function canvasGraphicsSetStrokeColorSpace(raw) { |
|
|
|
function canvasGraphicsSetStrokeColorSpacefunction(raw) { |
|
|
|
|
|
|
|
this.current.strokeColorSpace = ColorSpace.fromIR(raw); |
|
|
|
this.current.strokeColorSpace = ColorSpace.fromIR(raw); |
|
|
|
}, |
|
|
|
}, |
|
|
|
setFillColorSpace: function canvasGraphicsSetFillColorSpace(raw) { |
|
|
|
setFillColorSpace: function canvasGraphicsSetFillColorSpace(raw) { |
|
|
@ -549,7 +548,7 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
var color = cs.getRgb(arguments); |
|
|
|
var color = cs.getRgb(arguments); |
|
|
|
this.setStrokeRGBColor.apply(this, color); |
|
|
|
this.setStrokeRGBColor.apply(this, color); |
|
|
|
}, |
|
|
|
}, |
|
|
|
getColorN_IR_Pattern: function(IR, cs) { |
|
|
|
getColorN_IR_Pattern: function canvasGraphicsGetColorN_IR_Pattern(IR, cs) { |
|
|
|
if (IR[0] == 'TilingPattern') { |
|
|
|
if (IR[0] == 'TilingPattern') { |
|
|
|
var args = IR[1]; |
|
|
|
var args = IR[1]; |
|
|
|
var base = cs.base; |
|
|
|
var base = cs.base; |
|
|
@ -665,8 +664,8 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
error('Should not call beginImageData'); |
|
|
|
error('Should not call beginImageData'); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
paintFormXObjectBegin: |
|
|
|
paintFormXObjectBegin: function canvasGraphicsPaintFormXObjectBegin(matrix, |
|
|
|
function canvasGraphicsPaintFormXObject(matrix, bbox) { |
|
|
|
bbox) { |
|
|
|
this.save(); |
|
|
|
this.save(); |
|
|
|
|
|
|
|
|
|
|
|
if (matrix && isArray(matrix) && 6 == matrix.length) |
|
|
|
if (matrix && isArray(matrix) && 6 == matrix.length) |
|
|
@ -681,11 +680,11 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
paintFormXObjectEnd: function() { |
|
|
|
paintFormXObjectEnd: function canvasGraphicsPaintFormXObjectEnd() { |
|
|
|
this.restore(); |
|
|
|
this.restore(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
paintJpegXObject: function(objId, w, h) { |
|
|
|
paintJpegXObject: function canvasGraphicsPaintJpegXObject(objId, w, h) { |
|
|
|
var image = this.objs.get(objId); |
|
|
|
var image = this.objs.get(objId); |
|
|
|
if (!image) { |
|
|
|
if (!image) { |
|
|
|
error('Dependent image isn\'t ready yet'); |
|
|
|
error('Dependent image isn\'t ready yet'); |
|
|
@ -704,7 +703,8 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
this.restore(); |
|
|
|
this.restore(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
paintImageMaskXObject: function(imgArray, inverseDecode, width, height) { |
|
|
|
paintImageMaskXObject: function canvasGraphicsPaintImageMaskXObject( |
|
|
|
|
|
|
|
imgArray, inverseDecode, width, height) { |
|
|
|
function applyStencilMask(buffer, inverseDecode) { |
|
|
|
function applyStencilMask(buffer, inverseDecode) { |
|
|
|
var imgArrayPos = 0; |
|
|
|
var imgArrayPos = 0; |
|
|
|
var i, j, mask, buf; |
|
|
|
var i, j, mask, buf; |
|
|
@ -752,7 +752,7 @@ var CanvasGraphics = (function canvasGraphics() { |
|
|
|
this.restore(); |
|
|
|
this.restore(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
paintImageXObject: function(imgData) { |
|
|
|
paintImageXObject: function canvasGraphicsPaintImageXObject(imgData) { |
|
|
|
this.save(); |
|
|
|
this.save(); |
|
|
|
var ctx = this.ctx; |
|
|
|
var ctx = this.ctx; |
|
|
|
var w = imgData.width; |
|
|
|
var w = imgData.width; |
|
|
|