This commit is contained in:
richboo111
2023-04-25 10:31:54 +08:00
parent 352bb15636
commit 0901cfc573
12 changed files with 784 additions and 90 deletions

View File

@@ -10,9 +10,11 @@ import (
"golang.org/x/text/transform"
"io/ioutil"
"net/http"
"regexp"
"strconv"
"strings"
"time"
"unicode"
)
/**
@@ -169,3 +171,48 @@ func FormatPrintOrderItem(foodName string, quantity int, price float64) string {
result += "<BR>"
return result
}
//正则计算宽度
func CalWidth(str string) int {
hzc := 0
for _, v := range str {
if unicode.Is(unicode.Han, v) {
hzc++
}
}
updateStr := regexp.MustCompile("[\u4e00-\u9fa5]{1,}").ReplaceAllString(str, "")
l := len(updateStr)
fmt.Println(hzc)
ans := 2*hzc + l
return ans
}
const (
MaxLineLength = 30
LineLength = 32
NewLineLength = 28
)
func FormatPrintOrderItemV2(foodName string, quantity, index int) string {
var (
restLen int
quantityStr = strconv.Itoa(quantity)
//quantityLen = CalcAsciiLenForPrint(quantityStr)
foodNameLen = CalWidth(foodName) + 3
result = ""
)
if foodNameLen >= MaxLineLength {
if n := foodNameLen / LineLength; n > 0 {
restLen = foodNameLen % LineLength
} else {
restLen = foodNameLen - LineLength
}
result += "<HB>" + utils.Int2Str(index) + `.` + foodName + "</HB>"
result += "<HB>" + StrRepeat(" ", MaxLineLength-restLen) + `x` + quantityStr + "</HB>"
} else {
result += "<HB>" + utils.Int2Str(index) + `.` + foodName + StrRepeat(" ", MaxLineLength-foodNameLen) + `x` + quantityStr + "</HB>"
}
//result += orderNameEmpty + "x" + quantityStr + StrRepeat(" ", MAX_QUANTITY_CHAR_LEN-quantityLen)
result += "<BR>"
return result
}