@ -1,8 +1,11 @@
@@ -1,8 +1,11 @@
// <canvas> contexts store most of the state we need natively.
// However, PDF needs a bit more state, which we store here.
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict' ;
// <canvas> contexts store most of the state we need natively.
// However, PDF needs a bit more state, which we store here.
var CanvasExtraState = ( function canvasExtraState ( ) {
function constructor ( old ) {
// Are soft masks and alpha values shapes or opacities?
@ -21,13 +24,18 @@ var CanvasExtraState = (function canvasExtraState() {
@@ -21,13 +24,18 @@ var CanvasExtraState = (function canvasExtraState() {
this . wordSpacing = 0 ;
this . textHScale = 1 ;
// Color spaces
this . fillColorSpace = new DeviceGrayCS ;
this . fillColorSpaceObj = null ;
this . strokeColorSpace = new DeviceGrayCS ;
this . strokeColorSpaceObj = null ;
this . fillColorObj = null ;
this . strokeColorObj = null ;
// Default fore and background colors
this . fillColor = '#000000' ;
this . strokeColor = '#000000' ;
// Note: fill alpha applies to all non-stroking operations
this . fillAlpha = 1 ;
this . strokeAlpha = 1 ;
this . old = old ;
}
@ -243,6 +251,13 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -243,6 +251,13 @@ var CanvasGraphics = (function canvasGraphics() {
case 'Font' :
this . setFont ( state [ 1 ] , state [ 2 ] ) ;
break ;
case 'CA' :
this . current . strokeAlpha = state [ 1 ] ;
break ;
case 'ca' :
this . current . fillAlpha = state [ 1 ] ;
this . ctx . globalAlpha = state [ 1 ] ;
break ;
}
}
} ,
@ -291,9 +306,13 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -291,9 +306,13 @@ var CanvasGraphics = (function canvasGraphics() {
rectangle : function canvasGraphicsRectangle ( 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 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' ) &&
strokeColor . type === 'Pattern' ) {
// for patterns, we transform to pattern space, calculate
@ -305,14 +324,17 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -305,14 +324,17 @@ var CanvasGraphics = (function canvasGraphics() {
} else {
ctx . stroke ( ) ;
}
this . consumePath ( ) ;
if ( consumePath )
this . consumePath ( ) ;
// Restore the global alpha to the fill alpha
ctx . globalAlpha = this . current . fillAlpha ;
} ,
closeStroke : function canvasGraphicsCloseStroke ( ) {
this . closePath ( ) ;
this . stroke ( ) ;
} ,
fill : function canvasGraphicsFill ( ) {
fill : function canvasGraphicsFill ( consumePath ) {
consumePath = typeof consumePath !== 'undefined' ? consumePath : true ;
var ctx = this . ctx ;
var fillColor = this . current . fillColor ;
@ -325,8 +347,8 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -325,8 +347,8 @@ var CanvasGraphics = (function canvasGraphics() {
} else {
ctx . fill ( ) ;
}
this . consumePath ( ) ;
if ( consumePath )
this . consumePath ( ) ;
} ,
eoFill : function canvasGraphicsEoFill ( ) {
var savedFillRule = this . setEOFillRule ( ) ;
@ -334,29 +356,8 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -334,29 +356,8 @@ var CanvasGraphics = (function canvasGraphics() {
this . restoreFillRule ( savedFillRule ) ;
} ,
fillStroke : function canvasGraphicsFillStroke ( ) {
var ctx = this . ctx ;
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 . fill ( false ) ;
this . stroke ( false ) ;
this . consumePath ( ) ;
} ,
@ -366,10 +367,12 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -366,10 +367,12 @@ var CanvasGraphics = (function canvasGraphics() {
this . restoreFillRule ( savedFillRule ) ;
} ,
closeFillStroke : function canvasGraphicsCloseFillStroke ( ) {
return this . fillStroke ( ) ;
this . closePath ( ) ;
this . fillStroke ( ) ;
} ,
closeEOFillStroke : function canvasGraphicsCloseEOFillStroke ( ) {
var savedFillRule = this . setEOFillRule ( ) ;
this . closePath ( ) ;
this . fillStroke ( ) ;
this . restoreFillRule ( savedFillRule ) ;
} ,
@ -646,8 +649,7 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -646,8 +649,7 @@ var CanvasGraphics = (function canvasGraphics() {
} ,
// Color
setStrokeColorSpace :
function canvasGraphicsSetStrokeColorSpacefunction ( raw ) {
setStrokeColorSpace : function canvasGraphicsSetStrokeColorSpace ( raw ) {
this . current . strokeColorSpace = ColorSpace . fromIR ( raw ) ;
} ,
setFillColorSpace : function canvasGraphicsSetFillColorSpace ( raw ) {
@ -658,7 +660,7 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -658,7 +660,7 @@ var CanvasGraphics = (function canvasGraphics() {
var color = cs . getRgb ( arguments ) ;
this . setStrokeRGBColor . apply ( this , color ) ;
} ,
getColorN _IR _Pattern : function ( IR , cs ) {
getColorN _IR _Pattern : function canvasGraphicsGetColorN _IR _Pattern ( IR , cs ) {
if ( IR [ 0 ] == 'TilingPattern' ) {
var args = IR [ 1 ] ;
var base = cs . base ;
@ -774,8 +776,8 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -774,8 +776,8 @@ var CanvasGraphics = (function canvasGraphics() {
error ( 'Should not call beginImageData' ) ;
} ,
paintFormXObjectBegin :
function canvasGraphicsPaintFormXObject ( matrix , bbox ) {
paintFormXObjectBegin : function canvasGraphicsPaintFormXObjectBegin ( matrix ,
bbox ) {
this . save ( ) ;
if ( matrix && isArray ( matrix ) && 6 == matrix . length )
@ -790,11 +792,11 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -790,11 +792,11 @@ var CanvasGraphics = (function canvasGraphics() {
}
} ,
paintFormXObjectEnd : function ( ) {
paintFormXObjectEnd : function canvasGraphicsPaintFormXObjectEnd ( ) {
this . restore ( ) ;
} ,
paintJpegXObject : function ( objId , w , h ) {
paintJpegXObject : function canvasGraphicsPaintJpegXObject ( objId , w , h ) {
var image = this . objs . get ( objId ) ;
if ( ! image ) {
error ( 'Dependent image isn\'t ready yet' ) ;
@ -813,7 +815,8 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -813,7 +815,8 @@ var CanvasGraphics = (function canvasGraphics() {
this . restore ( ) ;
} ,
paintImageMaskXObject : function ( imgArray , inverseDecode , width , height ) {
paintImageMaskXObject : function canvasGraphicsPaintImageMaskXObject (
imgArray , inverseDecode , width , height ) {
function applyStencilMask ( buffer , inverseDecode ) {
var imgArrayPos = 0 ;
var i , j , mask , buf ;
@ -861,7 +864,7 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -861,7 +864,7 @@ var CanvasGraphics = (function canvasGraphics() {
this . restore ( ) ;
} ,
paintImageXObject : function ( imgData ) {
paintImageXObject : function canvasGraphicsPaintImageXObject ( imgData ) {
this . save ( ) ;
var ctx = this . ctx ;
var w = imgData . width ;
@ -950,3 +953,4 @@ var CanvasGraphics = (function canvasGraphics() {
@@ -950,3 +953,4 @@ var CanvasGraphics = (function canvasGraphics() {
return constructor ;
} ) ( ) ;