From dcae7f43926adcfa3b082f4d0d2f0435fb61faef Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 30 Jan 2018 19:12:07 +0100 Subject: add height to each glyph --- hershey.go | 30 ++++++++++++++++++------------ main.go | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/hershey.go b/hershey.go index 6323d69..9b8d618 100644 --- a/hershey.go +++ b/hershey.go @@ -17,8 +17,9 @@ type Path []Point type Set []Path type Glyph struct { - Set Set - Width int + Set Set + Width int + Height int } type Font map[rune]Glyph @@ -35,18 +36,22 @@ func parsePoint(in uint8) int { func parseData(s string, w, h int) Set { var st Set - for i, el := range strings.Fields(s) { - var ph Path - if i > 0 { + scanner := bufio.NewScanner(strings.NewReader(s)) + scanner.Split(bufio.ScanWords) + for scanner.Scan() { + el := scanner.Text() + if len(el)%2 != 0 && el[0] == 'R' { el = el[1:] } + var l Path for n := 0; n < len(el); n += 2 { - var p Point - p.Y = w/2 + parsePoint(el[n]) - p.X = h/2 + parsePoint(el[n+1]) - ph = append(ph, p) + p := Point{ + Y: w/2 + parsePoint(el[n]), + X: h/2 + parsePoint(el[n+1]), + } + l = append(l, p) } - st = append(st, ph) + st = append(st, l) } return st } @@ -69,8 +74,9 @@ func loadFont(fname string) Font { r := parsePoint(line[9]) w := r - l fnt[rune(n)] = Glyph{ - Set: parseData(line[10:], w, 32), - Width: w, + Set: parseData(line[10:], w, 32), + Width: w, + Height: 32, } } if err := scanner.Err(); err != nil { diff --git a/main.go b/main.go index f90f82e..bfa97e6 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,6 @@ func printAll(f Font) { } func printStruct(f Font) { - fmt.Println("var height = 32") fmt.Println("var font = Font{") for i := 0; i < len(f); i++ { r := rune(i + 32) @@ -59,6 +58,7 @@ func printStruct(f Font) { } fmt.Println("},") fmt.Printf("Width: %v,\n", gl.Width) + fmt.Printf("Height: %v,\n", gl.Height) fmt.Println("},") } fmt.Println("}") -- cgit v1.2.3