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"
|
highString := " ghijklmnopqrstuvwxyz"
|
||||||
lowString := " GHIJKLMNOPQRSTUVWXY"
|
lowString := " GHIJKLMNOPQRSTUVWXY"
|
||||||
|
|
||||||
repeatStr := ""
|
encode := func(count int) string {
|
||||||
for repeatCount > maxRepeat {
|
var singleRepeatStr strings.Builder
|
||||||
repeatStr += getRepeatCode(maxRepeat, char)
|
high := count / 20
|
||||||
repeatCount -= maxRepeat
|
low := count % 20
|
||||||
}
|
|
||||||
|
|
||||||
high := repeatCount / 20
|
|
||||||
low := repeatCount % 20
|
|
||||||
|
|
||||||
if high > 0 {
|
if high > 0 {
|
||||||
repeatStr += string(highString[high])
|
singleRepeatStr.WriteByte(highString[high])
|
||||||
}
|
}
|
||||||
if low > 0 {
|
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.
|
// CompressASCII compresses the ASCII data of a ZPL Graphic Field using RLE.
|
||||||
|
|||||||
Reference in New Issue
Block a user