1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Using pdfjs-dist as a library for b2g viewer.

This commit is contained in:
Yury Delendik 2015-03-14 14:07:17 -05:00
parent 1da0b3a363
commit 1b847df2f3
8 changed files with 400 additions and 240 deletions

View file

@ -17,7 +17,7 @@
/*jshint globalstrict: false */
/* globals PDFJS, PDFViewer, PDFPageView, TextLayerBuilder, PDFLinkService,
DefaultTextLayerFactory, AnnotationsLayerBuilder, PDFHistory,
DefaultAnnotationsLayerFactory, getFileName */
DefaultAnnotationsLayerFactory, getFileName, ProgressBar */
// Initializing PDFJS global object (if still undefined)
if (typeof PDFJS === 'undefined') {
@ -42,4 +42,5 @@ if (typeof PDFJS === 'undefined') {
PDFJS.PDFHistory = PDFHistory;
PDFJS.getFileName = getFileName;
PDFJS.ProgressBar = ProgressBar;
}).call((typeof window === 'undefined') ? this : window);

View file

@ -18,7 +18,7 @@
SCROLLBAR_PADDING, VERTICAL_PADDING, MAX_AUTO_SCALE, CSS_UNITS,
DEFAULT_SCALE, scrollIntoView, getVisibleElements, RenderingStates,
PDFJS, Promise, TextLayerBuilder, PDFRenderingQueue,
AnnotationsLayerBuilder */
AnnotationsLayerBuilder, DEFAULT_SCALE_VALUE */
'use strict';
@ -149,7 +149,8 @@ var PDFViewer = (function pdfViewer() {
* @returns {number}
*/
get currentScale() {
return this._currentScale;
return this._currentScale !== UNKNOWN_SCALE ? this._currentScale :
DEFAULT_SCALE;
},
/**
@ -161,7 +162,7 @@ var PDFViewer = (function pdfViewer() {
}
if (!this.pdfDocument) {
this._currentScale = val;
this._currentScaleValue = val.toString();
this._currentScaleValue = val !== UNKNOWN_SCALE ? val.toString() : null;
return;
}
this._setScale(val, false);
@ -265,7 +266,7 @@ var PDFViewer = (function pdfViewer() {
// Fetch a single page so we can get a viewport that will be the default
// viewport for all pages
return firstPagePromise.then(function(pdfPage) {
var scale = this._currentScale || 1.0;
var scale = this.currentScale;
var viewport = pdfPage.getViewport(scale * CSS_UNITS);
for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
var textLayerFactory = null;
@ -523,10 +524,10 @@ var PDFViewer = (function pdfViewer() {
return;
}
if (scale && scale !== this.currentScale) {
if (scale && scale !== this._currentScale) {
this.currentScaleValue = scale;
} else if (this.currentScale === UNKNOWN_SCALE) {
this.currentScaleValue = DEFAULT_SCALE;
} else if (this._currentScale === UNKNOWN_SCALE) {
this.currentScaleValue = DEFAULT_SCALE_VALUE;
}
if (scale === 'page-fit' && !dest[4]) {

View file

@ -17,7 +17,8 @@
'use strict';
var CSS_UNITS = 96.0 / 72.0;
var DEFAULT_SCALE = 'auto';
var DEFAULT_SCALE_VALUE = 'auto';
var DEFAULT_SCALE = 1.0;
var UNKNOWN_SCALE = 0;
var MAX_AUTO_SCALE = 1.25;
var SCROLLBAR_PADDING = 40;

View file

@ -22,8 +22,8 @@
Promise, PDFLinkService, PDFOutlineView, PDFAttachmentView,
OverlayManager, PDFFindController, PDFFindBar, getVisibleElements,
watchScroll, PDFViewer, PDFRenderingQueue, PresentationModeState,
parseQueryString, RenderingStates, DEFAULT_SCALE, UNKNOWN_SCALE,
IGNORE_CURRENT_POSITION_ON_ZOOM: true */
parseQueryString, RenderingStates, UNKNOWN_SCALE,
DEFAULT_SCALE_VALUE, IGNORE_CURRENT_POSITION_ON_ZOOM: true */
'use strict';
@ -994,10 +994,10 @@ var PDFViewerApplication = {
this.page = 1;
}
if (this.pdfViewer.currentScale === UNKNOWN_SCALE) {
if (!this.pdfViewer.currentScaleValue) {
// Scale was not initialized: invalid bookmark or scale was not specified.
// Setting the default one.
this.setScale(DEFAULT_SCALE, true);
this.setScale(DEFAULT_SCALE_VALUE, true);
}
},
@ -1903,7 +1903,7 @@ window.addEventListener('keydown', function keydown(evt) {
// keeping it unhandled (to restore page zoom to 100%)
setTimeout(function () {
// ... and resetting the scale after browser adjusts its scale
PDFViewerApplication.setScale(DEFAULT_SCALE, true);
PDFViewerApplication.setScale(DEFAULT_SCALE_VALUE, true);
});
handled = false;
}