Merge branch 'master' of github.com:andreasgal/pdf.js
This commit is contained in:
commit
503d888036
28
pdf.js
28
pdf.js
@ -1777,7 +1777,7 @@ var XRef = (function() {
|
|||||||
if (e) {
|
if (e) {
|
||||||
// The stream might be in use elsewhere, so clone it.
|
// The stream might be in use elsewhere, so clone it.
|
||||||
if (IsStream(e))
|
if (IsStream(e))
|
||||||
e = e.makeSubStream(0);
|
e = e.makeSubStream(e.start, e.length, e.dict);
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
e = this.getEntry(num);
|
e = this.getEntry(num);
|
||||||
@ -2032,8 +2032,8 @@ var CanvasExtraState = (function() {
|
|||||||
this.fontSize = 0.0;
|
this.fontSize = 0.0;
|
||||||
this.textMatrix = IDENTITY_MATRIX;
|
this.textMatrix = IDENTITY_MATRIX;
|
||||||
// Current point (in user coordinates)
|
// Current point (in user coordinates)
|
||||||
this.curX = 0.0;
|
this.x = 0.0;
|
||||||
this.curY = 0.0;
|
this.y = 0.0;
|
||||||
// Start of text line (in text coordinates)
|
// Start of text line (in text coordinates)
|
||||||
this.lineX = 0.0;
|
this.lineX = 0.0;
|
||||||
this.lineY = 0.0;
|
this.lineY = 0.0;
|
||||||
@ -2251,6 +2251,8 @@ var CanvasGraphics = (function() {
|
|||||||
// Text
|
// Text
|
||||||
beginText: function() {
|
beginText: function() {
|
||||||
this.current.textMatrix = IDENTITY_MATRIX;
|
this.current.textMatrix = IDENTITY_MATRIX;
|
||||||
|
this.current.x = this.current.lineX = 0;
|
||||||
|
this.current.y = this.current.lineY = 0;
|
||||||
},
|
},
|
||||||
endText: function() {
|
endText: function() {
|
||||||
},
|
},
|
||||||
@ -2259,26 +2261,26 @@ var CanvasGraphics = (function() {
|
|||||||
if (!font)
|
if (!font)
|
||||||
return;
|
return;
|
||||||
this.current.fontSize = size;
|
this.current.fontSize = size;
|
||||||
this.ctx.font = this.current.fontSize +'px '+ font.BaseFont;
|
TODO("using hard-coded font for testing");
|
||||||
|
this.ctx.font = this.current.fontSize +'px "Nimbus Roman No9 L"';
|
||||||
},
|
},
|
||||||
moveText: function (x, y) {
|
moveText: function (x, y) {
|
||||||
this.current.lineX += x;
|
this.current.x = this.current.lineX += x;
|
||||||
this.current.lineY += y;
|
this.current.y = this.current.lineY += y;
|
||||||
// TODO transform
|
|
||||||
this.current.curX = this.current.lineX;
|
|
||||||
this.current.curY = this.current.lineY;
|
|
||||||
},
|
},
|
||||||
setTextMatrix: function(a, b, c, d, e, f) {
|
setTextMatrix: function(a, b, c, d, e, f) {
|
||||||
this.current.textMatrix = [ a, b, c, d, e, f ];
|
this.current.textMatrix = [ a, b, c, d, e, f ];
|
||||||
|
this.current.x = this.current.lineX = 0;
|
||||||
|
this.current.y = this.current.lineY = 0;
|
||||||
},
|
},
|
||||||
showText: function(text) {
|
showText: function(text) {
|
||||||
this.ctx.save();
|
this.ctx.save();
|
||||||
this.ctx.translate(0, 2 * this.current.curY);
|
this.ctx.translate(0, 2 * this.current.y);
|
||||||
this.ctx.scale(1, -1);
|
this.ctx.scale(1, -1);
|
||||||
this.ctx.transform.apply(this.ctx, this.current.textMatrix);
|
this.ctx.transform.apply(this.ctx, this.current.textMatrix);
|
||||||
|
|
||||||
this.ctx.fillText(text, this.current.curX, this.current.curY);
|
this.ctx.fillText(text, this.current.x, this.current.y);
|
||||||
this.current.curX += this.ctx.measureText(text).width;
|
this.current.x += this.ctx.measureText(text).width;
|
||||||
|
|
||||||
this.ctx.restore();
|
this.ctx.restore();
|
||||||
},
|
},
|
||||||
@ -2286,7 +2288,7 @@ var CanvasGraphics = (function() {
|
|||||||
for (var i = 0; i < arr.length; ++i) {
|
for (var i = 0; i < arr.length; ++i) {
|
||||||
var e = arr[i];
|
var e = arr[i];
|
||||||
if (IsNum(e)) {
|
if (IsNum(e)) {
|
||||||
this.current.curX -= e * 0.001 * this.current.fontSize;
|
this.current.x -= e * 0.001 * this.current.fontSize;
|
||||||
} else if (IsString(e)) {
|
} else if (IsString(e)) {
|
||||||
this.showText(e);
|
this.showText(e);
|
||||||
} else {
|
} else {
|
||||||
|
30
test.html
30
test.html
@ -9,6 +9,19 @@ body {
|
|||||||
padding: 0px;
|
padding: 0px;
|
||||||
background-color: #c0bdb7;
|
background-color: #c0bdb7;
|
||||||
}
|
}
|
||||||
|
#controls {
|
||||||
|
border-bottom: 1px solid black;
|
||||||
|
position:fixed;
|
||||||
|
left: 0px; top: 0px;
|
||||||
|
width: 100%;
|
||||||
|
padding: 7px;
|
||||||
|
background-color: rgb(242, 240, 238);
|
||||||
|
}
|
||||||
|
span#info {
|
||||||
|
float: right;
|
||||||
|
font: 14px sans-serif;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
#viewer {
|
#viewer {
|
||||||
margin: auto;
|
margin: auto;
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
@ -26,10 +39,14 @@ function load() {
|
|||||||
canvas = document.getElementById("canvas");
|
canvas = document.getElementById("canvas");
|
||||||
canvas.mozOpaque = true;
|
canvas.mozOpaque = true;
|
||||||
pageDisplay = document.getElementById("pageNumber");
|
pageDisplay = document.getElementById("pageNumber");
|
||||||
timeDisplay = document.getElementById("time");
|
infoDisplay = document.getElementById("info");
|
||||||
|
open("uncompressed.tracemonkey-pldi-09.pdf");
|
||||||
|
}
|
||||||
|
|
||||||
|
function open(url) {
|
||||||
|
document.title = url;
|
||||||
req = new XMLHttpRequest();
|
req = new XMLHttpRequest();
|
||||||
req.open("GET", "uncompressed.tracemonkey-pldi-09.pdf");
|
req.open("GET", url);
|
||||||
req.mozResponseType = req.responseType = "arraybuffer";
|
req.mozResponseType = req.responseType = "arraybuffer";
|
||||||
req.expected = (document.URL.indexOf("file:") == 0) ? 0 : 200;
|
req.expected = (document.URL.indexOf("file:") == 0) ? 0 : 200;
|
||||||
req.onreadystatechange = xhrstate;
|
req.onreadystatechange = xhrstate;
|
||||||
@ -68,7 +85,7 @@ function displayPage(num) {
|
|||||||
|
|
||||||
var t2 = Date.now();
|
var t2 = Date.now();
|
||||||
|
|
||||||
timeDisplay.innerHTML = (t1 - t0) + "/" + (t2 - t1) + " ms";
|
infoDisplay.innerHTML = "Time to render: "+ (t1 - t0) + "/" + (t2 - t1) + " ms";
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextPage() {
|
function nextPage() {
|
||||||
@ -91,12 +108,13 @@ function gotoPage(num) {
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload="load();">
|
<body onload="load();">
|
||||||
<div>
|
<div id="controls">
|
||||||
<button onclick="prevPage();">Previous</button>
|
<button onclick="prevPage();">Previous</button>
|
||||||
<button onclick="nextPage();">Next</button>
|
<button onclick="nextPage();">Next</button>
|
||||||
<input type="text" id="pageNumber" onchange="gotoPage(this.value);"
|
<input type="text" id="pageNumber" onchange="gotoPage(this.value);"
|
||||||
value="1" size="5"></input>
|
value="1" size="4"></input>
|
||||||
Time to render: <span id="time"></span>
|
<span id="info"></span>
|
||||||
|
</div>
|
||||||
<div id="viewer">
|
<div id="viewer">
|
||||||
<!-- Canvas dimensions must be specified in CSS pixels. CSS pixels
|
<!-- Canvas dimensions must be specified in CSS pixels. CSS pixels
|
||||||
-- are always 96 dpi. These dimensions are 8.5x11in at 96dpi. -->
|
-- are always 96 dpi. These dimensions are 8.5x11in at 96dpi. -->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user