use Array.sort to calculate glyph ranges instead of large typed arrays
This commit is contained in:
parent
fc4ca2a9dd
commit
52e1631030
41
fonts.js
41
fonts.js
@ -8,11 +8,6 @@
|
|||||||
*/
|
*/
|
||||||
var kMaxFontFileSize = 40000;
|
var kMaxFontFileSize = 40000;
|
||||||
|
|
||||||
/**
|
|
||||||
* Maximum number of glyphs per font.
|
|
||||||
*/
|
|
||||||
var kMaxGlyphsCount = 65526;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum time to wait for a font to be loaded by @font-face
|
* Maximum time to wait for a font to be loaded by @font-face
|
||||||
*/
|
*/
|
||||||
@ -310,24 +305,30 @@ var Font = (function () {
|
|||||||
aOffsets.currentOffset += tableEntry.length;
|
aOffsets.currentOffset += tableEntry.length;
|
||||||
aOffsets.virtualOffset += aData.length;
|
aOffsets.virtualOffset += aData.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCMAPTable(aGlyphs) {
|
|
||||||
var characters = new Uint16Array(kMaxGlyphsCount);
|
|
||||||
for (var i = 0; i < aGlyphs.length; i++)
|
|
||||||
characters[aGlyphs[i].unicode] = i + 1;
|
|
||||||
|
|
||||||
// Separate the glyphs into continuous range of codes, aka segment.
|
function getRanges(glyphs) {
|
||||||
|
// Array.sort() sorts by characters, not numerically, so convert to an
|
||||||
|
// array of characters.
|
||||||
|
var codes = [];
|
||||||
|
var length = glyphs.length;
|
||||||
|
for (var n = 0; n < length; ++n)
|
||||||
|
codes.push(String.fromCharCode(glyphs[n].unicode))
|
||||||
|
codes.sort();
|
||||||
|
|
||||||
var ranges = [];
|
var ranges = [];
|
||||||
var range = [];
|
for (var n = 0; n < length; ) {
|
||||||
var count = characters.length;
|
var range = [];
|
||||||
for (var i = 0; i < count; i++) {
|
do {
|
||||||
if (characters[i]) {
|
var current = codes[n++].charCodeAt(0);
|
||||||
range.push(i);
|
range.push(current);
|
||||||
} else if (range.length) {
|
} while (n < length && current + 1 == codes[n].charCodeAt(0));
|
||||||
ranges.push(range.slice());
|
ranges.push(range);
|
||||||
range = [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return ranges;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createCMAPTable(aGlyphs) {
|
||||||
|
var ranges = getRanges(aGlyphs);
|
||||||
|
|
||||||
// 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user