add constructor

This commit is contained in:
legoff.laurent 2011-03-15 17:27:27 +00:00
parent af5f13b7f4
commit 92e18565ff
4 changed files with 32 additions and 15 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

After

Width:  |  Height:  |  Size: 158 KiB

View file

@ -6,7 +6,9 @@ import (
"time"
"log"
"os"
"io/ioutil"
"bufio"
"strings"
"image"
"image/png"
"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d"
@ -43,8 +45,15 @@ func main() {
gc.Scale(1, -1)
gc.Translate(0, -380)
lastTime := time.Nanoseconds()
src, err := os.Open("../../test_files/tiger.ps", 0, 0)
if err != nil {
return
}
defer src.Close()
bytes, err := ioutil.ReadAll(src)
reader := strings.NewReader(string(bytes))
interpreter := postscript.NewInterpreter(gc)
interpreter.ExecuteFile("../../test_files/tiger.ps")
interpreter.Execute(reader)
dt := time.Nanoseconds() - lastTime
fmt.Printf("Draw image: %f ms\n", float64(dt)*1e-6)
saveToPngFile("../../TestPostscript.png", i)

View file

@ -1,16 +1,18 @@
include $(GOROOT)/src/Make.inc
TARG=postscript-go.googlecode.com/svn/trunk/postscript-go/src/pkg/postscript
GOFILES=\
GOFILES=operators_array.go\
operators_dictionary.go\
operators_misc.go\
procedure.go\
interpreter.go\
operators_conflict.go\
operators_graphics.go\
operators_relational.go\
scanner.go\
operators.go\
operators_control.go\
operators_dictionary.go\
operators_graphics.go\
operators_math.go\
operators_relational.go\
operators_stack.go\
procedure.go\
scanner.go\
include $(GOROOT)/src/Make.pkg

View file

@ -7,6 +7,7 @@ import (
"os"
"log"
"strconv"
"io"
"draw2d.googlecode.com/svn/trunk/draw2d/src/pkg/draw2d"
)
@ -47,21 +48,26 @@ func NewDictionary(prealloc int) Dictionary {
func (interpreter *Interpreter) GetGraphicContext() *draw2d.GraphicContext {
return interpreter.gc
}
func (interpreter *Interpreter) ExecuteFile(filePath string) {
src, err := os.Open(filePath, 0, 0)
if src == nil {
log.Printf("can't open file; err=%s\n", err.String())
return
}
func (interpreter *Interpreter) Execute(reader io.Reader) {
var scanner Scanner
scanner.Init(src)
scanner.Init(reader)
token := scanner.Scan()
for token != EOF {
interpreter.scan(&scanner, token)
token = scanner.Scan()
}
}
func (interpreter *Interpreter) ExecuteFile(filePath string) os.Error {
src, err := os.Open(filePath, 0, 0)
if src == nil {
log.Printf("can't open file; err=%s\n", err.String())
return err
}
defer src.Close()
interpreter.Execute(src)
return nil
}
func (interpreter *Interpreter) computeReference(ref string) {
value, _ := interpreter.FindValueInDictionaries(ref)
if value == nil {