Package org.apache.batik.svggen

Examples of org.apache.batik.svggen.SVGGraphics2D


        String filename = includedFiles[i];
        File absoluteFile = new File(filesetBaseDir, filename);
        File destinationFile = new File(toDir, m.mapFileName(filename)[0]);
        MathBase base = null;
                                float baseline = 0;
        SVGGraphics2D canvas = null;

        Document inputDocument;
        try {
          inputDocument = MathMLParserSupport.parseFile(absoluteFile);
          Map<ParameterKey, String> params = MathBase.getDefaultParameters();
          params.put(ParameterKey.FontSize, ((Integer) m_size).toString());
          params.put(ParameterKey.OutFileType, "image/svg+xml");
          // Font f = new Font(m_font, Font.PLAIN, m_size);
          base = MathMLParserSupport.createMathBaseFromDocument(inputDocument, params);

          DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
          Document outputDocument = domImpl.createDocument(null, "svg", null);
          canvas = new SVGGraphics2D(outputDocument);

                                        baseline = base.getDescender(canvas);
          float width = base.getWidth(canvas);
          float height = base.getHeight(canvas);
          Dimension d = new Dimension();
          d.setSize(width, height);
          canvas.setSVGCanvasSize(d);

          base.paint(canvas);

        } catch (SAXException e) {
          log("Error reading file " + absoluteFile.getName(), Project.MSG_WARN);
        } catch (IOException e) {
          log("Error reading file " + absoluteFile.getName(), Project.MSG_WARN);
        }

        // Write out the result.
        try {
          Writer out = new OutputStreamWriter(new FileOutputStream(destinationFile), "UTF-8");
          canvas.stream(out, false);   // false = don't use CSS.
          out.flush()
          out.close();
          log("Processed file " + absoluteFile.getName(), Project.MSG_INFO);
        } catch (IOException se) {
          log("Cannot write to output file: " + se.getMessage());
View Full Code Here


        // Create an instance of org.w3c.dom.Document
        Document document = domImpl.createDocument(null, "svg", null);

        // Create an instance of the SVG Generator
        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

        // set the precision to avoid a null pointer exception in Batik 1.5
        svgGenerator.getGeneratorContext().setPrecision(3);

        // Other opts:
        svgGenerator.getGeneratorContext().setEmbeddedFontsOn(true);
//        svgGenerator.setFont( new Font("SansSerif", Font.PLAIN, 8) );

        // Ask the chart to render into the SVG Graphics2D implementation
        chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, width, height), null);

        // Finally, stream out SVG to a file using UTF-8 character to
        // byte encoding
        boolean useCSS = true;

        svgGenerator.stream(out, useCSS);
       
    }
View Full Code Here

    // Set up the map
    SVGGeneratorContext ctx1 = SVGGeneratorContext.createDefault(document);
    SVGGeneratorContext ctx = ctx1;
    ctx.setComment("Generated by GeoTools2 with Batik SVG Generator");
   
    SVGGraphics2D g2d = new SVGGraphics2D(ctx, true);
   
    g2d.setSVGCanvasSize(canvasSize);
   
    StreamingRenderer renderer = new StreamingRenderer();
    renderer.setMapContent(map);
   
    Rectangle outputArea = new Rectangle(g2d.getSVGCanvasSize());
    ReferencedEnvelope dataArea = map.getMaxBounds();
   
    LOGGER.finest("rendering map");
    renderer.paint(g2d, outputArea, dataArea);
    LOGGER.finest("writing to file");
    OutputStreamWriter osw = null;
    try {
        osw = new OutputStreamWriter(out, "UTF-8");
        g2d.stream(osw);
    } finally {
        if (osw != null)
            osw.close();
    }
   
