xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerem...@apache.org
Subject svn commit: r390751 - in /xmlgraphics/commons/trunk: examples/ examples/java/ examples/java/java2d/ examples/java/java2d/ps/ src/java/org/apache/xmlgraphics/java2d/ps/ src/java/org/apache/xmlgraphics/ps/
Date Sat, 01 Apr 2006 21:01:17 GMT
Author: jeremias
Date: Sat Apr  1 13:01:14 2006
New Revision: 390751

URL: http://svn.apache.org/viewcvs?rev=390751&view=rev
Log:
Ported the PostScript Graphics2D code from FOP.
All FOP-specific font handling code has been extracted by creating a "TextHandler" interface
which is responsible for all text operations. There's a default implementation (StrokingTextHandler)
which paints all text as shapes. It is used if no other TextHandler instance is supplied.
Added an example which shows how to use EPSDocumentGraphics2D.

Added:
    xmlgraphics/commons/trunk/examples/
    xmlgraphics/commons/trunk/examples/java/
    xmlgraphics/commons/trunk/examples/java/java2d/
    xmlgraphics/commons/trunk/examples/java/java2d/ps/
    xmlgraphics/commons/trunk/examples/java/java2d/ps/EPSExample1.java   (with props)
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/AbstractPSDocumentGraphics2D.java
      - copied, changed from r390740, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/EPSDocumentGraphics2D.java
      - copied, changed from r390740, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/EPSDocumentGraphics2D.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSDocumentGraphics2D.java
      - copied, changed from r390740, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
      - copied, changed from r390712, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2D.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/StrokingTextHandler.java
  (with props)
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/TextHandler.java 
 (with props)
Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSImageUtils.java

