Fixing large cmap-s; reduce changes in the indent encoding
This commit is contained in:
parent
fe01091053
commit
1f047495b1
77
fonts.js
77
fonts.js
@ -594,19 +594,24 @@ var Font = (function Font() {
|
||||
var codes = [];
|
||||
var length = glyphs.length;
|
||||
for (var n = 0; n < length; ++n)
|
||||
codes.push(String.fromCharCode(glyphs[n].unicode));
|
||||
codes.sort();
|
||||
codes.push({ unicode: glyphs[n].unicode, code: n });
|
||||
codes.sort(function(a, b) {
|
||||
return a.unicode - b.unicode;
|
||||
});
|
||||
|
||||
// Split the sorted codes into ranges.
|
||||
var ranges = [];
|
||||
for (var n = 0; n < length; ) {
|
||||
var start = codes[n++].charCodeAt(0);
|
||||
var start = codes[n].unicode;
|
||||
var startCode = codes[n].code;
|
||||
++n;
|
||||
var end = start;
|
||||
while (n < length && end + 1 == codes[n].charCodeAt(0)) {
|
||||
while (n < length && end + 1 == codes[n].unicode) {
|
||||
++end;
|
||||
++n;
|
||||
}
|
||||
ranges.push([start, end]);
|
||||
var endCode = codes[n - 1].code;
|
||||
ranges.push([start, end, startCode, endCode]);
|
||||
}
|
||||
|
||||
return ranges;
|
||||
@ -635,22 +640,39 @@ var Font = (function Font() {
|
||||
var idRangeOffsets = '';
|
||||
var glyphsIds = '';
|
||||
var bias = 0;
|
||||
for (var i = 0; i < segCount - 1; i++) {
|
||||
var range = ranges[i];
|
||||
var start = range[0];
|
||||
var end = range[1];
|
||||
var offset = (segCount - i) * 2 + bias * 2;
|
||||
bias += (end - start + 1);
|
||||
|
||||
startCount += string16(start);
|
||||
endCount += string16(end);
|
||||
idDeltas += string16(0);
|
||||
idRangeOffsets += string16(offset);
|
||||
if (deltas) {
|
||||
for (var i = 0; i < segCount - 1; i++) {
|
||||
var range = ranges[i];
|
||||
var start = range[0];
|
||||
var end = range[1];
|
||||
var offset = (segCount - i) * 2 + bias * 2;
|
||||
bias += (end - start + 1);
|
||||
|
||||
startCount += string16(start);
|
||||
endCount += string16(end);
|
||||
idDeltas += string16(0);
|
||||
idRangeOffsets += string16(offset);
|
||||
|
||||
var startCode = range[2];
|
||||
var endCode = range[3];
|
||||
for (var j = startCode; j <= endCode; ++j)
|
||||
glyphsIds += string16(deltas[j]);
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < segCount - 1; i++) {
|
||||
var range = ranges[i];
|
||||
var start = range[0];
|
||||
var end = range[1];
|
||||
var startCode = range[2];
|
||||
|
||||
startCount += string16(start);
|
||||
endCount += string16(end);
|
||||
idDeltas += string16((startCode - start + 1) & 0xFFFF);
|
||||
idRangeOffsets += string16(0);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < glyphs.length; i++)
|
||||
glyphsIds += string16(deltas ? deltas[i] : i + 1);
|
||||
|
||||
endCount += '\xFF\xFF';
|
||||
startCount += '\xFF\xFF';
|
||||
idDeltas += '\x00\x01';
|
||||
@ -1124,7 +1146,7 @@ var Font = (function Font() {
|
||||
tables.push(cmap);
|
||||
}
|
||||
|
||||
var encoding = properties.encoding;
|
||||
var encoding = properties.encoding, i;
|
||||
if (!encoding[0]) {
|
||||
// the font is directly characters to glyphs with no encoding
|
||||
// so create an identity encoding
|
||||
@ -1132,18 +1154,25 @@ var Font = (function Font() {
|
||||
for (i = 0; i < numGlyphs; i++) {
|
||||
var width = widths[i];
|
||||
encoding[i] = {
|
||||
unicode: i + kCmapGlyphOffset,
|
||||
unicode: i <= 0x1f || (i >= 127 && i <= 255) ?
|
||||
i + kCmapGlyphOffset : i,
|
||||
width: IsNum(width) ? width : properties.defaultWidth
|
||||
};
|
||||
}
|
||||
} else {
|
||||
for (var code in encoding)
|
||||
encoding[code].unicode += kCmapGlyphOffset;
|
||||
for (i = 0; i <= 0x1f; i++)
|
||||
encoding[i].unicode += kCmapGlyphOffset;
|
||||
for (i = 127; i <= 255; i++)
|
||||
encoding[i].unicode += kCmapGlyphOffset;
|
||||
}
|
||||
|
||||
var glyphs = [];
|
||||
for (var i = 1; i < numGlyphs; i++)
|
||||
glyphs.push({ unicode: i + kCmapGlyphOffset });
|
||||
for (i = 1; i < numGlyphs; i++) {
|
||||
glyphs.push({
|
||||
unicode: i <= 0x1f || (i >= 127 && i <= 255) ?
|
||||
i + kCmapGlyphOffset : i
|
||||
});
|
||||
}
|
||||
cmap.data = createCMapTable(glyphs);
|
||||
} else {
|
||||
replaceCMapTable(cmap, font, properties);
|
||||
|
1
test/pdfs/wnv_chinese.pdf.link
Normal file
1
test/pdfs/wnv_chinese.pdf.link
Normal file
@ -0,0 +1 @@
|
||||
http://www.cdc.gov/ncidod/dvbid/westnile/languages/chinese.pdf
|
@ -69,6 +69,12 @@
|
||||
"rounds": 1,
|
||||
"type": "load"
|
||||
},
|
||||
{ "id": "wnv_chinese-pdf",
|
||||
"file": "pdfs/wnv_chinese.pdf",
|
||||
"link": true,
|
||||
"rounds": 1,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "i9-pdf",
|
||||
"file": "pdfs/i9.pdf",
|
||||
"link": true,
|
||||
|
Loading…
Reference in New Issue
Block a user