View Full Code Here

          svgRoot.setAttributeNS(null, "width", "2400");
          svgRoot.setAttributeNS(null, "height", "1600");
         

          // Create an instance of the SVG Generator.
          SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

          // Finally, stream out SVG to the standard output using
          // UTF-8 encoding.
          boolean useCSS = true; // we want to use CSS style attributes
          //Writer out = new OutputStreamWriter(System.out, "UTF-8");
         
          //OutputStream out = httpServletResponse.getOutputStream();
      //httpServletResponse.setContentType("APPLICATION/OCTET-STREAM");
      //httpServletResponse.setHeader("Content-Disposition","attachment; filename=\"" + requestedFile + "\"");
          Writer out = new OutputStreamWriter(System.out, "UTF-8");

         
          svgGenerator.stream(out, useCSS);

     
    } catch (Exception er) {
      log.error("ERROR ", er);
      System.out.println("Error exporting: " + er);
View Full Code Here

      //httpServletResponse.setContentType("APPLICATION/OCTET-STREAM");
      //httpServletResponse.setHeader("Content-Disposition","attachment; filename=\"" + requestedFile + "\"");
          Writer out = new OutputStreamWriter(System.out, "UTF-8");

          //Create an instance of the SVG Generator.
          SVGGraphics2D svgGenerator = new SVGGraphics2D(doc);
          svgGenerator.stream(out, useCSS);
         

    } catch (Exception er) {
      log.error("ERROR ", er);
      System.out.println("Error exporting: " + er);
View Full Code Here

          svgRoot.setAttributeNS(null, "width", "2400");
          svgRoot.setAttributeNS(null, "height", "1600");
         

          // Create an instance of the SVG Generator.
          SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

          // Finally, stream out SVG to the standard output using
          // UTF-8 encoding.
          boolean useCSS = true; // we want to use CSS style attributes
          //Writer out = new OutputStreamWriter(System.out, "UTF-8");
         
          //OutputStream out = httpServletResponse.getOutputStream();
      //httpServletResponse.setContentType("APPLICATION/OCTET-STREAM");
      //httpServletResponse.setHeader("Content-Disposition","attachment; filename=\"" + requestedFile + "\"");
          Writer out = new OutputStreamWriter(System.out, "UTF-8");

          //StringWriter out = new StringWriter();
         
          svgGenerator.stream(out, useCSS);
    } catch (Exception er) {
      log.error("ERROR ", er);
      System.out.println("Error exporting: " + er);
      er.printStackTrace();
    }
