SHARE
TWEET

Untitled

a guest Jun 15th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.ByteArrayInputStream;
  2. import java.io.ByteArrayOutputStream;
  3.  
  4. import org.apache.batik.transcoder.TranscoderInput;
  5. import org.apache.batik.transcoder.TranscoderOutput;
  6. import org.apache.batik.transcoder.image.PNGTranscoder;
  7.  
  8. public class SVGHelperDesktop extends SVGHelper {
  9.     @Override
  10.     public byte[] convertSvgToPng(String svgXml, float png_width)
  11.             throws SVGConversionException {
  12.         byte[] resultPngBytes = null;
  13.  
  14.         try {
  15.             ByteArrayInputStream inputSvgBytes = new
  16.                     ByteArrayInputStream(svgXml.getBytes());
  17.             TranscoderInput input_svg_image = new
  18.                     TranscoderInput(inputSvgBytes);
  19.  
  20.             ByteArrayOutputStream outputPngBytes = new ByteArrayOutputStream();
  21.             TranscoderOutput output_png_image = new TranscoderOutput(outputPngBytes);
  22.  
  23.             PNGTranscoder svgToPngConverter = new PNGTranscoder();
  24.             svgToPngConverter.addTranscodingHint(PNGTranscoder.KEY_WIDTH, png_width);
  25.             svgToPngConverter.transcode(input_svg_image, output_png_image);
  26.  
  27.             resultPngBytes = outputPngBytes.toByteArray();
  28.  
  29.             outputPngBytes.flush();
  30.             outputPngBytes.close();
  31.         } catch (Exception e) {
  32.             throw new SVGConversionException("Error converting SVG to PNG", e);
  33.         }
  34.  
  35.         return resultPngBytes;
  36.     }
  37. }
  38.      
  39. style="... font-family:Aharoni;-inkscape-font-specification:'Aharoni, Bold';font-variant-ligatures:normal; ..."
  40.      
  41. import org.apache.batik.css.parser.ExtendedParser;
  42. import org.apache.batik.css.parser.Parser;
  43. import org.w3c.css.sac.CSSException;
  44. import java.io.IOException;
  45.  
  46. public class InkscapeCssParser extends Parser {
  47.     public void parseStyleDeclaration(String source)
  48.             throws CSSException, IOException {
  49.         source = source.replaceAll(";-inkscape", ";inkscape");
  50.         super.parseStyleDeclaration(source);
  51.     }
  52. }
  53.      
  54. JSVGCanvas mSvgCanvas;
  55. XMLResourceDescriptor.setCSSParserClassName(InkscapeCssParser.class.getName());
  56. mSvgCanvas.setURI(svgUrl.toString());
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top