-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows for easy extensibility of custom page sizes as well as for defining more standard sizes.
- Loading branch information
Showing
8 changed files
with
93 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// PageSize.swift | ||
// PDFViewKit | ||
// | ||
// Copyright (C) 2024 Sören Gade | ||
// See LICENSE for full license. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A type that defines page sizes. | ||
public protocol PageSize { | ||
|
||
/// The page's physical width. | ||
var width: Measurement<UnitLength> { get } | ||
|
||
/// The page's physical height. | ||
var height: Measurement<UnitLength> { get } | ||
|
||
/// The page's size aspect ratio. | ||
var aspectRatio: CGFloat { get } | ||
|
||
/// Calculates the page's dot size at the given ``DPI`` rendering scale. | ||
/// | ||
/// - Parameters: | ||
/// - dpi: The page resolution of dots per inch. | ||
func size(atDPI dpi: DPI) -> CGSize | ||
|
||
} | ||
|
||
// MARK: Default implementation | ||
|
||
public extension PageSize { | ||
|
||
var aspectRatio: CGFloat { | ||
width.converted(to: .millimeters).value / height.converted(to: .millimeters).value | ||
} | ||
|
||
func size(atDPI dpi: DPI) -> CGSize { | ||
CGSize( | ||
width: width.converted(to: .inches).value * dpi.rawValue, | ||
height: height.converted(to: .inches).value * dpi.rawValue | ||
) | ||
} | ||
|
||
} |