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

@@ -9,10 +9,12 @@ import (
"io/ioutil"
r "math/rand"
"net/http"
"regexp"
"strconv"
"strings"
"sync"
"time"
"unicode"
)
type API struct {
@@ -155,3 +157,74 @@ func FormatPrintOrderItem(foodName string, quantity int, price float64) string {
result += "<BR>"
return result
}
const (
ROW_MAX_CHAR_LEN = 34
LAST_ROW_MAX_NAME_CHAR_LEN = 16
MAX_NAME_CHAR_LEN = 16
MaxLineLength = 30
LineLength = 32
NewLineLength = 28
)
//不带单价版本
func FormatPrintOrderItemV2(foodName string, quantity, cnt int) string {
var (
result = ""
restLen int
)
quantityStr := strconv.Itoa(quantity)
foodNameLen := CalWidth(foodName) + 3
if foodNameLen >= MaxLineLength {
if n := foodNameLen / LineLength; n > 0 {
restLen = foodNameLen % LineLength
} else {
restLen = foodNameLen - LineLength
}
result += `<font# bolder=0 height=2 width=1>` + utils.Int2Str(cnt) + `.` + foodName
result += StrRepeat(" ", MaxLineLength-restLen) + `x` + quantityStr + `</font#>`
} else {
result += `<font# bolder=0 height=2 width=1>` + utils.Int2Str(cnt) + `.` + foodName + StrRepeat(" ", MaxLineLength-foodNameLen) + `x` + quantityStr + `</font#>`
}
result += "<BR>"
fmt.Println(result)
return result
}
func FormatPrintOrderItemBigV2(foodName string, quantity, cnt int) string {
var (
result = ""
restLen int
)
quantityStr := strconv.Itoa(quantity)
foodNameLen := CalWidth(foodName) + 3
if foodNameLen >= MaxLineLength {
if n := foodNameLen / LineLength; n > 0 {
restLen = foodNameLen % LineLength
} else {
restLen = foodNameLen - LineLength
}
result += `<font# bolder=1 height=2 width=1>` + utils.Int2Str(cnt) + `.` + foodName
result += StrRepeat(" ", MaxLineLength-restLen) + `x` + quantityStr + `</font#>`
} else {
result += `<font# bolder=1 height=2 width=1>` + utils.Int2Str(cnt) + `.` + foodName + StrRepeat(" ", MaxLineLength-foodNameLen) + `x` + quantityStr + `</font#>`
}
result += "<BR>"
fmt.Println(result)
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
}