Skip to content

Commit

Permalink
Avoid ppi<10 causing UI to break (#1240)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrini committed Sep 15, 2023
1 parent 7361245 commit fa43ed5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/BookReader/BookModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,9 @@ export class PageModel {
* @param {PageIndex} index
*/
constructor(book, index) {
// TODO: Get default from config
this.ppi = book._getDataProp(index, 'ppi', book.ppi);
// Values less than 10 cause the UI to not work correctly
const pagePPI = book._getDataProp(index, 'ppi', book.ppi);
this.ppi = Math.max(pagePPI < 10 ? book.ppi : pagePPI, 10);
this.book = book;
this.index = index;
this.width = book.getPageWidth(index);
Expand Down
16 changes: 8 additions & 8 deletions tests/jest/BookReader/BookModel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const SAMPLE_DATA = [

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

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


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

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

test('caches result', () => {
Expand Down

0 comments on commit fa43ed5

Please sign in to comment.