Skip to content

Commit eee2497

Browse files
committed
Release 0.3.0
2 parents 7f457c9 + f802dc0 commit eee2497

File tree

199 files changed

+15325
-12372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+15325
-12372
lines changed

.codebeatignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.codebeatsettings

Lines changed: 0 additions & 7 deletions
This file was deleted.

.scripts/ci.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
echo "Swift 3 Continuous Integration";
4-
53
# Determine OS
64
UNAME=`uname`;
75
if [[ $UNAME == "Darwin" ]];

.scripts/coverage.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ fi
1414
echo "🖥 Operating System: $OS";
1515

1616
PROJ_NAME="SwiftyHaru"
17-
SCHEME_NAME="${PROJ_NAME}"
17+
SCHEME_NAME="${PROJ_NAME}-Package"
1818

1919
echo "🚀 Testing: $SCHEME_NAME";
2020

2121
rvm install 2.2.3
2222
gem install xcpretty
2323
make generate-xcodeproj
24-
WORKING_DIRECTORY=$(PWD) xcodebuild -project $PROJ_NAME.xcodeproj -scheme $SCHEME_NAME -sdk macosx10.12 -destination arch=x86_64 -configuration Debug -enableCodeCoverage YES test | xcpretty
24+
WORKING_DIRECTORY=$(PWD) xcodebuild -project $PROJ_NAME.xcodeproj -scheme $SCHEME_NAME -destination arch=x86_64 -configuration Debug -enableCodeCoverage YES test | xcpretty
2525
bash <(curl -s https://codecov.io/bash)
2626

2727
echo "✅ Done";

.travis.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@ language: generic
22

33
matrix:
44
include:
5-
- os: osx
6-
osx_image: xcode8.3
7-
env: SWIFT_VERSION="3.1" RUN_TESTS="NO" POD_LINT="YES"
8-
- os: osx
9-
osx_image: xcode8.3
10-
env: SWIFT_VERSION="3.1" RUN_TESTS="YES" POD_LINT="NO"
11-
- os: linux
5+
- name: "pod lib lint"
6+
os: osx
7+
osx_image: xcode10.1
8+
env: SWIFT_VERSION="4.2" RUN_TESTS="NO" POD_LINT="YES"
9+
- name: "Running tests (macOS)"
10+
os: osx
11+
osx_image: xcode10.1
12+
env: SWIFT_VERSION="4.2" RUN_TESTS="YES" POD_LINT="NO"
13+
- name: "Running tests (Ubuntu 18.04)"
14+
os: linux
1215
sudo: required
13-
dist: trusty
14-
env: SWIFT_VERSION="3.1" RUN_TESTS="YES" POD_LINT="NO"
16+
dist: xenial
17+
env: SWIFT_VERSION="4.2" RUN_TESTS="YES" POD_LINT="NO"
1518

1619
script:
1720
- if [[ $POD_LINT == "YES" ]]; then
18-
gem install cocoapods;
21+
gem install cocoapods --pre;
1922
pod repo update --silent;
20-
pod lib lint --swift-version=$SWIFT_VERSION --allow-warnings;
23+
pod lib lint --allow-warnings --verbose;
2124
fi
2225
- if [[ $RUN_TESTS == "YES" ]]; then
2326
eval .scripts/ci.sh;

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# Change Log
22

3+
## [0.3.0](https://github.com/WeirdMath/SwiftyHaru/tree/0.3.0) (2018-12-24)
4+
5+
Please note that this version requires Swift 4.2.
6+
7+
**Breaking changes:**
8+
9+
(Those are a bit massive, sorry.)
10+
11+
- `PDFPage.draw(_:)` is removed. The closure for drawing can now be passed to the `PDFDocument.addPage(_:)` family of methods. This is because multiple calls of `PDFPage.draw(_:)` resulted in redundant drawing operations (when resetting the context to the default state before each call). To migrate, merge your multiple calls of `PDFPage.draw(_:)` to one call of `PDFDocument.addPage(_:)`. Pay attention that because of this the `DrawingContext.textLeading` property is initially set to 0 (not 11 like before), so you may want to change its value before doing any text operations. Also, if you need to access the `PDFPage`'s properties from the drawing closure, use the `DrawingContext.page` property.
12+
- `PDFPage.draw(object:position:)` and `PDFPage.draw(object:x:y:)` are removed. Use the `DrawingContext.draw(_:position:)` and `DrawingContext.draw(_:x:y:)` methods instead.
13+
- `DashStyle.pattern` and `DashStyle.phase` are now `let`, since changing those values wasn't in any way validated.
14+
- `Vector` is now a separate type, not a typealias for `Point`. Its intefrace has slightly changed: the fields have been renamed from `x` and `y` to `dx` and `dy`. This new type includes some arithmetic operators that make its use simpler.
15+
- The required method `draw(in:position:)` of the `Drawable` protocol is marked `throws`.
16+
- `PDFDocument.setEncryptionMode(to:)` and `PDFDocument.setPermissions(to:)` are removed. Use the `PDFDocument.setPassword(owner:user:permissions:encryptionMode:)` method instead.
17+
- `DrawingContext.withNewGState(_:)` doesn't throw if its argument doesn't. Same for `DrawingContext.clip(to:rule:_:)`. If the graphics state stack depth exceeds `static DrawingContext.maxGraphicsStateDepth`, a precondition failure occures.
18+
- `static PDFError.exceedGStateLimit` is removed.
19+
20+
**Implemented features:**
21+
22+
- `AffineTransform` struct that helps you easily apply transforms like rotation, scaling and translation to a document's coordinate system.
23+
- Concatenating the transformation matrix of a page + convenience methods for translation, scaling and rotation.
24+
- Getting the current transformation matrix of a page.
25+
- Added conformance to `Hashable` for many types.
26+
- Improved debug descriptions for `Color` and the geometric types.
27+
328
## [0.2.0](https://github.com/WeirdMath/SwiftyHaru/tree/0.2.0) (2017-06-25)
429

530
Please note that this version requires Swift 3.1.

Demo/Demo.playground/Pages/Arcs.xcplaygroundpage/Contents.swift

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,75 +8,74 @@
88
import SwiftyHaru
99

1010
let document = PDFDocument()
11-
let page = document.addPage(width: 200, height: 220)
11+
try document.addPage(width: 200, height: 220) { context in
1212
/*:
1313
Let's draw the grid for convenience.
1414
*/
15-
16-
let horizontalLabels = stride(from: 50, through: 150, by: 50).map(String.init)
17-
let verticalLabels = stride(from: 10, through: 210, by: 10).map(String.init)
18-
19-
let labels = Grid.Labels(top: Grid.LabelParameters(sequence: "" + horizontalLabels,
20-
offset: Vector(x: 0, y: -6)),
21-
bottom: Grid.LabelParameters(sequence: "" + horizontalLabels,
22-
offset: Vector(x: 0, y: 6)),
23-
left: Grid.LabelParameters(sequence: "" + verticalLabels,
24-
frequency: 1,
25-
offset: Vector(x: 6, y: 0)))
26-
27-
let serifs = Grid.Serifs(top: .default,
28-
bottom: .default,
29-
left: Grid.SerifParameters(frequency: 1),
30-
right: nil)
31-
32-
let grid = Grid(width: page.width, height: page.height, labels: labels, serifs: serifs)
33-
page.draw(object: grid, position: .zero)
15+
let horizontalLabels = stride(from: 50, through: 150, by: 50).map(String.init)
16+
let verticalLabels = stride(from: 10, through: 210, by: 10).map(String.init)
17+
18+
let labels = Grid.Labels(top: Grid.LabelParameters(sequence: "" + horizontalLabels,
19+
offset: Vector(dx: 0, dy: -6)),
20+
bottom: Grid.LabelParameters(sequence: "" + horizontalLabels,
21+
offset: Vector(dx: 0, dy: 6)),
22+
left: Grid.LabelParameters(sequence: "" + verticalLabels,
23+
frequency: 1,
24+
offset: Vector(dx: 6, dy: 0)))
25+
26+
let serifs = Grid.Serifs(top: .default,
27+
bottom: .default,
28+
left: Grid.SerifParameters(frequency: 1),
29+
right: nil)
30+
31+
let grid = Grid(width: context.page.width,
32+
height: context.page.height,
33+
labels: labels,
34+
serifs: serifs)
35+
try context.draw(grid, position: .zero)
3436
/*:
3537
Then draw a pie chart.
3638
- a: 45% red
3739
- b: 25% blue
3840
- c: 15% green
3941
- d: other yellow
4042
*/
41-
42-
let center = Point(x: 100, y: 100)
43-
44-
var temporaryPosition: Point
45-
46-
var a = Path()
47-
.moving(to: center)
48-
.appendingLine(toX: 100, y: 180)
49-
.appendingArc(center: center,
50-
radius: 80,
51-
beginningAngle: 0,
52-
endAngle: 360 * 0.45)
53-
temporaryPosition = a.currentPosition
54-
a.appendLine(to: center)
55-
56-
var b = Path()
57-
.moving(to: center)
58-
.appendingLine(to: temporaryPosition)
59-
.appendingArc(center: center, radius: 80, beginningAngle: 360 * 0.45, endAngle: 360 * 0.7)
60-
temporaryPosition = b.currentPosition
61-
b.appendLine(to: center)
62-
63-
var c = Path()
64-
.moving(to: center)
65-
.appendingLine(to: temporaryPosition)
66-
.appendingArc(center: center, radius: 80, beginningAngle: 360 * 0.7, endAngle: 360 * 0.85)
67-
temporaryPosition = c.currentPosition
68-
c.appendLine(to: center)
69-
70-
var d = Path()
71-
.moving(to: center)
72-
.appendingLine(to: temporaryPosition)
73-
.appendingArc(center: center, radius: 80, beginningAngle: 360 * 0.85, endAngle: 360)
74-
.appendingLine(to: center)
75-
76-
// Draw center circle
77-
let centerCircle = Path().appendingCircle(center: center, radius: 30)
78-
79-
page.draw { context in
43+
let center = Point(x: 100, y: 100)
44+
45+
var temporaryPosition: Point
46+
47+
var a = Path()
48+
.moving(to: center)
49+
.appendingLine(toX: 100, y: 180)
50+
.appendingArc(center: center,
51+
radius: 80,
52+
beginningAngle: 0,
53+
endAngle: 360 * 0.45)
54+
temporaryPosition = a.currentPosition
55+
a.appendLine(to: center)
56+
57+
var b = Path()
58+
.moving(to: center)
59+
.appendingLine(to: temporaryPosition)
60+
.appendingArc(center: center, radius: 80, beginningAngle: 360 * 0.45, endAngle: 360 * 0.7)
61+
temporaryPosition = b.currentPosition
62+
b.appendLine(to: center)
63+
64+
var c = Path()
65+
.moving(to: center)
66+
.appendingLine(to: temporaryPosition)
67+
.appendingArc(center: center, radius: 80, beginningAngle: 360 * 0.7, endAngle: 360 * 0.85)
68+
temporaryPosition = c.currentPosition
69+
c.appendLine(to: center)
70+
71+
var d = Path()
72+
.moving(to: center)
73+
.appendingLine(to: temporaryPosition)
74+
.appendingArc(center: center, radius: 80, beginningAngle: 360 * 0.85, endAngle: 360)
75+
.appendingLine(to: center)
76+
77+
// Draw center circle
78+
let centerCircle = Path().appendingCircle(center: center, radius: 30)
8079

8180
context.fillColor = #colorLiteral(red: 0.9254902005, green: 0.2352941185, blue: 0.1019607857, alpha: 1)
8281
context.fill(a)
@@ -99,4 +98,4 @@
9998
document.display()
10099
/*:
101100
[Previous page](@previous) • **[Table of contents](Table%20of%20contents)** • [Next page](@next)
102-
*/
101+
*/

Demo/Demo.playground/Pages/Fonts.xcplaygroundpage/Contents.swift

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
([Original example that uses LibHaru](https://github.com/libharu/libharu/wiki/Examples#font_democ))
77
*/
88
import SwiftyHaru
9-
109
/*:
1110
Define our list of fonts:
1211
*/
@@ -30,58 +29,51 @@
3029
Setup our document:
3130
*/
3231
let document = PDFDocument()
33-
let page = document.addPage()
3432
let pageTitle = "Font Demo"
3533

34+
try document.addPage { context in
3635
/*:
3736
Print the lines and the title of the page:
3837
*/
39-
page.draw { context in
40-
4138
let rectangle = Path()
4239
.appendingRectangle(x: 50,
4340
y: 50,
44-
width: page.width - 100,
45-
height: page.height - 110)
41+
width: context.page.width - 100,
42+
height: context.page.height - 110)
4643

4744
context.stroke(rectangle)
4845

46+
context.textLeading = 11
4947
context.fontSize = 24
5048
let textWidth = context.textWidth(for: pageTitle)
51-
context.show(text: pageTitle,
52-
atX: (page.width - textWidth) / 2,
53-
y: page.height - 50)
54-
}
49+
try context.show(text: pageTitle,
50+
atX: (context.page.width - textWidth) / 2,
51+
y: context.page.height - 50)
5552
/*:
5653
Output subtitle:
5754
*/
58-
page.draw { context in
59-
6055
context.fontSize = 16
61-
context.show(text: "<Standerd Type1 fonts samples>",
62-
atX: 60,
63-
y: page.height - 80)
64-
}
56+
try context.show(text: "<Standerd Type1 fonts samples>",
57+
atX: 60,
58+
y: context.page.height - 80)
6559
/*:
6660
And finally let's test each font:
6761
*/
68-
page.draw { context in
69-
70-
var textPosition = Point(x: 60, y: page.height - 105)
62+
var textPosition = Point(x: 60, y: context.page.height - 105)
7163

7264
let sampleText = "abcdefgABCDEFG12345!#$%&+-@?"
7365

7466
for font in fontList {
7567

7668
context.fontSize = 9
7769
context.font = .helvetica
78-
context.show(text: font.name, atPosition: textPosition)
79-
textPosition = textPosition + Vector(x: 0, y: -18)
70+
try context.show(text: font.name, atPosition: textPosition)
71+
textPosition = textPosition + Vector(dx: 0, dy: -18)
8072

8173
context.fontSize = 20
8274
context.font = font
83-
context.show(text: sampleText, atPosition: textPosition)
84-
textPosition = textPosition + Vector(x: 0, y: -20)
75+
try context.show(text: sampleText, atPosition: textPosition)
76+
textPosition = textPosition + Vector(dx: 0, dy: -20)
8577
}
8678
}
8779
/*:

Demo/Demo.playground/Pages/Grid Sheet.xcplaygroundpage/Contents.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,23 @@
2020
Let's setup our document.
2121
*/
2222
let document = PDFDocument()
23-
let page = document.addPage(width: 400, height: 600)
2423
/*:
2524
And set some parameters
2625
*/
2726
let topLabelParameters =
2827
Grid.LabelParameters(sequence: createLabelSequence(stride: 50),
2928
frequency: 5,
30-
offset: Vector(x: 0, y: -6))
29+
offset: Vector(dx: 0, dy: -6))
3130

3231
let bottomLabelParameters =
3332
Grid.LabelParameters(sequence: createLabelSequence(stride: 50),
3433
frequency: 5,
35-
offset: Vector(x: 0, y: 6))
34+
offset: Vector(dx: 0, dy: 6))
3635

3736
let leftLabelParameters =
3837
Grid.LabelParameters(sequence: createLabelSequence(stride: 10),
3938
frequency: 1,
40-
offset: Vector(x: 6, y: 0))
39+
offset: Vector(dx: 6, dy: 0))
4140

4241
let labels = Grid.Labels(top: topLabelParameters,
4342
bottom: bottomLabelParameters,
@@ -54,12 +53,13 @@
5453
/*:
5554
Finally, assemble everything:
5655
*/
57-
let grid = Grid(width: page.width,
58-
height: page.height,
59-
labels: labels,
60-
serifs: serifs)
61-
62-
page.draw(object: grid, position: .zero)
56+
try document.addPage(width: 400, height: 600) { context in
57+
let grid = Grid(width: context.page.width,
58+
height: context.page.height,
59+
labels: labels,
60+
serifs: serifs)
61+
try context.draw(grid, position: .zero)
62+
}
6363
/*:
6464
Yep, it's that simple.
6565

0 commit comments

Comments
 (0)