Package org.apache.xmlgraphics.java2d.ps

Examples of org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D


    public static void generateEPSusingJava2D(File outputFile) throws IOException {
        OutputStream out = new java.io.FileOutputStream(outputFile);
        out = new java.io.BufferedOutputStream(out);
        try {
            //Instantiate the EPSDocumentGraphics2D instance
            EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
            g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
           
            //Set up the document size
            g2d.setupDocument(out, 400, 200); //400pt x 200pt
           
            //Paint a bounding box
            g2d.drawRect(0, 0, 400, 200);
           
            //A few rectangles rotated and with different color
            Graphics2D copy = (Graphics2D)g2d.create();
            int c = 12;
            for (int i = 0; i < c; i++) {
                float f = ((i + 1) / (float)c);
                Color col = new Color(0.0f, 1 - f, 0.0f);
                copy.setColor(col);
                copy.fillRect(70, 90, 50, 50);
                copy.rotate(-2 * Math.PI / (double)c, 70, 90);
            }
            copy.dispose();
           
            //Some text
            g2d.rotate(-0.25);
            g2d.setColor(Color.RED);
            g2d.setFont(new Font("sans-serif", Font.PLAIN, 36));
            g2d.drawString("Hello world!", 140, 140);
            g2d.setColor(Color.RED.darker());
            g2d.setFont(new Font("serif", Font.PLAIN, 36));
            g2d.drawString("Hello world!", 140, 180);
           
            //Cleanup
            g2d.finish();
        } finally {
            IOUtils.closeQuietly(out);
        }
    }
View Full Code Here


    public static void generateEPSusingJava2D(File outputFile) throws IOException {
        OutputStream out = new java.io.FileOutputStream(outputFile);
        out = new java.io.BufferedOutputStream(out);
        try {
            //Instantiate the EPSDocumentGraphics2D instance
            EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
            g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
           
            //Set up the document size
            g2d.setupDocument(out, 400, 200); //400pt x 200pt
           
            //Paint a bounding box
            g2d.drawRect(0, 0, 400, 200);
           
            //A few rectangles rotated and with different color
            Graphics2D copy = (Graphics2D)g2d.create();
            int c = 12;
            for (int i = 0; i < c; i++) {
                float f = ((i + 1) / (float)c);
                Color col = new Color(0.0f, 1 - f, 0.0f);
                copy.setColor(col);
                copy.fillRect(70, 90, 50, 50);
                copy.rotate(-2 * Math.PI / (double)c, 70, 90);
            }
            copy.dispose();
           
            //Some text
            g2d.rotate(-0.25);
            g2d.setColor(Color.RED);
            g2d.setFont(new Font("sans-serif", Font.PLAIN, 36));
            g2d.drawString("Hello world!", 140, 140);
            g2d.setColor(Color.RED.darker());
            g2d.setFont(new Font("serif", Font.PLAIN, 36));
            g2d.drawString("Hello world!", 140, 180);
           
            //Cleanup
            g2d.finish();
        } finally {
            IOUtils.closeQuietly(out);
        }
    }
View Full Code Here

    public static void generateEPSusingJava2D(File outputFile) throws IOException {
        OutputStream out = new java.io.FileOutputStream(outputFile);
        out = new java.io.BufferedOutputStream(out);
        try {
            //Instantiate the EPSDocumentGraphics2D instance
            EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
            g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());

            //Set up the document size
            g2d.setupDocument(out, 400, 200); //400pt x 200pt

            //Paint a bounding box
            g2d.drawRect(0, 0, 400, 200);

            g2d.setFont(new Font("sans-serif", Font.BOLD, 14));
            g2d.drawString("Color usage example:", 10, 20);
            g2d.setFont(new Font("sans-serif", Font.PLAIN, 12));
            g2d.drawString("RGB", 10, 84);
            g2d.drawString("CMYK", 60, 84);
            g2d.drawString("(Lab)", 110, 84);
            g2d.drawString("(Named)", 160, 84);

            //We're creating a few boxes all filled with some variant of the
            //"Postgelb" (postal yellow) color as used by Swiss Post.

            Color colRGB = new Color(255, 204, 0);
            g2d.setColor(colRGB);
            g2d.fillRect(10, 30, 40, 40);

            //Just convert RGB to CMYK and use that
            float[] compsRGB = colRGB.getColorComponents(null);
            DeviceCMYKColorSpace cmykCS = ColorSpaces.getDeviceCMYKColorSpace();
            float[] compsCMYK = cmykCS.fromRGB(compsRGB);
            Color colCMYK = DeviceCMYKColorSpace.createCMYKColor(compsCMYK);
            g2d.setColor(colCMYK);
            g2d.fillRect(60, 30, 40, 40);

            //Try CIELab (not implemented, yet)
            CIELabColorSpace d50 = ColorSpaces.getCIELabColorSpaceD50();
            Color colLab = d50.toColor(83.25f, 16.45f, 96.89f, 1.0f);
            g2d.setColor(colLab);
            g2d.fillRect(110, 30, 40, 40);

            //Try named color (Separation, not implemented, yet)
            float[] c1xyz = d50.toCIEXYZNative(83.25f, 16.45f, 96.89f);
            NamedColorSpace postgelb = new NamedColorSpace("Postgelb", c1xyz);
            Color colNamed = new Color(postgelb, new float[] {1.0f}, 1.0f);
            g2d.setColor(colNamed);
            g2d.fillRect(160, 30, 40, 40);

            //Cleanup
            g2d.finish();
        } finally {
            IOUtils.closeQuietly(out);
        }
    }
