Merge branch 'master' of https://github.com/andreasgal/pdf.js.git into hacks
Conflicts: fonts.js
This commit is contained in:
commit
a14b9f13ef
@ -9,9 +9,14 @@ yet to integrate it into Firefox. We will explore that possibility once
|
|||||||
pdf.js is production ready. Until then we aim to publish a Firefox
|
pdf.js is production ready. Until then we aim to publish a Firefox
|
||||||
PDF reader extension powered by pdf.js.
|
PDF reader extension powered by pdf.js.
|
||||||
|
|
||||||
|
Our demo site is here:
|
||||||
|
|
||||||
|
http://andreasgal.github.com/pdf.js/
|
||||||
|
|
||||||
You can read more about pdf.js here:
|
You can read more about pdf.js here:
|
||||||
|
|
||||||
http://andreasgal.com/2011/06/15/pdf-js/
|
http://andreasgal.com/2011/06/15/pdf-js/
|
||||||
|
|
||||||
http://blog.mozilla.com/cjones/2011/06/15/overview-of-pdf-js-guts/
|
http://blog.mozilla.com/cjones/2011/06/15/overview-of-pdf-js-guts/
|
||||||
|
|
||||||
follow us on twitter: @pdfjs
|
follow us on twitter: @pdfjs
|
||||||
|
@ -43,12 +43,12 @@ var PDFViewer = {
|
|||||||
lastPagesDrawn: [],
|
lastPagesDrawn: [],
|
||||||
|
|
||||||
visiblePages: function() {
|
visiblePages: function() {
|
||||||
const pageBottomMargin = 20;
|
const pageBottomMargin = 10;
|
||||||
var windowTop = window.pageYOffset;
|
var windowTop = window.pageYOffset;
|
||||||
var windowBottom = window.pageYOffset + window.innerHeight;
|
var windowBottom = window.pageYOffset + window.innerHeight;
|
||||||
|
|
||||||
var pageHeight, page;
|
var pageHeight, page;
|
||||||
var i, n = PDFViewer.numberOfPages, currentHeight = 0;
|
var i, n = PDFViewer.numberOfPages, currentHeight = pageBottomMargin;
|
||||||
for (i = 1; i <= n; i++) {
|
for (i = 1; i <= n; i++) {
|
||||||
var page = PDFViewer.pdf.getPage(i);
|
var page = PDFViewer.pdf.getPage(i);
|
||||||
pageHeight = PDFViewer.pageHeight(page) + pageBottomMargin;
|
pageHeight = PDFViewer.pageHeight(page) + pageBottomMargin;
|
||||||
@ -130,14 +130,7 @@ var PDFViewer = {
|
|||||||
var fonts = [];
|
var fonts = [];
|
||||||
page.compile(gfx, fonts);
|
page.compile(gfx, fonts);
|
||||||
|
|
||||||
var loadFont = function() {
|
FontLoader.bind(fonts, function() { page.display(gfx); });
|
||||||
if (!FontLoader.bind(fonts)) {
|
|
||||||
pageTimeout = window.setTimeout(loadFont, 10);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
page.display(gfx);
|
|
||||||
}
|
|
||||||
loadFont();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -197,14 +190,7 @@ var PDFViewer = {
|
|||||||
var fonts = [];
|
var fonts = [];
|
||||||
page.compile(gfx, fonts);
|
page.compile(gfx, fonts);
|
||||||
|
|
||||||
var loadFont = function() {
|
FontLoader.bind(fonts, function() { page.display(gfx); });
|
||||||
if (!FontLoader.bind(fonts)) {
|
|
||||||
pageTimeout = window.setTimeout(loadFont, 10);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
page.display(gfx);
|
|
||||||
}
|
|
||||||
loadFont();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
311
pdf.js
311
pdf.js
@ -3266,7 +3266,6 @@ var CanvasExtraState = (function() {
|
|||||||
this.fontSize = 0;
|
this.fontSize = 0;
|
||||||
this.textMatrix = IDENTITY_MATRIX;
|
this.textMatrix = IDENTITY_MATRIX;
|
||||||
this.leading = 0;
|
this.leading = 0;
|
||||||
this.colorSpace = null;
|
|
||||||
// Current point (in user coordinates)
|
// Current point (in user coordinates)
|
||||||
this.x = 0;
|
this.x = 0;
|
||||||
this.y = 0;
|
this.y = 0;
|
||||||
@ -3277,6 +3276,9 @@ var CanvasExtraState = (function() {
|
|||||||
this.charSpace = 0;
|
this.charSpace = 0;
|
||||||
this.wordSpace = 0;
|
this.wordSpace = 0;
|
||||||
this.textHScale = 100;
|
this.textHScale = 100;
|
||||||
|
// Color spaces
|
||||||
|
this.fillColorSpace = null;
|
||||||
|
this.strokeColorSpace = null;
|
||||||
}
|
}
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
};
|
};
|
||||||
@ -3544,7 +3546,8 @@ var CanvasGraphics = (function() {
|
|||||||
capHeight: descriptor.get("CapHeight"),
|
capHeight: descriptor.get("CapHeight"),
|
||||||
flags: descriptor.get("Flags"),
|
flags: descriptor.get("Flags"),
|
||||||
italicAngle: descriptor.get("ItalicAngle"),
|
italicAngle: descriptor.get("ItalicAngle"),
|
||||||
fixedPitch: false
|
fixedPitch: false,
|
||||||
|
textMatrix: IDENTITY_MATRIX
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -3869,6 +3872,11 @@ var CanvasGraphics = (function() {
|
|||||||
} else {
|
} else {
|
||||||
text = Fonts.charsToUnicode(text);
|
text = Fonts.charsToUnicode(text);
|
||||||
this.ctx.translate(this.current.x, -1 * this.current.y);
|
this.ctx.translate(this.current.x, -1 * this.current.y);
|
||||||
|
|
||||||
|
var font = Fonts.lookup(this.current.fontName);
|
||||||
|
if (font)
|
||||||
|
this.ctx.transform.apply(this.ctx, font.properties.textMatrix);
|
||||||
|
|
||||||
this.ctx.fillText(text, 0, 0);
|
this.ctx.fillText(text, 0, 0);
|
||||||
this.current.x += Fonts.measureText(text);
|
this.current.x += Fonts.measureText(text);
|
||||||
}
|
}
|
||||||
@ -3911,51 +3919,36 @@ var CanvasGraphics = (function() {
|
|||||||
|
|
||||||
// Color
|
// Color
|
||||||
setStrokeColorSpace: function(space) {
|
setStrokeColorSpace: function(space) {
|
||||||
// TODO real impl
|
this.current.strokeColorSpace =
|
||||||
|
ColorSpace.parse(space, this.xref, this.res);
|
||||||
},
|
},
|
||||||
setFillColorSpace: function(space) {
|
setFillColorSpace: function(space) {
|
||||||
// TODO real impl
|
this.current.fillColorSpace =
|
||||||
if (space.name === "Pattern")
|
ColorSpace.parse(space, this.xref, this.res);
|
||||||
this.current.colorSpace = "Pattern";
|
|
||||||
else
|
|
||||||
this.current.colorSpace = "DeviceRGB";
|
|
||||||
},
|
},
|
||||||
setStrokeColor: function(/*...*/) {
|
setStrokeColor: function(/*...*/) {
|
||||||
// TODO real impl
|
var cs = this.getStrokeColorSpace();
|
||||||
if (1 === arguments.length) {
|
var color = cs.getRgb(arguments);
|
||||||
this.setStrokeGray.apply(this, arguments);
|
this.setStrokeRGBColor.apply(this, color);
|
||||||
} else if (3 === arguments.length) {
|
|
||||||
this.setStrokeRGBColor.apply(this, arguments);
|
|
||||||
} else if (4 === arguments.length) {
|
|
||||||
this.setStrokeCMYKColor.apply(this, arguments);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
setStrokeColorN: function(/*...*/) {
|
setStrokeColorN: function(/*...*/) {
|
||||||
// TODO real impl
|
// TODO real impl
|
||||||
|
TODO("check for special color spaces");
|
||||||
this.setStrokeColor.apply(this, arguments);
|
this.setStrokeColor.apply(this, arguments);
|
||||||
},
|
},
|
||||||
setFillColor: function(/*...*/) {
|
setFillColor: function(/*...*/) {
|
||||||
// TODO real impl
|
var cs = this.getFillColorSpace();
|
||||||
if (1 === arguments.length) {
|
if (cs.name == "Pattern") {
|
||||||
this.setFillGray.apply(this, arguments);
|
TODO("implement Pattern fill");
|
||||||
} else if (3 === arguments.length) {
|
return;
|
||||||
this.setFillRGBColor.apply(this, arguments);
|
|
||||||
} else if (4 === arguments.length) {
|
|
||||||
this.setFillCMYKColor.apply(this, arguments);
|
|
||||||
}
|
}
|
||||||
|
var color = cs.getRgb(arguments);
|
||||||
|
this.setFillRGBColor.apply(this, color);
|
||||||
},
|
},
|
||||||
setFillColorN: function(/*...*/) {
|
setFillColorN: function(/*...*/) {
|
||||||
// TODO real impl
|
var cs = this.getFillColorSpace();
|
||||||
var colorSpace = this.current.colorSpace;
|
|
||||||
if (!colorSpace) {
|
|
||||||
var stateStack = this.stateStack;
|
|
||||||
var i = stateStack.length - 1;
|
|
||||||
while (!colorSpace && i >= 0) {
|
|
||||||
colorSpace = stateStack[i--].colorSpace;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.current.colorSpace == "Pattern") {
|
if (cs.name == "Pattern") {
|
||||||
var patternName = arguments[0];
|
var patternName = arguments[0];
|
||||||
if (IsName(patternName)) {
|
if (IsName(patternName)) {
|
||||||
var xref = this.xref;
|
var xref = this.xref;
|
||||||
@ -4333,6 +4326,36 @@ var CanvasGraphics = (function() {
|
|||||||
var bi = (255 * (1 - Math.min(1, y * (1 - k) + k))) | 0;
|
var bi = (255 * (1 - Math.min(1, y * (1 - k) + k))) | 0;
|
||||||
return "rgb("+ ri +","+ gi +","+ bi +")";
|
return "rgb("+ ri +","+ gi +","+ bi +")";
|
||||||
},
|
},
|
||||||
|
getFillColorSpace: function() {
|
||||||
|
var cs = this.current.fillColorSpace;
|
||||||
|
if (cs)
|
||||||
|
return cs;
|
||||||
|
|
||||||
|
var states = this.stateStack;
|
||||||
|
var i = states.length - 1;
|
||||||
|
while (i >= 0 && !(cs = states[i].fillColorSpace))
|
||||||
|
--i;
|
||||||
|
|
||||||
|
if (cs)
|
||||||
|
return cs;
|
||||||
|
else
|
||||||
|
return new DeviceRgbCS();
|
||||||
|
},
|
||||||
|
getStrokeColorSpace: function() {
|
||||||
|
var cs = this.current.strokeColorSpace;
|
||||||
|
if (cs)
|
||||||
|
return cs;
|
||||||
|
|
||||||
|
var states = this.stateStack;
|
||||||
|
var i = states.length - 1;
|
||||||
|
while (i >= 0 && !(cs = states[i].strokeColorSpace))
|
||||||
|
--i;
|
||||||
|
|
||||||
|
if (cs)
|
||||||
|
return cs;
|
||||||
|
else
|
||||||
|
return new DeviceRgbCS();
|
||||||
|
},
|
||||||
// We generally keep the canvas context set for
|
// We generally keep the canvas context set for
|
||||||
// nonzero-winding, and just set evenodd for the operations
|
// nonzero-winding, and just set evenodd for the operations
|
||||||
// that need them.
|
// that need them.
|
||||||
@ -4350,51 +4373,90 @@ var CanvasGraphics = (function() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
var ColorSpace = (function() {
|
var ColorSpace = (function() {
|
||||||
function constructor(xref, cs) {
|
function constructor() {
|
||||||
|
error("should not call ColorSpace constructor");
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor.parse = function colorspace_parse(cs, xref, res) {
|
||||||
|
if (IsName(cs)) {
|
||||||
|
var colorSpaces = res.get("ColorSpace");
|
||||||
|
if (colorSpaces) {
|
||||||
|
var refcs = colorSpaces.get(cs.name);
|
||||||
|
if (refcs)
|
||||||
|
cs = refcs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cs = xref.fetchIfRef(cs);
|
||||||
|
|
||||||
if (IsName(cs)) {
|
if (IsName(cs)) {
|
||||||
var mode = cs.name;
|
var mode = cs.name;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
case "DeviceGray":
|
case "DeviceGray":
|
||||||
case "G":
|
case "G":
|
||||||
this.numComps = 1;
|
return new DeviceGrayCS();
|
||||||
break;
|
break;
|
||||||
case "DeviceRGB":
|
case "DeviceRGB":
|
||||||
this.numComps = 3;
|
case "RGB":
|
||||||
|
return new DeviceRgbCS();
|
||||||
break;
|
break;
|
||||||
|
case "DeviceCMYK":
|
||||||
|
case "CMYK":
|
||||||
|
return new DeviceCmykCS();
|
||||||
|
break;
|
||||||
|
case "Pattern":
|
||||||
|
return new PatternCS(null);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error("unrecognized colorspace " + mode);
|
||||||
}
|
}
|
||||||
TODO("fill in color space constructor");
|
|
||||||
} else if (IsArray(cs)) {
|
} else if (IsArray(cs)) {
|
||||||
var mode = cs[0].name;
|
var mode = cs[0].name;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
|
||||||
var stream = cs[1];
|
|
||||||
stream = xref.fetchIfRef(stream);
|
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case "DeviceGray":
|
case "DeviceGray":
|
||||||
case "G":
|
case "G":
|
||||||
this.stream = stream;
|
return new DeviceGrayCS();
|
||||||
this.dict = stream.dict;
|
break;
|
||||||
this.numComps = 1;
|
case "DeviceRGB":
|
||||||
|
case "RGB":
|
||||||
|
return new DeviceRgbCS();
|
||||||
|
break;
|
||||||
|
case "DeviceCMYK":
|
||||||
|
case "CMYK":
|
||||||
|
return new DeviceCmykCS();
|
||||||
|
break;
|
||||||
|
case "CalGray":
|
||||||
|
return new DeviceGrayCS();
|
||||||
|
break;
|
||||||
|
case "CalRGB":
|
||||||
|
return new DeviceRgbCS();
|
||||||
break;
|
break;
|
||||||
case "ICCBased":
|
case "ICCBased":
|
||||||
|
var stream = xref.fetchIfRef(cs[1]);
|
||||||
var dict = stream.dict;
|
var dict = stream.dict;
|
||||||
|
var numComps = dict.get("N");
|
||||||
this.stream = stream;
|
if (numComps == 1)
|
||||||
this.dict = dict;
|
return new DeviceGrayCS();
|
||||||
this.numComps = dict.get("N");
|
else if (numComps == 3)
|
||||||
|
return new DeviceRgbCS();
|
||||||
|
else if (numComps == 4)
|
||||||
|
return new DeviceCmykCS();
|
||||||
|
break;
|
||||||
|
case "Pattern":
|
||||||
|
return new PatternCS();
|
||||||
break;
|
break;
|
||||||
case "Indexed":
|
case "Indexed":
|
||||||
this.stream = stream;
|
var base = ColorSpace.parse(cs[1], xref, res);
|
||||||
this.dict = stream.dict;
|
var hiVal = cs[2];
|
||||||
var base = cs[1];
|
var lookup = xref.fetchIfRef(cs[3]);
|
||||||
var hival = cs[2];
|
return new IndexedCS(base, hiVal, lookup);
|
||||||
assertWellFormed(0 <= hival && hival <= 255, "hival in range");
|
case "Lab":
|
||||||
var lookupTable = cs[3];
|
case "Seperation":
|
||||||
TODO("implement 'Indexed' color space");
|
case "DeviceN":
|
||||||
this.numComps = 3; // HACK
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
error("unrecognized color space object '"+ mode +"'");
|
error("unrecognized color space object '"+ mode +"'");
|
||||||
}
|
}
|
||||||
@ -4403,9 +4465,137 @@ var ColorSpace = (function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return constructor;
|
||||||
|
})();
|
||||||
|
|
||||||
|
var PatternCS = (function() {
|
||||||
|
function constructor() {
|
||||||
|
this.name = "Pattern";
|
||||||
|
}
|
||||||
|
constructor.prototype = {};
|
||||||
|
|
||||||
|
return constructor;
|
||||||
|
})();
|
||||||
|
|
||||||
|
var IndexedCS = (function() {
|
||||||
|
function constructor(base, highVal, lookup) {
|
||||||
|
this.name = "Indexed";
|
||||||
|
this.numComps = 1;
|
||||||
|
this.defaultColor = [0];
|
||||||
|
|
||||||
|
this.base = base;
|
||||||
|
var baseNumComps = base.numComps;
|
||||||
|
this.highVal = highVal;
|
||||||
|
|
||||||
|
var length = baseNumComps * highVal;
|
||||||
|
var lookupArray = new Uint8Array(length);
|
||||||
|
if (IsStream(lookup)) {
|
||||||
|
var bytes = lookup.getBytes(length);
|
||||||
|
lookupArray.set(bytes);
|
||||||
|
} else if (IsString(lookup)) {
|
||||||
|
for (var i = 0; i < length; ++i)
|
||||||
|
lookupArray[i] = lookup.charCodeAt(i);
|
||||||
|
} else {
|
||||||
|
error("Unrecognized lookup table");
|
||||||
|
}
|
||||||
|
this.lookup = lookupArray;
|
||||||
|
}
|
||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
|
getRgb: function graycs_getRgb(color) {
|
||||||
|
var lookup = this.lookup;
|
||||||
|
var base = this.base;
|
||||||
|
var numComps = base.numComps;
|
||||||
|
|
||||||
|
var c = [];
|
||||||
|
for (var i = 0; i < numComps; ++i)
|
||||||
|
c.push(lookup[i])
|
||||||
|
return this.base.getRgb(c);
|
||||||
|
},
|
||||||
|
getRgbBuffer: function graycs_getRgbBuffer(input) {
|
||||||
|
var base = this.base;
|
||||||
|
var numComps = base.numComps;
|
||||||
|
var lookup = this.lookup;
|
||||||
|
var length = input.length;
|
||||||
|
|
||||||
|
var baseBuf = new Uint8Array(length * numComps);
|
||||||
|
var baseBufPos = 0;
|
||||||
|
for (var i = 0; i < length; ++i) {
|
||||||
|
var lookupPos = input[i];
|
||||||
|
for (var j = 0; j < numComps ; ++j) {
|
||||||
|
baseBuf[baseBufPos++] = lookup[lookupPos + j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.getRgbBuffer(baseBuf);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return constructor;
|
||||||
|
})();
|
||||||
|
|
||||||
|
var DeviceGrayCS = (function() {
|
||||||
|
function constructor() {
|
||||||
|
this.name = "DeviceGray";
|
||||||
|
this.numComps = 1;
|
||||||
|
this.defaultColor = [0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
constructor.prototype = {
|
||||||
|
getRgb: function graycs_getRgb(color) {
|
||||||
|
var c = color[0];
|
||||||
|
return [c, c, c];
|
||||||
|
},
|
||||||
|
getRgbBuffer: function graycs_getRgbBuffer(input) {
|
||||||
|
var length = input.length;
|
||||||
|
var rgbBuf = new Uint8Array(length);
|
||||||
|
for (var i = 0, j = 0; i < length; ++i) {
|
||||||
|
var c = input[i];
|
||||||
|
rgbBuf[j++] = c;
|
||||||
|
rgbBuf[j++] = c;
|
||||||
|
rgbBuf[j++] = c;
|
||||||
|
}
|
||||||
|
return rgbBuf;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return constructor;
|
||||||
|
})();
|
||||||
|
|
||||||
|
var DeviceRgbCS = (function() {
|
||||||
|
function constructor() {
|
||||||
|
this.name = "DeviceRGB";
|
||||||
|
this.numComps = 3;
|
||||||
|
this.defaultColor = [0, 0, 0];
|
||||||
|
}
|
||||||
|
constructor.prototype = {
|
||||||
|
getRgb: function graycs_getRgb(color) {
|
||||||
|
return color;
|
||||||
|
},
|
||||||
|
getRgbBuffer: function graycs_getRgbBuffer(input) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return constructor;
|
||||||
|
})();
|
||||||
|
|
||||||
|
var DeviceCmykCS = (function() {
|
||||||
|
function constructor() {
|
||||||
|
this.name = "DeviceCMYK";
|
||||||
|
this.numComps = 4;
|
||||||
|
this.defaultColor = [0, 0, 0, 1];
|
||||||
|
}
|
||||||
|
constructor.prototype = {
|
||||||
|
getRgb: function graycs_getRgb(color) {
|
||||||
|
var c = color[0], y = color[1], m = color[2], k = color[3];
|
||||||
|
var ri = (1 - Math.min(1, c * (1 - k) + k)) | 0;
|
||||||
|
var gi = (1 - Math.min(1, m * (1 - k) + k)) | 0;
|
||||||
|
var bi = (1 - Math.min(1, y * (1 - k) + k)) | 0;
|
||||||
|
return [ri, gi, bi];
|
||||||
|
},
|
||||||
|
getRgbBuffer: function graycs_getRgbBuffer(colorBuf) {
|
||||||
|
error("conversion from rgb to cmyk not implemented for images");
|
||||||
|
return colorBuf;
|
||||||
|
}
|
||||||
|
};
|
||||||
return constructor;
|
return constructor;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -4443,11 +4633,8 @@ var PDFImage = (function() {
|
|||||||
}
|
}
|
||||||
this.bpc = bitsPerComponent;
|
this.bpc = bitsPerComponent;
|
||||||
|
|
||||||
var colorSpaces = res.get("ColorSpace");
|
var colorSpace = dict.get2("ColorSpace", "CS");
|
||||||
var csStream = xref.fetchIfRef(dict.get2("ColorSpace", "CS"));
|
this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
|
||||||
if (IsName(csStream) && inline)
|
|
||||||
csStream = colorSpaces.get(csStream);
|
|
||||||
this.colorSpace = new ColorSpace(xref, csStream);
|
|
||||||
|
|
||||||
this.numComps = this.colorSpace.numComps;
|
this.numComps = this.colorSpace.numComps;
|
||||||
this.decode = dict.get2("Decode", "D");
|
this.decode = dict.get2("Decode", "D");
|
||||||
@ -4523,7 +4710,7 @@ var PDFImage = (function() {
|
|||||||
output[i] = Math.round(255 * ret / ((1 << bpc) - 1));
|
output[i] = Math.round(255 * ret / ((1 << bpc) - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output;
|
return this.colorSpace.getRbaBuffer(output);
|
||||||
},
|
},
|
||||||
getOpacity: function getOpacity() {
|
getOpacity: function getOpacity() {
|
||||||
var smask = this.smask;
|
var smask = this.smask;
|
||||||
|
51
test/test.py
51
test/test.py
@ -16,6 +16,9 @@ REFDIR = 'ref'
|
|||||||
TMPDIR = 'tmp'
|
TMPDIR = 'tmp'
|
||||||
VERBOSE = False
|
VERBOSE = False
|
||||||
|
|
||||||
|
SERVER_HOST = "localhost"
|
||||||
|
SERVER_PORT = 8080
|
||||||
|
|
||||||
class TestOptions(OptionParser):
|
class TestOptions(OptionParser):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
OptionParser.__init__(self, **kwargs)
|
OptionParser.__init__(self, **kwargs)
|
||||||
@ -41,7 +44,7 @@ class TestOptions(OptionParser):
|
|||||||
if options.browser and options.browserManifestFile:
|
if options.browser and options.browserManifestFile:
|
||||||
print "Warning: ignoring browser argument since manifest file was also supplied"
|
print "Warning: ignoring browser argument since manifest file was also supplied"
|
||||||
if not options.browser and not options.browserManifestFile:
|
if not options.browser and not options.browserManifestFile:
|
||||||
self.error("No test browsers found. Use --browserManifest or --browser args.")
|
print "No browser arguments supplied, so just starting server on port %s." % SERVER_PORT
|
||||||
return options
|
return options
|
||||||
|
|
||||||
def prompt(question):
|
def prompt(question):
|
||||||
@ -295,7 +298,9 @@ def setUp(options):
|
|||||||
testBrowsers = makeBrowserCommands(options.browserManifestFile)
|
testBrowsers = makeBrowserCommands(options.browserManifestFile)
|
||||||
elif options.browser:
|
elif options.browser:
|
||||||
testBrowsers = [makeBrowserCommand({"path":options.browser, "name":None})]
|
testBrowsers = [makeBrowserCommand({"path":options.browser, "name":None})]
|
||||||
assert len(testBrowsers) > 0
|
|
||||||
|
if options.browserManifestFile or options.browser:
|
||||||
|
assert len(testBrowsers) > 0
|
||||||
|
|
||||||
with open(options.manifestFile) as mf:
|
with open(options.manifestFile) as mf:
|
||||||
manifestList = json.load(mf)
|
manifestList = json.load(mf)
|
||||||
@ -320,9 +325,11 @@ def startBrowsers(browsers, options):
|
|||||||
for b in browsers:
|
for b in browsers:
|
||||||
b.setup()
|
b.setup()
|
||||||
print 'Launching', b.name
|
print 'Launching', b.name
|
||||||
|
host = 'http://%s:%s' % (SERVER_HOST, SERVER_PORT)
|
||||||
|
path = '/test/test_slave.html?'
|
||||||
qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile)
|
qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile)
|
||||||
qs += '&path=' + b.path
|
qs += '&path=' + b.path
|
||||||
b.start('http://localhost:8080/test/test_slave.html?'+ qs)
|
b.start(host + path + qs)
|
||||||
|
|
||||||
def teardownBrowsers(browsers):
|
def teardownBrowsers(browsers):
|
||||||
for b in browsers:
|
for b in browsers:
|
||||||
@ -476,7 +483,8 @@ def maybeUpdateRefImages(options, browser):
|
|||||||
print 'done'
|
print 'done'
|
||||||
|
|
||||||
def startReftest(browser):
|
def startReftest(browser):
|
||||||
url = "http://127.0.0.1:8080/test/resources/reftest-analyzer.xhtml"
|
url = "http://%s:%s" % (SERVER_HOST, SERVER_PORT)
|
||||||
|
url += "/test/resources/reftest-analyzer.xhtml"
|
||||||
url += "#web=/test/eq.log"
|
url += "#web=/test/eq.log"
|
||||||
try:
|
try:
|
||||||
browser.setup()
|
browser.setup()
|
||||||
@ -487,20 +495,8 @@ def startReftest(browser):
|
|||||||
teardownBrowsers([browser])
|
teardownBrowsers([browser])
|
||||||
print "Completed reftest usage."
|
print "Completed reftest usage."
|
||||||
|
|
||||||
def main():
|
def runTests(options, browsers):
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
optionParser = TestOptions()
|
|
||||||
options, args = optionParser.parse_args()
|
|
||||||
options = optionParser.verifyOptions(options)
|
|
||||||
if options == None:
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
httpd = TestServer(('127.0.0.1', 8080), PDFTestHandler)
|
|
||||||
httpd_thread = threading.Thread(target=httpd.serve_forever)
|
|
||||||
httpd_thread.setDaemon(True)
|
|
||||||
httpd_thread.start()
|
|
||||||
|
|
||||||
browsers = setUp(options)
|
|
||||||
try:
|
try:
|
||||||
startBrowsers(browsers, options)
|
startBrowsers(browsers, options)
|
||||||
while not State.done:
|
while not State.done:
|
||||||
@ -517,5 +513,26 @@ def main():
|
|||||||
print "\nStarting reftest harness to examine %d eq test failures." % State.numEqFailures
|
print "\nStarting reftest harness to examine %d eq test failures." % State.numEqFailures
|
||||||
startReftest(browsers[0])
|
startReftest(browsers[0])
|
||||||
|
|
||||||
|
def main():
|
||||||
|
optionParser = TestOptions()
|
||||||
|
options, args = optionParser.parse_args()
|
||||||
|
options = optionParser.verifyOptions(options)
|
||||||
|
if options == None:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
httpd = TestServer((SERVER_HOST, SERVER_PORT), PDFTestHandler)
|
||||||
|
httpd_thread = threading.Thread(target=httpd.serve_forever)
|
||||||
|
httpd_thread.setDaemon(True)
|
||||||
|
httpd_thread.start()
|
||||||
|
|
||||||
|
browsers = setUp(options)
|
||||||
|
if len(browsers) > 0:
|
||||||
|
runTests(options, browsers)
|
||||||
|
else:
|
||||||
|
# just run the server
|
||||||
|
print "Running HTTP server. Press Ctrl-C to quit."
|
||||||
|
while True:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -115,25 +115,18 @@ function nextPage() {
|
|||||||
failure = 'page setup: '+ e.toString();
|
failure = 'page setup: '+ e.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
var fontLoaderTimer = null;
|
if (!failure) {
|
||||||
function checkFontsLoaded() {
|
|
||||||
try {
|
try {
|
||||||
if (!FontLoader.bind(fonts)) {
|
FontLoader.bind(fonts, function() { snapshotCurrentPage(gfx); });
|
||||||
fontLoaderTimer = window.setTimeout(checkFontsLoaded, 10);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
failure = 'fonts: '+ e.toString();
|
failure = 'fonts: '+ e.toString();
|
||||||
}
|
}
|
||||||
snapshotCurrentPage(gfx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (failure) {
|
if (failure) {
|
||||||
// Skip font loading if there was a failure, since the fonts might
|
// Skip right to snapshotting if there was a failure, since the
|
||||||
// be in an inconsistent state.
|
// fonts might be in an inconsistent state.
|
||||||
snapshotCurrentPage(gfx);
|
snapshotCurrentPage(gfx);
|
||||||
} else {
|
|
||||||
checkFontsLoaded();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
* CharString or to understand the structure of the CFF format.
|
* 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
|
* Build a charset by assigning the glyph name and the human readable form
|
||||||
* of the glyph data.
|
* of the glyph data.
|
||||||
@ -380,6 +378,9 @@ var Type2Parser = function(aFilePath) {
|
|||||||
* writeToFile(fontData, "/tmp/pdf.js." + fontCount + ".cff");
|
* writeToFile(fontData, "/tmp/pdf.js." + fontCount + ".cff");
|
||||||
*/
|
*/
|
||||||
function writeToFile(aBytes, aFilePath) {
|
function writeToFile(aBytes, aFilePath) {
|
||||||
|
if (!("netscape" in window))
|
||||||
|
return;
|
||||||
|
|
||||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
var Cc = Components.classes,
|
var Cc = Components.classes,
|
||||||
Ci = Components.interfaces;
|
Ci = Components.interfaces;
|
||||||
@ -388,7 +389,7 @@ function writeToFile(aBytes, aFilePath) {
|
|||||||
|
|
||||||
var stream = Cc["@mozilla.org/network/file-output-stream;1"]
|
var stream = Cc["@mozilla.org/network/file-output-stream;1"]
|
||||||
.createInstance(Ci.nsIFileOutputStream);
|
.createInstance(Ci.nsIFileOutputStream);
|
||||||
stream.init(file, 0x04 | 0x08 | 0x20, 600, 0);
|
stream.init(file, 0x04 | 0x08 | 0x20, 0x180, 0);
|
||||||
|
|
||||||
var bos = Cc["@mozilla.org/binaryoutputstream;1"]
|
var bos = Cc["@mozilla.org/binaryoutputstream;1"]
|
||||||
.createInstance(Ci.nsIBinaryOutputStream);
|
.createInstance(Ci.nsIBinaryOutputStream);
|
||||||
|
24
viewer.js
24
viewer.js
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var pdfDocument, canvas, pageScale, pageDisplay, pageNum, numPages, pageTimeout;
|
var pdfDocument, canvas, pageScale, pageDisplay, pageNum, numPages;
|
||||||
function load(userInput) {
|
function load(userInput) {
|
||||||
canvas = document.getElementById("canvas");
|
canvas = document.getElementById("canvas");
|
||||||
canvas.mozOpaque = true;
|
canvas.mozOpaque = true;
|
||||||
@ -53,8 +53,6 @@ function gotoPage(num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function displayPage(num) {
|
function displayPage(num) {
|
||||||
window.clearTimeout(pageTimeout);
|
|
||||||
|
|
||||||
document.getElementById("pageNumber").value = num;
|
document.getElementById("pageNumber").value = num;
|
||||||
|
|
||||||
var t0 = Date.now();
|
var t0 = Date.now();
|
||||||
@ -82,22 +80,18 @@ function displayPage(num) {
|
|||||||
page.compile(gfx, fonts);
|
page.compile(gfx, fonts);
|
||||||
var t2 = Date.now();
|
var t2 = Date.now();
|
||||||
|
|
||||||
function loadFont() {
|
function displayPage() {
|
||||||
if (!FontLoader.bind(fonts)) {
|
var t3 = Date.now();
|
||||||
pageTimeout = window.setTimeout(loadFont, 10);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var t3 = Date.now();
|
page.display(gfx);
|
||||||
|
|
||||||
page.display(gfx);
|
var t4 = Date.now();
|
||||||
|
|
||||||
var t4 = Date.now();
|
var infoDisplay = document.getElementById("info");
|
||||||
|
infoDisplay.innerHTML = "Time to load/compile/fonts/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + "/" + (t4 - t3) + " ms";
|
||||||
|
}
|
||||||
|
|
||||||
var infoDisplay = document.getElementById("info");
|
FontLoader.bind(fonts, displayPage);
|
||||||
infoDisplay.innerHTML = "Time to load/compile/fonts/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + "/" + (t4 - t3) + " ms";
|
|
||||||
};
|
|
||||||
loadFont();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextPage() {
|
function nextPage() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user