|
@@ -207,6 +207,7 @@ func (cf *ColorFont) GetCharacter(c int) ([][]byte, int) {
|
|
|
|
|
|
func thedraw_to_ansi(c int) int {
|
|
|
trans := []int{0, 4, 2, 6, 1, 5, 3, 7}
|
|
|
+ // 0, 1, 2, 3, 4, 5, 6, 7
|
|
|
return trans[c]
|
|
|
}
|
|
|
|
|
@@ -411,6 +412,83 @@ func (bf *ColorFont) Output(input string) ([]string, int) {
|
|
|
return output, max
|
|
|
}
|
|
|
|
|
|
+// Given a color to look for, see if it is in the color byte.
|
|
|
+// 0x01 = Upper match
|
|
|
+// 0x02 = Lower match
|
|
|
+func MatchStyle(color byte, look byte) int {
|
|
|
+ var match int = 0
|
|
|
+ if ((color >> 4) & 0x07) == look {
|
|
|
+ // Top
|
|
|
+ match |= 1
|
|
|
+ }
|
|
|
+ if (color & 0x07) == look {
|
|
|
+ // Bottom
|
|
|
+ match |= 2
|
|
|
+ }
|
|
|
+ return match
|
|
|
+}
|
|
|
+
|
|
|
+// Update a color byte with the new color information.
|
|
|
+// Style 0x01 = Upper, 0x02 = Lower, 0x03 = Both.
|
|
|
+func PatchColor(color byte, new_color byte, style int) byte {
|
|
|
+ var c byte = color
|
|
|
+ if style&1 == 1 {
|
|
|
+ c = (c & 0x8f) | new_color<<4
|
|
|
+ }
|
|
|
+ if style&2 == 2 {
|
|
|
+ c = (c & 0xf8) | new_color
|
|
|
+ }
|
|
|
+ return c
|
|
|
+}
|
|
|
+
|
|
|
+// Scan a ColorFont for a specific color.
|
|
|
+// This returns a map key of character Index + line Index
|
|
|
+// with an array of [2]int (Index, Style) to change.
|
|
|
+func (cf *ColorFont) Scan(find_color int) map[[2]int][][2]int {
|
|
|
+ var Targets map[[2]int][][2]int = make(map[[2]int][][2]int, 0)
|
|
|
+ // Scan the font looking for the given color FG/BG
|
|
|
+ // Covert color code to TheDraw Color
|
|
|
+ actual := byte(thedraw_to_ansi(find_color))
|
|
|
+
|
|
|
+ for charIndex := range cf.Data {
|
|
|
+ for lineIndex := range cf.Data[charIndex] {
|
|
|
+ var found bool = false
|
|
|
+ var patches [][2]int = make([][2]int, 0)
|
|
|
+ for offset := 1; offset < len(cf.Data[charIndex][lineIndex]); offset += 2 {
|
|
|
+ color := cf.Data[charIndex][lineIndex][offset]
|
|
|
+ style := MatchStyle(color, actual)
|
|
|
+ if style != 0 {
|
|
|
+ // log.Printf("color: %x actual %x style: %d\n", color, actual, style)
|
|
|
+ patches = append(patches, [2]int{offset, style})
|
|
|
+ found = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if found {
|
|
|
+ pos := [2]int{charIndex, lineIndex}
|
|
|
+ Targets[pos] = make([][2]int, len(patches))
|
|
|
+ for i := range patches {
|
|
|
+ Targets[pos][i] = patches[i]
|
|
|
+ }
|
|
|
+ // Targets[pos] = patches
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Targets
|
|
|
+}
|
|
|
+
|
|
|
+// This modifies the font color, using the Targets found with
|
|
|
+// Scan.
|
|
|
+func (cf *ColorFont) Modify(new_color int, Targets map[[2]int][][2]int) {
|
|
|
+ // Covert color code to TheDraw Color
|
|
|
+ actual := byte(thedraw_to_ansi(new_color))
|
|
|
+ for pos, patch := range Targets {
|
|
|
+ for _, p := range patch {
|
|
|
+ cf.Data[pos[0]][pos[1]][p[0]] = PatchColor(cf.Data[pos[0]][pos[1]][p[0]], actual, p[1])
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
func CP437Bytes_to_Unicode(cp437 []byte) string {
|
|
|
var result string
|
|
|
|
|
@@ -734,3 +812,4 @@ func CP437Bytes_to_Unicode(cp437 []byte) string {
|
|
|
// fmt.Printf("\n")
|
|
|
return result
|
|
|
}
|
|
|
+*/
|