Skip to content

Commit

Permalink
#2: Implement Grid Sheet demo
Browse files Browse the repository at this point in the history
  • Loading branch information
broadwaylamb committed Nov 5, 2016
1 parent d853cd5 commit 02531b6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Demo/GridSheet.playground/Contents.swift
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()
17 changes: 17 additions & 0 deletions Demo/GridSheet.playground/Sources/ViewConfiguration.swift
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
}
}
4 changes: 4 additions & 0 deletions Demo/GridSheet.playground/contents.xcplayground
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>
3 changes: 3 additions & 0 deletions Demo/SwiftyHaru.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 02531b6

Please sign in to comment.