Merge pull request #716 from brendandahl/alphatrans
Alpha Transparency Support
This commit is contained in:
		
						commit
						f8b689fb26
					
				| @ -33,6 +33,9 @@ var CanvasExtraState = (function canvasExtraState() { | |||||||
|     // 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; | ||||||
|   } |   } | ||||||
| @ -211,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; | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
| @ -259,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
 | ||||||
| @ -273,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; | ||||||
| 
 | 
 | ||||||
| @ -293,8 +310,8 @@ var CanvasGraphics = (function canvasGraphics() { | |||||||
|       } else { |       } else { | ||||||
|         ctx.fill(); |         ctx.fill(); | ||||||
|       } |       } | ||||||
| 
 |       if (consumePath) | ||||||
|       this.consumePath(); |         this.consumePath(); | ||||||
|     }, |     }, | ||||||
|     eoFill: function canvasGraphicsEoFill() { |     eoFill: function canvasGraphicsEoFill() { | ||||||
|       var savedFillRule = this.setEOFillRule(); |       var savedFillRule = this.setEOFillRule(); | ||||||
| @ -302,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(); | ||||||
|     }, |     }, | ||||||
|  | |||||||
| @ -405,6 +405,8 @@ var PartialEvaluator = (function partialEvaluator() { | |||||||
|                     case 'D': |                     case 'D': | ||||||
|                     case 'RI': |                     case 'RI': | ||||||
|                     case 'FL': |                     case 'FL': | ||||||
|  |                     case 'CA': | ||||||
|  |                     case 'ca': | ||||||
|                       gsStateObj.push([key, value]); |                       gsStateObj.push([key, value]); | ||||||
|                       break; |                       break; | ||||||
|                     case 'Font': |                     case 'Font': | ||||||
| @ -428,8 +430,6 @@ var PartialEvaluator = (function partialEvaluator() { | |||||||
|                     case 'SA': |                     case 'SA': | ||||||
|                     case 'BM': |                     case 'BM': | ||||||
|                     case 'SMask': |                     case 'SMask': | ||||||
|                     case 'CA': |  | ||||||
|                     case 'ca': |  | ||||||
|                     case 'AIS': |                     case 'AIS': | ||||||
|                     case 'TK': |                     case 'TK': | ||||||
|                       TODO('graphic state operator ' + key); |                       TODO('graphic state operator ' + key); | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								test/pdfs/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								test/pdfs/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -13,3 +13,5 @@ | |||||||
| !simpletype3font.pdf | !simpletype3font.pdf | ||||||
| !sizes.pdf | !sizes.pdf | ||||||
| !close-path-bug.pdf | !close-path-bug.pdf | ||||||
|  | !alphatrans.pdf | ||||||
|  | 
 | ||||||
|  | |||||||
							
								
								
									
										
											BIN
										
									
								
								test/pdfs/alphatrans.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test/pdfs/alphatrans.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -222,5 +222,11 @@ | |||||||
|        "file": "pdfs/close-path-bug.pdf", |        "file": "pdfs/close-path-bug.pdf", | ||||||
|        "rounds": 1, |        "rounds": 1, | ||||||
|        "type": "eq" |        "type": "eq" | ||||||
|  |     }, | ||||||
|  |     {  "id": "alphatrans", | ||||||
|  |        "file": "pdfs/alphatrans.pdf", | ||||||
|  |        "link": false, | ||||||
|  |        "rounds": 1, | ||||||
|  |        "type": "eq" | ||||||
|     } |     } | ||||||
| ] | ] | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user