-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d853cd5
commit 02531b6
Showing
4 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import SwiftyHaru | ||
|
||
func createLabelSequence(stride: Int) -> AnySequence<String> { | ||
|
||
let seq = sequence(first: 0, next: { $0 + stride }).lazy.map(String.init) | ||
|
||
return "" + AnySequence(seq).dropFirst() | ||
} | ||
|
||
let document = PDFDocument() | ||
let page = document.addPage(width: 400, height: 600) | ||
|
||
let topLabelParameters = | ||
Grid.LabelParameters(sequence: createLabelSequence(stride: 50), | ||
frequency: 5, | ||
offset: Vector(x: 0, y: -6)) | ||
|
||
let bottomLabelParameters = | ||
Grid.LabelParameters(sequence: createLabelSequence(stride: 50), | ||
frequency: 5, | ||
offset: Vector(x: 0, y: 6)) | ||
|
||
let leftLabelParameters = | ||
Grid.LabelParameters(sequence: createLabelSequence(stride: 10), | ||
frequency: 1, | ||
offset: Vector(x: 6, y: 0)) | ||
|
||
let labels = Grid.Labels(top: topLabelParameters, | ||
bottom: bottomLabelParameters, | ||
left: leftLabelParameters, | ||
right: nil) | ||
|
||
let verticalSerifParameters = Grid.SerifParameters(frequency: 1) | ||
let horizontalSerifParameters = Grid.SerifParameters(frequency: 5) | ||
|
||
let serifs = Grid.Serifs(top: horizontalSerifParameters, | ||
bottom: horizontalSerifParameters, | ||
left: verticalSerifParameters, | ||
right: nil) | ||
|
||
let grid = Grid(width: page.width, | ||
height: page.height, | ||
labels: labels, | ||
serifs: serifs) | ||
|
||
page.draw(object: grid, position: .zero) | ||
|
||
document.display() |
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,17 @@ | ||
import Quartz | ||
import PlaygroundSupport | ||
import SwiftyHaru | ||
|
||
public extension SwiftyHaru.PDFDocument { | ||
|
||
public func display() { | ||
|
||
let view = PDFView(frame: NSRect(x: 0, y: 0, width: 480, height: 640)) | ||
|
||
view.document = PDFDocument(data: getData()) | ||
|
||
view.scaleFactor = 0.75 | ||
|
||
PlaygroundPage.current.liveView = view | ||
} | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='macos'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.