Fix double page with different dimensions

In case two pages were displayed with different dimensions, the bigger page might take up more than 50% of the screen.
In this case the bigger page got limited to 50% which caused in to unintentionally get reduced in size
This commit is contained in:
schroda
2024-12-16 21:13:07 +01:00
parent 942d8699c1
commit 15a70760ca
4 changed files with 29 additions and 15 deletions

View File

@@ -37,9 +37,11 @@ const getPageWidth = (
pageScaleMode: IReaderSettings['pageScaleMode'],
isDoublePage?: boolean,
readerWidth?: IReaderSettings['readerWidth'],
shouldStretchPage?: IReaderSettings['shouldStretchPage'],
isImage?: boolean,
): string => {
if (isImage && isDoublePage) {
// only return 50% in case pages should get stretched, otherwise, pages might unintentionally shrink in size (e.g. 2 pages with different dimensions, the bigger page will shrink due to taking up more than 50%)
if (isImage && isDoublePage && shouldStretchPage) {
return '50%';
}
@@ -133,7 +135,7 @@ export const getImageWidthStyling = (
readerWidth?: IReaderSettings['readerWidth'],
isImage?: boolean,
): CSSObject => {
const width = getPageWidth(pageScaleMode, isDoublePage, readerWidth, isImage);
const width = getPageWidth(pageScaleMode, isDoublePage, readerWidth, shouldStretchPage, isImage);
// setting the "width" of the wrapper is required for being able to properly size the image placeholders
const staticReaderWidthForWrapper = applyStyles(
@@ -185,6 +187,24 @@ export const getImageWidthStyling = (
}
};
export const getImageMarginStyling = (
readingMode: IReaderSettings['readingMode'],
doublePage: boolean,
objectFitPosition?: 'left' | 'right',
): CSSObject => ({
...applyStyles(!isContinuousReadingMode(readingMode), {
my: 'auto',
...applyStyles(doublePage, {
// the applied margin is the opposite of the objectFitPosition
...applyStyles(objectFitPosition === 'right', { ml: 'auto ' }),
...applyStyles(objectFitPosition === 'left', { mr: 'auto ' }),
}),
}),
...applyStyles(isContinuousReadingMode(readingMode), {
m: 'auto',
}),
});
export const createSinglePageData = (url: string, index: number): ReaderStatePages['pages'][number]['primary'] => ({
index,
alt: `Page #${index + 1}`,