|
@@ -31,8 +31,15 @@ func FontFixup(offsets []uint16, data *[]byte) bool {
|
|
return fixed
|
|
return fixed
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func StripANSIColors(text string) string {
|
|
|
|
+ var re *regexp.Regexp
|
|
|
|
+
|
|
|
|
+ re, _ = regexp.Compile("\x1b\\[[0-9;]*m")
|
|
|
|
+ return re.ReplaceAllString(text, "")
|
|
|
|
+}
|
|
|
|
+
|
|
func Show(parts []string) {
|
|
func Show(parts []string) {
|
|
- reset := "\x1b[0m"
|
|
|
|
|
|
+ var reset string = "\x1b[0m"
|
|
|
|
|
|
if len(parts) > 0 {
|
|
if len(parts) > 0 {
|
|
for _, line := range parts {
|
|
for _, line := range parts {
|
|
@@ -63,50 +70,158 @@ func FontInfo(characters []int) (lower bool, lowerUnique bool, available string)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-func ShowBlockFont(name string, bf *door.BlockFont) {
|
|
|
|
- low, uniq, avail := FontInfo(bf.Characters)
|
|
|
|
- fmt.Printf("Font: %s (LowerCase %t, Unique Lower %t, [%s]\n", name, low, uniq, avail)
|
|
|
|
|
|
+func ShowBlockFontSize(bf *door.BlockFont, text string, width int) {
|
|
|
|
+ var output []string
|
|
|
|
+ output, _ = bf.Output(text)
|
|
|
|
+ if width == 0 || len(output[0]) < width {
|
|
|
|
+ Show(output)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- output, _ := bf.Output("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
- Show(output)
|
|
|
|
|
|
+ var pos int = 1
|
|
|
|
|
|
- if low && uniq {
|
|
|
|
- output, _ := bf.Output("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
|
|
+ for text != "" {
|
|
|
|
+ nextPart:
|
|
|
|
+ for pos = 1; pos < len(text); pos++ {
|
|
|
|
+ output, _ = bf.Output(text[:pos])
|
|
|
|
+
|
|
|
|
+ if len(output[0]) >= width {
|
|
|
|
+ // use previous
|
|
|
|
+ output, _ = bf.Output(text[:pos-1])
|
|
|
|
+ Show(output)
|
|
|
|
+ text = text[pos-1:]
|
|
|
|
+ goto nextPart
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ output, _ = bf.Output(text)
|
|
Show(output)
|
|
Show(output)
|
|
|
|
+ text = ""
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
|
|
- leftovers := avail
|
|
|
|
- reg, _ := regexp.Compile("[a-zA-Z]+")
|
|
|
|
- left := reg.ReplaceAllString(leftovers, "")
|
|
|
|
|
|
+func ShowBlockFont(name string, bf *door.BlockFont, width int) {
|
|
|
|
+ var low, uniq bool
|
|
|
|
+ var avail string
|
|
|
|
+ low, uniq, avail = FontInfo(bf.Characters)
|
|
|
|
+ fmt.Printf("Font: %s (LowerCase %t, Unique Lower %t, [%s]\n", name, low, uniq, avail)
|
|
|
|
+
|
|
|
|
+ ShowBlockFontSize(bf, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", width)
|
|
|
|
+ /*
|
|
|
|
+ var output []string
|
|
|
|
+ output, _ = bf.Output("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
+ Show(output)
|
|
|
|
+ */
|
|
|
|
+ if low && uniq {
|
|
|
|
+ ShowBlockFontSize(bf, "abcdefghijklmnopqrstuvwxyz", width)
|
|
|
|
+ /*
|
|
|
|
+ output, _ = bf.Output("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
+ Show(output)
|
|
|
|
+ */
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var leftovers string = avail
|
|
|
|
+ var reg *regexp.Regexp
|
|
|
|
+ reg, _ = regexp.Compile("[a-zA-Z]+")
|
|
|
|
+ var left string = reg.ReplaceAllString(leftovers, "")
|
|
// output, _ = bf.Output("abcdef")
|
|
// output, _ = bf.Output("abcdef")
|
|
// Show(output)
|
|
// Show(output)
|
|
if len(left) > 0 {
|
|
if len(left) > 0 {
|
|
- output, _ = bf.Output(left)
|
|
|
|
- Show(output)
|
|
|
|
|
|
+ ShowBlockFontSize(bf, left, width)
|
|
|
|
+ /*
|
|
|
|
+ output, _ = bf.Output(left)
|
|
|
|
+ Show(output)
|
|
|
|
+ */
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func ShowColorFont(name string, cf *door.ColorFont) {
|
|
|
|
- low, uniq, avail := FontInfo(cf.Characters)
|
|
|
|
- fmt.Printf("Font: %s (LowerCase %t, Unique Lower %t, [%s]\n", name, low, uniq, avail)
|
|
|
|
|
|
+func ShowColorFontSize(bf *door.ColorFont, text string, width int) {
|
|
|
|
+ var output []string
|
|
|
|
+ output, _ = bf.Output(text)
|
|
|
|
+ if width == 0 || len(output[0]) < width {
|
|
|
|
+ Show(output)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- // fmt.Printf("Font: %s\n", name)
|
|
|
|
- output, _ := cf.Output("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
- Show(output)
|
|
|
|
|
|
+ // Guessing doesn't work very well
|
|
|
|
+ var pos int = 1
|
|
|
|
+
|
|
|
|
+ for text != "" {
|
|
|
|
+ nextPart:
|
|
|
|
+ // fmt.Printf("TEXT: [%s]\n", text)
|
|
|
|
+ for pos = 1; pos < len(text); pos++ {
|
|
|
|
+ output, _ = bf.Output(text[:pos])
|
|
|
|
+ // fmt.Println(pos, len(StripANSIColors(output[0])))
|
|
|
|
+
|
|
|
|
+ if len(StripANSIColors(output[0])) >= width {
|
|
|
|
+ // use previous
|
|
|
|
+ output, _ = bf.Output(text[:pos-1])
|
|
|
|
+ // fmt.Println("OUT:", text[:pos-1])
|
|
|
|
+ Show(output)
|
|
|
|
+ text = text[pos-1:]
|
|
|
|
+ // fmt.Println("TEXT:", text)
|
|
|
|
+ goto nextPart
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ output, _ = bf.Output(text)
|
|
|
|
+ Show(output)
|
|
|
|
+ text = ""
|
|
|
|
+ }
|
|
|
|
|
|
- if low && uniq {
|
|
|
|
- output, _ := cf.Output("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
|
|
+ /*
|
|
|
|
+ var guess int = len(StripANSIColors(output[0])) / len(text)
|
|
|
|
+ guess = (width / guess)
|
|
|
|
+
|
|
|
|
+ for text != "" {
|
|
|
|
+ var part string
|
|
|
|
+ if guess >= len(text) {
|
|
|
|
+ part = text
|
|
|
|
+ } else {
|
|
|
|
+ part = text[0:guess]
|
|
|
|
+ }
|
|
|
|
+ output, _ = bf.Output(part)
|
|
|
|
+ Show(output)
|
|
|
|
+ if guess >= len(text) {
|
|
|
|
+ text = ""
|
|
|
|
+ } else {
|
|
|
|
+ text = text[guess:]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+func ShowColorFont(name string, cf *door.ColorFont, width int) {
|
|
|
|
+ var low, uniq bool
|
|
|
|
+ var avail string
|
|
|
|
+ low, uniq, avail = FontInfo(cf.Characters)
|
|
|
|
+ fmt.Printf("Font: %s (LowerCase %t, Unique Lower %t, [%s]\n", name, low, uniq, avail)
|
|
|
|
+
|
|
|
|
+ ShowColorFontSize(cf, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", width)
|
|
|
|
+ /*
|
|
|
|
+ // fmt.Printf("Font: %s\n", name)
|
|
|
|
+ var output []string
|
|
|
|
+ output, _ = cf.Output("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
Show(output)
|
|
Show(output)
|
|
|
|
+ */
|
|
|
|
+ if low && uniq {
|
|
|
|
+ ShowColorFontSize(cf, "abcdefghijklmnopqrstuvwxyz", width)
|
|
|
|
+ /*
|
|
|
|
+ output, _ = cf.Output("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
+ Show(output)
|
|
|
|
+ */
|
|
}
|
|
}
|
|
|
|
|
|
- leftovers := avail
|
|
|
|
- reg, _ := regexp.Compile("[a-zA-Z]+")
|
|
|
|
- left := reg.ReplaceAllString(leftovers, "")
|
|
|
|
|
|
+ var leftovers string = avail
|
|
|
|
+ var reg *regexp.Regexp
|
|
|
|
+ reg, _ = regexp.Compile("[a-zA-Z]+")
|
|
|
|
+ var left string = reg.ReplaceAllString(leftovers, "")
|
|
// output, _ = bf.Output("abcdef")
|
|
// output, _ = bf.Output("abcdef")
|
|
// Show(output)
|
|
// Show(output)
|
|
if len(left) > 0 {
|
|
if len(left) > 0 {
|
|
- output, _ = cf.Output(left)
|
|
|
|
- Show(output)
|
|
|
|
|
|
+ ShowColorFontSize(cf, left, width)
|
|
|
|
+ /*
|
|
|
|
+ output, _ = cf.Output(left)
|
|
|
|
+ Show(output)
|
|
|
|
+ */
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -154,7 +269,7 @@ func ShowFont(name string, f FontOutput) {
|
|
*/
|
|
*/
|
|
|
|
|
|
// displays fonts
|
|
// displays fonts
|
|
-func DisplayFonts(filename string, fonts []string) {
|
|
|
|
|
|
+func DisplayFonts(filename string, fonts []string, width int) {
|
|
f, err := os.Open(filename)
|
|
f, err := os.Open(filename)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Printf("Open(%s): %s\n", filename, err)
|
|
fmt.Printf("Open(%s): %s\n", filename, err)
|
|
@@ -233,7 +348,7 @@ func DisplayFonts(filename string, fonts []string) {
|
|
fmt.Printf("%s : BLOCK FONT FAIL\n", Name)
|
|
fmt.Printf("%s : BLOCK FONT FAIL\n", Name)
|
|
} else {
|
|
} else {
|
|
// ShowFont(Name, &bf)
|
|
// ShowFont(Name, &bf)
|
|
- ShowBlockFont(Name, &bf)
|
|
|
|
|
|
+ ShowBlockFont(Name, &bf, width)
|
|
}
|
|
}
|
|
case 2:
|
|
case 2:
|
|
cf := ExtractColor(Name, letterOffsets, data)
|
|
cf := ExtractColor(Name, letterOffsets, data)
|
|
@@ -241,7 +356,7 @@ func DisplayFonts(filename string, fonts []string) {
|
|
fmt.Printf("%s : COLOR FONT FAIL\n", Name)
|
|
fmt.Printf("%s : COLOR FONT FAIL\n", Name)
|
|
} else {
|
|
} else {
|
|
// ShowFont(Name, &cf)
|
|
// ShowFont(Name, &cf)
|
|
- ShowColorFont(Name, &cf)
|
|
|
|
|
|
+ ShowColorFont(Name, &cf, width)
|
|
}
|
|
}
|
|
default:
|
|
default:
|
|
fmt.Printf("Sorry, I can't handle Font: %s Type %d!\n", Name, FontType)
|
|
fmt.Printf("Sorry, I can't handle Font: %s Type %d!\n", Name, FontType)
|
|
@@ -255,14 +370,14 @@ func DisplayFonts(filename string, fonts []string) {
|
|
if len(bf.Characters) == 0 {
|
|
if len(bf.Characters) == 0 {
|
|
fmt.Printf("%s : BLOCK FONT FAIL\n", Name)
|
|
fmt.Printf("%s : BLOCK FONT FAIL\n", Name)
|
|
} else {
|
|
} else {
|
|
- ShowBlockFont(Name, &bf)
|
|
|
|
|
|
+ ShowBlockFont(Name, &bf, width)
|
|
}
|
|
}
|
|
case 2:
|
|
case 2:
|
|
cf := ExtractColor(Name, letterOffsets, data)
|
|
cf := ExtractColor(Name, letterOffsets, data)
|
|
if len(cf.Characters) == 0 {
|
|
if len(cf.Characters) == 0 {
|
|
fmt.Printf("%s : COLOR FONT FAIL\n", Name)
|
|
fmt.Printf("%s : COLOR FONT FAIL\n", Name)
|
|
} else {
|
|
} else {
|
|
- ShowColorFont(Name, &cf)
|
|
|
|
|
|
+ ShowColorFont(Name, &cf, width)
|
|
}
|
|
}
|
|
default:
|
|
default:
|
|
fmt.Printf("Sorry, I can't handle Font: %s Type %d!\n", Name, FontType)
|
|
fmt.Printf("Sorry, I can't handle Font: %s Type %d!\n", Name, FontType)
|