Skip to content

Commit fa43ed5

Browse files
authored
Avoid ppi<10 causing UI to break (#1240)
1 parent 7361245 commit fa43ed5

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/BookReader/BookModel.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,9 @@ export class PageModel {
352352
* @param {PageIndex} index
353353
*/
354354
constructor(book, index) {
355-
// TODO: Get default from config
356-
this.ppi = book._getDataProp(index, 'ppi', book.ppi);
355+
// Values less than 10 cause the UI to not work correctly
356+
const pagePPI = book._getDataProp(index, 'ppi', book.ppi);
357+
this.ppi = Math.max(pagePPI < 10 ? book.ppi : pagePPI, 10);
357358
this.book = book;
358359
this.index = index;
359360
this.width = book.getPageWidth(index);

tests/jest/BookReader/BookModel.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const SAMPLE_DATA = [
2424

2525
describe('getMedianPageSizeInches', () => {
2626
test('handles single page data', () => {
27-
const bm = new BookModel({ data: SAMPLE_DATA.slice(0, 1), options: {ppi: 1} });
28-
expect(bm.getMedianPageSizeInches()).toEqual({ width: 123, height: 123 });
27+
const bm = new BookModel({ data: SAMPLE_DATA.slice(0, 1), options: {ppi: 10} });
28+
expect(bm.getMedianPageSizeInches()).toEqual({ width: 12.3, height: 12.3 });
2929
});
3030

3131
test('handles odd pages data', () => {
@@ -39,8 +39,8 @@ describe('getMedianPageSizeInches', () => {
3939
Object.assign(data[0][0], sizes[0]);
4040
Object.assign(data[1][0], sizes[1]);
4141
Object.assign(data[1][1], sizes[2]);
42-
const bm = new BookModel({ data, options: {ppi: 1} });
43-
expect(bm.getMedianPageSizeInches()).toEqual({ width: 200, height: 2200 });
42+
const bm = new BookModel({ data, options: {ppi: 10} });
43+
expect(bm.getMedianPageSizeInches()).toEqual({ width: 20, height: 220 });
4444
});
4545

4646

@@ -56,8 +56,8 @@ describe('getMedianPageSizeInches', () => {
5656
Object.assign(data[1][0], sizes[1]);
5757
Object.assign(data[1][1], sizes[2]);
5858
Object.assign(data[2][0], sizes[3]);
59-
const bm = new BookModel({ data, options: {ppi: 1} });
60-
expect(bm.getMedianPageSizeInches()).toEqual({ width: 300, height: 2300 });
59+
const bm = new BookModel({ data, options: {ppi: 10} });
60+
expect(bm.getMedianPageSizeInches()).toEqual({ width: 30, height: 230 });
6161
});
6262

6363
test('does not lexicographic sort for median', () => {
@@ -71,8 +71,8 @@ describe('getMedianPageSizeInches', () => {
7171
Object.assign(data[0][0], sizes[0]);
7272
Object.assign(data[1][0], sizes[1]);
7373
Object.assign(data[1][1], sizes[2]);
74-
const bm = new BookModel({ data, options: {ppi: 1} });
75-
expect(bm.getMedianPageSizeInches()).toEqual({ width: 30, height: 30 });
74+
const bm = new BookModel({ data, options: {ppi: 10} });
75+
expect(bm.getMedianPageSizeInches()).toEqual({ width: 3, height: 3 });
7676
});
7777

7878
test('caches result', () => {

0 commit comments

Comments
 (0)