Added font loading in the multi-page viewer. Added support for changing the zoom/scale factor.
This commit is contained in:
parent
a9451a309f
commit
87fef70bbf
@ -2,6 +2,7 @@
|
|||||||
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
background-color: #929292;
|
||||||
font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial, Verdana, sans-serif;
|
font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial, Verdana, sans-serif;
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
@ -17,6 +18,10 @@ span {
|
|||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.control {
|
||||||
|
margin: 0px 20px 0px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
.page {
|
.page {
|
||||||
width: 816px;
|
width: 816px;
|
||||||
height: 1056px;
|
height: 1056px;
|
||||||
@ -43,8 +48,6 @@ span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#viewer {
|
#viewer {
|
||||||
background-color: #929292;
|
|
||||||
margin: 32px 0px 0px;
|
margin: 32px 0px 0px;
|
||||||
padding: 8px 0px;
|
padding: 8px 0px;
|
||||||
width: 100%;
|
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,20 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="controls">
|
<div id="controls">
|
||||||
|
<span class="control">
|
||||||
<button id="previousPageButton">Previous</button>
|
<button id="previousPageButton">Previous</button>
|
||||||
<button id="nextPageButton">Next</button>
|
<button id="nextPageButton">Next</button>
|
||||||
|
</span>
|
||||||
|
<span class="control">
|
||||||
<input type="text" id="pageNumber" value="1" size="2"/>
|
<input type="text" id="pageNumber" value="1" size="2"/>
|
||||||
<span>/</span>
|
<span>/</span>
|
||||||
<span id="numPages">--</span>
|
<span id="numPages">--</span>
|
||||||
|
</span>
|
||||||
|
<span class="control">
|
||||||
|
<span>Zoom</span>
|
||||||
|
<input type="text" id="scale" value="100" size="2"/>
|
||||||
|
<span>%</span>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="viewer"></div>
|
<div id="viewer"></div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -49,6 +49,8 @@ var PDFViewer = {
|
|||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
div.id = 'pageContainer' + num;
|
div.id = 'pageContainer' + num;
|
||||||
div.className = 'page';
|
div.className = 'page';
|
||||||
|
div.style.width = PDFViewer.pageWidth() + 'px';
|
||||||
|
div.style.height = PDFViewer.pageHeight() + 'px';
|
||||||
|
|
||||||
PDFViewer.element.appendChild(anchor);
|
PDFViewer.element.appendChild(anchor);
|
||||||
PDFViewer.element.appendChild(div);
|
PDFViewer.element.appendChild(div);
|
||||||
@ -76,8 +78,8 @@ var PDFViewer = {
|
|||||||
|
|
||||||
// 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.5in x 11in at 96dpi.
|
// are always 96 dpi. These dimensions are 8.5in x 11in at 96dpi.
|
||||||
canvas.width = 816;
|
canvas.width = PDFViewer.pageWidth();
|
||||||
canvas.height = 1056;
|
canvas.height = PDFViewer.pageHeight();
|
||||||
|
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
ctx.save();
|
ctx.save();
|
||||||
@ -92,14 +94,66 @@ var PDFViewer = {
|
|||||||
// we can trigger the actual page rendering with page.display
|
// we can trigger the actual page rendering with page.display
|
||||||
page.compile(gfx, fonts);
|
page.compile(gfx, fonts);
|
||||||
|
|
||||||
// This should be called when font loading is complete
|
var fontsReady = true;
|
||||||
page.display(gfx);
|
|
||||||
|
|
||||||
|
// Inspect fonts and translate the missing one
|
||||||
|
var fontCount = fonts.length;
|
||||||
|
|
||||||
|
for (var i = 0; i < fontCount; i++) {
|
||||||
|
var font = fonts[i];
|
||||||
|
|
||||||
|
if (Fonts[font.name]) {
|
||||||
|
fontsReady = fontsReady && !Fonts[font.name].loading;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
new Font(font.name, font.file, font.properties);
|
||||||
|
|
||||||
|
fontsReady = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pageInterval;
|
||||||
|
var delayLoadFont = function() {
|
||||||
|
for (var i = 0; i < fontCount; i++) {
|
||||||
|
if (Fonts[font.name].loading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clearInterval(pageInterval);
|
||||||
|
|
||||||
|
PDFViewer.drawPage(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fontsReady) {
|
||||||
|
pageInterval = setInterval(delayLoadFont, 10);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
page.display(gfx);
|
||||||
div.appendChild(canvas);
|
div.appendChild(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
changeScale: function(num) {
|
||||||
|
while (PDFViewer.element.childNodes.length > 0) {
|
||||||
|
PDFViewer.element.removeChild(PDFViewer.element.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
PDFViewer.scale = num / 100;
|
||||||
|
|
||||||
|
if (PDFViewer.pdf) {
|
||||||
|
for (var i = 1; i <= PDFViewer.numberOfPages; i++) {
|
||||||
|
PDFViewer.createPage(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PDFViewer.numberOfPages > 0) {
|
||||||
|
PDFViewer.drawPage(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
goToPage: function(num) {
|
goToPage: function(num) {
|
||||||
if (0 <= num && num <= PDFViewer.numberOfPages) {
|
if (0 <= num && num <= PDFViewer.numberOfPages) {
|
||||||
PDFViewer.pageNumber = num;
|
PDFViewer.pageNumber = num;
|
||||||
@ -225,7 +279,13 @@ window.onload = function() {
|
|||||||
var nextPageButton = document.getElementById('nextPageButton');
|
var nextPageButton = document.getElementById('nextPageButton');
|
||||||
nextPageButton.onclick = PDFViewer.goToNextPage;
|
nextPageButton.onclick = PDFViewer.goToNextPage;
|
||||||
|
|
||||||
|
var scaleInput = document.getElementById('scale');
|
||||||
|
scaleInput.onchange = function(evt) {
|
||||||
|
PDFViewer.changeScale(this.value);
|
||||||
|
};
|
||||||
|
|
||||||
PDFViewer.pageNumber = parseInt(PDFViewer.queryParams.page) || PDFViewer.pageNumber;
|
PDFViewer.pageNumber = parseInt(PDFViewer.queryParams.page) || PDFViewer.pageNumber;
|
||||||
|
PDFViewer.scale = parseInt(scaleInput.value) / 100 || 1.0;
|
||||||
PDFViewer.open(PDFViewer.queryParams.file || PDFViewer.url);
|
PDFViewer.open(PDFViewer.queryParams.file || PDFViewer.url);
|
||||||
|
|
||||||
window.onscroll = function(evt) {
|
window.onscroll = function(evt) {
|
||||||
|
Loading…
Reference in New Issue
Block a user