File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -9,18 +9,29 @@ import SwiftUI
99
1010public struct Code39View : View {
1111
12- private let barcode : [ BarWidth ]
12+ public let content : String
1313
1414 public init ( _ content: String ) {
15- self . barcode = encodeToCode39 ( content)
15+ self . content = content
1616 }
1717
1818 public var body : some View {
1919 Canvas { context, size in
20- let intercharacterGapCount = ( barcode. count % 9 ) - 1
21- let narrowBarWidth = size. width / CGFloat( ( ( ( ( barcode. count - intercharacterGapCount) / 9 ) * 15 ) + intercharacterGapCount) )
20+ let prefixSuffixCount = 2
21+
22+ let characterCount = content. count + prefixSuffixCount
23+
24+ let gapCount = content. count + 1
25+
26+ let weightPerCharacter = 15
27+
28+ let totalUnits = ( characterCount * weightPerCharacter) + gapCount
29+
30+ let narrowBarWidth = size. width / CGFloat( totalUnits)
31+
2232 var currentX : CGFloat = 0
23- for (index, barWidth) in barcode. enumerated ( ) {
33+
34+ for (index, barWidth) in encodeToCode39 ( content) . enumerated ( ) {
2435 let barColor : Color = index % 2 == 0 ? . black : . white
2536 let barWidth : CGFloat = barWidth == . narrow ? narrowBarWidth : narrowBarWidth * 3
2637 var barPath = Path ( )
You can’t perform that action at this time.
0 commit comments