Skip to content

Commit

Permalink
Create swift.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
scchn committed Jan 9, 2024
1 parent 6c7c282 commit 8525280
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Swift

on: [push]

jobs:
build:
name: Swift on ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
4 changes: 2 additions & 2 deletions Sources/ZPLBuilder/Commands/FieldOrientation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public struct FieldOrientation: ZPLCommandConvertible {
public var justification: FieldJustification?
public var command: String {
if let justification {
"^FW\(orientation.rawValue),\(justification.rawValue)"
return "^FW\(orientation.rawValue),\(justification.rawValue)"
} else {
"^FW\(orientation.rawValue)"
return "^FW\(orientation.rawValue)"
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/ZPLBuilder/Commands/FieldOrigin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public struct FieldOrigin: ZPLCommandConvertible {
public var justification: FieldJustification?
public var command: String {
if let justification {
"^FO\(x),\(y),\(justification.rawValue)"
return "^FO\(x),\(y),\(justification.rawValue)"
} else {
"^FO\(x),\(y)"
return "^FO\(x),\(y)"
}
}
}
4 changes: 2 additions & 2 deletions Sources/ZPLBuilder/Commands/FieldTypeset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public struct FieldTypeset: ZPLCommandConvertible {
public var justification: FieldJustification?
public var command: String {
if let justification {
"^FT\(x),\(y),\(justification.rawValue)"
return "^FT\(x),\(y),\(justification.rawValue)"
} else {
"^FT\(x),\(y)"
return "^FT\(x),\(y)"
}
}

Expand Down
24 changes: 15 additions & 9 deletions Sources/ZPLBuilder/Utils/ZPLImageEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ public class ZPLImageEncoder {
}

public func encode(cgImage: CGImage, targetSize: CGSize?) -> ZPLImage? {
let width = if let width = targetSize?.width {
Int(width)
let width: Int
let height: Int

if let targetWidth = targetSize?.width {
width = Int(targetWidth)
} else {
cgImage.width
width = cgImage.width
}
let height = if let height = targetSize?.height {
Int(height)

if let targetHeight = targetSize?.height {
height = Int(targetHeight)
} else {
cgImage.height
height = cgImage.height
}

guard width > 0, height > 0, cgImage.width > 0, cgImage.height > 0 else {
Expand Down Expand Up @@ -110,10 +114,12 @@ public class ZPLImageEncoder {
componentValue <<= Self.componentValueSize - pos
}

let components = if componentValue <= 15 {
"0" + String(componentValue, radix: 16, uppercase: true)
let components: String

if componentValue <= 15 {
components = "0" + String(componentValue, radix: 16, uppercase: true)
} else {
String(componentValue, radix: 16, uppercase: true)
components = String(componentValue, radix: 16, uppercase: true)
}

block(x, y, components, x == width - 1)
Expand Down
12 changes: 6 additions & 6 deletions Sources/ZPLBuilder/ZPLBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import Foundation
@resultBuilder
public struct ZPLBuilder {
public static func buildBlock(_ components: ZPLComponent...) -> ZPLComponent {
ZPL(commands: components.flatMap(\.zpl.commands))
return ZPL(commands: components.flatMap(\.zpl.commands))
}

public static func buildArray(_ components: [ZPLComponent]) -> ZPLComponent {
ZPL(commands: components.flatMap(\.zpl.commands))
return ZPL(commands: components.flatMap(\.zpl.commands))
}

public static func buildEither(first component: ZPLComponent) -> ZPLComponent {
component
return component
}

public static func buildEither(second component: ZPLComponent) -> ZPLComponent {
component
return component
}

public static func buildOptional(_ component: ZPLComponent?) -> ZPLComponent {
if let component {
component
return component
} else {
ZPL(commands: [])
return ZPL(commands: [])
}
}
}

0 comments on commit 8525280

Please sign in to comment.