Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add copy to TextShape #651

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion C4/UI/TextShape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import UIKit
import Foundation

/// TextShape defines a concrete subclass of Shape that draws a bezier curve whose shape looks like text.
public class TextShape: Shape {
public class TextShape: Shape, NSCopying {
/// The text used to define the shape's path. Defaults to "C4".
public var text: String = "C4" {
didSet {
Expand Down Expand Up @@ -112,4 +112,8 @@ public class TextShape: Shape {
}
return Path(path: textPath)
}

public func copyWithZone(zone: NSZone) -> AnyObject {
return TextShape(text: text, font: font)!
}
}
31 changes: 31 additions & 0 deletions C4Tests/TextShapeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright © 2014 C4
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: The above copyright
// notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

import C4
import XCTest

class TextShaeTests: XCTestCase {
func testCopy() {
let textShape = TextShape(text: "Text")!
let textShapeCopy = textShape.copy() as! TextShape
XCTAssertEqual(textShape.text, textShapeCopy.text)
//TODO: test font equality
// XCTAssertEqual(textShape.font, textShapeCopy.font)
}
}
4 changes: 4 additions & 0 deletions C4iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
61BBAF631BC372BD00A03FD0 /* StoredAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61BBAF621BC372BD00A03FD0 /* StoredAnimation.swift */; };
61BBAF651BC38C1200A03FD0 /* View+KeyValues.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61BBAF641BC38C1200A03FD0 /* View+KeyValues.swift */; };
A94E3BD419E0E9390039A9C4 /* C4.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 614F824319DB5ED3001DF1D4 /* C4.framework */; };
A964C5E01CA4B5F2008D976B /* TextShapeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A964C5DF1CA4B5F2008D976B /* TextShapeTests.swift */; };
A96F4F451B538330002B3A46 /* ColorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9596D401A054B4F0023323D /* ColorTests.swift */; };
A96F4F461B538330002B3A46 /* MathTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9596D411A054B4F0023323D /* MathTests.swift */; };
A96F4F471B538330002B3A46 /* PointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9596D421A054B4F0023323D /* PointTests.swift */; };
Expand Down Expand Up @@ -156,6 +157,7 @@
A9596D411A054B4F0023323D /* MathTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MathTests.swift; sourceTree = "<group>"; };
A9596D421A054B4F0023323D /* PointTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PointTests.swift; sourceTree = "<group>"; };
A9596D431A054B4F0023323D /* VectorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VectorTests.swift; sourceTree = "<group>"; };
A964C5DF1CA4B5F2008D976B /* TextShapeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextShapeTests.swift; sourceTree = "<group>"; };
A96F505A1B5385A5002B3A46 /* C4App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = C4App.app; sourceTree = BUILT_PRODUCTS_DIR; };
A96F505D1B5385A5002B3A46 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A96F505E1B5385A5002B3A46 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -280,6 +282,7 @@
A9596D421A054B4F0023323D /* PointTests.swift */,
61B92B4B1C7B96B8003BD61C /* RectTests.swift */,
A9596D431A054B4F0023323D /* VectorTests.swift */,
A964C5DF1CA4B5F2008D976B /* TextShapeTests.swift */,
A988A9161A4F57330044007C /* TransformTests.swift */,
A9596D281A054A960023323D /* Supporting Files */,
);
Expand Down Expand Up @@ -664,6 +667,7 @@
A96F4F4A1B538330002B3A46 /* TransformTests.swift in Sources */,
A96F4F491B538330002B3A46 /* VectorTests.swift in Sources */,
A96F4F461B538330002B3A46 /* MathTests.swift in Sources */,
A964C5E01CA4B5F2008D976B /* TextShapeTests.swift in Sources */,
A96F4F451B538330002B3A46 /* ColorTests.swift in Sources */,
A96F4F471B538330002B3A46 /* PointTests.swift in Sources */,
61B92B4C1C7B96B8003BD61C /* RectTests.swift in Sources */,
Expand Down