Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature/reader setting add scale small pages #615

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/navbar/ReaderNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export function ReaderNavBar(props: IProps) {
loadNextOnEnding={settings.loadNextOnEnding}
skipDupChapters={settings.skipDupChapters}
fitPageToWindow={settings.fitPageToWindow}
scalePage={settings.scalePage}
readerType={settings.readerType}
offsetFirstPage={settings.offsetFirstPage}
readerWidth={settings.readerWidth}
Expand Down
8 changes: 6 additions & 2 deletions src/components/reader/DoublePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const DoublePage = forwardRef((props: IProps, ref: any) => {
const imgStyle = {
...baseImgStyle,
width: settings.fitPageToWindow ? baseImgStyle.width : `calc(${baseImgStyle.width} * 0.5)`,
minWidth:
settings.fitPageToWindow && settings.scalePage
? `calc(${baseImgStyle.minWidth} * 0.5)`
: baseImgStyle.minWidth,
maxWidth: settings.fitPageToWindow ? `calc(${baseImgStyle.maxWidth} * 0.5)` : baseImgStyle.maxWidth,
};

Expand All @@ -54,7 +58,7 @@ export const DoublePage = forwardRef((props: IProps, ref: any) => {
alt={`Page #${index}`}
imgRef={imgRef}
spinnerStyle={spinnerStyle}
imgStyle={imgStyle}
imgStyle={{ ...imgStyle, objectPosition: settings.readerType === 'DoubleLTR' ? 'right' : 'left' }}
/>
<SpinnerImage
src={image2src}
Expand All @@ -66,7 +70,7 @@ export const DoublePage = forwardRef((props: IProps, ref: any) => {
width: 'calc(50% - 5px)',
marginLeft: '5px',
}}
imgStyle={imgStyle}
imgStyle={{ ...imgStyle, objectPosition: settings.readerType === 'DoubleLTR' ? 'left' : 'right' }}
/>
</Box>
);
Expand Down
49 changes: 31 additions & 18 deletions src/components/reader/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,41 @@ export const isHorizontalReaderType = (readerType: ReaderType): boolean =>
['ContinuesHorizontalLTR', 'ContinuesHorizontalRTL'].includes(readerType);

export function imageStyle(settings: IReaderSettings): any {
const isVertical = settings.readerType === 'ContinuesVertical';
const isHorizontal = isHorizontalReaderType(settings.readerType);
if (settings.fitPageToWindow || isHorizontal) {
return {
marginLeft: isHorizontal ? '7px' : 0,
marginRight: isHorizontal ? '7px' : 0,
marginBottom: settings.readerType === 'ContinuesVertical' ? '15px' : 0,
width: 'auto',
maxWidth: settings.fitPageToWindow && !isHorizontal ? 'calc(100vw - (100vw - 100%))' : undefined,
height: 'auto',
minHeight: isHorizontal ? '100vh' : undefined,
maxHeight: '100vh',
objectFit: 'contain',
};
}

return {
marginBottom: settings.readerType === 'ContinuesVertical' ? '15px' : 0,
minWidth: '10vw',
const baseStyling = {
margin: 0,
width: `${settings.readerWidth}%`,
maxWidth: '100%',
objectFit: 'contain',
};

const continuesVerticalStyling = {
marginBottom: '15px',
};

const continuesHorizontalStyling = {
width: undefined,
minHeight: '100vh',
maxHeight: '100vh',
marginLeft: '7px',
marginRight: '7px',
};

const fitToPageStyling = {
width: undefined,
height: undefined,
minWidth: settings.scalePage ? 'calc(100vw - (100vw - 100%))' : undefined,
maxWidth: 'calc(100vw - (100vw - 100%))',
minHeight: settings.scalePage ? '100vh' : undefined,
maxHeight: '100vh',
};

return {
...baseStyling,
...(isHorizontal ? continuesHorizontalStyling : undefined),
...(isVertical ? continuesVerticalStyling : undefined),
...(settings.fitPageToWindow && !isHorizontal ? fitToPageStyling : undefined),
};
}

interface IProps {
Expand Down
11 changes: 11 additions & 0 deletions src/components/reader/ReaderSettingsOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function ReaderSettingsOptions({
skipDupChapters,
setSettingValue,
fitPageToWindow,
scalePage,
offsetFirstPage,
readerWidth,
}: IProps) {
Expand Down Expand Up @@ -75,6 +76,16 @@ export function ReaderSettingsOptions({
/>
</ListItem>
)}
{fitPageToWindowEligible && fitPageToWindow && (
<ListItem>
<ListItemText primary={t('reader.settings.label.scale_page')} />
<Switch
edge="end"
checked={scalePage}
onChange={(e) => setSettingValue('scalePage', e.target.checked)}
/>
</ListItem>
)}
{(readerType === 'DoubleLTR' || readerType === 'DoubleRTL') && (
<ListItem>
<ListItemText primary={t('reader.settings.label.offset_first_page')} />
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@
"offset_first_page": "Offset first page",
"reader_type": "Reader type",
"reader_width": "Reader width",
"scale_page": "Scale small pages",
"show_page_number": "Show page number",
"skip_dup_chapters": "Skip duplicate chapters",
"static_navigation": "Static navigation"
Expand Down
1 change: 1 addition & 0 deletions src/screens/settings/DefaultReaderSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export function DefaultReaderSettings() {
loadNextOnEnding={settings.loadNextOnEnding}
skipDupChapters={settings.skipDupChapters}
fitPageToWindow={settings.fitPageToWindow}
scalePage={settings.scalePage}
readerType={settings.readerType}
offsetFirstPage={settings.offsetFirstPage}
readerWidth={settings.readerWidth}
Expand Down
1 change: 1 addition & 0 deletions src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export interface IReaderSettings {
loadNextOnEnding: boolean;
skipDupChapters: boolean;
fitPageToWindow: boolean;
scalePage: boolean;
readerType: ReaderType;
offsetFirstPage: boolean;
readerWidth: number;
Expand Down
2 changes: 2 additions & 0 deletions src/util/readerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const getDefaultSettings = (): IReaderSettings => ({
loadNextOnEnding: false,
skipDupChapters: true,
fitPageToWindow: true,
scalePage: false,
readerType: 'ContinuesVertical',
offsetFirstPage: false,
readerWidth: 50,
Expand Down Expand Up @@ -83,6 +84,7 @@ export const checkAndHandleMissingStoredReaderSettings = async (
loadNextOnEnding: undefined,
skipDupChapters: undefined,
fitPageToWindow: undefined,
scalePage: undefined,
readerType: undefined,
offsetFirstPage: undefined,
readerWidth: undefined,
Expand Down
Loading