Fix incorrect aspect ratio of structured-content images (#1776)

This commit is contained in:
toasted-nutbread 2021-06-28 21:46:54 -04:00 committed by GitHub
parent af706dea7e
commit 9f3d267e24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,15 +83,15 @@ class StructuredContentGenerator {
const hasPreferredWidth = (typeof preferredWidth === 'number'); const hasPreferredWidth = (typeof preferredWidth === 'number');
const hasPreferredHeight = (typeof preferredHeight === 'number'); const hasPreferredHeight = (typeof preferredHeight === 'number');
const aspectRatio = ( const invAspectRatio = (
hasPreferredWidth && hasPreferredHeight ? hasPreferredWidth && hasPreferredHeight ?
preferredWidth / preferredHeight : preferredHeight / preferredWidth :
width / height height / width
); );
const usedWidth = ( const usedWidth = (
hasPreferredWidth ? hasPreferredWidth ?
preferredWidth : preferredWidth :
(hasPreferredHeight ? preferredHeight * aspectRatio : width) (hasPreferredHeight ? preferredHeight * invAspectRatio : width)
); );
const node = this._createElement('a', 'gloss-image-link'); const node = this._createElement('a', 'gloss-image-link');
@ -139,7 +139,7 @@ class StructuredContentGenerator {
imageContainer.title = title; imageContainer.title = title;
} }
aspectRatioSizer.style.paddingTop = `${aspectRatio * 100.0}%`; aspectRatioSizer.style.paddingTop = `${invAspectRatio * 100.0}%`;
if (this._mediaLoader !== null) { if (this._mediaLoader !== null) {
this._mediaLoader.loadMedia( this._mediaLoader.loadMedia(