Просмотр исходного кода

This fixes font-out so it outputs to single file.

Before it was placing each font in a single file.
Wrong description of what script does in ansi-to-go.py.
Steve Thielemann 2 лет назад
Родитель
Сommit
ea9ceeb2b8
2 измененных файлов с 45 добавлено и 29 удалено
  1. 1 1
      ansi-to-go.py
  2. 44 28
      font-out.go

+ 1 - 1
ansi-to-go.py

@@ -3,7 +3,7 @@
 import sys
 
 ##
-## Convert ANSI art files to C++ header file.
+## Convert ANSI art files to go file.
 ##
 
 filenames = sys.argv

+ 44 - 28
font-out.go

@@ -94,7 +94,7 @@ func text_to_hextext(line string) string {
 }
 
 func ExtractColor(name string, offsets []uint16, data []byte) {
-	fmt.Printf("Extract Color Font: %s\n", name)
+	// fmt.Printf("Extract Color Font: %s\n", name)
 	var indexes []int
 	var blocks [][][]byte
 	var current [][]byte
@@ -155,18 +155,20 @@ func ExtractColor(name string, offsets []uint16, data []byte) {
 		}
 	}
 
-	// Handle Names with spaces
-	filename := fmt.Sprintf("%s_font.go", strings.Replace(name, " ", "", -1))
+	/*
+		// Handle Names with spaces
+		filename := fmt.Sprintf("%s_font.go", strings.Replace(name, " ", "", -1))
 
-	fp, err := os.Create(filename)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Printf("Writing: %s\n", filename)
-
-	defer fp.Close()
-	writer := bufio.NewWriter(fp)
+		fp, err := os.Create(filename)
+		if err != nil {
+			panic(err)
+		}
+		fmt.Printf("Writing: %s\n", filename)
 
+		defer fp.Close()
+		writer := bufio.NewWriter(fp)
+	*/
+	writer := bufio.NewWriter(os.Stdout)
 	// writer.WriteString("package main\n")
 	writer.WriteString("// " + name + "\n\n")
 
@@ -206,7 +208,7 @@ func ExtractColor(name string, offsets []uint16, data []byte) {
 }
 
 func ExtractBlock(name string, offsets []uint16, data []byte) {
-	fmt.Printf("Extract Block Font: %s\n", name)
+	// fmt.Printf("Extract Block Font: %s\n", name)
 	var indexes []int
 	var blocks [][][]byte
 	var current [][]byte
@@ -264,17 +266,20 @@ func ExtractBlock(name string, offsets []uint16, data []byte) {
 		}
 	}
 
-	// Handle Names with spaces
-	filename := fmt.Sprintf("%s_font.go", strings.Replace(name, " ", "", -1))
+	/*
+		// Handle Names with spaces
+		filename := fmt.Sprintf("%s_font.go", strings.Replace(name, " ", "", -1))
 
-	fp, err := os.Create(filename)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Printf("Writing: %s\n", filename)
+		fp, err := os.Create(filename)
+		if err != nil {
+			panic(err)
+		}
+		fmt.Printf("Writing: %s\n", filename)
 
-	defer fp.Close()
-	writer := bufio.NewWriter(fp)
+		defer fp.Close()
+		writer := bufio.NewWriter(fp)
+	*/
+	writer := bufio.NewWriter(os.Stdout)
 
 	// Should this output routine be part of the BlockFont?
 	// I think so!
@@ -374,7 +379,7 @@ func ExtractFonts(filename string, fonts []string) {
 			case 2:
 				ExtractColor(Name, letterOffsets, data)
 			default:
-				fmt.Printf("Sorry, I can't handle Font: %s Type %d!\n", Name, FontType)
+				fmt.Printf("// Sorry, I can't handle Font: %s Type %d!\n", Name, FontType)
 			}
 		} else {
 			for _, f := range fonts {
@@ -385,7 +390,7 @@ func ExtractFonts(filename string, fonts []string) {
 					case 2:
 						ExtractColor(Name, letterOffsets, data)
 					default:
-						fmt.Printf("Sorry, I can't handle Font: %s Type %d!\n", Name, FontType)
+						fmt.Printf("// Sorry, I can't handle Font: %s Type %d!\n", Name, FontType)
 					}
 					break
 				}
@@ -395,7 +400,7 @@ func ExtractFonts(filename string, fonts []string) {
 }
 
 func main() {
-	fmt.Println("Font-Out - A TDF (TheDraw Font) file processor.")
+
 	var fonts string
 	var defaultPackage string = "main"
 	var listFonts bool
@@ -408,11 +413,22 @@ func main() {
 	flag.Parse()
 
 	if flag.NArg() == 0 {
+		fmt.Println("Font-Out - A TDF (TheDraw Font) file processor.")
 		fmt.Println("No TDF filenames given.")
 		flag.PrintDefaults()
 		os.Exit(2)
 	}
 
+	if !listFonts {
+		fmt.Printf("package %s\n\n", defaultPackage)
+		fmt.Println("import (")
+		fmt.Println("  \"red-green/door\"")
+		fmt.Println(")")
+		fmt.Println("")
+	} else {
+		fmt.Println("Font-Out - A TDF (TheDraw Font) file processor.")
+	}
+
 	var fontList []string
 	if len(fonts) > 0 {
 		fontList = strings.Split(fonts, ",")
@@ -431,10 +447,10 @@ func main() {
 	for _, fontfile := range flag.Args() {
 		if listFonts {
 			ListFonts(fontfile)
-		}
-
-		if len(fontList) > 0 {
-			ExtractFonts(fontfile, fontList)
+		} else {
+			if len(fontList) > 0 {
+				ExtractFonts(fontfile, fontList)
+			}
 		}
 	}
 }