aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-05-22 14:02:52 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-05-22 14:02:52 +0200
commitea653ce3bf266fb3c3f6b917b3924b0328f5d4a4 (patch)
tree7302107f595ad8822b75a413dca2d52b93a151ef
parent9b2b5ec2c339805b3604c41a48cedf3db4fcf868 (diff)
Generalize
-rw-r--r--drawtext/main.go3
-rw-r--r--text.go10
2 files changed, 7 insertions, 6 deletions
diff --git a/drawtext/main.go b/drawtext/main.go
index 751041c..5f02e5d 100644
--- a/drawtext/main.go
+++ b/drawtext/main.go
@@ -2,6 +2,7 @@ package main
import (
"flag"
+ "os"
"dim13.org/robo"
)
@@ -20,5 +21,5 @@ func main() {
robo.Initialize(handle, 113, robo.Portrait)
robo.A4.UpperRight(handle.Writer)
robo.Triple{100, 100, 100}.Factor(handle.Writer)
- robo.PrintStdin(handle.Writer, robo.Unit(*scale))
+ robo.Print(handle.Writer, os.Stdin, robo.Unit(*scale))
}
diff --git a/text.go b/text.go
index 3ee2073..d13f766 100644
--- a/text.go
+++ b/text.go
@@ -2,8 +2,8 @@ package robo
import (
"bufio"
+ "io"
"log"
- "os"
)
type Font map[rune]Glyph
@@ -15,19 +15,19 @@ type Glyph struct {
type Set []Path
-func PrintStdin(c *bufio.Writer, scale Unit) {
+func Print(c *bufio.Writer, in io.Reader, scale Unit) {
var off Point
- scanner := bufio.NewScanner(os.Stdin)
+ scanner := bufio.NewScanner(in)
for scanner.Scan() {
- font.printChar(c, scanner.Text(), scale, &off)
+ font.putchar(c, scanner.Text(), scale, &off)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}
-func (f Font) printChar(c *bufio.Writer, s string, scale Unit, off *Point) {
+func (f Font) putchar(c *bufio.Writer, s string, scale Unit, off *Point) {
for _, ch := range s {
gl, ok := f[ch]
if ok {