Skip to content

Commit

Permalink
Merge pull request mozilla#5135 from nnethercote/identity-cmap-proper
Browse files Browse the repository at this point in the history
Make IdentityCMaps more compact.
  • Loading branch information
yurydelendik committed Aug 6, 2014
2 parents 666cf02 + 51055e5 commit 5786014
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions src/core/cmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,69 @@ var CMap = (function CMapClosure() {

return [0, 1];
}

};
return CMap;
})();

// A special case of CMap, where the _map array implicitly has a length of
// 65535 and each element is equal to its index.
var IdentityCMap = (function IdentityCMapClosure() {
function IdentityCMap(vertical, n) {
CMap.call(this);
this.vertical = vertical;
this.addCodespaceRange(n, 0, 0xffff);
this.mapCidRange(0, 0xffff, 0);
}
Util.inherit(IdentityCMap, CMap, {});

IdentityCMap.prototype = {
addCodespaceRange: CMap.prototype.addCodespaceRange,

mapCidRange: function(low, high, dstLow) {
error('should not call mapCidRange');
},

mapBfRange: function(low, high, dstLow) {
error('should not call mapBfRange');
},

mapBfRangeToArray: function(low, high, array) {
error('should not call mapBfRangeToArray');
},

mapOne: function(src, dst) {
error('should not call mapCidOne');
},

lookup: function(code) {
return (isInt(code) && code <= 0xffff) ? code : undefined;
},

contains: function(code) {
return isInt(code) && code <= 0xffff;
},

forEach: function(callback) {
for (var i = 0; i <= 0xffff; i++) {
callback(i, i);
}
},

charCodeOf: function(value) {
return (isInt(value) && value <= 0xffff) ? value : -1;
},

getMap: function() {
// Sometimes identity maps must be instantiated, but it's rare.
var map = new Array(0x10000);
for (var i = 0; i <= 0xffff; i++) {
map[i] = i;
}
return map;
},

readCharCode: CMap.prototype.readCharCode
};

return IdentityCMap;
})();

Expand Down

0 comments on commit 5786014

Please sign in to comment.