Add JpegStreamProxy - doesnt seem to be used anywhere in the example.pdf file
This commit is contained in:
parent
ddd8aeffb9
commit
04cec20384
@ -19,6 +19,38 @@ ImageCanvasProxy.prototype.getCanvas = function() {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var JpegStreamProxyCounter = 0;
|
||||||
|
// WebWorker Proxy for JpegStream.
|
||||||
|
var JpegStreamProxy = (function() {
|
||||||
|
function constructor(bytes, dict) {
|
||||||
|
this.id = JpegStreamProxyCounter++;
|
||||||
|
this.dict = dict;
|
||||||
|
|
||||||
|
// create DOM image.
|
||||||
|
postMessage("jpeg_stream");
|
||||||
|
postMessage({
|
||||||
|
id: this.id,
|
||||||
|
str: bytesToString(bytes)
|
||||||
|
});
|
||||||
|
|
||||||
|
// var img = new Image();
|
||||||
|
// img.src = "data:image/jpeg;base64," + window.btoa(bytesToString(bytes));
|
||||||
|
// this.domImage = img;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor.prototype = {
|
||||||
|
getImage: function() {
|
||||||
|
return this;
|
||||||
|
// return this.domImage;
|
||||||
|
},
|
||||||
|
getChar: function() {
|
||||||
|
error("internal error: getChar is not valid on JpegStream");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return constructor;
|
||||||
|
})();
|
||||||
|
|
||||||
function CanvasProxy(width, height) {
|
function CanvasProxy(width, height) {
|
||||||
var stack = this.$stack = [];
|
var stack = this.$stack = [];
|
||||||
|
|
||||||
@ -72,9 +104,11 @@ function CanvasProxy(width, height) {
|
|||||||
"$showText"
|
"$showText"
|
||||||
];
|
];
|
||||||
|
|
||||||
this.drawImage = function(canvas, x, y) {
|
this.drawImage = function(image, x, y, width, height, sx, sy, swidth, sheight) {
|
||||||
if (canvas instanceof ImageCanvasProxy) {
|
if (image instanceof ImageCanvasProxy) {
|
||||||
stack.push(["$drawCanvas", [canvas.imgData, x, y, canvas.width, canvas.height]]);
|
stack.push(["$drawCanvas", [image.imgData, x, y, image.width, image.height]]);
|
||||||
|
} else if(image instanceof JpegStreamProxy) {
|
||||||
|
stack.push(["$drawImage", [image.id, x, y, sx, sy, swidth, sheight]])
|
||||||
} else {
|
} else {
|
||||||
throw "unkown type to drawImage";
|
throw "unkown type to drawImage";
|
||||||
}
|
}
|
||||||
@ -139,9 +173,7 @@ function CanvasProxy(width, height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CanvasProxy.prototype.flush = function() {
|
CanvasProxy.prototype.flush = function() {
|
||||||
// postMessage("log");
|
|
||||||
// postMessage(JSON.stringify([this.$stack.length]));
|
|
||||||
postMessage("canvas_proxy_stack");
|
postMessage("canvas_proxy_stack");
|
||||||
postMessage(JSON.stringify(this.$stack));
|
postMessage(this.$stack);
|
||||||
this.$stack.length = 0;
|
this.$stack.length = 0;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ function toc(msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var myWorker = new Worker('worker.js');
|
var myWorker = new Worker('worker.js');
|
||||||
|
var images = {};
|
||||||
|
|
||||||
var currentX = 0;
|
var currentX = 0;
|
||||||
var currentXStack = [];
|
var currentXStack = [];
|
||||||
@ -47,6 +48,15 @@ var special = {
|
|||||||
var imgData = ctx.getImageData(0, 0, width, height);
|
var imgData = ctx.getImageData(0, 0, width, height);
|
||||||
imgData.data = data;
|
imgData.data = data;
|
||||||
ctx.putImageData(imgData, x, y);
|
ctx.putImageData(imgData, x, y);
|
||||||
|
},
|
||||||
|
|
||||||
|
"$drawImage": function(id, x, y, sx, sy, swidth, sheight) {
|
||||||
|
var image = images[id];
|
||||||
|
if (!image) {
|
||||||
|
throw "Image not found";
|
||||||
|
}
|
||||||
|
ctx.drawImage(image, x, y, image.width, image.height,
|
||||||
|
sx, sy, swidth, sheight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +80,7 @@ const CANVAS_PROXY_STACK = 1;
|
|||||||
const LOG = 2;
|
const LOG = 2;
|
||||||
const FONT = 3;
|
const FONT = 3;
|
||||||
const PDF_NUM_PAGE = 4;
|
const PDF_NUM_PAGE = 4;
|
||||||
|
const JPEG_STREAM = 5;
|
||||||
|
|
||||||
var onMessageState = WAIT;
|
var onMessageState = WAIT;
|
||||||
var fontStr = null;
|
var fontStr = null;
|
||||||
@ -96,11 +107,21 @@ myWorker.onmessage = function(event) {
|
|||||||
case "font":
|
case "font":
|
||||||
onMessageState = FONT;
|
onMessageState = FONT;
|
||||||
return;
|
return;
|
||||||
|
case "jpeg_stream":
|
||||||
|
onMessageState = JPEG_STREAM;
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
throw "unkown state: " + data
|
throw "unkown state: " + data
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case JPEG_STREAM:
|
||||||
|
var img = new Image();
|
||||||
|
img.src = "data:image/jpeg;base64," + window.btoa(data.str);
|
||||||
|
images[data.id] = img;
|
||||||
|
console.log("got image", data.id)
|
||||||
|
break;
|
||||||
|
|
||||||
case PDF_NUM_PAGE:
|
case PDF_NUM_PAGE:
|
||||||
console.log(data);
|
console.log(data);
|
||||||
maxPages = parseInt(data);
|
maxPages = parseInt(data);
|
||||||
@ -133,7 +154,7 @@ myWorker.onmessage = function(event) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CANVAS_PROXY_STACK:
|
case CANVAS_PROXY_STACK:
|
||||||
var stack = JSON.parse(data);
|
var stack = data;
|
||||||
gStack = stack;
|
gStack = stack;
|
||||||
console.log("canvas stack size", stack.length)
|
console.log("canvas stack size", stack.length)
|
||||||
|
|
||||||
@ -188,7 +209,7 @@ function nextPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function prevPage() {
|
function prevPage() {
|
||||||
if (currentPage == 0) return;
|
if (currentPage == 1) return;
|
||||||
currentPage--;
|
currentPage--;
|
||||||
showPage(currentPage);
|
showPage(currentPage);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,9 @@ importScripts("pdf.js");
|
|||||||
importScripts("fonts.js");
|
importScripts("fonts.js");
|
||||||
importScripts("glyphlist.js")
|
importScripts("glyphlist.js")
|
||||||
|
|
||||||
|
// Use the JpegStreamProxy proxy.
|
||||||
|
JpegStream = JpegStreamProxy;
|
||||||
|
|
||||||
// var array = new Uint8Array(2);
|
// var array = new Uint8Array(2);
|
||||||
// array[0] = 1;
|
// array[0] = 1;
|
||||||
// array[1] = 300;
|
// array[1] = 300;
|
||||||
|
Loading…
Reference in New Issue
Block a user