Fix regression caused by pull request #491. Glyphs in positions that match complex scripts or special characters can be messed up by the browser when drawn to the canvas. Limit to fonts with a small to medium sized glyph set.

This commit is contained in:
Adil Allawi 2011-10-03 10:16:18 +01:00
parent 1508c03414
commit 118668cb53

View File

@ -11,6 +11,10 @@ var kMaxWaitForFontFace = 1000;
// Unicode Private Use Area // Unicode Private Use Area
var kCmapGlyphOffset = 0xE000; var kCmapGlyphOffset = 0xE000;
var kSizeOfGlyphArea = 0x1900;
//start of CJK block
var kUnicodeCJKStart = 0x2E80;
// PDF Glyph Space Units are one Thousandth of a TextSpace Unit // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
// except for Type 3 fonts // except for Type 3 fonts
@ -1212,19 +1216,25 @@ var Font = (function Font() {
} }
var encoding = properties.encoding, i; var encoding = properties.encoding, i;
// offsetting glyphs to avoid problematic unicode ranges should only be
// done for fonts with a medium-sized glyph count otherwise we could
// overflow the glyph range or overwrite existing glyph positions
var cmapGlyphOffset = numGlyphs < kSizeOfGlyphArea ? kCmapGlyphOffset : 0;
for (i in encoding) { for (i in encoding) {
if (encoding.hasOwnProperty(i)) { if (encoding.hasOwnProperty(i)) {
var unicode = encoding[i].unicode; var unicode = encoding[i].unicode;
if (unicode <= 0x1f || (unicode >= 127 && unicode <= 255)) if (unicode <= 0x1f || (unicode >= 127 && unicode <= kUnicodeCJKStart))
encoding[i].unicode = unicode += kCmapGlyphOffset; encoding[i].unicode = unicode += cmapGlyphOffset;
} }
} }
var glyphs = []; var glyphs = [];
for (i = 1; i < numGlyphs; i++) { for (i = 1; i < numGlyphs; i++) {
glyphs.push({ glyphs.push({
unicode: i <= 0x1f || (i >= 127 && i <= 255) ? unicode: i <= 0x1f || (i >= 127 && i < kUnicodeCJKStart) ?
i + kCmapGlyphOffset : i i + cmapGlyphOffset : i
}); });
} }
cmap.data = createCMapTable(glyphs); cmap.data = createCMapTable(glyphs);