mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2026-02-17 13:52:14 +01:00
Updated embed PDF Added Autozoom Added file page size to metadata for use in calculations for autozoom, will come in handy elsewhere. --------- Co-authored-by: James Brunton <jbrunton96@gmail.com>
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import {
|
|
ProcessedFileMetadata,
|
|
ProcessedFilePage,
|
|
StirlingFileStub,
|
|
} from '@app/types/fileContext';
|
|
|
|
export interface PageDimensions {
|
|
width: number | null;
|
|
height: number | null;
|
|
}
|
|
|
|
export function getPageDimensions(
|
|
page?: ProcessedFilePage | null
|
|
): PageDimensions {
|
|
const width =
|
|
typeof page?.width === 'number' && page.width > 0 ? page.width : null;
|
|
const height =
|
|
typeof page?.height === 'number' && page.height > 0 ? page.height : null;
|
|
|
|
return { width, height };
|
|
}
|
|
|
|
export function getFirstPageDimensionsFromMetadata(
|
|
metadata?: ProcessedFileMetadata | null
|
|
): PageDimensions {
|
|
if (!metadata?.pages?.length) {
|
|
return { width: null, height: null };
|
|
}
|
|
|
|
return getPageDimensions(metadata.pages[0]);
|
|
}
|
|
|
|
export function getFirstPageDimensionsFromStub(
|
|
file?: StirlingFileStub
|
|
): PageDimensions {
|
|
return getFirstPageDimensionsFromMetadata(file?.processedFile);
|
|
}
|
|
|
|
export function getFirstPageAspectRatioFromMetadata(
|
|
metadata?: ProcessedFileMetadata | null
|
|
): number | null {
|
|
const { width, height } = getFirstPageDimensionsFromMetadata(metadata);
|
|
if (width && height) {
|
|
return height / width;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function getFirstPageAspectRatioFromStub(
|
|
file?: StirlingFileStub
|
|
): number | null {
|
|
return getFirstPageAspectRatioFromMetadata(file?.processedFile);
|
|
}
|