Skip to content

Commit

Permalink
allow no specified size
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Nov 9, 2017
1 parent 7860711 commit c4e60ff
Show file tree
Hide file tree
Showing 43 changed files with 74 additions and 43 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Pods
- __archive
- examples
- frameworks/speculid/Models/VCS.swift
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ script:
- xcodebuild -exportArchive -archivePath ./build/Products/Speculid.xcarchive -exportOptionsPlist ./exportOptions.plist -exportPath ./build/Products/App
- open Build/Products/App/Speculid.app
- osascript -e 'tell application "Speculid" to quit'
- Build/Products/App/Speculid.app/Contents/MacOS/Speculid examples/Assets/macOS\ AppIcon.speculid
#- diff examples/shasum <(./shasum.sh)
#- xcodebuild -workspace speculid.xcworkspace -scheme Speculid test
# after_success:
Expand Down
4 changes: 4 additions & 0 deletions Speculid.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
B3B5E9E81F96C74C004A6BEB /* CommandLineRunner.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B5E9E71F96C74C004A6BEB /* CommandLineRunner.swift */; };
B3B5E9EA1F96C777004A6BEB /* SpeculidApplicationModeParserProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B5E9E91F96C777004A6BEB /* SpeculidApplicationModeParserProtocol.swift */; };
B3B5E9EC1F96C7D5004A6BEB /* SpeculidApplicationModeParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3B5E9EB1F96C7D5004A6BEB /* SpeculidApplicationModeParser.swift */; };
B3D2F6AD1FB3EB7F00BF7AC1 /* shasum.sh in Resources */ = {isa = PBXBuildFile; fileRef = B3D2F6AC1FB3EB7E00BF7AC1 /* shasum.sh */; };
B3D32A021F9A5D760042B46F /* help.txt in Resources */ = {isa = PBXBuildFile; fileRef = B3D32A011F9A5D750042B46F /* help.txt */; };
B3D32A041F9A5E8F0042B46F /* CommandLineRunnerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D32A031F9A5E8F0042B46F /* CommandLineRunnerTest.swift */; };
B3D32A061F9A5FEE0042B46F /* FileHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3D32A051F9A5FEE0042B46F /* FileHandle.swift */; };
Expand Down Expand Up @@ -412,6 +413,7 @@
B3B5E9E71F96C74C004A6BEB /* CommandLineRunner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandLineRunner.swift; sourceTree = "<group>"; };
B3B5E9E91F96C777004A6BEB /* SpeculidApplicationModeParserProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpeculidApplicationModeParserProtocol.swift; sourceTree = "<group>"; };
B3B5E9EB1F96C7D5004A6BEB /* SpeculidApplicationModeParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpeculidApplicationModeParser.swift; sourceTree = "<group>"; };
B3D2F6AC1FB3EB7E00BF7AC1 /* shasum.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = shasum.sh; sourceTree = "<group>"; };
B3D32A011F9A5D750042B46F /* help.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = help.txt; sourceTree = "<group>"; };
B3D32A031F9A5E8F0042B46F /* CommandLineRunnerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandLineRunnerTest.swift; sourceTree = "<group>"; };
B3D32A051F9A5FEE0042B46F /* FileHandle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileHandle.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -517,6 +519,7 @@
B3033B181F9AED7600787279 /* configuration */ = {
isa = PBXGroup;
children = (
B3D2F6AC1FB3EB7E00BF7AC1 /* shasum.sh */,
B3B049C81FA262A8002906B1 /* exportOptions.plist */,
B3033B1A1F9AEE9A00787279 /* .gitignore */,
B3033B191F9AEE9900787279 /* .travis.yml */,
Expand Down Expand Up @@ -1152,6 +1155,7 @@
buildActionMask = 2147483647;
files = (
B3033B1B1F9AEE9A00787279 /* .travis.yml in Resources */,
B3D2F6AD1FB3EB7F00BF7AC1 /* shasum.sh in Resources */,
B3033B1C1F9AEE9A00787279 /* .gitignore in Resources */,
B318906E1F91A06C00D0EFA0 /* .swiftlint.yml in Resources */,
B3B049C91FA262A8002906B1 /* exportOptions.plist in Resources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "1"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
Expand All @@ -89,7 +89,11 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "&quot;${SRCROOT}/__archive/examples/Assets/macOS AppIcon.speculid&quot;"
argument = "&quot;${SRCROOT}/examples/Assets/macOS AppIcon.speculid&quot;"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "&quot;${SRCROOT}/examples/Assets/Image Set.speculid&quot;"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions frameworks/cairosvg/CairoInterface.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ + (double) mapSize: (CGSize) size toDimension: (GeometryDimension) dimensions {
return dimensions.value/size.width;
case kHeight:
return dimensions.value/size.height;
case kScale:
return dimensions.value;
case kUnspecified:
return 1.0;
}
}

Expand Down
4 changes: 3 additions & 1 deletion frameworks/cairosvg/Dimension.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

typedef NS_ENUM(NSUInteger, Dimension) {
kWidth,
kHeight
kHeight,
kScale,
kUnspecified
};

#endif /* Dimension_h */
6 changes: 5 additions & 1 deletion frameworks/cairosvg/GeometryDimension.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
#import "Dimension.h"

typedef struct GeometryDimension {
int value;
CGFloat value;
Dimension dimension;
} GeometryDimension;

extern const struct GeometryDimension GeometryDimensionUnspecified = {
.value = 0,
.dimension = kUnspecified
};
#endif /* GeometryDimension_h */
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation

@available(*, deprecated: 2.0.0)
public struct NoGeometrySpecifiedError: Error {
public let asset: AssetSpecificationProtocol
public let specification: SpeculidSpecificationsFileProtocol
Expand All @@ -16,19 +17,28 @@ public struct SpeculidImageSpecificationBuilder: SpeculidImageSpecificationBuild
andAsset asset: AssetSpecificationProtocol) throws -> ImageSpecification {
let destinationFile = try ImageFile(url: destinationURL)

let geometry: GeometryProtocol
let geometryObj: GeometryProtocol?

if let size = asset.size {
geometry = try Geometry(size: size, preferWidth: true).scaling(by: asset.scale)
geometryObj = try Geometry(size: size, preferWidth: true).scaling(by: asset.scale)
} else if let specificationsGeomtetry = specifications.geometry {
geometry = specificationsGeomtetry.scaling(by: asset.scale)
geometryObj = specificationsGeomtetry.scaling(by: asset.scale)
} else if let scale = asset.scale {
geometryObj = Geometry(value: .scale(scale))
} else {
throw NoGeometrySpecifiedError(forAsset: asset, withSpecs: specifications)
geometryObj = nil
}

let geometry: Geometry?
if let geometryValue = geometryObj?.value {
geometry = Geometry(value: geometryValue)
} else {
geometry = nil
}

return ImageSpecification(
file: destinationFile,
geometryDimension: Geometry(value: geometry.value),
geometryDimension: geometry,
removeAlphaChannel: specifications.removeAlpha,
backgroundColor: specifications.background)
}
Expand Down
6 changes: 4 additions & 2 deletions frameworks/speculid/Extensions/GeometryValue.Multiply.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ public extension GeometryValue {
public static func * (left: GeometryValue, right: CGFloat) -> GeometryValue {
switch left {
case let .height(value):
return .height(Int(CGFloat(value) * right))
return .height(value * right)
case let .width(value):
return .width(Int(CGFloat(value) * right))
return .width(value * right)
case let .scale(value):
return .scale(value * right)
}
}
}
29 changes: 15 additions & 14 deletions frameworks/speculid/Models/Geometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,29 @@ public struct BadGeometryStringValueError: Error {
public struct BadGeometryCGSizeValueError: Error {
public let size: CGSize
}
extension GeometryValue: CustomStringConvertible {
func scaledBy(_ scale: Int) -> GeometryValue {
extension GeometryValue {
func scaledBy(_ scale: CGFloat) -> GeometryValue {
switch self {
case let .width(value) : return .width(value * scale)
case let .height(value): return .height(value * scale)
case let .scale(value): return .scale(CGFloat(scale) * value)
}
}

public var description: String {
switch self {
case let .width(value): return "\(value)"
case let .height(value): return "x\(value)"
case let .scale(value): return "\(value)x"
}
}

public init?(string: String) {
if let intValue = Int(string) {
self = .width(intValue)
} else if let intValue = Int(String(string[string.index(after: string.startIndex)...])), string[string.startIndex] == "x" {
self = .height(intValue)

if let intValue = Double(string) {
self = .width(CGFloat(intValue))
} else if let intValue = Double(String(string[string.index(after: string.startIndex)...])), string[string.startIndex] == "x" {
self = .height(CGFloat(intValue))
} else {
return nil
}
Expand All @@ -41,16 +44,16 @@ extension Geometry {
}

if preferWidth == false {
value = .height(Int(size.height))
value = .height(size.height)
} else {
value = .width(Int(size.width))
value = .width(size.width)
}
}
}

public struct Geometry: GeometryProtocol, Codable {
public let value: GeometryValue
public func text(scaledBy scale: Int) -> String {
public func text(scaledBy scale: CGFloat) -> String {
return value.scaledBy(scale).description
}

Expand All @@ -75,18 +78,16 @@ public struct Geometry: GeometryProtocol, Codable {
try container.encode(value.description)
}

public var description: String {
return value.description
}

public init(value: GeometryValue) {
self.value = value
}

internal init(dimension: CairoSVG.Dimension, value: Int) {
internal init?(dimension: CairoSVG.Dimension, value: CGFloat) {
switch dimension {
case .height: self.value = .height(value)
case .width: self.value = .width(value)
case .scale: self.value = .scale(value)
case .unspecified: return nil
}
}
}
7 changes: 5 additions & 2 deletions frameworks/speculid/Models/GeometryValue.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Foundation

@available(*, deprecated: 2.0.0)
public enum GeometryValue {
case width(Int)
case height(Int)
case width(CGFloat)
case height(CGFloat)
case scale(CGFloat)
}
14 changes: 9 additions & 5 deletions frameworks/speculid/Models/ImageSpecification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import CairoSVG

let _file = aDecoder.decodeObject(forKey: "file") as? ImageFileProtocol
let _dimensionValue = aDecoder.decodeObject(forKey: "geometryDimensionValue") as? UInt
let _value = aDecoder.decodeObject(forKey: "geometryValue") as? Int
let _value = aDecoder.decodeObject(forKey: "geometryValue") as? CGFloat
let backgroundColor = aDecoder.decodeObject(forKey: "backgroundColor") as? CairoColorProtocol
let _removeAlphaChannel = aDecoder.decodeObject(forKey: "removeAlphaChannel") as? Bool

Expand All @@ -31,10 +31,10 @@ import CairoSVG
}

public let file: ImageFileProtocol
public let geometryDimension: Geometry
public let geometryDimension: Geometry?
public let removeAlphaChannel: Bool
public let backgroundColor: CairoColorProtocol?
public init(file: ImageFileProtocol, geometryDimension: Geometry, removeAlphaChannel: Bool = false, backgroundColor: CairoColorProtocol? = nil) {
public init(file: ImageFileProtocol, geometryDimension: Geometry? = nil, removeAlphaChannel: Bool = false, backgroundColor: CairoColorProtocol? = nil) {
self.file = file
self.geometryDimension = geometryDimension
self.removeAlphaChannel = removeAlphaChannel
Expand All @@ -43,9 +43,13 @@ import CairoSVG
}

public var geometry: CairoSVG.GeometryDimension {
guard let geometryDimension = self.geometryDimension else {
return CairoSVG.GeometryDimensionUnspecified
}
switch geometryDimension.value {
case let .height(value): return CairoSVG.GeometryDimension(value: Int32(value), dimension: .height)
case let .width(value): return CairoSVG.GeometryDimension(value: Int32(value), dimension: .width)
case let .height(value): return CairoSVG.GeometryDimension(value: value, dimension: .height)
case let .width(value): return CairoSVG.GeometryDimension(value: value, dimension: .width)
case let .scale(value): return CairoSVG.GeometryDimension(value: value, dimension: .scale)
}
}
}
7 changes: 0 additions & 7 deletions frameworks/speculid/Models/ScaledGeometry.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import Foundation
public struct ScaledGeometry: GeometryProtocol {
public func text(scaledBy scale: Int) -> String {
return base.scaling(by: scale * self.scale).description
}

public let base: GeometryProtocol
public let scale: Int
Expand All @@ -12,10 +9,6 @@ public struct ScaledGeometry: GeometryProtocol {
self.scale = scale
}

public var description: String {
return base.text(scaledBy: scale)
}

public var value: GeometryValue {

return base.value * CGFloat(scale)
Expand Down
4 changes: 1 addition & 3 deletions frameworks/speculid/Protocols/GeometryProtocol.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Foundation

public protocol GeometryProtocol: CustomStringConvertible {
@available(*, deprecated: 2.0.0)
func text(scaledBy scale: Int) -> String
public protocol GeometryProtocol {

var value: GeometryValue {
get
Expand Down
2 changes: 1 addition & 1 deletion __archive/shasum.sh → shasum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ while IFS= read -r -d $'\0' line; do
$speculid_path "$line" >/dev/null
done
wait
(cd $assets_dir && find . -type f \( -iname \*.icns -o -iname \*.png \) -print0 | sort -z | xargs -0 shasum -a 512 | shasum -a 512)
(cd $assets_dir && find . -type f \( -iname \*.icns -o -iname \*.png \) -print0 | sort -z | xargs -0 shasum -a 512 | shasum -a 512)

0 comments on commit c4e60ff

Please sign in to comment.