|
@@ -12,6 +12,22 @@ type BlockFont struct {
|
|
|
data [][][]byte
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+func BytesHexed(output []byte) {
|
|
|
+ fmt.Printf("BH: ")
|
|
|
+ for _, ch := range output {
|
|
|
+ fmt.Printf("%02x ", ch)
|
|
|
+ }
|
|
|
+ fmt.Println("")
|
|
|
+}
|
|
|
+
|
|
|
+func BytesArrayHexed(output *[][]byte) {
|
|
|
+ for _, out := range *output {
|
|
|
+ BytesHexed(out)
|
|
|
+ }
|
|
|
+}
|
|
|
+*/
|
|
|
+
|
|
|
// Make []strings all the same length
|
|
|
func normalizeBlock(block *[][]byte) {
|
|
|
var max int
|
|
@@ -77,14 +93,16 @@ func expandBlock(block *[][]byte) {
|
|
|
}
|
|
|
|
|
|
// Given text, translate to thedraw font.
|
|
|
-func (bf *BlockFont) Output(input string) [][]byte {
|
|
|
+func (bf *BlockFont) Output(input string) ([][]byte, int) {
|
|
|
var out [][]byte
|
|
|
+ var max int
|
|
|
|
|
|
for _, ch := range input {
|
|
|
// fmt.Printf("%d %x\n", ch, ch)
|
|
|
block := bf.GetCharacter(int(ch))
|
|
|
// fmt.Println("ok")
|
|
|
l := len(block)
|
|
|
+ max += l
|
|
|
if l != 0 {
|
|
|
if len(out) == 0 {
|
|
|
// First time
|
|
@@ -118,7 +136,7 @@ func (bf *BlockFont) Output(input string) [][]byte {
|
|
|
normalizeBlock(&out)
|
|
|
// fmt.Println("normalizeBlock done")
|
|
|
}
|
|
|
- return out
|
|
|
+ return out, len(out[0])
|
|
|
}
|
|
|
|
|
|
type ColorFont struct {
|
|
@@ -156,9 +174,13 @@ func normalizeColor(block *[][]byte) int {
|
|
|
// l := len(line)
|
|
|
blank := []byte{0x20, 0x0f}
|
|
|
for len((*block)[idx]) < max {
|
|
|
- for _, b := range blank {
|
|
|
- (*block)[idx] = append((*block)[idx], b)
|
|
|
- }
|
|
|
+ (*block)[idx] = append((*block)[idx], blank...)
|
|
|
+
|
|
|
+ /*
|
|
|
+ for _, b := range blank {
|
|
|
+ (*block)[idx] = append((*block)[idx], b)
|
|
|
+ }
|
|
|
+ */
|
|
|
// (*block)[idx] += strings.Repeat(" \x0f", max-l/2)
|
|
|
}
|
|
|
}
|
|
@@ -171,7 +193,7 @@ func (cf *ColorFont) GetCharacter(c int) ([][]byte, int) {
|
|
|
if c == 32 {
|
|
|
blank := []byte{0x20, 0x0f, 0x20, 0x0f}
|
|
|
result = append(result, blank) // " \x0f \x0f")
|
|
|
- return result, len(result[0])
|
|
|
+ return result, len(result[0]) / 2
|
|
|
}
|
|
|
|
|
|
if c >= 33 && c <= 126 {
|
|
@@ -181,7 +203,11 @@ func (cf *ColorFont) GetCharacter(c int) ([][]byte, int) {
|
|
|
return result, 0
|
|
|
}
|
|
|
result = cf.data[cf.characters[c]]
|
|
|
+ // fmt.Println("Character:")
|
|
|
+ // BytesArrayHexed(&result)
|
|
|
+ // fmt.Println("normalizing...")
|
|
|
max := normalizeColor(&result)
|
|
|
+ // BytesArrayHexed(&result)
|
|
|
// StringHexO(&result)
|
|
|
return result, max
|
|
|
} else {
|
|
@@ -271,12 +297,12 @@ func Colorize(input []byte) []byte {
|
|
|
// runes := []rune(input)
|
|
|
var previous int
|
|
|
|
|
|
- // StringHexed(input)
|
|
|
+ // BytesHexed(input)
|
|
|
|
|
|
for pos := 0; pos < len(input); pos += 2 {
|
|
|
ch := input[pos]
|
|
|
color := int(input[pos+1])
|
|
|
- // fmt.Printf("%d : %d / %x, %d\n", pos, ch, ch, color)
|
|
|
+ // fmt.Printf("%d : CH %d / %x, Color %d / %x\n", pos, ch, ch, color, color)
|
|
|
colorstring := ColorOutput(previous, color)
|
|
|
for _, c := range []byte(colorstring) {
|
|
|
result = append(result, c)
|
|
@@ -304,13 +330,17 @@ func expandColor(block *[][]byte, need int) {
|
|
|
*block = append(*block, bytes.Repeat(blank, need))
|
|
|
}
|
|
|
|
|
|
-func (bf *ColorFont) Output(input string) [][]byte {
|
|
|
+func (bf *ColorFont) Output(input string) ([][]byte, int) {
|
|
|
var out [][]byte
|
|
|
var max int
|
|
|
|
|
|
for _, ch := range input {
|
|
|
// fmt.Printf("%d %x\n", ch, ch)
|
|
|
block, blklen := bf.GetCharacter(int(ch))
|
|
|
+ if blklen == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
l := len(block)
|
|
|
max += blklen
|
|
|
if l != 0 {
|
|
@@ -323,14 +353,21 @@ func (bf *ColorFont) Output(input string) [][]byte {
|
|
|
if len(out) != 0 {
|
|
|
for l > len(out) {
|
|
|
// We need to expand the out
|
|
|
- expandColor(&out, max-blklen)
|
|
|
+ expandColor(&out, len(out[0])/2)
|
|
|
// ExpandColor(&out)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for l > len(block) {
|
|
|
+ for len(out) > len(block) {
|
|
|
// We need to expand the block out
|
|
|
- expandColor(&block, len(block[0])/2)
|
|
|
+ expandColor(&block, len(block)/2)
|
|
|
+ }
|
|
|
+
|
|
|
+ // Normalizing the character blocks
|
|
|
+ normalizeColor(&block)
|
|
|
+
|
|
|
+ if len(out) != len(block) {
|
|
|
+ panic(fmt.Sprintf("len(out) %d != len(block) %d", len(out), len(block)))
|
|
|
}
|
|
|
|
|
|
// Ok, we have something!
|
|
@@ -350,12 +387,17 @@ func (bf *ColorFont) Output(input string) [][]byte {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ if len(out) == 0 {
|
|
|
+ return out, 0
|
|
|
+ }
|
|
|
+
|
|
|
// StringHexO(&out)
|
|
|
+ max = len(out[0]) / 2
|
|
|
|
|
|
for idx, _ := range out {
|
|
|
out[idx] = Colorize(out[idx])
|
|
|
}
|
|
|
- return out
|
|
|
+ return out, max
|
|
|
}
|
|
|
|
|
|
func CP437Bytes_to_Unicode(cp437 []byte) string {
|