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: Handle non uniform thumbnail sizes #896

Merged
merged 3 commits into from
Jan 23, 2019

Conversation

ConradJChan
Copy link
Contributor

thumbnails non uniform page sizes

@boxcla
Copy link

boxcla commented Jan 18, 2019

Verified that @ConradJChan has signed the CLA. Thanks for the pull request!

// In case the current page ratio is same as the first page
// or in case it's larger (which means that it's wider), keep
// the width at the max thumbnail width
canvasWidth = THUMBNAIL_WIDTH_MAX;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this live up with let canvasWidth = THUMBNAIL_WIDTH_MAX as a default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will get rid of canvasWidth

src/lib/ThumbnailsSidebar.js Show resolved Hide resolved
const canvas = document.createElement('canvas');

return this.pdfViewer.pdfDocument
.getPage(itemIndex + 1)
.getPage(pageNum)
.then((page) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth moving these to named class methods to avoid recreating the functions each time? It usually wouldn't matter, but I think we're doing this many times a second on scroll, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only get invoked at when the debounced scroll handler fires, and when the image isn't already cached, so maybe it's ok as is?

// Add the height and width to the image to be the same as the thumbnail
// so that the css `object-fit` rule will work
imageEl.style.width = `${DEFAULT_THUMBNAILS_SIDEBAR_WIDTH}px`;
imageEl.style.height = `${DEFAULT_THUMBNAILS_SIDEBAR_WIDTH / this.pageRatio}px`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any rounding required to avoid fractional pixels?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the modern desktop browsers all support sub pixel rendering right now, i'll investigate and maybe do a follow up PR to see if I can get away from fractional values

@@ -36,9 +36,8 @@ $thumbnail-border-radius: 4px;
}

.bp-thumbnail-image {
border-radius: $thumbnail-border-radius;
object-fit: contain;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating PR to use background-image

@@ -49,6 +49,8 @@ class ThumbnailsSidebar {
this.createThumbnailImage = this.createThumbnailImage.bind(this);
this.generateThumbnailImages = this.generateThumbnailImages.bind(this);
this.thumbnailClickHandler = this.thumbnailClickHandler.bind(this);
this.getThumbnailDataURL = this.getThumbnailDataURL.bind(this);
this.createImageEl = this.createImageEl.bind(this);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much would I need to bribe you to alphabetize these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💰

@ConradJChan ConradJChan merged commit 57fb24e into box:thumbnails-sidebar Jan 23, 2019
@ConradJChan ConradJChan deleted the thumbnails-nonuniform branch January 23, 2019 21:44
ConradJChan pushed a commit to ConradJChan/box-content-preview that referenced this pull request Feb 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants