Ejemplo n.º 1
0
func parseScript(fn, font string) ([]*svgmod.Command, error) {
	f, err := os.Open(fn)
	defer f.Close()
	if err != nil {
		return nil, err
	}
	commands := make([]*svgmod.Command, 0)
	nc := 0
	s := bufio.NewScanner(f)
	for s.Scan() {
		ct := s.Text()
		if strings.HasPrefix(ct, "#") {
			continue
		}
		if ok, _ := regexp.MatchString("^ *$", ct); ok {
			continue
		}
		c, err := svgmod.Parse(strings.TrimLeft(ct, " "), font)
		if err != nil {
			return commands, err
		}
		commands = append(commands, c)
		nc++
	}
	return commands[:nc], s.Err()
}
Ejemplo n.º 2
0
func parseCommand(e, font string) ([]*svgmod.Command, error) {
	ctxt := strings.Split(e, ";")
	commands := make([]*svgmod.Command, len(ctxt))
	nc := 0
	for _, ct := range ctxt {
		c, err := svgmod.Parse(strings.TrimLeft(ct, " "), font)
		if err != nil {
			return commands, err
		}
		commands[nc] = c
		nc++
	}
	return commands[:nc], nil
}