org.freehep.graphicsio.emf.EMFGraphics2D Java Examples

The following examples show how to use org.freehep.graphicsio.emf.EMFGraphics2D. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SaveImage.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {

  try {

    if (fileType.equals(FileType.EMF)) {
      OutputStream out2 = new java.io.FileOutputStream(file);
      EMFGraphics2D g2d2 = new EMFGraphics2D(out2, new Dimension(width, height));
      g2d2.startExport();
      chart.draw(g2d2, new Rectangle(width, height));
      g2d2.endExport();
      g2d2.closeStream();
    }

    if (fileType.equals(FileType.EPS)) {
      OutputStream out = new java.io.FileOutputStream(file);
      EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
      g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
      g2d.setupDocument(out, width, height);
      chart.draw(g2d, new Rectangle(width, height));
      g2d.finish();
      out.flush();
      out.close();
    }
  } catch (IOException e) {
    MZmineCore.getDesktop().displayErrorMessage("Unable to save image.");
    e.printStackTrace();
  }
}
 
Example #2
Source File: SwingExportUtil.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Writes swing to EMF
 * 
 * @param panel
 * @param fileName
 * @throws Exception
 */
public static void writeToEMF(JComponent panel, File fileName) throws IOException {
  // print the panel to pdf
  int width = panel.getWidth();
  int height = panel.getWidth();
  logger.info(
      () -> MessageFormat.format("Exporting panel to EMF file (width x height; {0} x {1}): {2}",
          width, height, fileName.getAbsolutePath()));

  VectorGraphics g = new EMFGraphics2D(fileName, new Dimension(width, height));
  g.startExport();
  panel.print(g);
  g.endExport();
}
 
Example #3
Source File: ChartExportUtil.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public static void writeChartToEMF(JFreeChart chart, int width, int height, File name)
    throws IOException {
  try {
    VectorGraphics g = new EMFGraphics2D(name, new Dimension(width, height));
    g.startExport();
    Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height);
    chart.draw(g, rectangle2d);
    g.endExport();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    throw e;
  }
}
 
Example #4
Source File: ChartExportUtil.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public static void writeChartToEMF(JFreeChart chart, int width, int height, File name)
    throws IOException {
  try {
    VectorGraphics g = new EMFGraphics2D(name, new Dimension(width, height));
    g.startExport();
    Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height);
    chart.draw((Graphics2D) g, rectangle2d);
    g.endExport();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    throw e;
  }
}
 
Example #5
Source File: SaveImage.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public void run() {

    try {

      if (fileType.equals(FileType.EMF)) {
        OutputStream out2 = new java.io.FileOutputStream(file);
        EMFGraphics2D g2d2 = new EMFGraphics2D(out2, new Dimension(width, height));
        g2d2.startExport();
        chart.draw(g2d2, new Rectangle(width, height));
        g2d2.endExport();
        g2d2.closeStream();
      }

      if (fileType.equals(FileType.EPS)) {
        OutputStream out = new java.io.FileOutputStream(file);
        EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
        g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
        g2d.setupDocument(out, width, height);
        chart.draw(g2d, new Rectangle(width, height));
        g2d.finish();
        out.flush();
        out.close();
      }
    } catch (IOException e) {
      MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(),
          "Unable to save image.");
      e.printStackTrace();
    }
  }
 
Example #6
Source File: SwingExportUtil.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Writes swing to EMF
 * 
 * @param panel
 * @param fileName
 * @throws Exception
 */
public static void writeToEMF(JComponent panel, File fileName) throws IOException {
  // print the panel to pdf
  int width = panel.getWidth();
  int height = panel.getWidth();
  logger.info(
      () -> MessageFormat.format("Exporting panel to EMF file (width x height; {0} x {1}): {2}",
          width, height, fileName.getAbsolutePath()));

  VectorGraphics g = new EMFGraphics2D(fileName, new Dimension(width, height));
  g.startExport();
  panel.print(g);
  g.endExport();
}
 
Example #7
Source File: ChartExportUtil.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public static void writeChartToEMF(JFreeChart chart, int width, int height, File name)
    throws IOException {
  try {
    VectorGraphics g = new EMFGraphics2D(name, new Dimension(width, height));
    g.startExport();
    Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height);
    chart.draw((Graphics2D) g, rectangle2d);
    g.endExport();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    throw e;
  }
}
 
Example #8
Source File: PIDEF0painter.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
private void writeEMF(OutputStream stream) throws IOException {
    EMFGraphics2D g = new EMFGraphics2D(stream, size);
    g.startExport();
    paint(g, 0, 0);
    g.endExport();
}
 
Example #9
Source File: JFreeChartUtils.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public static void exportToImageFile(ChartViewer chartNode, File file, ImgFileType fileType) {

    final JFreeChart chart = chartNode.getChart();
    final int width = (int) chartNode.getWidth();
    final int height = (int) chartNode.getHeight();

    try {

      switch (fileType) {

        case JPG:
          ExportUtils.writeAsJPEG(chart, width, height, file);
          break;

        case PNG:
          ExportUtils.writeAsPNG(chart, width, height, file);
          break;

        case SVG:
          setDrawSeriesLineAsPath(chart, true);
          ExportUtils.writeAsSVG(chart, width, height, file);
          setDrawSeriesLineAsPath(chart, false);
          break;

        case PDF:
          setDrawSeriesLineAsPath(chart, true);
          ExportUtils.writeAsPDF(chart, width, height, file);
          setDrawSeriesLineAsPath(chart, false);
          break;

        case EMF:
          FileOutputStream out2 = new FileOutputStream(file);
          setDrawSeriesLineAsPath(chart, true);
          EMFGraphics2D g2d2 = new EMFGraphics2D(out2, new Dimension(width, height));
          g2d2.startExport();
          chart.draw(g2d2, new Rectangle(width, height));
          g2d2.endExport();
          setDrawSeriesLineAsPath(chart, false);
          break;

        case EPS:
          FileOutputStream out = new FileOutputStream(file);
          setDrawSeriesLineAsPath(chart, true);
          EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
          g2d.setGraphicContext(new GraphicContext());
          g2d.setupDocument(out, width, height);
          chart.draw(g2d, new Rectangle(width, height));
          g2d.finish();
          setDrawSeriesLineAsPath(chart, false);
          out.close();
          break;

      }

    } catch (IOException e) {
      MZmineGUI.displayMessage("Unable to save image: " + e.getMessage());
      e.printStackTrace();
    }
  }
 
Example #10
Source File: Fh_Svg2Emf.java    From svg2vector with Apache License 2.0 4 votes vote down vote up
@Override
public void setPropertyBackground(boolean on) {
	this.properties.setProperty(EMFGraphics2D.BACKGROUND, on);
}
 
Example #11
Source File: Fh_Svg2Emf.java    From svg2vector with Apache License 2.0 4 votes vote down vote up
@Override
public void setPropertyBackgroundColor(Color color) {
	this.properties.setProperty(EMFGraphics2D.BACKGROUND_COLOR, color);
}
 
Example #12
Source File: Fh_Svg2Emf.java    From svg2vector with Apache License 2.0 4 votes vote down vote up
@Override
public void setPropertyTransparent(boolean on) {
	this.properties.setProperty(EMFGraphics2D.TRANSPARENT, on);
}