View Full Code Here

            Double y = Double.valueOf(graphObject.get(graphObject.size()-4).toString()).doubleValue();
           
            //log.debug("x,y,width,height: "+x+","+y+","+width+","+height);
           
            //Draw a Painting
              SVGGraphics2D svgGenerator_temp = new SVGGraphics2D(svgGenerator);
              //SVGGraphics2D svgGenerator2 = new SVGGraphics2D(document);
              
              log.debug("pointsList: "+pointsList);
              this.drawPointsObject(svgGenerator_temp, pointsList, new Color(col), lineWidth, x, y, alpha);
             
          } else if (graphType.equals("rectangle")) {
           
            /*actionObject[0] = 'rectangle';
            actionObject[1] = stroke;
            actionObject[2] = line;
            actionObject[3] = fill;
            actionObject[4] = strokeDis;
            actionObject[5] = fillDis;
            actionObject[6] = this.currentrectangleOpacity;*/
           
            Integer lineWidth = Integer.valueOf(graphObject.get(2).toString()).intValue();
           
            Integer stroke = Integer.valueOf(graphObject.get(1).toString()).intValue();
            Integer strokeDis= Integer.valueOf(graphObject.get(4).toString()).intValue();
           
            Color strokeColor = null;
            if (strokeDis != -1) {
              strokeColor = new Color(stroke);
            }
           
            Integer fill = Integer.valueOf(graphObject.get(3).toString()).intValue();
            Integer fillDis= Integer.valueOf(graphObject.get(5).toString()).intValue();
           
            Color fillColor = null;
            if (fillDis != -1) {
              fillColor = new Color(fill);
            }
           
            Float alpha = Float.valueOf(graphObject.get(6).toString()).floatValue();
           
            Double x = Double.valueOf(graphObject.get(graphObject.size()-5).toString()).doubleValue();
            Double y = Double.valueOf(graphObject.get(graphObject.size()-4).toString()).doubleValue();
            Double width = Double.valueOf(graphObject.get(graphObject.size()-3).toString()).doubleValue();
            Double height = Double.valueOf(graphObject.get(graphObject.size()-2).toString()).doubleValue();
         
            SVGGraphics2D svgGenerator_temp = new SVGGraphics2D(svgGenerator);
            this.paintRect2D(svgGenerator_temp, x, y, width, height, strokeColor, lineWidth, fillColor, alpha);
           
          } else if (graphType.equals("ellipse")) {
           
            Integer lineWidth = Integer.valueOf(graphObject.get(2).toString()).intValue();
           
            Integer stroke = Integer.valueOf(graphObject.get(1).toString()).intValue();
            Integer strokeDis= Integer.valueOf(graphObject.get(4).toString()).intValue();
           
            Color strokeColor = null;
            if (strokeDis != -1) {
              strokeColor = new Color(stroke);
            }
           
            Integer fill = Integer.valueOf(graphObject.get(3).toString()).intValue();
            Integer fillDis= Integer.valueOf(graphObject.get(5).toString()).intValue();
           
            Color fillColor = null;
            if (fillDis != -1) {
              fillColor = new Color(fill);
            }
           
            Float alpha = Float.valueOf(graphObject.get(6).toString()).floatValue();
           
            Double x = Double.valueOf(graphObject.get(graphObject.size()-5).toString()).doubleValue();
            Double y = Double.valueOf(graphObject.get(graphObject.size()-4).toString()).doubleValue();
            Double width = Double.valueOf(graphObject.get(graphObject.size()-3).toString()).doubleValue();
            Double height = Double.valueOf(graphObject.get(graphObject.size()-2).toString()).doubleValue();
         
            SVGGraphics2D svgGenerator_temp = new SVGGraphics2D(svgGenerator);
            this.paintEllipse2D(svgGenerator_temp, x, y, width, height, strokeColor, lineWidth, fillColor, alpha);
           
          } else if (graphType.equals("letter")) {
           
            String text = graphObject.get(1).toString();
            Color fontColor = new Color (Integer.valueOf(graphObject.get(2).toString()).intValue());
            Integer fontSize = Integer.valueOf(graphObject.get(3).toString()).intValue();
           
            String fontStyle = graphObject.get(4).toString();
            Integer style = null;
            if (fontStyle.equals("plain")) {
              style = Font.PLAIN;
            } else if (fontStyle.equals("bold")) {
              style = Font.BOLD;
            } else if (fontStyle.equals("italic")) {
              style = Font.ITALIC;
            } else if (fontStyle.equals("bolditalic")) {
              style = Font.ITALIC+Font.BOLD;
            }
           
            log.debug("fontStyle,style "+style+" fs: "+fontStyle);
           
            Double x = Double.valueOf(graphObject.get(graphObject.size()-5).toString()).doubleValue();
            Double y = Double.valueOf(graphObject.get(graphObject.size()-4).toString()).doubleValue();
            Double width = Double.valueOf(graphObject.get(graphObject.size()-3).toString()).doubleValue();
            Double height = Double.valueOf(graphObject.get(graphObject.size()-2).toString()).doubleValue();
           
            SVGGraphics2D svgGenerator_temp = new SVGGraphics2D(svgGenerator);
            this.paintTextByWidthHeight(svgGenerator_temp, (int) Math.round(x), (int) Math.round(y), (int) Math.round(width),
                  (int) Math.round(height), text, style, fontSize, fontColor);
           
          } else if (graphType.equals("drawarrow")) {
           
            Integer thickness = Integer.valueOf(graphObject.get(2).toString()).intValue();
           
            Integer stroke = Integer.valueOf(graphObject.get(1).toString()).intValue();
            Integer strokeDis= Integer.valueOf(graphObject.get(4).toString()).intValue();
           
            Color strokeColor = null;
            if (strokeDis != -1) {
              strokeColor = new Color(stroke);
            }
           
            Integer fill = Integer.valueOf(graphObject.get(3).toString()).intValue();
            Integer fillDis= Integer.valueOf(graphObject.get(5).toString()).intValue();
           
            Color fillColor = null;
            if (fillDis != -1) {
              fillColor = new Color(fill);
            }
           
            Float alpha = Float.valueOf(graphObject.get(6).toString()).floatValue();
           
            Double x = Double.valueOf(graphObject.get(graphObject.size()-5).toString()).doubleValue();
            Double y = Double.valueOf(graphObject.get(graphObject.size()-4).toString()).doubleValue();
            //Double width = Double.valueOf(graphObject.get(graphObject.size()-3).toString()).doubleValue();
            //Double height = Double.valueOf(graphObject.get(graphObject.size()-2).toString()).doubleValue();
           
            Double x1 = Double.valueOf(graphObject.get(7).toString()).doubleValue();
            Double y1 = Double.valueOf(graphObject.get(8).toString()).doubleValue();
            Double x2 = Double.valueOf(graphObject.get(9).toString()).doubleValue();
            Double y2 = Double.valueOf(graphObject.get(10).toString()).doubleValue();
           
            GeomPoint start = new GeomPoint();
              start.setLocation(x+x1,y+y1);
              GeomPoint end = new GeomPoint();
              end.setLocation(x+x2,y+y2);
             
              SVGGraphics2D svgGenerator_temp = new SVGGraphics2D(svgGenerator);
              this.drawArrow(svgGenerator_temp, start, end, thickness, alpha, strokeColor,fillColor);
          } else if (graphType.equals("image")) {
           
            //log.debug("graphObject image "+graphObject);
            //log.debug("",graphObject);
           
            String room = graphObject.get(6).toString();
            String parentPath = graphObject.get(5).toString();
            String fileItemName = graphObject.get(3).toString();
           
            String imageFilePath = ScopeApplicationAdapter.webAppPath + File.separatorChar +
                OpenmeetingsVariables.UPLOAD_DIR + File.separatorChar + room + File.separatorChar;
           
            if (parentPath.length() > 1) {
              imageFilePath += parentPath + File.separatorChar;
            }
           
            //log.debug("fileItemName: "+fileItemName);
           
            String full_path = imageFilePath + fileItemName;
            File myFile = new File(full_path);
           
            if (myFile.exists() && myFile.canRead()) {
             
              Image myImage = ImageIO.read(myFile);
             
              int x = (int) Math.round(Double.valueOf(graphObject.get(graphObject.size()-5).toString()).doubleValue());
              int y = (int) Math.round(Double.valueOf(graphObject.get(graphObject.size()-4).toString()).doubleValue());
              int width = (int) Math.round(Double.valueOf(graphObject.get(graphObject.size()-3).toString()).doubleValue());
              int height = (int) Math.round(Double.valueOf(graphObject.get(graphObject.size()-2).toString()).doubleValue());
             
              SVGGraphics2D svgGenerator_temp = new SVGGraphics2D(svgGenerator);
              svgGenerator_temp.drawImage(myImage, x, y, width, height, null);
             
            } else {
              log.error("tried to inculde a non existing File into SVG/Image Export Path: "+full_path);
            }
           
          } else if(graphType.equals("line") || graphType.equals("uline")) {
           
//            actionObject[0] = 'line';
//                actionObject[1] = stroke;
//                actionObject[2] = line;
//                actionObject[3] = opacity;
//                actionObject[4] = x1 
//                actionObject[5] = y1; 
//                actionObject[6] = x2;   
//                actionObject[7] = y2;   
//                actionObject[8] = this.counter;
//                actionObject[9] = x;
//                actionObject[10] = y;
//                actionObject[11] = width;
//                actionObject[12] = height; 
//                actionObject[13] = newName;
           
          Integer lineWidth = Integer.valueOf(graphObject.get(2).toString()).intValue();
           
            Integer stroke = Integer.valueOf(graphObject.get(1).toString()).intValue();
            Color strokeColor = new Color(stroke);
           
            Float alpha = Float.valueOf(graphObject.get(3).toString()).floatValue();
           
            Double x = Double.valueOf(graphObject.get(graphObject.size()-5).toString()).doubleValue();
            Double y = Double.valueOf(graphObject.get(graphObject.size()-4).toString()).doubleValue();
            //Double width = Double.valueOf(graphObject.get(graphObject.size()-3).toString()).doubleValue();
            //Double height = Double.valueOf(graphObject.get(graphObject.size()-2).toString()).doubleValue();

            Double x1 = Double.valueOf(graphObject.get(4).toString()).doubleValue();
            Double y1 = Double.valueOf(graphObject.get(5).toString()).doubleValue();
            Double x2 = Double.valueOf(graphObject.get(6).toString()).doubleValue();
            Double y2 = Double.valueOf(graphObject.get(7).toString()).doubleValue();
           
            SVGGraphics2D svgGenerator_temp = new SVGGraphics2D(svgGenerator);
            this.drawLine(svgGenerator_temp, x1, y1, x2, y2, strokeColor, lineWidth, x, y, alpha);
           
          } else {
            log.error("tried to include a non supported Graph-Object graphType: "+graphType);
          }
