Merge pull request #30 from vingtetun/master
Add a fake name table to works with Firefox trunk
This commit is contained in:
commit
1a70bb6612
112
pdf.js
112
pdf.js
@ -80,6 +80,7 @@ var Stream = (function() {
|
||||
getBytes: function(length) {
|
||||
var bytes = this.bytes;
|
||||
var pos = this.pos;
|
||||
|
||||
var end = pos + length;
|
||||
var strEnd = this.end;
|
||||
if (!end || end > strEnd)
|
||||
@ -1424,6 +1425,7 @@ var XRef = (function() {
|
||||
this.xrefstms[pos] = 1; // avoid infinite recursion
|
||||
this.readXRef(pos);
|
||||
}
|
||||
|
||||
return dict;
|
||||
},
|
||||
readXRefStream: function(stream) {
|
||||
@ -1545,6 +1547,7 @@ var XRef = (function() {
|
||||
this.cache[num] = e;
|
||||
return e;
|
||||
}
|
||||
|
||||
// compressed entry
|
||||
stream = this.fetch(new Ref(e.offset, 0));
|
||||
if (!IsStream(stream))
|
||||
@ -1612,6 +1615,7 @@ var Page = (function() {
|
||||
// content was compiled
|
||||
return;
|
||||
}
|
||||
|
||||
var xref = this.xref;
|
||||
var content;
|
||||
var resources = xref.fetchIfRef(this.resources);
|
||||
@ -1846,7 +1850,7 @@ var CanvasExtraState = (function() {
|
||||
|
||||
const Encodings = {
|
||||
get ExpertEncoding() {
|
||||
return shadow(this, "ExpertEncoding", [
|
||||
return shadow(this, "ExpertEncoding", [ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
"space","exclamsmall","Hungarumlautsmall",,"dollaroldstyle","dollarsuperior",
|
||||
"ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior",
|
||||
"twodotenleader","onedotenleader","comma","hyphen","period","fraction",
|
||||
@ -1881,7 +1885,7 @@ const Encodings = {
|
||||
]);
|
||||
},
|
||||
get MacExpertEncoding() {
|
||||
return shadow(this, "MacExpertEncoding", [
|
||||
return shadow(this, "MacExpertEncoding", [ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
"space","exclamsmall","Hungarumlautsmall","centoldstyle","dollaroldstyle",
|
||||
"dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior",
|
||||
"parenrightsuperior","twodotenleader","onedotenleader","comma","hyphen","period",
|
||||
@ -1915,7 +1919,7 @@ const Encodings = {
|
||||
]);
|
||||
},
|
||||
get MacRomanEncoding() {
|
||||
return shadow(this, "MacRomanEncoding", [
|
||||
return shadow(this, "MacRomanEncoding", [ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
"space","exclam","quotedbl","numbersign","dollar","percent","ampersand",
|
||||
"quotesingle","parenleft","parenright","asterisk","plus","comma","hyphen",
|
||||
"period","slash","zero","one","two","three","four","five","six","seven","eight",
|
||||
@ -1945,7 +1949,7 @@ const Encodings = {
|
||||
]);
|
||||
},
|
||||
get StandardEncoding() {
|
||||
return shadow(this, "StandardEncoding", [
|
||||
return shadow(this, "StandardEncoding", [ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
"space","exclam","quotedbl","numbersign","dollar","percent","ampersand",
|
||||
"quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period",
|
||||
"slash","zero","one","two","three","four","five","six","seven","eight","nine",
|
||||
@ -1965,7 +1969,7 @@ const Encodings = {
|
||||
]);
|
||||
},
|
||||
get WinAnsiEncoding() {
|
||||
return shadow(this, "WinAnsiEncoding", [
|
||||
return shadow(this, "WinAnsiEncoding", [ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
"space","exclam","quotedbl","numbersign","dollar","percent","ampersand",
|
||||
"quotesingle","parenleft","parenright","asterisk","plus","comma","hyphen",
|
||||
"period","slash","zero","one","two","three","four","five","six","seven","eight",
|
||||
@ -1996,7 +2000,7 @@ const Encodings = {
|
||||
]);
|
||||
},
|
||||
get zapfDingbatsEncoding() {
|
||||
return shadow(this, "zapfDingbatsEncoding", [
|
||||
return shadow(this, "zapfDingbatsEncoding", [ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
|
||||
"space","a1","a2","a202","a3","a4","a5","a119","a118","a117","a11","a12","a13",
|
||||
"a14","a15","a16","a105","a17","a18","a19","a20","a21","a22","a23","a24","a25",
|
||||
"a26","a27","a28","a6","a7","a8","a9","a10","a29","a30","a31","a32","a33","a34",
|
||||
@ -2142,12 +2146,19 @@ var CanvasGraphics = (function() {
|
||||
error("FontFile not found for font: " + fontName);
|
||||
fontFile = xref.fetchIfRef(fontFile);
|
||||
|
||||
// Generate the custom cmap of the font if needed
|
||||
// Fonts with an embedded cmap but without any assignment in
|
||||
// it are not yet supported, so ask the fonts loader to ignore
|
||||
// them to not pay a stupid one sec latence.
|
||||
var ignoreFont = true;
|
||||
|
||||
var encodingMap = {};
|
||||
var charset = [];
|
||||
if (fontDict.has("Encoding")) {
|
||||
ignoreFont = false;
|
||||
|
||||
var encoding = xref.fetchIfRef(fontDict.get("Encoding"));
|
||||
if (IsDict(encoding)) {
|
||||
// Build an map between codes and glyphs
|
||||
// Build a map between codes and glyphs
|
||||
var differences = encoding.get("Differences");
|
||||
var index = 0;
|
||||
for (var j = 0; j < differences.length; j++) {
|
||||
@ -2157,26 +2168,96 @@ var CanvasGraphics = (function() {
|
||||
|
||||
// Get the font charset if any
|
||||
var charset = descriptor.get("CharSet");
|
||||
if (charset) {
|
||||
if (charset)
|
||||
assertWellFormed(IsString(charset), "invalid charset");
|
||||
|
||||
charset = charset.split("/");
|
||||
}
|
||||
} else if (IsName(encoding)) {
|
||||
var encoding = Encodings[encoding.name];
|
||||
if (!encoding)
|
||||
error("Unknown font encoding");
|
||||
|
||||
var widths = xref.fetchIfRef(fontDict.get("Widths"));
|
||||
var index = 0;
|
||||
for (var j = 0; j < encoding.length; j++) {
|
||||
encodingMap[index++] = GlyphsUnicode[encoding[j]];
|
||||
}
|
||||
|
||||
var firstChar = xref.fetchIfRef(fontDict.get("FirstChar"));
|
||||
var widths = xref.fetchIfRef(fontDict.get("Widths"));
|
||||
assertWellFormed(IsArray(widths) && IsInt(firstChar),
|
||||
"invalid font Widths or FirstChar");
|
||||
var charset = [];
|
||||
|
||||
for (var j = 0; j < widths.length; j++) {
|
||||
if (widths[j])
|
||||
charset.push(encoding[j + firstChar]);
|
||||
}
|
||||
}
|
||||
} else if (fontDict.has("ToUnicode")) {
|
||||
var cmapObj = xref.fetchIfRef(fontDict.get("ToUnicode"));
|
||||
if (IsName(cmapObj)) {
|
||||
error("ToUnicode file cmap translation not implemented");
|
||||
} else if (IsStream(cmapObj)) {
|
||||
var encoding = Encodings["WinAnsiEncoding"];
|
||||
var firstChar = xref.fetchIfRef(fontDict.get("FirstChar"));
|
||||
for (var i = firstChar; i < encoding.length; i++)
|
||||
encodingMap[i] = new Name(encoding[i]);
|
||||
|
||||
var tokens = [];
|
||||
var token = "";
|
||||
|
||||
var buffer = cmapObj.ensureBuffer ? cmapObj.ensureBuffer() : cmapObj;
|
||||
var cmap = cmapObj.getBytes(buffer.byteLength);
|
||||
for (var i =0; i < cmap.length; i++) {
|
||||
var byte = cmap[i];
|
||||
if (byte == 0x20 || byte == 0x0A || byte == 0x3C || byte == 0x3E) {
|
||||
switch (token) {
|
||||
case "useCMap":
|
||||
error("useCMap is not implemented");
|
||||
break;
|
||||
|
||||
case "beginbfrange":
|
||||
ignoreFont = false;
|
||||
case "begincodespacerange":
|
||||
token = "";
|
||||
tokens = [];
|
||||
break;
|
||||
|
||||
case "endcodespacerange":
|
||||
TODO("Support CMap ranges");
|
||||
break;
|
||||
|
||||
case "endbfrange":
|
||||
for (var j = 0; j < tokens.length; j+=3) {
|
||||
var startRange = parseInt("0x" + tokens[j]);
|
||||
var endRange = parseInt("0x" + tokens[j+1]);
|
||||
var code = parseInt("0x" + tokens[j+2]);
|
||||
|
||||
for (var k = startRange; k <= endRange; k++) {
|
||||
encodingMap[k] = GlyphsUnicode[encoding[code]];
|
||||
charset.push(encoding[code++]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "beginfbchar":
|
||||
case "endfbchar":
|
||||
error("fbchar parsing is not implemented");
|
||||
break;
|
||||
|
||||
default:
|
||||
if (token.length) {
|
||||
tokens.push(token);
|
||||
token = "";
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (byte == 0x5B || byte == 0x5D) {
|
||||
error("CMAP list parsing is not implemented");
|
||||
} else {
|
||||
token += String.fromCharCode(byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var subType = fontDict.get("Subtype");
|
||||
@ -2188,7 +2269,8 @@ var CanvasGraphics = (function() {
|
||||
type: subType.name,
|
||||
encoding: encodingMap,
|
||||
charset: charset,
|
||||
bbox: bbox
|
||||
bbox: bbox,
|
||||
ignore: ignoreFont
|
||||
};
|
||||
|
||||
return {
|
||||
@ -2448,6 +2530,7 @@ var CanvasGraphics = (function() {
|
||||
fontName = fontDescriptor.get("FontName").name.replace("+", "_");
|
||||
Fonts.active = fontName;
|
||||
}
|
||||
|
||||
if (!fontName) {
|
||||
// TODO: fontDescriptor is not available, fallback to default font
|
||||
this.current.fontSize = size;
|
||||
@ -2485,7 +2568,7 @@ var CanvasGraphics = (function() {
|
||||
this.ctx.transform.apply(this.ctx, this.current.textMatrix);
|
||||
this.ctx.scale(1, -1);
|
||||
this.ctx.translate(0, -2 * this.current.y);
|
||||
this.ctx.fillText(Fonts.chars2Unicode(text), this.current.x, this.current.y);
|
||||
this.ctx.fillText(Fonts.charsToUnicode(text), this.current.x, this.current.y);
|
||||
this.current.x += this.ctx.measureText(text).width;
|
||||
|
||||
this.ctx.restore();
|
||||
@ -2858,7 +2941,6 @@ var CanvasGraphics = (function() {
|
||||
error("Invalid image width or height");
|
||||
|
||||
var ctx = this.ctx;
|
||||
|
||||
// scale the image to the unit square
|
||||
ctx.scale(1/w, -1/h);
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
* CharString or to understand the structure of the CFF format.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Build a charset by assigning the glyph name and the human readable form
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var pdfDocument, canvas, numPages, pageDisplay, pageNum, pageInterval;
|
||||
var pdfDocument, canvas, pageDisplay, pageNum, numPages, pageInterval;
|
||||
function load(userInput) {
|
||||
canvas = document.getElementById("canvas");
|
||||
canvas.mozOpaque = true;
|
||||
@ -52,8 +52,7 @@ function gotoPage(num) {
|
||||
}
|
||||
|
||||
function displayPage(num) {
|
||||
if (pageNum != num)
|
||||
window.clearTimeout(pageInterval);
|
||||
window.clearInterval(pageInterval);
|
||||
|
||||
document.getElementById("pageNumber").value = num;
|
||||
|
||||
@ -96,7 +95,7 @@ function displayPage(num) {
|
||||
if (Fonts[font.name].loading)
|
||||
return;
|
||||
}
|
||||
clearInterval(pageInterval);
|
||||
window.clearInterval(pageInterval);
|
||||
|
||||
var t3 = Date.now();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user