Merge remote-tracking branch 'upstream/master'
This commit is contained in:
		
						commit
						9343df134d
					
				| @ -543,7 +543,7 @@ var CipherTransformFactory = (function() { | |||||||
|       key[i++] = 0x54; |       key[i++] = 0x54; | ||||||
|     } |     } | ||||||
|     var hash = md5(key, 0, i); |     var hash = md5(key, 0, i); | ||||||
|     return hash.subarray(0, Math.min(key.length, 16)); |     return hash.subarray(0, Math.min(encryptionKey.length + 5, 16)); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   function buildCipherConstructor(cf, name, num, gen, key) { |   function buildCipherConstructor(cf, name, num, gen, key) { | ||||||
|  | |||||||
							
								
								
									
										79
									
								
								fonts.js
									
									
									
									
									
								
							
							
						
						
									
										79
									
								
								fonts.js
									
									
									
									
									
								
							| @ -1284,8 +1284,6 @@ var Font = (function Font() { | |||||||
|           var charcode = chars.charCodeAt(i); |           var charcode = chars.charCodeAt(i); | ||||||
|           var unicode = encoding[charcode]; |           var unicode = encoding[charcode]; | ||||||
|           if ('undefined' == typeof(unicode)) { |           if ('undefined' == typeof(unicode)) { | ||||||
|             // FIXME/issue 233: we're hitting this in test/pdf/sizes.pdf
 |  | ||||||
|             // at the moment, for unknown reasons.
 |  | ||||||
|             warn('Unencoded charcode ' + charcode); |             warn('Unencoded charcode ' + charcode); | ||||||
|             unicode = charcode; |             unicode = charcode; | ||||||
|           } |           } | ||||||
| @ -1485,16 +1483,22 @@ var Type1Parser = function() { | |||||||
|           // TODO Clean this code
 |           // TODO Clean this code
 | ||||||
|           if (value == 13) { |           if (value == 13) { | ||||||
|             if (charstring.length == 2) { |             if (charstring.length == 2) { | ||||||
|  |               lsb = charstring[0]; | ||||||
|               width = charstring[1]; |               width = charstring[1]; | ||||||
|  |               charstring.splice(0, 1); | ||||||
|             } else if (charstring.length == 4 && charstring[3] == 'div') { |             } else if (charstring.length == 4 && charstring[3] == 'div') { | ||||||
|  |               lsb = charstring[0]; | ||||||
|               width = charstring[1] / charstring[2]; |               width = charstring[1] / charstring[2]; | ||||||
|  |               charstring.splice(0, 1); | ||||||
|  |             } else if (charstring.length == 4 && charstring[2] == 'div') { | ||||||
|  |               lsb = charstring[0] / charstring[1]; | ||||||
|  |               width = charstring[3]; | ||||||
|  |               charstring.splice(0, 3); | ||||||
|             } else { |             } else { | ||||||
|               error('Unsupported hsbw format: ' + charstring); |               error('Unsupported hsbw format: ' + charstring); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             lsb = charstring[0]; |  | ||||||
|             charstring.push(lsb, 'hmoveto'); |             charstring.push(lsb, 'hmoveto'); | ||||||
|             charstring.splice(0, 1); |  | ||||||
|             continue; |             continue; | ||||||
|           } |           } | ||||||
|           command = charStringDictionary[value]; |           command = charStringDictionary[value]; | ||||||
| @ -1584,13 +1588,12 @@ var Type1Parser = function() { | |||||||
|         while (i < count && (eexecStr[i] == ' ' || eexecStr[i] == '\n')) |         while (i < count && (eexecStr[i] == ' ' || eexecStr[i] == '\n')) | ||||||
|           ++i; |           ++i; | ||||||
| 
 | 
 | ||||||
|         var t = ''; |         var token = ''; | ||||||
|         while (i < count && !(eexecStr[i] == ' ' || eexecStr[i] == '\n')) |         while (i < count && !(eexecStr[i] == ' ' || eexecStr[i] == '\n')) | ||||||
|           t += eexecStr[i++]; |           token += eexecStr[i++]; | ||||||
| 
 |  | ||||||
|         return t; |  | ||||||
|       } |  | ||||||
| 
 | 
 | ||||||
|  |         return token; | ||||||
|  |       }; | ||||||
|       var c = eexecStr[i]; |       var c = eexecStr[i]; | ||||||
| 
 | 
 | ||||||
|       if ((glyphsSection || subrsSection) && c == 'R') { |       if ((glyphsSection || subrsSection) && c == 'R') { | ||||||
| @ -1674,18 +1677,28 @@ var Type1Parser = function() { | |||||||
|     return program; |     return program; | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   this.extractFontHeader = function t1_extractFontProgram(stream) { |   this.extractFontHeader = function t1_extractFontHeader(stream, properties) { | ||||||
|     var headerString = ''; |     var headerString = ''; | ||||||
|     for (var i = 0; i < stream.length; i++) |     for (var i = 0; i < stream.length; i++) | ||||||
|       headerString += String.fromCharCode(stream[i]); |       headerString += String.fromCharCode(stream[i]); | ||||||
| 
 | 
 | ||||||
|     var info = { |  | ||||||
|       textMatrix: null |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     var token = ''; |     var token = ''; | ||||||
|     var count = headerString.length; |     var count = headerString.length; | ||||||
|     for (var i = 0; i < count; i++) { |     for (var i = 0; i < count; i++) { | ||||||
|  |       var getToken = function() { | ||||||
|  |         var char = headerString[i]; | ||||||
|  |         while (i < count && (char == ' ' || char == '\n' || char == '/')) | ||||||
|  |           char = headerString[++i]; | ||||||
|  | 
 | ||||||
|  |         var token = ''; | ||||||
|  |         while (i < count && !(char == ' ' || char == '\n' || char == '/')) { | ||||||
|  |           token += char; | ||||||
|  |           char = headerString[++i]; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return token; | ||||||
|  |       }; | ||||||
|  | 
 | ||||||
|       var c = headerString[i]; |       var c = headerString[i]; | ||||||
|       if (c == ' ' || c == '\n') { |       if (c == ' ' || c == '\n') { | ||||||
|         switch (token) { |         switch (token) { | ||||||
| @ -1699,7 +1712,25 @@ var Type1Parser = function() { | |||||||
|             // Make the angle into the right direction
 |             // Make the angle into the right direction
 | ||||||
|             matrix[2] *= -1; |             matrix[2] *= -1; | ||||||
| 
 | 
 | ||||||
|             info.textMatrix = matrix; |             properties.textMatrix = matrix; | ||||||
|  |             break; | ||||||
|  |           case '/Encoding': | ||||||
|  |             if (!properties.builtInEncoding) | ||||||
|  |               break; | ||||||
|  | 
 | ||||||
|  |             var size = parseInt(getToken()); | ||||||
|  |             getToken(); // read in 'array'
 | ||||||
|  | 
 | ||||||
|  |             for (var j = 0; j < size; j++) { | ||||||
|  |               var token = getToken(); | ||||||
|  |               if (token == 'dup') { | ||||||
|  |                 var index = parseInt(getToken()); | ||||||
|  |                 var glyph = getToken(); | ||||||
|  |                 properties.encoding[index] = GlyphsUnicode[glyph]; | ||||||
|  |                 getToken(); // read the in 'put'
 | ||||||
|  |                 j = index; | ||||||
|  |               } | ||||||
|  |             } | ||||||
|             break; |             break; | ||||||
|         } |         } | ||||||
|         token = ''; |         token = ''; | ||||||
| @ -1707,8 +1738,6 @@ var Type1Parser = function() { | |||||||
|         token += c; |         token += c; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
|     return info; |  | ||||||
|   }; |   }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| @ -1792,13 +1821,11 @@ var CFF = function(name, file, properties) { | |||||||
|   var length2 = file.dict.get('Length2'); |   var length2 = file.dict.get('Length2'); | ||||||
| 
 | 
 | ||||||
|   var headerBlock = file.getBytes(length1); |   var headerBlock = file.getBytes(length1); | ||||||
|   var header = type1Parser.extractFontHeader(headerBlock); |   type1Parser.extractFontHeader(headerBlock, properties); | ||||||
|   for (var info in header) |  | ||||||
|     properties[info] = header[info]; |  | ||||||
| 
 | 
 | ||||||
|   // Decrypt the data blocks and retrieve it's content
 |   // Decrypt the data blocks and retrieve it's content
 | ||||||
|   var eexecBlock = file.getBytes(length2); |   var eexecBlock = file.getBytes(length2); | ||||||
|   var data = type1Parser.extractFontProgram(eexecBlock); |   var data = type1Parser.extractFontProgram(eexecBlock, properties); | ||||||
|   for (var info in data.properties) |   for (var info in data.properties) | ||||||
|     properties[info] = data.properties[info]; |     properties[info] = data.properties[info]; | ||||||
| 
 | 
 | ||||||
| @ -1868,15 +1895,14 @@ CFF.prototype = { | |||||||
| 
 | 
 | ||||||
|   getOrderedCharStrings: function cff_getOrderedCharStrings(glyphs) { |   getOrderedCharStrings: function cff_getOrderedCharStrings(glyphs) { | ||||||
|     var charstrings = []; |     var charstrings = []; | ||||||
|  |     var missings = []; | ||||||
| 
 | 
 | ||||||
|     for (var i = 0; i < glyphs.length; i++) { |     for (var i = 0; i < glyphs.length; i++) { | ||||||
|       var glyph = glyphs[i]; |       var glyph = glyphs[i]; | ||||||
|       var unicode = GlyphsUnicode[glyph.glyph]; |       var unicode = GlyphsUnicode[glyph.glyph]; | ||||||
|       if (!unicode) { |       if (!unicode) { | ||||||
|         if (glyph.glyph != '.notdef') { |         if (glyph.glyph != '.notdef') | ||||||
|           warn(glyph.glyph + |           missings.push(glyph.glyph); | ||||||
|                ' does not have an entry in the glyphs unicode dictionary'); |  | ||||||
|         } |  | ||||||
|       } else { |       } else { | ||||||
|         charstrings.push({ |         charstrings.push({ | ||||||
|           glyph: glyph, |           glyph: glyph, | ||||||
| @ -1888,6 +1914,9 @@ CFF.prototype = { | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     if (missings.length) | ||||||
|  |       warn(missings + ' does not have unicode in the glyphs dictionary'); | ||||||
|  | 
 | ||||||
|     charstrings.sort(function charstrings_sort(a, b) { |     charstrings.sort(function charstrings_sort(a, b) { | ||||||
|       return a.unicode - b.unicode; |       return a.unicode - b.unicode; | ||||||
|     }); |     }); | ||||||
|  | |||||||
							
								
								
									
										69
									
								
								pdf.js
									
									
									
									
									
								
							
							
						
						
									
										69
									
								
								pdf.js
									
									
									
									
									
								
							| @ -208,6 +208,11 @@ var DecodeStream = (function() { | |||||||
|           this.readBlock(); |           this.readBlock(); | ||||||
| 
 | 
 | ||||||
|         var end = this.bufferLength; |         var end = this.bufferLength; | ||||||
|  | 
 | ||||||
|  |         // checking if bufferLength is still 0 then
 | ||||||
|  |         // the buffer has to be initialized
 | ||||||
|  |         if (!end) | ||||||
|  |           this.buffer = new Uint8Array(0); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       this.pos = end; |       this.pos = end; | ||||||
| @ -3340,11 +3345,11 @@ var Page = (function() { | |||||||
|       var xref = this.xref; |       var xref = this.xref; | ||||||
|       var content = xref.fetchIfRef(this.content); |       var content = xref.fetchIfRef(this.content); | ||||||
|       var resources = xref.fetchIfRef(this.resources); |       var resources = xref.fetchIfRef(this.resources); | ||||||
|       if (IsArray(this.content)) { |       if (IsArray(content)) { | ||||||
|         // fetching items
 |         // fetching items
 | ||||||
|         var i, n = content.length; |         var i, n = content.length; | ||||||
|         for (i = 0; i < n; ++i) |         for (i = 0; i < n; ++i) | ||||||
|           content[i] = xref.fetchIfRef(this.content[i]); |           content[i] = xref.fetchIfRef(content[i]); | ||||||
|         content = new StreamsSequenceStream(content); |         content = new StreamsSequenceStream(content); | ||||||
|       } |       } | ||||||
|       this.code = gfx.compile(content, xref, resources, fonts, images); |       this.code = gfx.compile(content, xref, resources, fonts, images); | ||||||
| @ -4191,6 +4196,7 @@ var PartialEvaluator = (function() { | |||||||
|         fd = fontDict.get('FontDescriptor'); |         fd = fontDict.get('FontDescriptor'); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|  |       var builtInEncoding = false; | ||||||
|       var encodingMap = {}; |       var encodingMap = {}; | ||||||
|       var glyphMap = {}; |       var glyphMap = {}; | ||||||
|       var charset = []; |       var charset = []; | ||||||
| @ -4261,9 +4267,11 @@ var PartialEvaluator = (function() { | |||||||
|         if (!baseEncoding) { |         if (!baseEncoding) { | ||||||
|           var type = subType.name; |           var type = subType.name; | ||||||
|           if (type == 'TrueType') { |           if (type == 'TrueType') { | ||||||
|             baseEncoding = Encodings.WinAnsiEncoding.slice(0); |             baseEncoding = Encodings.WinAnsiEncoding.slice(); | ||||||
|           } else if (type == 'Type1') { |           } else if (type == 'Type1') { | ||||||
|             baseEncoding = Encodings.StandardEncoding.slice(0); |             baseEncoding = Encodings.StandardEncoding.slice(); | ||||||
|  |             if (!diffEncoding.length) | ||||||
|  |               builtInEncoding = true; | ||||||
|           } else { |           } else { | ||||||
|             error('Unknown type of font'); |             error('Unknown type of font'); | ||||||
|           } |           } | ||||||
| @ -4285,6 +4293,7 @@ var PartialEvaluator = (function() { | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (fontDict.has('ToUnicode')) { |         if (fontDict.has('ToUnicode')) { | ||||||
|  |           encodingMap['empty'] = true; | ||||||
|           var cmapObj = xref.fetchIfRef(fontDict.get('ToUnicode')); |           var cmapObj = xref.fetchIfRef(fontDict.get('ToUnicode')); | ||||||
|           if (IsName(cmapObj)) { |           if (IsName(cmapObj)) { | ||||||
|             error('ToUnicode file cmap translation not implemented'); |             error('ToUnicode file cmap translation not implemented'); | ||||||
| @ -4419,6 +4428,7 @@ var PartialEvaluator = (function() { | |||||||
|         subtype: fileType, |         subtype: fileType, | ||||||
|         widths: glyphWidths, |         widths: glyphWidths, | ||||||
|         encoding: encodingMap, |         encoding: encodingMap, | ||||||
|  |         builtInEncoding: builtInEncoding, | ||||||
|         charset: charset, |         charset: charset, | ||||||
|         firstChar: fontDict.get('FirstChar'), |         firstChar: fontDict.get('FirstChar'), | ||||||
|         lastChar: fontDict.get('LastChar'), |         lastChar: fontDict.get('LastChar'), | ||||||
| @ -5102,15 +5112,18 @@ var CanvasGraphics = (function() { | |||||||
| 
 | 
 | ||||||
|       var tmpCanvas = new this.ScratchCanvas(w, h); |       var tmpCanvas = new this.ScratchCanvas(w, h); | ||||||
|       var tmpCtx = tmpCanvas.getContext('2d'); |       var tmpCtx = tmpCanvas.getContext('2d'); | ||||||
|  |       if (imageObj.imageMask) { | ||||||
|  |         var fillColor = this.current.fillColor; | ||||||
|  |         tmpCtx.fillStyle = (fillColor && fillColor.type === 'Pattern') ? | ||||||
|  |           fillColor.getPattern(tmpCtx) : fillColor; | ||||||
|  |         tmpCtx.fillRect(0, 0, w, h); | ||||||
|  |       } | ||||||
|       var imgData = tmpCtx.getImageData(0, 0, w, h); |       var imgData = tmpCtx.getImageData(0, 0, w, h); | ||||||
|       var pixels = imgData.data; |       var pixels = imgData.data; | ||||||
| 
 | 
 | ||||||
|       if (imageObj.imageMask) { |       if (imageObj.imageMask) { | ||||||
|         var inverseDecode = imageObj.decode && imageObj.decode[0] > 0; |         var inverseDecode = !!imageObj.decode && imageObj.decode[0] > 0; | ||||||
|         // TODO fillColor pattern support
 |         imageObj.applyStencilMask(pixels, inverseDecode); | ||||||
|         var fillColor = this.current.fillColor; |  | ||||||
|         imageObj.fillUsingStencilMask(pixels, fillColor, |  | ||||||
|                                       inverseDecode); |  | ||||||
|       } else |       } else | ||||||
|         imageObj.fillRgbaBuffer(pixels); |         imageObj.fillRgbaBuffer(pixels); | ||||||
| 
 | 
 | ||||||
| @ -5990,26 +6003,26 @@ var PDFImage = (function() { | |||||||
|       } |       } | ||||||
|       return buf; |       return buf; | ||||||
|     }, |     }, | ||||||
|     fillUsingStencilMask: function fillUsingStencilMask(buffer, |     applyStencilMask: function applyStencilMask(buffer, inverseDecode) { | ||||||
|       cssRgb, inverseDecode) { |       var width = this.width, height = this.height; | ||||||
|       var m = /rgb\((\d+),(\d+),(\d+)\)/.exec(cssRgb); // parse CSS color
 |       var bitStrideLength = (width + 7) >> 3; | ||||||
|       var r = m[1] | 0, g = m[2] | 0, b = m[3] | 0; |       var imgArray = this.image.getBytes(bitStrideLength * height); | ||||||
|       var bufferLength = this.width * this.height; |       var imgArrayPos = 0; | ||||||
|       var imgArray = this.image.getBytes((bufferLength + 7) >> 3); |       var i, j, mask, buf; | ||||||
|       var i, mask; |       // removing making non-masked pixels transparent
 | ||||||
|       var bufferPos = 0, imgArrayPos = 0; |       var bufferPos = 3; // alpha component offset
 | ||||||
|       for (i = 0; i < bufferLength; i++) { |       for (i = 0; i < height; i++) { | ||||||
|         var buf = imgArray[imgArrayPos++]; |         mask = 0; | ||||||
|         for (mask = 128; mask > 0; mask >>= 1) { |         for (j = 0; j < width; j++) { | ||||||
|           if (!(buf & mask) != inverseDecode) { |           if (!mask) { | ||||||
|             buffer[bufferPos++] = r; |             buf = imgArray[imgArrayPos++]; | ||||||
|             buffer[bufferPos++] = g; |             mask = 128; | ||||||
|             buffer[bufferPos++] = b; |  | ||||||
|             buffer[bufferPos++] = 255; |  | ||||||
|           } else { |  | ||||||
|             buffer[bufferPos + 3] = 0; |  | ||||||
|             bufferPos += 4; |  | ||||||
|           } |           } | ||||||
|  |           if (!(buf & mask) == inverseDecode) { | ||||||
|  |             buffer[bufferPos] = 0; | ||||||
|  |           } | ||||||
|  |           bufferPos += 4; | ||||||
|  |           mask >>= 1; | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user