Ver Fonte

Attempt to fix broken fonts. "Menu" demo option.

Steve Thielemann há 3 anos atrás
pai
commit
85c23d5dd2
2 ficheiros alterados com 46 adições e 0 exclusões
  1. 36 0
      font-out.go
  2. 10 0
      testdoor/testdoor.go

+ 36 - 0
font-out.go

@@ -92,6 +92,26 @@ func text_to_hextext(line string) string {
 	return output
 }
 
+// Attempt to fix broken fonts.
+// This verifies that the character offsets are proceeded
+// by a null character.
+func FontFixup(offsets []uint16, data *[]byte) bool {
+	fixed := false
+	for _, offset := range offsets {
+		if offset == 65535 {
+			continue
+		}
+		if offset == 0 {
+			continue
+		}
+		if (*data)[offset-1] != 0 {
+			(*data)[offset-1] = 0
+			fixed = true
+		}
+	}
+	return fixed
+}
+
 func ExtractColor(name string, offsets []uint16, data []byte) {
 	fmt.Printf("Extract Color Font: %s\n", name)
 	var indexes []int
@@ -150,12 +170,18 @@ func ExtractColor(name string, offsets []uint16, data []byte) {
 			single = append(single, -1)
 			continue
 		}
+		found := false
 		for idx, i := range indexes {
 			if o == uint16(i) {
 				single = append(single, idx)
+				found = true
 				break
 			}
 		}
+		if !found {
+			fmt.Printf("Unable to locate index %d / %x (font corrupted)", o, o)
+			return
+		}
 	}
 
 	// Handle Names with spaces
@@ -265,12 +291,18 @@ func ExtractBlock(name string, offsets []uint16, data []byte) {
 			single = append(single, -1)
 			continue
 		}
+		found := false
 		for idx, i := range indexes {
 			if o == uint16(i) {
 				single = append(single, idx)
+				found = true
 				break
 			}
 		}
+		if !found {
+			fmt.Printf("Unable to locate index %d / %x (font corrupted)", o, o)
+			return
+		}
 	}
 
 	// Handle Names with spaces
@@ -372,6 +404,10 @@ func ExtractFonts(filename string, fonts []string) {
 		data := make([]byte, BlockSize)
 		binary.Read(f, binary.LittleEndian, &data)
 
+		if FontFixup(letterOffsets, &data) {
+			fmt.Printf("Attempting to *FIX* Font %s\n", Name)
+		}
+
 		// Special case where they are asking for all fonts
 		if len(fonts) == 1 && fonts[0] == "*" {
 			switch FontType {

+ 10 - 0
testdoor/testdoor.go

@@ -57,6 +57,7 @@ func MainMenu() door.Menu {
 	m.AddSelection("D", "Display Information (dropfile, screen)")
 	m.AddSelection("F", "Font Demo")
 	m.AddSelection("I", "Input Prompt Demo")
+	m.AddSelection("M", "Menu Demo")
 	m.AddSelection("P", "Progress Bars Demo")
 	m.AddSelection("S", "Show Panel")
 
@@ -114,6 +115,7 @@ func font_demo(d *door.Door) {
 			d.Write(fmt.Sprintf("%s%s%s", centering, string(o), door.Reset) + door.CRNL)
 		}
 	}
+	d.Write(door.CRNL)
 
 	fab := FontAnarchyBlue()
 	output, l = fab.Output("Bugz is Here!")
@@ -126,6 +128,7 @@ func font_demo(d *door.Door) {
 			d.Write(centering + string(o) + door.Reset + door.CRNL)
 		}
 	}
+	d.Write(door.CRNL)
 
 	unchain := FontUnchained()
 	output, l = unchain.Output("Hi There!")
@@ -138,6 +141,8 @@ func font_demo(d *door.Door) {
 			d.Write(centering + string(o) + door.Reset + door.CRNL)
 		}
 	}
+	d.Write(door.CRNL)
+	press_a_key(d)
 
 	asylum := FontAsylum()
 	output, l = asylum.Output("Bugz ROCKS")
@@ -151,6 +156,7 @@ func font_demo(d *door.Door) {
 			d.Write(centering + string(o) + door.Reset + door.CRNL)
 		}
 	}
+	d.Write(door.CRNL)
 
 	brain := FontBrainDmgBlu()
 	output, l = brain.Output("I'm so BLUE")
@@ -163,6 +169,7 @@ func font_demo(d *door.Door) {
 			d.Write(centering + string(o) + door.Reset + door.CRNL)
 		}
 	}
+	d.Write(door.CRNL)
 
 }
 
@@ -320,6 +327,9 @@ func main() {
 			d.Write(door.Reset + door.CRNL + door.CRNL)
 			input_demo(&d)
 			press_a_key(&d)
+		case 'M':
+			d.Write(door.Reset + door.CRNL + "TO DO:  Provide menu of options to select from..." + door.CRNL)
+			press_a_key(&d)
 		case 'P':
 			progress_bars(&d)
 			press_a_key(&d)