diff --git a/lib/sheet_viewer_page.dart b/lib/sheet_viewer_page.dart index ecd563d..edd5248 100644 --- a/lib/sheet_viewer_page.dart +++ b/lib/sheet_viewer_page.dart @@ -117,45 +117,54 @@ class _SheetViewerPageState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, + spacing: 0, children: [ - Stack( - children: [ - PdfPageView( - key: ValueKey(page), - document: document, - pageNumber: page, - maximumDpi: 300, - ), - Positioned.fill( - child: Container( - alignment: Alignment.bottomCenter, - padding: EdgeInsets.only(bottom: 5), - child: Text('$page / $numPages'), - ), - ), - ], - ), - Visibility( - visible: twoPageMode == true, + Expanded( child: Stack( children: [ PdfPageView( key: ValueKey(page), document: document, - pageNumber: page + 1, + pageNumber: page, maximumDpi: 300, - // alignment: Alignment.center, + alignment: twoPageMode + ? Alignment.centerRight + : Alignment.center, ), Positioned.fill( child: Container( alignment: Alignment.bottomCenter, padding: EdgeInsets.only(bottom: 5), - child: Text('${page + 1} / $numPages'), + child: Text('$page / $numPages'), ), ), ], ), ), + Visibility( + visible: twoPageMode == true, + child: Expanded( + child: Stack( + children: [ + PdfPageView( + key: ValueKey(page), + document: document, + pageNumber: page + 1, + maximumDpi: 300, + alignment: Alignment.centerLeft, + // alignment: Alignment.center, + ), + Positioned.fill( + child: Container( + alignment: Alignment.bottomCenter, + padding: EdgeInsets.only(bottom: 5), + child: Text('${page + 1} / $numPages'), + ), + ), + ], + ), + ), + ), ], ), ), @@ -167,13 +176,21 @@ class _SheetViewerPageState extends State { child: SizedBox.expand( child: LayoutBuilder( builder: (context, constraints) { + final maxSize = Size( + constraints.maxWidth, + constraints.maxHeight, + ); + final pageSizeUnscaled = document!.pages + .elementAt(page) + .size; + final pageSizeScaled = calcScaledPageSize( + maxSize, + pageSizeUnscaled, + ); return DrawingBoard( background: SizedBox( - width: calcScaledPageWidth( - constraints.maxHeight, - document!.pages.elementAt(page).size, - ), - height: constraints.maxHeight, + width: pageSizeScaled.width, + height: pageSizeScaled.height, child: PdfPageView( document: document, pageNumber: page, @@ -250,7 +267,25 @@ class _SheetViewerPageState extends State { ); } - double calcScaledPageWidth(double parentHeight, Size pageSize) { - return parentHeight * pageSize.width / pageSize.height; + Size calcScaledPageSize(Size parentSize, Size pageSize) { + // page restricted by height + log.info("ParentSize: ${parentSize.width}, ${parentSize.height}"); + log.info("ParentSizeRatio: ${parentSize.aspectRatio}"); + log.info("PageSizeRatio: ${pageSize.aspectRatio}"); + if (parentSize.aspectRatio > pageSize.aspectRatio) { + log.info("Restricted by height"); + final height = parentSize.height; + final width = height * pageSize.aspectRatio; + log.info("Size: $width, $height"); + return Size(width, height); + } + // page restricted by width + else { + log.info("Restricted by height"); + final width = parentSize.width; + final height = width / pageSize.aspectRatio; + log.info("Size: $width, $height"); + return Size(width, height); + } } }