Browse Source

Clean up a bit the CMAP ranges creation loop

Vivien Nicolas 14 years ago
parent
commit
cebdda3f35
  1. 19
      PDFFont.js

19
PDFFont.js

@ -6,6 +6,11 @@
*/ */
var kMaxFontFileSize = 40000; var kMaxFontFileSize = 40000;
/**
* Maximum number of glyphs per font.
*/
var kMaxGlyphsCount = 1024;
/** /**
* Hold a map of decoded fonts and of the standard fourteen Type1 fonts and * Hold a map of decoded fonts and of the standard fourteen Type1 fonts and
@ -143,28 +148,22 @@ Font.prototype = {
}, },
_createCMAPTable: function font_createCMAPTable(aGlyphs) { _createCMAPTable: function font_createCMAPTable(aGlyphs) {
var data = new Array(1000); var characters = new Array(kMaxGlyphsCount);
for (var i = 0; i < aGlyphs.length; i++) for (var i = 0; i < aGlyphs.length; i++)
data[aGlyphs[i].unicode] = i + 1; characters[aGlyphs[i].unicode] = i + 1;
// Separate the glyphs into continuous range of codes, aka segment. // Separate the glyphs into continuous range of codes, aka segment.
var ranges = []; var ranges = [];
var range = []; var range = [];
for (var i = 0; i < data.length; i++) { for (var i = 0; i < characters.length; i++) {
var char = data[i]; if (characters[i]) {
if (char) {
range.push(i); range.push(i);
} else if (range.length) { } else if (range.length) {
if (0) {
log("create a new range of " + range.length + " chars width min: " + range[0] + " to max: " + range[range.length - 1]);
log("range content is: " + range);
}
ranges.push(range.slice()); ranges.push(range.slice());
range = []; range = [];
} }
} }
// The size in bytes of the header is equal to the size of the // The size in bytes of the header is equal to the size of the
// different fields * length of a short + (size of the 4 parallels arrays // different fields * length of a short + (size of the 4 parallels arrays
// describing segments * length of a short). // describing segments * length of a short).

Loading…
Cancel
Save