Refine ZPL repeat code generation for CompressedASCII (#10)
This commit is contained in:
39
zplgfa.go
39
zplgfa.go
@@ -71,23 +71,40 @@ func getRepeatCode(repeatCount int, char string) string {
|
||||
highString := " ghijklmnopqrstuvwxyz"
|
||||
lowString := " GHIJKLMNOPQRSTUVWXY"
|
||||
|
||||
repeatStr := ""
|
||||
for repeatCount > maxRepeat {
|
||||
repeatStr += getRepeatCode(maxRepeat, char)
|
||||
repeatCount -= maxRepeat
|
||||
}
|
||||
|
||||
high := repeatCount / 20
|
||||
low := repeatCount % 20
|
||||
encode := func(count int) string {
|
||||
var singleRepeatStr strings.Builder
|
||||
high := count / 20
|
||||
low := count % 20
|
||||
|
||||
if high > 0 {
|
||||
repeatStr += string(highString[high])
|
||||
singleRepeatStr.WriteByte(highString[high])
|
||||
}
|
||||
if low > 0 {
|
||||
repeatStr += string(lowString[low])
|
||||
singleRepeatStr.WriteByte(lowString[low])
|
||||
}
|
||||
|
||||
return repeatStr + char
|
||||
singleRepeatStr.WriteString(char)
|
||||
return singleRepeatStr.String()
|
||||
}
|
||||
|
||||
if repeatCount > maxRepeat {
|
||||
var repeatStr strings.Builder
|
||||
remainder := repeatCount % maxRepeat
|
||||
quotient := repeatCount / maxRepeat
|
||||
|
||||
if remainder > 0 {
|
||||
repeatStr.WriteString(encode(remainder))
|
||||
}
|
||||
|
||||
maxEncoding := encode(maxRepeat)
|
||||
for i := 0; i < quotient; i++ {
|
||||
repeatStr.WriteString(maxEncoding)
|
||||
}
|
||||
|
||||
return repeatStr.String()
|
||||
}
|
||||
|
||||
return encode(repeatCount)
|
||||
}
|
||||
|
||||
// CompressASCII compresses the ASCII data of a ZPL Graphic Field using RLE.
|
||||
|
||||
Reference in New Issue
Block a user