aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-05-14 20:10:02 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-05-14 20:10:02 +0200
commitd5d7d91ccbc70bd68c9c2f218505af6b74fbb7a8 (patch)
tree08dcc2c6043b7ff6e65cc90580f7f44222a22182
parent30913cc232c7bd22dbd34e06bff137ab48218cb6 (diff)
Normalize and scale
-rw-r--r--hershey.go64
-rw-r--r--main.go3
2 files changed, 19 insertions, 48 deletions
diff --git a/hershey.go b/hershey.go
index 6da6553..713da1f 100644
--- a/hershey.go
+++ b/hershey.go
@@ -17,9 +17,8 @@ type Path []Point
type Set []Path
type Glyph struct {
- N, K int
- L, R int
- S Set
+ S Set
+ W int
}
type Font map[rune]Glyph
@@ -34,7 +33,7 @@ func parsePoint(in uint8) int {
return int(in) - int('R')
}
-func parseData(s string) Set {
+func parseData(s string, w, h, scale int) Set {
var st Set
for i, el := range strings.Fields(s) {
var ph Path
@@ -43,8 +42,8 @@ func parseData(s string) Set {
}
for n := 0; n < len(el); n += 2 {
var p Point
- p.X = parsePoint(el[n])
- p.Y = parsePoint(el[n+1])
+ p.Y = scale * (w/2 + parsePoint(el[n]))
+ p.X = scale * (h/2 + parsePoint(el[n+1]))
ph = append(ph, p)
}
st = append(st, ph)
@@ -64,14 +63,16 @@ func loadFont(fname string) Font {
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
- gl := Glyph{
- N: parseInt(line[0:5]),
- K: parseInt(line[5:8]),
- L: parsePoint(line[8]),
- R: parsePoint(line[9]),
- S: parseData(line[10:]),
+ n := parseInt(line[0:5])
+ //k := parseInt(line[5:8])
+ l := parsePoint(line[8])
+ r := parsePoint(line[9])
+ w := r - l
+ scale := 5
+ fnt[rune(n)] = Glyph{
+ S: parseData(line[10:], w, 32, scale),
+ W: w * scale,
}
- fnt[rune(gl.N)] = gl
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
@@ -80,17 +81,14 @@ func loadFont(fname string) Font {
}
func (p Point) String() string {
- return fmt.Sprintf("(%v %v)", p.X, p.Y)
+ return fmt.Sprintf("%v,%v,", p.X, p.Y)
}
func (p Path) String() (s string) {
- for i, pt := range p {
+ //s = fmt.Sprint("Y0,", p[0])
+ s = fmt.Sprint("M", p[0], "D")
+ for _, pt := range p[1:] {
s += fmt.Sprint(pt)
- if i < len(p)-1 {
- s += fmt.Sprint(",")
- } else {
- s += fmt.Sprint(" ")
- }
}
return
}
@@ -106,32 +104,6 @@ func (g Glyph) String() string {
return fmt.Sprint(g.S)
}
-func (g Glyph) Width() int {
- return g.R - g.L
-}
-
-func (g Glyph) Max() (x, y int) {
- var top, bottom int
- var left, right int
- for _, pt := range g.S {
- for _, p := range pt {
- if p.X > right {
- right = p.X
- }
- if p.X < left {
- left = p.X
- }
- if p.Y > top {
- top = p.Y
- }
- if p.Y < bottom {
- bottom = p.Y
- }
- }
- }
- return right - left, top - bottom
-}
-
func (f Font) Select(n []int) Font {
ret := make(Font)
for i, p := range n {
diff --git a/main.go b/main.go
index 38ca8d8..6492d3c 100644
--- a/main.go
+++ b/main.go
@@ -36,8 +36,7 @@ func main() {
m := getMap("data/" + v)
for k, gl := range fnt.Select(m) {
- w, h := gl.Max()
- fmt.Println(string(k), gl.Width(), w, h, gl)
+ fmt.Println(string(k), gl)
}
}
}