|
@@ -33,7 +33,7 @@ func normalizeBlock(block *[][]byte) {
|
|
var max int
|
|
var max int
|
|
// StringO(block)
|
|
// StringO(block)
|
|
for _, line := range *block {
|
|
for _, line := range *block {
|
|
- l := len(line)
|
|
|
|
|
|
+ var l int = len(line)
|
|
if max < l {
|
|
if max < l {
|
|
max = l
|
|
max = l
|
|
}
|
|
}
|
|
@@ -63,7 +63,7 @@ func (bf *BlockFont) GetCharacter(c int) [][]byte {
|
|
// 33-126 are the possible characters.
|
|
// 33-126 are the possible characters.
|
|
if c >= 33 && c <= 126 {
|
|
if c >= 33 && c <= 126 {
|
|
c -= 33
|
|
c -= 33
|
|
- idx := bf.Characters[c]
|
|
|
|
|
|
+ var idx int = bf.Characters[c]
|
|
if idx == -1 {
|
|
if idx == -1 {
|
|
// This character is not supported by this font.
|
|
// This character is not supported by this font.
|
|
return result
|
|
return result
|
|
@@ -80,8 +80,8 @@ func (bf *BlockFont) GetCharacter(c int) [][]byte {
|
|
|
|
|
|
func expandBlock(block *[][]byte) {
|
|
func expandBlock(block *[][]byte) {
|
|
// l := len((*block)[0])
|
|
// l := len((*block)[0])
|
|
- l := len((*block)[0])
|
|
|
|
- blank := []byte{0x20}
|
|
|
|
|
|
+ var l int = len((*block)[0])
|
|
|
|
+ var blank []byte = []byte{0x20}
|
|
*block = append(*block, bytes.Repeat(blank, l))
|
|
*block = append(*block, bytes.Repeat(blank, l))
|
|
}
|
|
}
|
|
|
|
|
|
@@ -94,7 +94,7 @@ func (bf *BlockFont) Output(input string) ([]string, int) {
|
|
// fmt.Printf("%d %x\n", ch, ch)
|
|
// fmt.Printf("%d %x\n", ch, ch)
|
|
block := bf.GetCharacter(int(ch))
|
|
block := bf.GetCharacter(int(ch))
|
|
// fmt.Println("ok")
|
|
// fmt.Println("ok")
|
|
- l := len(block)
|
|
|
|
|
|
+ var l int = len(block)
|
|
max += l
|
|
max += l
|
|
if l != 0 {
|
|
if l != 0 {
|
|
if len(out) == 0 {
|
|
if len(out) == 0 {
|
|
@@ -162,7 +162,7 @@ func normalizeColor(block *[][]byte) int {
|
|
}
|
|
}
|
|
for idx := range *block {
|
|
for idx := range *block {
|
|
// l := len(line)
|
|
// l := len(line)
|
|
- blank := []byte{0x20, 0x0f}
|
|
|
|
|
|
+ var blank []byte = []byte{0x20, 0x0f}
|
|
for len((*block)[idx]) < max {
|
|
for len((*block)[idx]) < max {
|
|
(*block)[idx] = append((*block)[idx], blank...)
|
|
(*block)[idx] = append((*block)[idx], blank...)
|
|
|
|
|
|
@@ -181,14 +181,14 @@ func (cf *ColorFont) GetCharacter(c int) ([][]byte, int) {
|
|
var result [][]byte
|
|
var result [][]byte
|
|
|
|
|
|
if c == 32 {
|
|
if c == 32 {
|
|
- blank := []byte{0x20, 0x0f, 0x20, 0x0f}
|
|
|
|
|
|
+ var blank []byte = []byte{0x20, 0x0f, 0x20, 0x0f}
|
|
result = append(result, blank) // " \x0f \x0f")
|
|
result = append(result, blank) // " \x0f \x0f")
|
|
return result, len(result[0]) / 2
|
|
return result, len(result[0]) / 2
|
|
}
|
|
}
|
|
|
|
|
|
if c >= 33 && c <= 126 {
|
|
if c >= 33 && c <= 126 {
|
|
c -= 33
|
|
c -= 33
|
|
- idx := cf.Characters[c]
|
|
|
|
|
|
+ var idx int = cf.Characters[c]
|
|
if idx == -1 {
|
|
if idx == -1 {
|
|
return result, 0
|
|
return result, 0
|
|
}
|
|
}
|
|
@@ -196,7 +196,7 @@ func (cf *ColorFont) GetCharacter(c int) ([][]byte, int) {
|
|
// fmt.Println("Character:")
|
|
// fmt.Println("Character:")
|
|
// BytesArrayHexed(&result)
|
|
// BytesArrayHexed(&result)
|
|
// fmt.Println("normalizing...")
|
|
// fmt.Println("normalizing...")
|
|
- max := normalizeColor(&result)
|
|
|
|
|
|
+ var max int = normalizeColor(&result)
|
|
// BytesArrayHexed(&result)
|
|
// BytesArrayHexed(&result)
|
|
// StringHexO(&result)
|
|
// StringHexO(&result)
|
|
return result, max
|
|
return result, max
|
|
@@ -206,7 +206,7 @@ func (cf *ColorFont) GetCharacter(c int) ([][]byte, int) {
|
|
}
|
|
}
|
|
|
|
|
|
func thedraw_to_ansi(c int) int {
|
|
func thedraw_to_ansi(c int) int {
|
|
- trans := []int{0, 4, 2, 6, 1, 5, 3, 7}
|
|
|
|
|
|
+ var trans []int = []int{0, 4, 2, 6, 1, 5, 3, 7}
|
|
// 0, 1, 2, 3, 4, 5, 6, 7
|
|
// 0, 1, 2, 3, 4, 5, 6, 7
|
|
return trans[c]
|
|
return trans[c]
|
|
}
|
|
}
|
|
@@ -237,8 +237,8 @@ func ColorSplit(color int) ColorParts {
|
|
}
|
|
}
|
|
|
|
|
|
func ColorOutput(previous int, color int) string {
|
|
func ColorOutput(previous int, color int) string {
|
|
- prev := ColorSplit(previous)
|
|
|
|
- c := ColorSplit(color)
|
|
|
|
|
|
+ var prev ColorParts = ColorSplit(previous)
|
|
|
|
+ var c ColorParts = ColorSplit(color)
|
|
var codes []int8
|
|
var codes []int8
|
|
|
|
|
|
if c.Bold {
|
|
if c.Bold {
|
|
@@ -287,10 +287,10 @@ func Colorize(input []byte) []byte {
|
|
// BytesHexed(input)
|
|
// BytesHexed(input)
|
|
|
|
|
|
for pos := 0; pos < len(input); pos += 2 {
|
|
for pos := 0; pos < len(input); pos += 2 {
|
|
- ch := input[pos]
|
|
|
|
- color := int(input[pos+1])
|
|
|
|
|
|
+ var ch byte = input[pos]
|
|
|
|
+ var color int = int(input[pos+1])
|
|
// fmt.Printf("%d : CH %d / %x, Color %d / %x\n", pos, ch, ch, color, color)
|
|
// fmt.Printf("%d : CH %d / %x, Color %d / %x\n", pos, ch, ch, color, color)
|
|
- colorstring := ColorOutput(previous, color)
|
|
|
|
|
|
+ var colorstring string = ColorOutput(previous, color)
|
|
result = append(result, []byte(colorstring)...)
|
|
result = append(result, []byte(colorstring)...)
|
|
/*
|
|
/*
|
|
for _, c := range []byte(colorstring) {
|
|
for _, c := range []byte(colorstring) {
|
|
@@ -317,7 +317,7 @@ func __expandColor(block *[]string, need int) {
|
|
*/
|
|
*/
|
|
|
|
|
|
func expandColor(block *[][]byte, need int) {
|
|
func expandColor(block *[][]byte, need int) {
|
|
- blank := []byte{0x20, 0x0f}
|
|
|
|
|
|
+ var blank []byte = []byte{0x20, 0x0f}
|
|
// *block = append(*block, strings.Repeat(" \x0f", need))
|
|
// *block = append(*block, strings.Repeat(" \x0f", need))
|
|
*block = append(*block, bytes.Repeat(blank, need))
|
|
*block = append(*block, bytes.Repeat(blank, need))
|
|
}
|
|
}
|
|
@@ -328,12 +328,14 @@ func (bf *ColorFont) Output(input string) ([]string, int) {
|
|
|
|
|
|
for _, ch := range input {
|
|
for _, ch := range input {
|
|
// fmt.Printf("%d %x\n", ch, ch)
|
|
// fmt.Printf("%d %x\n", ch, ch)
|
|
- block, blklen := bf.GetCharacter(int(ch))
|
|
|
|
|
|
+ var block [][]byte
|
|
|
|
+ var blklen int
|
|
|
|
+ block, blklen = bf.GetCharacter(int(ch))
|
|
if blklen == 0 {
|
|
if blklen == 0 {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
- l := len(block)
|
|
|
|
|
|
+ var l int = len(block)
|
|
max += blklen
|
|
max += blklen
|
|
if l != 0 {
|
|
if l != 0 {
|
|
if len(out) == 0 {
|
|
if len(out) == 0 {
|
|
@@ -366,7 +368,7 @@ func (bf *ColorFont) Output(input string) ([]string, int) {
|
|
panic(fmt.Sprintf("len(out) %d != len(block) %d", len(out), len(block)))
|
|
panic(fmt.Sprintf("len(out) %d != len(block) %d", len(out), len(block)))
|
|
}
|
|
}
|
|
|
|
|
|
- blank := []byte{0x20, 0x0f}
|
|
|
|
|
|
+ var blank []byte = []byte{0x20, 0x0f}
|
|
// Ok, we have something!
|
|
// Ok, we have something!
|
|
for idx, b := range block {
|
|
for idx, b := range block {
|
|
/*
|
|
/*
|
|
@@ -450,15 +452,15 @@ func (cf *ColorFont) Scan(find_color int) ColorMap {
|
|
var Targets ColorMap = make(ColorMap, 0)
|
|
var Targets ColorMap = make(ColorMap, 0)
|
|
// Scan the font looking for the given color FG/BG
|
|
// Scan the font looking for the given color FG/BG
|
|
// Covert color code to TheDraw Color
|
|
// Covert color code to TheDraw Color
|
|
- actual := byte(thedraw_to_ansi(find_color))
|
|
|
|
|
|
+ var actual byte = byte(thedraw_to_ansi(find_color))
|
|
|
|
|
|
for charIndex := range cf.Data {
|
|
for charIndex := range cf.Data {
|
|
for lineIndex := range cf.Data[charIndex] {
|
|
for lineIndex := range cf.Data[charIndex] {
|
|
var found bool = false
|
|
var found bool = false
|
|
var patches [][2]int = make([][2]int, 0)
|
|
var patches [][2]int = make([][2]int, 0)
|
|
for offset := 1; offset < len(cf.Data[charIndex][lineIndex]); offset += 2 {
|
|
for offset := 1; offset < len(cf.Data[charIndex][lineIndex]); offset += 2 {
|
|
- color := cf.Data[charIndex][lineIndex][offset]
|
|
|
|
- style := MatchStyle(color, actual)
|
|
|
|
|
|
+ var color byte = cf.Data[charIndex][lineIndex][offset]
|
|
|
|
+ var style int = MatchStyle(color, actual)
|
|
if style != 0 {
|
|
if style != 0 {
|
|
// log.Printf("color: %x actual %x style: %d\n", color, actual, style)
|
|
// log.Printf("color: %x actual %x style: %d\n", color, actual, style)
|
|
patches = append(patches, [2]int{offset, style})
|
|
patches = append(patches, [2]int{offset, style})
|
|
@@ -466,7 +468,7 @@ func (cf *ColorFont) Scan(find_color int) ColorMap {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if found {
|
|
if found {
|
|
- pos := [2]int{charIndex, lineIndex}
|
|
|
|
|
|
+ var pos [2]int = [2]int{charIndex, lineIndex}
|
|
Targets[pos] = make([][2]int, len(patches))
|
|
Targets[pos] = make([][2]int, len(patches))
|
|
for i := range patches {
|
|
for i := range patches {
|
|
Targets[pos][i] = patches[i]
|
|
Targets[pos][i] = patches[i]
|
|
@@ -482,7 +484,7 @@ func (cf *ColorFont) Scan(find_color int) ColorMap {
|
|
// Scan.
|
|
// Scan.
|
|
func (cf *ColorFont) Modify(new_color int, Targets ColorMap) {
|
|
func (cf *ColorFont) Modify(new_color int, Targets ColorMap) {
|
|
// Covert color code to TheDraw Color
|
|
// Covert color code to TheDraw Color
|
|
- actual := byte(thedraw_to_ansi(new_color))
|
|
|
|
|
|
+ var actual byte = byte(thedraw_to_ansi(new_color))
|
|
for pos, patch := range Targets {
|
|
for pos, patch := range Targets {
|
|
for _, p := range patch {
|
|
for _, p := range patch {
|
|
cf.Data[pos[0]][pos[1]][p[0]] = PatchColor(cf.Data[pos[0]][pos[1]][p[0]], actual, p[1])
|
|
cf.Data[pos[0]][pos[1]][p[0]] = PatchColor(cf.Data[pos[0]][pos[1]][p[0]], actual, p[1])
|