View Full Code Here

        super();
    }

    /** {@inheritDoc} */
    protected AbstractPSDocumentGraphics2D createDocumentGraphics2D() {
        return new EPSDocumentGraphics2D(false);
    }
View Full Code Here

    public static void generateEPSusingJava2D(File outputFile) throws IOException {
        OutputStream out = new java.io.FileOutputStream(outputFile);
        out = new java.io.BufferedOutputStream(out);
        try {
            //Instantiate the EPSDocumentGraphics2D instance
            EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
            g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());

            //Set up the document size
            g2d.setupDocument(out, 400, 200); //400pt x 200pt

            //Paint a bounding box
            g2d.drawRect(0, 0, 400, 200);

            //A few rectangles rotated and with different color
            Graphics2D copy = (Graphics2D)g2d.create();
            int c = 12;
            for (int i = 0; i < c; i++) {
                float f = ((i + 1) / (float)c);
                Color col = new Color(0.0f, 1 - f, 0.0f);
                copy.setColor(col);
                copy.fillRect(70, 90, 50, 50);
                copy.rotate(-2 * Math.PI / (double)c, 70, 90);
            }
            copy.dispose();

            //Some text
            g2d.rotate(-0.25);
            g2d.setColor(Color.RED);
            g2d.setFont(new Font("sans-serif", Font.PLAIN, 36));
            g2d.drawString("Hello world!", 140, 140);
            g2d.setColor(Color.RED.darker());
            g2d.setFont(new Font("serif", Font.PLAIN, 36));
            g2d.drawString("Hello world!", 140, 180);

            //Cleanup
            g2d.finish();
        } finally {
            IOUtils.closeQuietly(out);
        }
    }
View Full Code Here

        super();
    }

    /** {@inheritDoc} */
    protected AbstractPSDocumentGraphics2D createDocumentGraphics2D() {
        return new EPSDocumentGraphics2D(false);
    }
View Full Code Here

        super();
    }

    /** {@inheritDoc} */
    protected AbstractPSDocumentGraphics2D createDocumentGraphics2D() {
        return new EPSDocumentGraphics2D(false);
    }
View Full Code Here

        super();
    }

    /** @see AbstractPSTranscoder#createDocumentGraphics2D() */
    protected AbstractPSDocumentGraphics2D createDocumentGraphics2D() {
        return new EPSDocumentGraphics2D(false);
    }
View Full Code Here

        super();
    }

    /** @see AbstractPSTranscoder#createDocumentGraphics2D() */
    protected AbstractPSDocumentGraphics2D createDocumentGraphics2D() {
        return new EPSDocumentGraphics2D(false);
    }
View Full Code Here

      Configuration c = cfgBuilder.buildFromFile(configFile);

      FontInfo fontInfo = PDFDocumentGraphics2DConfigurator.createFontInfo(c, false);

      OutputStream out = new FileOutputStream("example_eps.eps");
      EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
      g2d.setGraphicContext(new GraphicContext());
      g2d.setCustomTextHandler(new NativeTextHandler(g2d, fontInfo));
      g2d.setupDocument(out, 200, 100);
      g2d.setFont(new Font("Arial", Font.PLAIN, 12));
      g2d.drawString("Hi there Arial", 50, 50);
      g2d.finish();
      out.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D

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.