Example #1
0
func (messageToClient *MessageToClientDef) BuildSvgMessageToClient(svgDir string, command string, fileName string, svgJsonData *SvgJsonDataDef) *gkerr.GkErrDef {
	var gkErr *gkerr.GkErrDef

	if !validateSvgFileName(fileName) {
		gkErr = gkerr.GenGkErr("invalid svg fileName", nil, ERROR_ID_INVALID_SVG_FILENAME)
		return gkErr
	}

	messageToClient.Command = command

	jsonFileName := svgDir + string(os.PathSeparator) + fileName + ".json"
	svgFileName := svgDir + string(os.PathSeparator) + fileName + ".svg"

	messageToClient.JsonData, gkErr = gkcommon.GetFileContents(jsonFileName)
	if gkErr != nil {
		return gkErr
	}
	messageToClient.Data, gkErr = gkcommon.GetFileContents(svgFileName)
	if gkErr != nil {
		return gkErr
	}
	messageToClient.Data, gkErr = gksvg.FixSvgData(messageToClient.Data, fileName)
	if gkErr != nil {
		return gkErr
	}

	if svgJsonData != nil {
		messageToClient.JsonData, gkErr = templateTranslateJsonData(messageToClient.JsonData, svgJsonData)
		if gkErr != nil {
			return gkErr
		}
	}

	return nil
}
Example #2
0
func main() {

	var inputFileName *string = flag.String("in", "", "svg input filename")
	var outputFileName *string = flag.String("out", "", "svg output filename")

	flag.Parse()

	if (*inputFileName == "") || (*outputFileName == "") {
		flag.PrintDefaults()
		return
	}

	var inputData []byte
	var err error

	inputData, err = readSvgData(*inputFileName)
	if err != nil {
		fmt.Printf("error reading file: %v\n", err)
		return
	}

	var gkErr *gkerr.GkErrDef

	var index int
	index = strings.LastIndex(*inputFileName, "/")
	var prefix string
	prefix = (*inputFileName)[index+1:]
	prefix = prefix[:len(prefix)-4]

	var outputData []byte

	outputData, gkErr = gksvg.FixSvgData(inputData, prefix)
	if gkErr != nil {
		fmt.Printf("error fixing svg file: %s\n", gkErr.String())
		return
	}

	err = writeSvgData(*outputFileName, outputData)
	if err != nil {
		fmt.Printf("error writing file: %v\n", err)
		return
	}
}