Package org.apache.batik.svggen

Examples of org.apache.batik.svggen.SVGGraphics2D


            Double height = Double.valueOf(graphObject.get(graphObject.size()-2).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 +
                        "upload" + 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

           
            // 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);
           
            // Ask the test to render into the SVG Graphics2D implementation
            getGISDisplay().printLayers(svgGenerator, new gistoolkit.features.Envelope(0, 0, getGISDisplay().getWidth(), getGISDisplay().getHeight()));
           
            // Finally, stream out SVG to the file output using UTF-8
            // character to byte encoding
            boolean useCSS = true; // we want to use CSS style attribute
            try{
                FileOutputStream fout = new FileOutputStream(tempFile);
                BufferedOutputStream bout = new BufferedOutputStream(fout);
                Writer out = new OutputStreamWriter(bout, "UTF-8");
                svgGenerator.stream(out, useCSS);
                bout.flush();
                bout.close();
                fout.close();
            }
            catch (IOException e){
View Full Code Here

            = ExtensibleSVGDOMImplementation.getDOMImplementation();

        Document doc = domImpl.createDocument(SVG_NAMESPACE_URI,
                                              SVG_SVG_TAG, null);

        SVGGraphics2D svgGenerator = new SVGGraphics2D(doc);

        painter.paint(svgGenerator);

        //
        // Set the size and viewBox on the output document
        //
        int vpX = currentStore.getVpX();
        int vpY = currentStore.getVpY();
        int vpW = currentStore.getVpW();
        int vpH = currentStore.getVpH();
        svgGenerator.setSVGCanvasSize(new Dimension(vpW, vpH));

        Element svgRoot = svgGenerator.getRoot();
        svgRoot.setAttributeNS(null, SVG_VIEW_BOX_ATTRIBUTE,
                               "" + vpX + " " + vpY + " " +
                               vpW + " " + vpH );

        //
View Full Code Here

                            Document document = docBuilder.newDocument();
                            Element svgelem = document.createElement("svg");
                            document.appendChild(svgelem);

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

                            // draw the chart in the SVG generator
                            chart.draw(svgGenerator, new Rectangle(widht,
                                    height));
                            Element el = svgGenerator.getRoot();
                            el.setAttributeNS(null, "viewBox", "0 0 " + widht
                                    + " " + height + "");
                            el.setAttributeNS(null, "style",
                                    "width:100%;height:100%;");
                            el.setAttributeNS(null, "preserveAspectRatio",
                                    getSvgAspectRatio());

                            // Write svg to buffer
                            ByteArrayOutputStream baoutputStream = new ByteArrayOutputStream();
                            Writer out;
                            try {
                                OutputStream outputStream = gzipEnabled ? new GZIPOutputStream(
                                        baoutputStream) : baoutputStream;
                                out = new OutputStreamWriter(outputStream,
                                        "UTF-8");
                                /*
                                 * don't use css, FF3 can'd deal with the result
                                 * perfectly: wrong font sizes
                                 */
                                boolean useCSS = false;
                                svgGenerator.stream(el, out, useCSS, false);
                                outputStream.flush();
                                outputStream.close();
                                bytestream = new ByteArrayInputStream(
                                        baoutputStream.toByteArray());
                            } catch (UnsupportedEncodingException e) {
View Full Code Here

        SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(domFactory);
        GraphicContextDefaults defaults
            = new GraphicContextDefaults();
        defaults.font = new Font("Arial", Font.PLAIN, 12);
        ctx.setGraphicContextDefaults(defaults);
        SVGGraphics2D g2d = new SVGGraphics2D(ctx, false);

        g2d.setSVGCanvasSize(CANVAS_SIZE);

        Painter painter = new BasicShapes();
        painter.paint(g2d);

        StringWriter swA = new StringWriter();
        g2d.stream(g2d.getRoot(), swA);

        // Now, use the getRoot with argument
        domFactory = impl.createDocument(namespaceURI, SVG_SVG_TAG, null);
        ctx = SVGGeneratorContext.createDefault(domFactory);
        ctx.setGraphicContextDefaults(defaults);
        g2d = new SVGGraphics2D(ctx, false);

        g2d.setSVGCanvasSize(CANVAS_SIZE);

        painter.paint(g2d);

        StringWriter swB = new StringWriter();
        g2d.stream(g2d.getRoot(domFactory.getDocumentElement()),
                   swB);

        // Compare the two output: they should be identical
        if (swA.toString().equals(swB.toString())) {
            return reportSuccess();
View Full Code Here

      if ((height == -1) || (width == -1)) {
        throw new IOException("Could not determine map dimensions");
      }

      SVGGeneratorContext context = setupContext();
      SVGGraphics2D g = new SVGGraphics2D(context, true);

      g.setSVGCanvasSize(new Dimension((int) width, (int) height));

      // turn off/on anti aliasing
      if (wmsConfig.isSvgAntiAlias()) {
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
      } else {
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_OFF);
      }

      // enforce no more than x rendering errors
            int maxErrors = wmsConfig.getMaxRenderingErrors();
            MaxErrorEnforcer errorChecker = new MaxErrorEnforcer(renderer, maxErrors);

            // Add a render listener that ignores well known rendering exceptions and reports back non
            // ignorable ones
            final RenderExceptionStrategy nonIgnorableExceptionListener;
            nonIgnorableExceptionListener = new RenderExceptionStrategy(renderer);
            renderer.addRenderListener(nonIgnorableExceptionListener);

            renderer.paint(g, new Rectangle(g.getSVGCanvasSize()), getRenderingArea(), getRenderingTransform());
     
      // check if too many errors occurred
            if(errorChecker.exceedsMaxErrors()) {
                throw new WmsException("More than " + maxErrors + " rendering errors occurred, bailing out.",
                        "internalError", errorChecker.getLastException());
            }

            //check if a non ignorable error occurred
            if(nonIgnorableExceptionListener.exceptionOccurred()){
                Exception renderError = nonIgnorableExceptionListener.getException();
                throw new WmsException("Rendering process failed", "internalError", renderError);
            }
           
      // This method of output does not output the DOCTYPE definiition
      // TODO: make a config option that toggles wether doctype is
      // written out.
      OutputFormat format = new OutputFormat();
      XMLSerializer serializer = new XMLSerializer(
          new OutputStreamWriter(out, "UTF-8"), format);

            // this method does output the DOCTYPE def
             g.stream(new OutputStreamWriter(out,"UTF-8"));
      } catch(ParserConfigurationException e) {
          throw new WmsException("Unexpected exception", "internalError", e);
        } finally {
            // free up memory
            renderer = null;
View Full Code Here

    OutputStreamWriter writer = new OutputStreamWriter(baos, "UTF-8");
    DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
    Document document = domImpl.createDocument("cewolf-svg", "svg", null);
    SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
//    ctx.setComment("Generated by Cewolf using JFreeChart and Apache Batik SVG Generator");
    SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
    svgGenerator.setSVGCanvasSize(new Dimension(width, height));
    chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, width, height), null);
    svgGenerator.stream(writer, false);
    writer.close();
  }
