github.com/blend/go-sdk@v1.20220411.3/ansi/slant/_fontdata/main.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package main
     9  
    10  import (
    11  	"bufio"
    12  	"bytes"
    13  	"fmt"
    14  	"log"
    15  	"os"
    16  	"strings"
    17  )
    18  
    19  func main() {
    20  	contents, err := os.ReadFile("slant_letters.txt")
    21  	if err != nil {
    22  		log.Fatal(err)
    23  	}
    24  
    25  	letterHeight := 6
    26  
    27  	scanner := bufio.NewScanner(bytes.NewReader(contents))
    28  
    29  	var lineText string
    30  	var line int
    31  
    32  	fmt.Fprintln(os.Stdout, "[][]string{")
    33  
    34  	for scanner.Scan() {
    35  		lineText = scanner.Text()
    36  
    37  		if line == 0 {
    38  			fmt.Fprintln(os.Stdout, "\t{")
    39  		}
    40  		if line < letterHeight {
    41  			lineText = strings.TrimSuffix(strings.TrimSuffix(lineText, "@"), "@")
    42  			lineText = strings.ReplaceAll(lineText, "\"", "\\\"") // escape quotes
    43  			lineText = strings.ReplaceAll(lineText, "\\", "\\\\") // escape slashes
    44  			fmt.Fprintf(os.Stdout, "\t\t\"%s\",\n", lineText)
    45  			line++
    46  		}
    47  
    48  		if line == letterHeight || strings.HasSuffix(lineText, "@@") {
    49  			fmt.Fprintln(os.Stdout, "\t},")
    50  			line = 0
    51  		}
    52  	}
    53  
    54  	fmt.Fprintln(os.Stdout, "}")
    55  }