Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Decrease mobile web max pdf.js canvas size to 3MP #66

Merged
merged 2 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const MAX_SCALE = 10.0;
const MIN_SCALE = 0.1;
const DEFAULT_RANGE_REQUEST_CHUNK_SIZE = 393216; // 384KB
const LARGE_RANGE_REQUEST_CHUNK_SIZE = 1048576; // 1MB
const MOBILE_MAX_CANVAS_SIZE = 2949120; // ~3MP 1920x1536
const SHOW_PAGE_NUM_INPUT_CLASS = 'show-page-number-input';
const IS_SAFARI_CLASS = 'is-safari';
const SCROLL_EVENT_THROTTLE_INTERVAL = 200;
Expand Down Expand Up @@ -661,6 +662,9 @@ class DocBaseViewer extends BaseViewer {

// Disable text layer if user doesn't have download permissions
PDFJS.disableTextLayer = !checkPermission(file, PERMISSION_DOWNLOAD);

// Decrease mobile canvas size to ~3MP (1920x1536)
PDFJS.maxCanvasPixels = Browser.isMobile() ? MOBILE_MAX_CANVAS_SIZE : PDFJS.maxCanvasPixels;
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const DEFAULT_SCALE_DELTA = 1.1;
const MAX_SCALE = 10.0;
const MIN_SCALE = 0.1;
const SCROLL_END_TIMEOUT = 500;
const MOBILE_MAX_CANVAS_SIZE = 2949120; // ~3MP 1920x1536

const sandbox = sinon.sandbox.create();
let docBase;
Expand Down Expand Up @@ -1055,7 +1056,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {

it('should enable range requests if the file and browser meet the conditions', () => {
stubs.browser.returns('Chrome');

docBase.setupPdfjs();
expect(PDFJS.disableRange).to.be.false;
});
Expand All @@ -1069,6 +1069,12 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.setupPdfjs();
expect(PDFJS.disableTextLayer).to.be.true;
});

it('should decrease max canvas size to 3MP if on mobile', () => {
sandbox.stub(Browser, 'isMobile').returns(true);
docBase.setupPdfjs();
expect(PDFJS.maxCanvasPixels).to.equal(MOBILE_MAX_CANVAS_SIZE);
});
});

describe('initAnnotations()', () => {
Expand Down