View Full Code Here

            DOMImplementation domImpl = getDOMImpl();

            Document document = domImpl.createDocument("www.cs.man.ac.uk/~horridgm", "svg", null);

            // Get an instance of the svg generator
            SVGGraphics2D graphics2D = new SVGGraphics2D(document);

            graphics2D.getGeneratorContext().setPrecision(4);

            graphics2D.setClip(0, 0, width + 10, height + 10);

            if(getScale() != 100.0)
            {
                graphics2D.scale(getScale() / 100.0, getScale() / 100.0);
            }

            controller.getGraphView().draw(graphics2D, false, false, false, true);

            try
            {

                OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8");

                try
                {
                    graphics2D.stream(osw, true);
                }
                catch(SVGGraphics2DIOException e)
                {
                    e.printStackTrace();
                }
View Full Code Here

     */
    public TestReport runImpl() throws Exception {
        DefaultTestReport report
            = new DefaultTestReport(this);

        SVGGraphics2D g2d = buildSVGGraphics2D();
        g2d.setSVGCanvasSize(CANVAS_SIZE);

        //
        // Generate SVG content
        //
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        OutputStreamWriter osw = new OutputStreamWriter(bos, "UTF-8");
        try{
            painter.paint(g2d);
            configureSVGGraphics2D(g2d);
            g2d.stream(osw);
            osw.flush();
            bos.flush();
            bos.close();
        }catch(Exception e){
            StringWriter trace = new StringWriter();
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.