Browse Source

Updated tdfont, no more calls.

The Output routine handles calling CP437_to_Unicode.
Keep it simple.
Steve Thielemann 3 years ago
parent
commit
28ddc0e2c0
2 changed files with 34 additions and 87 deletions
  1. 24 41
      door/tdfont.go
  2. 10 46
      testdoor/testdoor.go

+ 24 - 41
door/tdfont.go

@@ -78,15 +78,6 @@ func (bf *BlockFont) GetCharacter(c int) [][]byte {
 	}
 }
 
-/*
-// expandBlock the number of strings, and make it match the length of [0].
-func __expandBlock(block *[]string) {
-	// l := len((*block)[0])
-	l := len([]rune((*block)[0]))
-	*block = append(*block, strings.Repeat(" ", l))
-}
-*/
-
 func expandBlock(block *[][]byte) {
 	// l := len((*block)[0])
 	l := len((*block)[0])
@@ -95,7 +86,7 @@ func expandBlock(block *[][]byte) {
 }
 
 // Given text, translate to thedraw font.
-func (bf *BlockFont) Output(input string) ([][]byte, int) {
+func (bf *BlockFont) Output(input string) ([]string, int) {
 	var out [][]byte
 	var max int
 
@@ -144,7 +135,16 @@ func (bf *BlockFont) Output(input string) ([][]byte, int) {
 		normalizeBlock(&out)
 		// fmt.Println("normalizeBlock done")
 	}
-	return out, len(out[0])
+
+	var output []string
+	for idx := range out {
+		if Unicode {
+			output = append(output, CP437_to_Unicode(string(out[idx])))
+		} else {
+			output = append(output, string(out[idx]))
+		}
+	}
+	return output, len(out[0])
 }
 
 type ColorFont struct {
@@ -152,26 +152,6 @@ type ColorFont struct {
 	Data       [][][]byte
 }
 
-/*
-// Make []strings all the same length
-func ___normalizeColor(block *[]string) int {
-	var max int
-	for _, line := range *block {
-		l := len([]rune(line))
-		if max < l {
-			max = l
-		}
-	}
-	for idx, line := range *block {
-		l := len([]rune(line))
-		if l < max {
-			(*block)[idx] += strings.Repeat(" \x0f", max-l/2)
-		}
-	}
-	return max
-}
-*/
-
 func normalizeColor(block *[][]byte) int {
 	var max int
 	for _, line := range *block {
@@ -225,13 +205,6 @@ func (cf *ColorFont) GetCharacter(c int) ([][]byte, int) {
 	}
 }
 
-/*
-func expandColor(block *[]string) {
-	l := len((*block)[0])
-	*block = append(*block, strings.Repeat(" \x0f", l/2))
-}
-*/
-
 func thedraw_to_ansi(c int) int {
 	trans := []int{0, 4, 2, 6, 1, 5, 3, 7}
 	return trans[c]
@@ -348,7 +321,7 @@ func expandColor(block *[][]byte, need int) {
 	*block = append(*block, bytes.Repeat(blank, need))
 }
 
-func (bf *ColorFont) Output(input string) ([][]byte, int) {
+func (bf *ColorFont) Output(input string) ([]string, int) {
 	var out [][]byte
 	var max int
 
@@ -416,7 +389,7 @@ func (bf *ColorFont) Output(input string) ([][]byte, int) {
 	}
 
 	if len(out) == 0 {
-		return out, 0
+		return []string{}, 0
 	}
 
 	// StringHexO(&out)
@@ -425,7 +398,17 @@ func (bf *ColorFont) Output(input string) ([][]byte, int) {
 	for idx := range out {
 		out[idx] = Colorize(out[idx])
 	}
-	return out, max
+
+	var output []string
+	for idx := range out {
+		if Unicode {
+			output = append(output, CP437_to_Unicode(string(out[idx])))
+		} else {
+			output = append(output, string(out[idx]))
+		}
+	}
+
+	return output, max
 }
 
 func CP437Bytes_to_Unicode(cp437 []byte) string {

+ 10 - 46
testdoor/testdoor.go

@@ -102,7 +102,7 @@ func display_ansi(d *door.Door) {
 }
 
 func font_demo(d *door.Door) {
-	var output [][]byte
+	var output []string
 	var l int
 	var centering string
 
@@ -117,11 +117,7 @@ func font_demo(d *door.Door) {
 		centering = strings.Repeat(" ", (door.Width-l)/2)
 
 		for _, o := range output {
-			if door.Unicode {
-				d.Write(fmt.Sprintf("%s%s%s", centering, door.CP437_to_Unicode(string(o)), door.Reset) + door.CRNL)
-			} else {
-				d.Write(fmt.Sprintf("%s%s%s", centering, string(o), door.Reset) + door.CRNL)
-			}
+			d.Write(fmt.Sprintf("%s%s%s", centering, o, door.Reset) + door.CRNL)
 		}
 		d.Write(door.CRNL)
 	}
@@ -136,11 +132,7 @@ func font_demo(d *door.Door) {
 		centering = strings.Repeat(" ", (door.Width-l)/2)
 
 		for _, o := range output {
-			if door.Unicode {
-				d.Write(centering + door.CP437_to_Unicode(string(o)) + door.Reset + door.CRNL)
-			} else {
-				d.Write(centering + string(o) + door.Reset + door.CRNL)
-			}
+			d.Write(centering + o + door.Reset + door.CRNL)
 		}
 		d.Write(door.CRNL)
 	}
@@ -155,11 +147,7 @@ func font_demo(d *door.Door) {
 		centering = strings.Repeat(" ", (door.Width-l)/2)
 
 		for _, o := range output {
-			if door.Unicode {
-				d.Write(centering + door.CP437_to_Unicode(string(o)) + door.Reset + door.CRNL)
-			} else {
-				d.Write(centering + string(o) + door.Reset + door.CRNL)
-			}
+			d.Write(centering + o + door.Reset + door.CRNL)
 		}
 		d.Write(door.CRNL)
 	}
@@ -175,11 +163,7 @@ func font_demo(d *door.Door) {
 		centering = strings.Repeat(" ", (door.Width-l)/2)
 
 		for _, o := range output {
-			if door.Unicode {
-				d.Write(centering + door.CP437_to_Unicode(string(o)) + door.Reset + door.CRNL)
-			} else {
-				d.Write(centering + string(o) + door.Reset + door.CRNL)
-			}
+			d.Write(centering + o + door.Reset + door.CRNL)
 		}
 		d.Write(door.CRNL)
 	}
@@ -194,11 +178,7 @@ func font_demo(d *door.Door) {
 		centering = strings.Repeat(" ", (door.Width-l)/2)
 
 		for _, o := range output {
-			if door.Unicode {
-				d.Write(centering + door.CP437_to_Unicode(string(o)) + door.Reset + door.CRNL)
-			} else {
-				d.Write(centering + string(o) + door.Reset + door.CRNL)
-			}
+			d.Write(centering + o + door.Reset + door.CRNL)
 		}
 		d.Write(door.CRNL)
 	}
@@ -209,11 +189,7 @@ func font_demo(d *door.Door) {
 		centering = strings.Repeat(" ", (door.Width-l)/2)
 
 		for _, o := range output {
-			if door.Unicode {
-				d.Write(centering + door.CP437_to_Unicode(string(o)) + door.Reset + door.CRNL)
-			} else {
-				d.Write(centering + string(o) + door.Reset + door.CRNL)
-			}
+			d.Write(centering + o + door.Reset + door.CRNL)
 		}
 		d.Write(door.CRNL)
 	}
@@ -229,11 +205,7 @@ func font_demo(d *door.Door) {
 		centering = strings.Repeat(" ", (door.Width-l)/2)
 
 		for _, o := range output {
-			if door.Unicode {
-				d.Write(centering + door.CP437_to_Unicode(string(o)) + door.Reset + door.CRNL)
-			} else {
-				d.Write(centering + string(o) + door.Reset + door.CRNL)
-			}
+			d.Write(centering + o + door.Reset + door.CRNL)
 		}
 		d.Write(door.CRNL)
 	}
@@ -247,11 +219,7 @@ func font_demo(d *door.Door) {
 		centering = strings.Repeat(" ", (door.Width-l)/2)
 
 		for _, o := range output {
-			if door.Unicode {
-				d.Write(centering + door.CP437_to_Unicode(string(o)) + door.Reset + door.CRNL)
-			} else {
-				d.Write(centering + string(o) + door.Reset + door.CRNL)
-			}
+			d.Write(centering + o + door.Reset + door.CRNL)
 		}
 		d.Write(door.CRNL)
 	}
@@ -265,11 +233,7 @@ func font_demo(d *door.Door) {
 		centering = strings.Repeat(" ", (door.Width-l)/2)
 
 		for _, o := range output {
-			if door.Unicode {
-				d.Write(centering + door.CP437_to_Unicode(string(o)) + door.Reset + door.CRNL)
-			} else {
-				d.Write(centering + string(o) + door.Reset + door.CRNL)
-			}
+			d.Write(centering + o + door.Reset + door.CRNL)
 		}
 		d.Write(door.CRNL)
 	}