import UIKit final class RDEPUBReaderEnvironment { weak var controller: RDEPUBReaderController? weak var readerView: RDReaderView? var displayEnvironment: any RDEPUBReaderDisplayEnvironment init( controller: RDEPUBReaderController, readerView: RDReaderView, displayEnvironment: any RDEPUBReaderDisplayEnvironment ) { self.controller = controller self.readerView = readerView self.displayEnvironment = displayEnvironment } func currentLayoutContext(configuration: RDEPUBReaderConfiguration) -> RDEPUBNavigatorLayoutContext { let containerSize = readerView?.bounds.size ?? .zero let viewSize = controller?.view.bounds.size ?? containerSize let resolvedSize = containerSize == .zero ? viewSize : containerSize return RDEPUBNavigatorLayoutContext( containerSize: resolvedSize, pagesPerScreen: readerView?.pagesPerScreen ?? 1, safeAreaInsets: controller?.view.safeAreaInsets ?? .zero, userInterfaceIdiom: controller?.traitCollection.userInterfaceIdiom ?? .phone, reflowableContentInsets: configuration.reflowableContentInsets ) } func currentTextRenderStyle(configuration: RDEPUBReaderConfiguration) -> RDEPUBTextRenderStyle { let font = configuration.fontChoice.font(ofSize: configuration.fontSize) let lineSpacing = max(font.lineHeight * (configuration.lineHeightMultiple - 1), 4) return RDEPUBTextRenderStyle( font: font, lineSpacing: lineSpacing, textColor: configuration.theme.contentTextColor, backgroundColor: configuration.theme.contentBackgroundColor ) } func currentTextLayoutConfig( configuration: RDEPUBReaderConfiguration, pageSize: CGSize ) -> RDEPUBTextLayoutConfig { RDEPUBTextLayoutConfig( frameWidth: max(pageSize.width, 1), frameHeight: max(pageSize.height, 1), edgeInsets: configuration.reflowableContentInsets, numberOfColumns: configuration.numberOfColumns, columnGap: configuration.columnGap, avoidOrphans: false, avoidWidows: false, avoidPageBreakInsideEnabled: true, hyphenation: true, imageMaxHeightRatio: 0.85, fallbackViewportSize: displayEnvironment.fallbackViewportSize ) } var currentBrightness: CGFloat { get { displayEnvironment.currentBrightness } set { displayEnvironment.currentBrightness = newValue } } var fallbackViewportSize: CGSize { displayEnvironment.fallbackViewportSize } }