2010-12-13 08:59:26 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2010-12-13 14:54:47 +00:00
|
|
|
"time"
|
2010-12-13 08:59:26 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"bufio"
|
|
|
|
"image"
|
|
|
|
"image/png"
|
|
|
|
"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d"
|
2010-12-13 12:01:24 +00:00
|
|
|
"postscript"
|
|
|
|
//"postscript-go.googlecode.com/svn/trunk/postscript-go/src/pkg/postscript"
|
2010-12-13 08:59:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func saveToPngFile(filePath string, m image.Image) {
|
|
|
|
f, err := os.Open(filePath, os.O_CREAT|os.O_WRONLY, 0600)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
b := bufio.NewWriter(f)
|
|
|
|
err = png.Encode(b, m)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
err = b.Flush()
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
fmt.Printf("Wrote %s OK.\n", filePath)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2010-12-13 23:04:53 +00:00
|
|
|
i := image.NewRGBA(600, 800)
|
2010-12-13 08:59:26 +00:00
|
|
|
gc := draw2d.NewGraphicContext(i)
|
|
|
|
gc.Translate(0, 380)
|
|
|
|
gc.Scale(1,-1)
|
|
|
|
gc.Translate(0, -380)
|
2010-12-13 14:54:47 +00:00
|
|
|
lastTime := time.Nanoseconds()
|
2010-12-13 08:59:26 +00:00
|
|
|
interpreter := postscript.NewInterpreter(gc)
|
|
|
|
interpreter.ExecuteFile("../../test_files/tiger.ps")
|
2010-12-13 14:54:47 +00:00
|
|
|
dt := time.Nanoseconds() - lastTime
|
|
|
|
fmt.Printf("Draw image: %f ms\n", float(dt)*1e-6)
|
2010-12-13 08:59:26 +00:00
|
|
|
saveToPngFile("../../TestPostscript.png", i)
|
|
|
|
}
|