Added: xmlgraphics/commons/trunk/examples/java/java2d/ps/EPSExample1.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/commons/trunk/examples/java/java2d/ps/EPSExample1.java?rev=390751&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/examples/java/java2d/ps/EPSExample1.java (added)
+++ xmlgraphics/commons/trunk/examples/java/java2d/ps/EPSExample1.java Sat Apr  1 13:01:14
2006
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package java2d.ps;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D;
+
+/**
+ * This example demonstrates how you can generate an EPS (Encapsulated PostScript) file in
Java
+ * using the EPSDocumentGraphics2D class from Apache XML Graphics Commons.
+ */
+public class EPSExample1 {
+
+    /**
+     * Creates an EPS file. The contents are painted using a Graphics2D implementation that
+     * generates an EPS file.
+     * @param outputFile the target file
+     * @throws IOException In case of an I/O error
+     */
+    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);
+        }
+    }
+    
+    /**
+     * Command-line interface
+     * @param args command-line arguments
+     */
+    public static void main(String[] args) {
+        try {
+            File targetDir;
+            if (args.length >= 1) {
+                targetDir = new File(args[0]);
+            } else {
+                targetDir = new File(".");
+            }
+            if (!targetDir.exists()) {
+                System.err.println("Target Directory does not exist: " + targetDir);
+            }
+            generateEPSusingJava2D(new File(targetDir, "eps-example1.eps"));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+}

Propchange: xmlgraphics/commons/trunk/examples/java/java2d/ps/EPSExample1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/AbstractPSDocumentGraphics2D.java
(from r390740, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java)
URL: http://svn.apache.org/viewcvs/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/AbstractPSDocumentGraphics2D.java?p2=xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/AbstractPSDocumentGraphics2D.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java&r1=390740&r2=390751&rev=390751&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/AbstractPSDocumentGraphics2D.java
(original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/AbstractPSDocumentGraphics2D.java
Sat Apr  1 13:01:14 2006
@@ -16,18 +16,16 @@
 
 /* $Id$ */
  
-package org.apache.fop.render.ps;
+package org.apache.xmlgraphics.java2d.ps;
 
-//Java
 import java.awt.Color;
 import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.io.OutputStream;
 import java.io.IOException;
 
-//FOP
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontSetup;
+import org.apache.xmlgraphics.ps.DSCConstants;
+import org.apache.xmlgraphics.ps.PSGenerator;
 
 /**
  * This class is a wrapper for the <tt>PSGraphics2D</tt> that
@@ -36,7 +34,7 @@
  *
  * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
  * @version $Id$
- * @see org.apache.fop.render.ps.PSGraphics2D
+ * @see org.apache.xmlgraphics.java2d.ps.PSGraphics2D
  */
 public abstract class AbstractPSDocumentGraphics2D extends PSGraphics2D {
 
@@ -68,11 +66,6 @@
      */
     AbstractPSDocumentGraphics2D(boolean textAsShapes) {
         super(textAsShapes);
-
-        if (!textAsShapes) {
-            fontInfo = new FontInfo();
-            FontSetup.setup(fontInfo, null, null);
-        }
     }
 
     /**
@@ -118,16 +111,16 @@
     }
 
     /**
-     * Set the dimensions of the SVG document that will be drawn.
-     * This is useful if the dimensions of the SVG document are different
+     * Set the dimensions of the document that will be drawn.
+     * This is useful if the dimensions of the document are different
      * from the PostScript document that is to be created.
-     * The result is scaled so that the SVG fits correctly inside the
+     * The result is scaled so that the document fits correctly inside the
      * PostScript document.
      * @param w the width of the page
      * @param h the height of the page
      * @throws IOException in case of an I/O problem
      */
-    public void setSVGDimension(float w, float h) throws IOException {
+    public void setViewportDimension(float w, float h) throws IOException {
         this.viewportWidth = w;
         this.viewportHeight = h;
         /*
@@ -188,7 +181,7 @@
     
 
     /** {@inheritDoc} */
-    protected void preparePainting() {
+    public void preparePainting() {
         if (this.pagePending) {
             return;
         }

Copied: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/EPSDocumentGraphics2D.java
(from r390740, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/EPSDocumentGraphics2D.java)
URL: http://svn.apache.org/viewcvs/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/EPSDocumentGraphics2D.java?p2=xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/EPSDocumentGraphics2D.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/EPSDocumentGraphics2D.java&r1=390740&r2=390751&rev=390751&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/EPSDocumentGraphics2D.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/EPSDocumentGraphics2D.java
Sat Apr  1 13:01:14 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003-2005 The Apache Software Foundation.
+ * Copyright 2003-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,19 +16,20 @@
 
 /* $Id$ */
  
-package org.apache.fop.render.ps;
+package org.apache.xmlgraphics.java2d.ps;
 
 import java.io.IOException;
 
-import org.apache.fop.Version;
+import org.apache.xmlgraphics.ps.DSCConstants;
+import org.apache.xmlgraphics.ps.PSProcSets;
 
 /**
  * This class is a wrapper for the <tt>AbstractPSDocumentGraphics2D</tt> that
  * is used to create EPS (Encapsulated PostScript) files instead of PS file.
  *
  * @version $Id$
- * @see org.apache.fop.render.ps.PSGraphics2D
- * @see org.apache.fop.render.ps.AbstractPSDocumentGraphics2D
+ * @see org.apache.xmlgraphics.java2d.ps.PSGraphics2D
+ * @see org.apache.xmlgraphics.java2d.ps.AbstractPSDocumentGraphics2D
  */
 public class EPSDocumentGraphics2D extends AbstractPSDocumentGraphics2D {
 
@@ -54,8 +55,8 @@
         //PostScript Header
         gen.writeln(DSCConstants.PS_ADOBE_30 + " " + DSCConstants.EPSF_30);
         gen.writeDSCComment(DSCConstants.CREATOR, 
-                    new String[] {"Apache FOP " + Version.getVersion() 
-                        + ": EPS Transcoder for SVG"});
+                    new String[] {"Apache XML Graphics Commons" 
+                        + ": EPS Generator for Java2D"});
         gen.writeDSCComment(DSCConstants.CREATION_DATE, 
                     new Object[] {new java.util.Date()});
         gen.writeDSCComment(DSCConstants.PAGES, new Integer(0));
@@ -68,8 +69,8 @@
         gen.writeDSCComment(DSCConstants.BEGIN_PROLOG);
         PSProcSets.writeFOPStdProcSet(gen);
         PSProcSets.writeFOPEPSProcSet(gen);
-        if (fontInfo != null) {
-            PSFontUtils.writeFontDict(gen, fontInfo);
+        if (customTextHandler != null) {
+            customTextHandler.writeSetup();
         }
         gen.writeDSCComment(DSCConstants.END_PROLOG);
     }
@@ -81,8 +82,8 @@
         gen.writeDSCComment(DSCConstants.PAGE_BBOX, new Object[]
                 {ZERO, ZERO, new Integer(width), new Integer(height)});
         gen.writeDSCComment(DSCConstants.BEGIN_PAGE_SETUP);
-        if (fontInfo != null) {         
-            gen.writeln("FOPFonts begin");
+        if (customTextHandler != null) {
+            customTextHandler.writePageSetup();
         }
     }
     

Copied: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSDocumentGraphics2D.java
(from r390740, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java)
URL: http://svn.apache.org/viewcvs/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSDocumentGraphics2D.java?p2=xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSDocumentGraphics2D.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java&r1=390740&r2=390751&rev=390751&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSDocumentGraphics2D.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSDocumentGraphics2D.java
Sat Apr  1 13:01:14 2006
@@ -16,17 +16,15 @@
 
 /* $Id$ */
 
-package org.apache.fop.render.ps;
+package org.apache.xmlgraphics.java2d.ps;
 
-//Java
 import java.awt.Graphics;
 import java.io.OutputStream;
 import java.io.IOException;
 
-//FOP
-import org.apache.fop.Version;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontSetup;
+import org.apache.xmlgraphics.ps.DSCConstants;
+import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.xmlgraphics.ps.PSProcSets;
 
 /**
  * This class is a wrapper for the <tt>PSGraphics2D</tt> that
@@ -35,11 +33,10 @@
  *
  * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
  * @version $Id$
- * @see org.apache.fop.render.ps.PSGraphics2D
+ * @see org.apache.xmlgraphics.java2d.ps.PSGraphics2D
  */
 public class PSDocumentGraphics2D extends AbstractPSDocumentGraphics2D {
 
-    
     /**
      * Create a new AbstractPSDocumentGraphics2D.
      * This is used to create a new PostScript document, the height,
@@ -86,8 +83,8 @@
         //PostScript Header
         gen.writeln(DSCConstants.PS_ADOBE_30);
         gen.writeDSCComment(DSCConstants.CREATOR,
-                    new String[] {"Apache FOP " + Version.getVersion() 
-                        + ": PostScript Transcoder for SVG"});
+                    new String[] {"Apache XML Graphics Commons" 
+                        + ": PostScript Generator for Java2D"});
         gen.writeDSCComment(DSCConstants.CREATION_DATE,
                     new Object[] {new java.util.Date()});
         gen.writeDSCComment(DSCConstants.PAGES, PSGenerator.ATEND);
@@ -107,8 +104,8 @@
         gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
         PSProcSets.writeFOPStdProcSet(gen);
         PSProcSets.writeFOPEPSProcSet(gen);
-        if (fontInfo != null) {
-            PSFontUtils.writeFontDict(gen, fontInfo);
+        if (customTextHandler != null) {
+            customTextHandler.writeSetup();
         }
         gen.writeDSCComment(DSCConstants.END_SETUP);
     }
@@ -124,8 +121,8 @@
         gen.writeln("/PageSize [" + width + " " + height + "]");
         gen.writeln("/ImagingBBox null");
         gen.writeln(">> setpagedevice");
-        if (fontInfo != null) {         
-            gen.writeln("FOPFonts begin");
+        if (customTextHandler != null) {
+            customTextHandler.writePageSetup();
         }
     }
     

Copied: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
(from r390712, xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2D.java)
URL: http://svn.apache.org/viewcvs/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java?p2=xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java&p1=xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2D.java&r1=390712&r2=390751&rev=390751&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSGraphics2D.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
Sat Apr  1 13:01:14 2006
@@ -16,7 +16,7 @@
 
 /* $Id$ */
 
-package org.apache.fop.render.ps;
+package org.apache.xmlgraphics.java2d.ps;
 
 //Java
 import java.text.AttributedCharacterIterator;
@@ -25,7 +25,7 @@
 import java.awt.Color;
 import java.awt.Dimension;
 /* java.awt.Font is not imported to avoid confusion with 
-      org.apache.fop.fonts.Font */ 
+      other classes called "Font" */ 
 import java.awt.GradientPaint;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
@@ -38,77 +38,50 @@
 import java.awt.Stroke;
 import java.awt.TexturePaint;
 import java.awt.color.ColorSpace;
-import java.awt.color.ICC_Profile;
-import java.awt.font.FontRenderContext;
-import java.awt.font.GlyphVector;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.PathIterator;
 import java.awt.image.BufferedImage;
-import java.awt.image.DataBuffer;
-import java.awt.image.DataBufferInt;
 import java.awt.image.ImageObserver;
-import java.awt.image.Raster;
 import java.awt.image.RenderedImage;
 import java.awt.image.renderable.RenderableImage;
 import java.io.IOException;
 
-//Batik
-import org.apache.batik.ext.awt.RenderingHintsKeyExt;
-import org.apache.batik.ext.awt.g2d.AbstractGraphics2D;
-import org.apache.batik.ext.awt.g2d.GraphicContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-//FOP
-import org.apache.fop.fonts.Font;
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.FontTriplet;
-import org.apache.fop.image.FopImage;
+import org.apache.xmlgraphics.java2d.AbstractGraphics2D;
+import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.ps.PSGenerator;
+import org.apache.xmlgraphics.ps.PSImageUtils;
 
 /**
- * This concrete implementation of <tt>AbstractGraphics2D</tt> is a
- * simple help to programmers to get started with their own
- * implementation of <tt>Graphics2D</tt>.
- * <tt>DefaultGraphics2D</tt> implements all the abstract methods
- * is <tt>AbstractGraphics2D</tt> and makes it easy to start
- * implementing a <tt>Graphic2D</tt> piece-meal.
+ * This is a concrete implementation of <tt>AbstractGraphics2D</tt> (and
+ * therefore of <tt>Graphics2D</tt>) which is able to generate PostScript
+ * code.
  *
  * @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
  * @version $Id$
- * @see org.apache.batik.ext.awt.g2d.AbstractGraphics2D
+ * @see org.apache.xmlgraphics.java2d.AbstractGraphics2D
  */
 public class PSGraphics2D extends AbstractGraphics2D {
 
     private static final AffineTransform IDENTITY_TRANSFORM = new AffineTransform();
     
-    /** the logger for this class */
-    protected Log log = LogFactory.getLog(PSTextPainter.class);
-
+    private static final boolean DEBUG = false;
+    
     /** the PostScript generator being created */
     protected PSGenerator gen;
 
     private boolean clippingDisabled = false;
 
-    /** Currently valid FontState */
-    protected Font font;
+    /** Fallback text handler */
+    protected TextHandler fallbackTextHandler = new StrokingTextHandler(this);
     
-    /** Overriding FontState */
-    protected Font overrideFont = null;
+    /** Custom text handler */
+    protected TextHandler customTextHandler;
     
-    /** the current (internal) font name */
-    protected String currentFontName;
-
-    /** the current font size in millipoints */
-    protected int currentFontSize;
-
     /**
      * the current colour for use in svg
      */
     protected Color currentColour = new Color(0, 0, 0);
 
-    /** FontInfo containing all available fonts */
-    protected FontInfo fontInfo;
-
     /**
      * Create a new Graphics2D that generates PostScript code.
      * @param textAsShapes True if text should be rendered as graphics
@@ -138,12 +111,9 @@
 
         setPSGenerator(g.gen);
         this.clippingDisabled = g.clippingDisabled;
-        this.font             = g.font;
-        this.overrideFont     = g.overrideFont;
-        this.currentFontName  = g.currentFontName;
-        this.currentFontSize  = g.currentFontSize;
+        this.fallbackTextHandler = g.fallbackTextHandler;
+        this.customTextHandler = g.customTextHandler;
         this.currentColour    = g.currentColour;
-        this.fontInfo         = g.fontInfo;
     }
 
     /**
@@ -154,19 +124,25 @@
         this.gen = gen;
     }
 
+    /** @return the PostScript generator used by this instance. */
+    public PSGenerator getPSGenerator() {
+        return this.gen;
+    }
+
     /**
      * Sets the GraphicContext
      * @param c GraphicContext to use
      */
     public void setGraphicContext(GraphicContext c) {
         gc = c;
-        setPrivateHints();
+        //setPrivateHints();
     }
 
+    /* TODO Add me back at the right place!!!
     private void setPrivateHints() {
         setRenderingHint(RenderingHintsKeyExt.KEY_AVOID_TILE_PAINTING, 
                 RenderingHintsKeyExt.VALUE_AVOID_TILE_PAINTING_ON);
-    }
+    }*/
 
     /**
      * Creates a new <code>Graphics</code> object that is
@@ -179,14 +155,6 @@
     }
 
     /**
-     * Return the font information associated with this object
-     * @return the FontInfo object
-     */
-    public FontInfo getFontInfo() {
-        return fontInfo;
-    }
-
-    /**
      * Central handler for IOExceptions for this class.
      * @param ioe IOException to handle
      */
@@ -199,7 +167,7 @@
      * This method is used by AbstractPSDocumentGraphics2D to prepare a new page if
      * necessary.
      */
-    protected void preparePainting() {
+    public void preparePainting() {
         //nop, used by AbstractPSDocumentGraphics2D
     }
 
@@ -231,7 +199,9 @@
     public boolean drawImage(Image img, int x, int y,
                              ImageObserver observer) {
         preparePainting();
-        log.debug("drawImage: " + x + ", " + y + " " + img.getClass().getName());
+        if (DEBUG) {
+            System.out.println("drawImage: " + x + ", " + y + " " + img.getClass().getName());
+        }
 
         final int width = img.getWidth(observer);
         final int height = img.getHeight(observer);
@@ -254,45 +224,13 @@
         }
         g.dispose();
 
-        final byte[] result = new byte[buf.getWidth() * buf.getHeight() * 3];
-        //final byte[] mask = new byte[buf.getWidth() * buf.getHeight()];
-
-        Raster raster = buf.getData();
-        DataBuffer bd = raster.getDataBuffer();
-
-        int count = 0;
-        //int maskpos = 0;
-        switch (bd.getDataType()) {
-        case DataBuffer.TYPE_INT:
-            int[][] idata = ((DataBufferInt)bd).getBankData();
-            for (int i = 0; i < idata.length; i++) {
-                for (int j = 0; j < idata[i].length; j++) {
-                    // mask[maskpos++] = (byte)((idata[i][j] >> 24) & 0xFF);
-                    if (((idata[i][j] >> 24) & 0xFF) != 255) {
-                        result[count++] = (byte)0xFF;
-                        result[count++] = (byte)0xFF;
-                        result[count++] = (byte)0xFF;
-                    } else {
-                        result[count++] = (byte)((idata[i][j] >> 16) & 0xFF);
-                        result[count++] = (byte)((idata[i][j] >> 8) & 0xFF);
-                        result[count++] = (byte)((idata[i][j]) & 0xFF);
-                    }
-                }
-            }
-            break;
-        default:
-            // error
-            break;
-        }
-
         try {
-            FopImage fopimg = new TempImage(width, height, result, null);
             AffineTransform at = getTransform();
             gen.saveGraphicsState();
             gen.concatMatrix(at);
             Shape imclip = getClip();
             writeClip(imclip);
-            PSImageUtils.renderBitmapImage(fopimg, 
+            PSImageUtils.renderBitmapImage(buf, 
                 x, y, width, height, gen);
             gen.restoreGraphicsState();
         } catch (IOException ioe) {
@@ -312,131 +250,6 @@
                                  BufferedImage.TYPE_INT_ARGB);
     }
 
-
-    class TempImage implements FopImage {
-        private int height;
-        private int width;
-        private int bitsPerPixel;
-        private ColorSpace colorSpace;
-        private byte[] bitmaps;
-        private byte[] mask;
-        private Color transparentColor;
-
-        TempImage(int width, int height, byte[] bitmaps,
-                  byte[] mask) {
-            this.height = height;
-            this.width = width;
-            this.bitsPerPixel = 8;
-            this.colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
-            this.bitmaps = bitmaps;
-            this.mask = mask;
-        }
-
-        public String getMimeType() {
-            return "application/octet-stream";
-        }
-
-        public String getOriginalURI() {
-            return "temp-image:" + this.toString();
-        }
-        
-        /**
-         * @see org.apache.fop.image.FopImage#load(int, org.apache.commons.logging.Log)
-         */
-        public boolean load(int type) {
-            switch (type) {
-                case FopImage.DIMENSIONS: break;
-                case FopImage.BITMAP: break;
-                case FopImage.ORIGINAL_DATA: break;
-                default: throw new RuntimeException("Unknown load type: " + type);
-            }
-            return true;
-        }
-
-        public int getWidth() {
-            return this.width;
-        }
-
-        public int getHeight() {
-            return this.height;
-        }
-
-        public ColorSpace getColorSpace() {
-            return this.colorSpace;
-        }
-
-        public ICC_Profile getICCProfile() {
-            return null;
-        }
-
-        public int getBitsPerPixel() {
-            return this.bitsPerPixel;
-        }
-
-        // For transparent images
-        public boolean isTransparent() {
-            return getTransparentColor() != null;
-        }
-
-        public Color getTransparentColor() {
-            return this.transparentColor;
-        }
-
-        public boolean hasSoftMask() {
-            return this.mask != null;
-        }
-
-        public byte[] getSoftMask() {
-            return this.mask;
-        }
-
-        public boolean isInverted() {
-            return false;
-        }
-        
-        public byte[] getBitmaps() {
-            return this.bitmaps;
-        }
-
-        // width * (bitsPerPixel / 8) * height, no ?
-        public int getBitmapsSize() {
-            return getWidth() * getHeight() * 3; //Assumes RGB!
-        }
-
-        // get compressed image bytes
-        // I don't know if we really need it, nor if it
-        // should be changed...
-        public byte[] getRessourceBytes() {
-            return null;
-        }
-
-        public int getRessourceBytesSize() {
-            return 0;
-        }
-
-        /** @see org.apache.fop.image.FopImage#getIntrinsicWidth() */
-        public int getIntrinsicWidth() {
-            return (int)(getWidth() * 72 / getHorizontalResolution());
-        }
-
-        /** @see org.apache.fop.image.FopImage#getIntrinsicHeight() */
-        public int getIntrinsicHeight() {
-            return (int)(getHeight() * 72 / getVerticalResolution());
-        }
-
-        /** @see org.apache.fop.image.FopImage#getHorizontalResolution() */
-        public double getHorizontalResolution() {
-            return 72;
-        }
-
-        /** @see org.apache.fop.image.FopImage#getVerticalResolution() */
-        public double getVerticalResolution() {
-            return 72;
-        }
-
-    }
-
-
     /**
      * Draws as much of the specified image as has already been scaled
      * to fit inside the specified rectangle.
@@ -474,7 +287,7 @@
     public boolean drawImage(Image img, int x, int y, int width, int height,
                              ImageObserver observer) {
         preparePainting();
-        log.warn("NYI: drawImage");
+        System.err.println("NYI: drawImage");
         return true;
     }
 
@@ -507,9 +320,9 @@
      */
     public void dispose() {
         this.gen = null;
-        this.font = null;
+        this.fallbackTextHandler = null;
+        this.customTextHandler = null;
         this.currentColour = null;
-        this.fontInfo = null;
     }
 
     /**
@@ -606,7 +419,7 @@
      * Establishes a clipping region
      * @param s Shape defining the clipping region
      */
-    protected void writeClip(Shape s) {
+    public void writeClip(Shape s) {
         if (s == null) {
             return;
         }
@@ -632,9 +445,9 @@
     protected void applyPaint(Paint paint, boolean fill) {
         preparePainting();
         if (paint instanceof GradientPaint) {
-            log.warn("NYI: Gradient paint");
+            System.err.println("NYI: Gradient paint");
         } else if (paint instanceof TexturePaint) {
-            log.warn("NYI: texture paint");
+            System.err.println("NYI: texture paint");
         }
     }
 
@@ -672,7 +485,7 @@
                 case BasicStroke.CAP_SQUARE:
                     gen.writeln("2 setlinecap");
                     break;
-                default: log.warn("Unsupported line cap: " + ec);
+                default: System.err.println("Unsupported line cap: " + ec);
                 }
 
                 int lj = bs.getLineJoin();
@@ -686,7 +499,7 @@
                 case BasicStroke.JOIN_BEVEL:
                     gen.writeln("2 setlinejoin");
                     break;
-                default: log.warn("Unsupported line join: " + lj);
+                default: System.err.println("Unsupported line join: " + lj);
                 }
                 float lw = bs.getLineWidth();
                 gen.writeln(gen.formatDouble(lw) + " setlinewidth");
@@ -721,7 +534,7 @@
      */
     public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
         preparePainting();
-        log.warn("NYI: drawRenderedImage");
+        System.err.println("NYI: drawRenderedImage");
     }
 
     /**
@@ -757,7 +570,7 @@
     public void drawRenderableImage(RenderableImage img,
                                     AffineTransform xform) {
         preparePainting();
-        log.warn("NYI: drawRenderableImage");
+        System.err.println("NYI: drawRenderableImage");
     }
 
     /**
@@ -765,7 +578,7 @@
      * @param c the color to set
      * @throws IOException In case of an I/O problem
      */
-    protected void establishColor(Color c) throws IOException {
+    public void establishColor(Color c) throws IOException {
         StringBuffer p = new StringBuffer();
         float[] comps = c.getColorComponents(null);
         
@@ -833,109 +646,17 @@
      * @see #setClip
      */
     public void drawString(String s, float x, float y) {
-        if (this.textAsShapes) {
-            drawStringAsShapes(s, x, y);
-        } else {
-            drawStringAsText(s, x, y);
-        }
-    }
-
-    /**
-     * Draw a string to the PostScript document. The text is painted as shapes.
-     * @param s the string to draw
-     * @param x the x position
-     * @param y the y position
-     */
-    public void drawStringAsShapes(String s, float x, float y) {
-        java.awt.Font awtFont = super.getFont();
-        FontRenderContext frc = super.getFontRenderContext();
-        GlyphVector gv = awtFont.createGlyphVector(frc, s);
-        Shape glyphOutline = gv.getOutline(x, y);
-        fill(glyphOutline);
-    }
-
-    /**
-     * Draw a string to the PostScript document. The text is painted using 
-     * text operations.
-     * @param s the string to draw
-     * @param x the x position
-     * @param y the y position
-     */
-    public void drawStringAsText(String s, float x, float y) {
-        preparePainting();
-        log.trace("drawString('" + s + "', " + x + ", " + y + ")");
         try {
-            if (this.overrideFont == null) {
-                java.awt.Font awtFont = getFont();
-                this.font = createFont(awtFont);
+            if (customTextHandler != null && !textAsShapes) {
+                customTextHandler.drawString(s, x, y);
             } else {
-                this.font = this.overrideFont;
-                this.overrideFont = null;
+                fallbackTextHandler.drawString(s, x, y);
             }
-            
-            //Color and Font state
-            establishColor(getColor());
-            establishCurrentFont();
-
-            //Clip
-            Shape imclip = getClip();
-            writeClip(imclip);
-
-            gen.saveGraphicsState();
-
-            //Prepare correct transformation
-            AffineTransform trans = getTransform();
-            gen.concatMatrix(trans);
-            gen.writeln(gen.formatDouble(x) + " "
-                      + gen.formatDouble(y) + " moveto ");
-            gen.writeln("1 -1 scale");
-      
-            StringBuffer sb = new StringBuffer("(");
-            escapeText(s, sb);
-            sb.append(") t ");
-    
-            gen.writeln(sb.toString());
-            
-            gen.restoreGraphicsState();        
         } catch (IOException ioe) {
             handleIOException(ioe);
         }
     }
 
-    private void escapeText(final String text, StringBuffer target) {
-        final int l = text.length();
-        for (int i = 0; i < l; i++) {
-            final char ch = text.charAt(i);
-            final char mch = this.font.mapChar(ch);
-            PSGenerator.escapeChar(mch, target);
-        }
-    }
-
-    private Font createFont(java.awt.Font f) {
-        String fontFamily = f.getFamily();
-        if (fontFamily.equals("sanserif")) {
-            fontFamily = "sans-serif";
-        }
-        int fontSize = 1000 * f.getSize();
-        String style = f.isItalic() ? "italic" : "normal";
-        int weight = f.isBold() ? Font.BOLD : Font.NORMAL;
-                
-        FontTriplet triplet = fontInfo.findAdjustWeight(fontFamily, style, weight);
-        if (triplet == null) {
-            triplet = fontInfo.findAdjustWeight("sans-serif", style, weight);
-        }
-        return fontInfo.getFontInstance(triplet, fontSize);
-    }
-
-    private void establishCurrentFont() throws IOException {
-        if ((currentFontName != this.font.getFontName()) 
-                || (currentFontSize != this.font.getFontSize())) {
-            gen.writeln(this.font.getFontName() + " " + this.font.getFontSize() + " F");
-            currentFontName = this.font.getFontName();
-            currentFontSize = this.font.getFontSize();
-        }
-    }
-
     /**
      * Renders the text of the specified iterator, using the
      * <code>Graphics2D</code> context's current <code>Paint</code>.
The
@@ -964,7 +685,7 @@
     public void drawString(AttributedCharacterIterator iterator, float x,
                            float y) {
         preparePainting();
-        log.warn("NYI: drawString(AttributedCharacterIterator)");
+        System.err.println("NYI: drawString(AttributedCharacterIterator)");
         /*
         try {
             gen.writeln("BT");
@@ -1093,14 +814,6 @@
     }
 
     /**
-     * Sets the overriding font.
-     * @param font Font to set
-     */
-    public void setOverrideFont(Font font) {
-        this.overrideFont = font;
-    }
-    
-    /**
      * Gets the font metrics for the specified font.
      * @return    the font metrics for the specified font.
      * @param     f the specified font
@@ -1128,7 +841,7 @@
      * @param     c1 the XOR alternation color
      */
     public void setXORMode(Color c1) {
-        log.warn("NYI: setXORMode");
+        System.err.println("NYI: setXORMode");
     }
 
 
@@ -1153,7 +866,7 @@
      */
     public void copyArea(int x, int y, int width, int height, int dx,
                          int dy) {
-        log.warn("NYI: copyArea");
+        System.err.println("NYI: copyArea");
     }
 
     /* --- for debugging

Added: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/StrokingTextHandler.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/StrokingTextHandler.java?rev=390751&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/StrokingTextHandler.java
(added)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/StrokingTextHandler.java
Sat Apr  1 13:01:14 2006
@@ -0,0 +1,56 @@
+/*
+ * Copyright 1999-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.java2d.ps;
+
+import java.awt.Shape;
+import java.awt.font.FontRenderContext;
+import java.awt.font.GlyphVector;
+import java.io.IOException;
+
+/**
+ * Default TextHandler implementation which paints text using graphics primitives (shapes).

+ */
+public class StrokingTextHandler implements TextHandler {
+
+    private PSGraphics2D g2d;
+    
+    public StrokingTextHandler(PSGraphics2D g2d) {
+        this.g2d = g2d;
+    }
+    
+    /** @see org.apache.xmlgraphics.java2d.ps.TextHandler#writeSetup() */
+    public void writeSetup() throws IOException {
+        //nop
+    }
+
+    /** @see org.apache.xmlgraphics.java2d.ps.TextHandler#writePageSetup() */
+    public void writePageSetup() throws IOException {
+        //nop
+    }
+
+    /** @see TextHandler#drawString(java.lang.String, float, float) */
+    public void drawString(String text, float x, float y) {
+        java.awt.Font awtFont = g2d.getFont();
+        FontRenderContext frc = g2d.getFontRenderContext();
+        GlyphVector gv = awtFont.createGlyphVector(frc, text);
+        Shape glyphOutline = gv.getOutline(x, y);
+        g2d.fill(glyphOutline);
+    }
+
+}

Propchange: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/StrokingTextHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/TextHandler.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/TextHandler.java?rev=390751&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/TextHandler.java (added)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/TextHandler.java Sat
Apr  1 13:01:14 2006
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.java2d.ps;
+
+import java.io.IOException;
+
+/**
+ * Interface which the PSGraphics2D class delegates text painting to.
+ */
+public interface TextHandler {
+
+    /**
+     * Draw some text.
+     * @param text the text to paint
+     * @param x the x-coordinate where the <code>String</code> should be rendered
+     * @param y the y-coordinate where the <code>String</code> should be rendered
+     * @throws IOException In case of an I/O error
+     */
+    public void drawString(String text, float x, float y) throws IOException;
+
+    /**
+     * Is called by when the "Setup" or "Prolog" of the PostScript document is generated.

+     * Subclasses can do font registration, for example.
+     * @throws IOException In case of an I/O error
+     */
+    public void writeSetup() throws IOException;
+
+    /**
+     * Is called by when a "PageSetup" section of the PostScript document is generated. 
+     * Subclasses can do some font initialization if necessary.
+     * @throws IOException In case of an I/O error
+     */
+    public void writePageSetup() throws IOException;
+    
+}

Propchange: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/java2d/ps/TextHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSImageUtils.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSImageUtils.java?rev=390751&r1=390750&r2=390751&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSImageUtils.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSImageUtils.java Sat Apr
 1 13:01:14 2006
@@ -38,7 +38,19 @@
  */
 public class PSImageUtils {
 
-    private static void writeImage(byte[] img,
+    /**
+     * Writes a bitmap image to the PostScript stream.
+     * @param img the bitmap image as a byte array
+     * @param imgDim the dimensions of the image
+     * @param imgName the name of the image
+     * @param targetRect the target rectangle to place the image in
+     * @param isJPEG true if "img" contains a DCT-encoded images, false if "img" contains
the 
+     *               decoded bitmap
+     * @param colorSpace the color space of the image
+     * @param gen the PostScript generator
+     * @throws IOException In case of an I/O exception
+     */
+    public static void writeImage(byte[] img,
             Dimension imgDim, String imgName,
             Rectangle2D targetRect, 
             boolean isJPEG, ColorSpace colorSpace,



---------------------------------------------------------------------
Apache XML Graphics Project URL: http://xmlgraphics.apache.org/
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message