View Full Code Here

      //int x, int y, int width, int height
    n.setBounds( x, y , width, height );
    n.setOpaque( false );
   
    //Text
    SVGGraphics2D svgGenerator2 = (SVGGraphics2D) g2d.create(x, y, width, height);

    //svgGenerator2.create(x, y, width, height);
    //svgGenerator2.draw(.dra)
    n.paint( svgGenerator2 );
   
View Full Code Here

    protected SVGGraphics2D buildSVGGraphics2D() {
        // CSSDocumentHandler.setParserClassName(CSS_PARSER_CLASS_NAME);
        DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
        String namespaceURI = SVGDOMImplementation.SVG_NAMESPACE_URI;
        Document domFactory = impl.createDocument(namespaceURI, SVG_SVG_TAG, null);
        return new SVGGraphics2D(domFactory);
    }
View Full Code Here

    public JPainterCompare(Painter painter){
        // First, create the AWT reference.
        JPainterComponent ref = new JPainterComponent(painter);

        // Now, generate the SVG from this Painter
        SVGGraphics2D g2d = buildSVGGraphics2D();

        g2d.setSVGCanvasSize(CANVAS_SIZE);

        //
        // Generate SVG content
        //
        File tmpFile = null;
        try{
            tmpFile = File.createTempFile(CONFIG_TMP_FILE_PREFIX,
                                          ".svg");
           
            OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(tmpFile), "UTF-8");

            painter.paint(g2d);
            g2d.stream(osw);
            osw.flush();
        }catch(Exception e){
            e.printStackTrace();
            throw new IllegalArgumentException
                (Messages.formatMessage(ERROR_COULD_NOT_TRANSCODE_TO_SVG,
View Full Code Here

TOP

Related Classes of org.apache.batik.svggen.SVGGraphics2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.