Refine ZPL repeat code generation for CompressedASCII (#10)

This commit is contained in:
Copilot
2026-02-22 00:36:45 +02:00
committed by GitHub
parent 98464cac0a
commit b89d47a378

View File

@@ -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.