java - Batik - Modify and saving of SVG results in not well formed XML -
i'm trying edit existing svg , save afterwards using batik (i need different formats , dom-manipulation).
what do:
adobe illustrator source file (cs 4.0) saved svg 1.0 glyphs (two embedded fonts) loaded batik (using saxsvgdocumentfactory, source below) dom-modifications (even without modifications problem occurs) saving using svgtranscoderafter transcoding new svg-file, filled xml, not able render in firefox or illustrator.
in firefox message xml not formed e.g.,
<glyph horiz-adv-x="249" unicode=""/> my code:
/////////////// // load template file (with embedded fonts) /////////////// file file = new file(svgfilepath); fileinputstream svginputstream = new fileinputstream(file); //////////////////// // load svg dom-tree //////////////////// string parser = xmlresourcedescriptor.getxmlparserclassname(); saxsvgdocumentfactory mill = new saxsvgdocumentfactory(parser); document doc = factory.createdocument(parser, svginputstream); //... /////////////////////// // generate output file /////////////////////// string savepath = "test.svg"; byte[] filedata = transcodetosvg(doc); fileoutputstream filesave = new fileoutputstream(savepath); filesave.write(filedata); filesave.close(); my transcoding code:
public byte[] transcodetosvg(document doc) throws transcoderexception { seek { //determine output type: svgtranscoder t = new svgtranscoder(); //set transcoder input/output transcoderinput input = new transcoderinput(doc); bytearrayoutputstream bytestream = new bytearrayoutputstream(); outputstreamwriter ostream = new outputstreamwriter(bytestream); transcoderoutput output = new transcoderoutput(ostream); //perform transcoding t.transcode(input, output); ostream.flush(); ostream.close(); homecoming bytestream.tobytearray(); } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); } homecoming null; }
david conrads hint unicode character lead me solution:
i missing right encoding of file.
after changing
outputstreamwriter ostream = new outputstreamwriter(bytestream); to
outputstreamwriter ostream = new outputstreamwriter(bytestream, "utf-8"); it works well.
java svg batik
No comments:
Post a Comment