Merge pull request #214 from saebekassebil/master
Dict object improvements. Performance.
This commit is contained in:
commit
df79f10f2f
6
fonts.js
6
fonts.js
@ -2,7 +2,7 @@
|
|||||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
var missingGlyphs = [];
|
||||||
var isWorker = (typeof window == 'undefined');
|
var isWorker = (typeof window == 'undefined');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1645,9 +1645,11 @@ CFF.prototype = {
|
|||||||
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 +
|
missingGlyphs.push(glyph.glyph);
|
||||||
|
warn(glyph.glyph +
|
||||||
' does not have an entry in the glyphs unicode dictionary');
|
' does not have an entry in the glyphs unicode dictionary');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
67
pdf.js
67
pdf.js
@ -1917,32 +1917,37 @@ var Cmd = (function() {
|
|||||||
|
|
||||||
var Dict = (function() {
|
var Dict = (function() {
|
||||||
function constructor() {
|
function constructor() {
|
||||||
this.map = Object.create(null);
|
this.map = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
get: function(key) {
|
get: function(key1, key2, key3) {
|
||||||
if (key in this.map)
|
var value;
|
||||||
return this.map[key];
|
if (typeof (value = this.map[key1]) != 'undefined' || key1 in this.map || typeof key2 == 'undefined') {
|
||||||
return null;
|
return value;
|
||||||
},
|
}
|
||||||
get2: function(key1, key2) {
|
if (typeof (value = this.map[key2]) != 'undefined' || key2 in this.map || typeof key3 == 'undefined') {
|
||||||
return this.get(key1) || this.get(key2);
|
return value;
|
||||||
},
|
}
|
||||||
get3: function(key1, key2, key3) {
|
|
||||||
return this.get(key1) || this.get(key2) || this.get(key3);
|
return this.map[key3] || null;
|
||||||
},
|
|
||||||
has: function(key) {
|
|
||||||
return key in this.map;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
set: function(key, value) {
|
set: function(key, value) {
|
||||||
this.map[key] = value;
|
this.map[key] = value;
|
||||||
},
|
},
|
||||||
forEach: function(aCallback) {
|
|
||||||
for (var key in this.map)
|
has: function(key) {
|
||||||
aCallback(key, this.map[key]);
|
return key in this.map;
|
||||||
|
},
|
||||||
|
|
||||||
|
forEach: function(callback) {
|
||||||
|
for (var key in this.map) {
|
||||||
|
callback.call(null, key, this.map[key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return constructor;
|
return constructor;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -2459,8 +2464,8 @@ var Parser = (function() {
|
|||||||
return stream;
|
return stream;
|
||||||
},
|
},
|
||||||
filter: function(stream, dict, length) {
|
filter: function(stream, dict, length) {
|
||||||
var filter = dict.get2('Filter', 'F');
|
var filter = dict.get('Filter', 'F');
|
||||||
var params = dict.get2('DecodeParms', 'DP');
|
var params = dict.get('DecodeParms', 'DP');
|
||||||
if (IsName(filter))
|
if (IsName(filter))
|
||||||
return this.makeFilter(stream, filter.name, length, params);
|
return this.makeFilter(stream, filter.name, length, params);
|
||||||
if (IsArray(filter)) {
|
if (IsArray(filter)) {
|
||||||
@ -3472,7 +3477,7 @@ var CanvasGraphics = (function() {
|
|||||||
assertWellFormed(IsName(fontName), 'invalid font name');
|
assertWellFormed(IsName(fontName), 'invalid font name');
|
||||||
fontName = fontName.name.replace('+', '_');
|
fontName = fontName.name.replace('+', '_');
|
||||||
|
|
||||||
var fontFile = descriptor.get3('FontFile', 'FontFile2', 'FontFile3');
|
var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
|
||||||
if (!fontFile)
|
if (!fontFile)
|
||||||
error('FontFile not found for font: ' + fontName);
|
error('FontFile not found for font: ' + fontName);
|
||||||
fontFile = xref.fetchIfRef(fontFile);
|
fontFile = xref.fetchIfRef(fontFile);
|
||||||
@ -4219,7 +4224,7 @@ var CanvasGraphics = (function() {
|
|||||||
if (background)
|
if (background)
|
||||||
TODO('handle background colors');
|
TODO('handle background colors');
|
||||||
|
|
||||||
var cs = shading.get2('ColorSpace', 'CS');
|
var cs = shading.get('ColorSpace', 'CS');
|
||||||
cs = ColorSpace.parse(cs, this.xref, this.res);
|
cs = ColorSpace.parse(cs, this.xref, this.res);
|
||||||
|
|
||||||
var types = [null,
|
var types = [null,
|
||||||
@ -4383,8 +4388,8 @@ var CanvasGraphics = (function() {
|
|||||||
|
|
||||||
var ctx = this.ctx;
|
var ctx = this.ctx;
|
||||||
var dict = image.dict;
|
var dict = image.dict;
|
||||||
var w = dict.get2('Width', 'W');
|
var w = dict.get('Width', 'W');
|
||||||
var h = dict.get2('Height', 'H');
|
var h = dict.get('Height', 'H');
|
||||||
// scale the image to the unit square
|
// scale the image to the unit square
|
||||||
ctx.scale(1 / w, -1 / h);
|
ctx.scale(1 / w, -1 / h);
|
||||||
|
|
||||||
@ -4879,18 +4884,18 @@ var PDFImage = (function() {
|
|||||||
// TODO cache rendered images?
|
// TODO cache rendered images?
|
||||||
|
|
||||||
var dict = image.dict;
|
var dict = image.dict;
|
||||||
this.width = dict.get2('Width', 'W');
|
this.width = dict.get('Width', 'W');
|
||||||
this.height = dict.get2('Height', 'H');
|
this.height = dict.get('Height', 'H');
|
||||||
|
|
||||||
if (this.width < 1 || this.height < 1)
|
if (this.width < 1 || this.height < 1)
|
||||||
error('Invalid image width or height');
|
error('Invalid image width or height');
|
||||||
|
|
||||||
this.interpolate = dict.get2('Interpolate', 'I') || false;
|
this.interpolate = dict.get('Interpolate', 'I') || false;
|
||||||
this.imageMask = dict.get2('ImageMask', 'IM') || false;
|
this.imageMask = dict.get('ImageMask', 'IM') || false;
|
||||||
|
|
||||||
var bitsPerComponent = image.bitsPerComponent;
|
var bitsPerComponent = image.bitsPerComponent;
|
||||||
if (!bitsPerComponent) {
|
if (!bitsPerComponent) {
|
||||||
bitsPerComponent = dict.get2('BitsPerComponent', 'BPC');
|
bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
|
||||||
if (!bitsPerComponent) {
|
if (!bitsPerComponent) {
|
||||||
if (this.imageMask)
|
if (this.imageMask)
|
||||||
bitsPerComponent = 1;
|
bitsPerComponent = 1;
|
||||||
@ -4900,11 +4905,11 @@ var PDFImage = (function() {
|
|||||||
}
|
}
|
||||||
this.bpc = bitsPerComponent;
|
this.bpc = bitsPerComponent;
|
||||||
|
|
||||||
var colorSpace = dict.get2('ColorSpace', 'CS');
|
var colorSpace = dict.get('ColorSpace', 'CS');
|
||||||
this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
|
this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
|
||||||
|
|
||||||
this.numComps = this.colorSpace.numComps;
|
this.numComps = this.colorSpace.numComps;
|
||||||
this.decode = dict.get2('Decode', 'D');
|
this.decode = dict.get('Decode', 'D');
|
||||||
|
|
||||||
var mask = xref.fetchIfRef(image.dict.get('Mask'));
|
var mask = xref.fetchIfRef(image.dict.get('Mask'));
|
||||||
var smask = xref.fetchIfRef(image.dict.get('SMask'));
|
var smask = xref.fetchIfRef(image.dict.get('SMask'));
|
||||||
@ -5062,7 +5067,7 @@ var PDFFunction = (function() {
|
|||||||
if (!typeFn)
|
if (!typeFn)
|
||||||
error('Unknown type of function');
|
error('Unknown type of function');
|
||||||
|
|
||||||
typeFn.apply(this, [fn, dict]);
|
typeFn.call(this, fn, dict);
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user