|
@@ -10,6 +10,82 @@ import (
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
+var Conversion [][2]int
|
|
|
+
|
|
|
+// copied from tdfont.go, and modified
|
|
|
+
|
|
|
+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]
|
|
|
+}
|
|
|
+
|
|
|
+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
|
|
|
+}
|
|
|
+
|
|
|
+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
|
|
|
+}
|
|
|
+
|
|
|
+func Scan(block [][][]byte, 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 block {
|
|
|
+ for lineIndex := range block[charIndex] {
|
|
|
+ var found bool = false
|
|
|
+ var patches [][2]int = make([][2]int, 0)
|
|
|
+ for offset := 1; offset < len(block[charIndex][lineIndex]); offset += 2 {
|
|
|
+ color := block[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
|
|
|
+}
|
|
|
+
|
|
|
+func Modify(block [][][]byte, 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 {
|
|
|
+ block[pos[0]][pos[1]][p[0]] = PatchColor(block[pos[0]][pos[1]][p[0]], actual, p[1])
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func ListFonts(filename string) {
|
|
|
|
|
|
f, err := os.Open(filename)
|
|
@@ -185,6 +261,17 @@ func ExtractColor(name string, offsets []uint16, data []byte) {
|
|
|
writer.WriteString(output)
|
|
|
writer.Flush()
|
|
|
|
|
|
+ if len(Conversion) > 0 {
|
|
|
+ // Color Convert time!
|
|
|
+ var Maps []map[[2]int][][2]int = make([]map[[2]int][][2]int, len(Conversion))
|
|
|
+ for idx, codes := range Conversion {
|
|
|
+ Maps[idx] = Scan(blocks, codes[0])
|
|
|
+ }
|
|
|
+ for idx, codes := range Conversion {
|
|
|
+ Modify(blocks, codes[1], Maps[idx])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
output = " Data: [][][]byte{"
|
|
|
for _, blk := range blocks {
|
|
|
output += "{"
|
|
@@ -399,19 +486,59 @@ func ExtractFonts(filename string, fonts []string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// Created so that multiple inputs can be accecpted
|
|
|
+type arrayFlags []string
|
|
|
+
|
|
|
+func (i *arrayFlags) String() string {
|
|
|
+ // change this, this is just can example to satisfy the interface
|
|
|
+ result := ""
|
|
|
+ for _, str := range *i {
|
|
|
+ if result != "" {
|
|
|
+ result += ", "
|
|
|
+ }
|
|
|
+ result += str
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
+func (i *arrayFlags) Set(value string) error {
|
|
|
+ *i = append(*i, strings.TrimSpace(value))
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func ParseColorConvert(convert arrayFlags) {
|
|
|
+ Conversion = make([][2]int, 0)
|
|
|
+ if len(convert) > 0 {
|
|
|
+ // Something to do
|
|
|
+ for _, color := range convert {
|
|
|
+ split := strings.Split(color, ",")
|
|
|
+ v1, _ := strconv.Atoi(split[0])
|
|
|
+ v2, _ := strconv.Atoi(split[1])
|
|
|
+ Conversion = append(Conversion, [2]int{v1, v2})
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func main() {
|
|
|
|
|
|
var fonts string
|
|
|
var defaultPackage string = "main"
|
|
|
var listFonts bool
|
|
|
var allFonts bool
|
|
|
+ var convert arrayFlags
|
|
|
|
|
|
flag.StringVar(&fonts, "f", "", "Font(s) to extract")
|
|
|
flag.BoolVar(&allFonts, "a", false, "Extract All Fonts")
|
|
|
flag.StringVar(&defaultPackage, "p", "main", "Package name to use")
|
|
|
flag.BoolVar(&listFonts, "l", false, "List Fonts")
|
|
|
+ flag.Var(&convert, "c", "Convert Color to Color n,n")
|
|
|
flag.Parse()
|
|
|
|
|
|
+ ParseColorConvert(convert)
|
|
|
+
|
|
|
+ // fmt.Printf("Convert: %#v\n", convert)
|
|
|
+ // fmt.Printf("Conversion: %#v\n", Conversion)
|
|
|
+
|
|
|
if flag.NArg() == 0 {
|
|
|
fmt.Println("Font-Out - A TDF (TheDraw Font) file processor.")
|
|
|
fmt.Println("No TDF filenames given.")
|