deweese     01/11/29 07:05:26

  Modified:    sources/org/apache/batik/ext/awt RenderingHintsKeyExt.java
               sources/org/apache/batik/ext/awt/image GraphicsUtil.java
                        SVGComposite.java
               sources/org/apache/batik/ext/awt/image/renderable
                        CompositeRable8Bit.java
               sources/org/apache/batik/ext/awt/image/rendered
                        Any2sRGBRed.java
               sources/org/apache/batik/transcoder/print
                        PrintTranscoder.java
  Added:       sources/org/apache/batik/ext/awt TranscodingHintKey.java
  Log:
  1) Printing bugs seem to be fixed (was pretty easy once I was willing
     to put in printing specific hacks).
  PR: 4831
  
  Revision  Changes    Path
  1.4       +10 -1     
xml-batik/sources/org/apache/batik/ext/awt/RenderingHintsKeyExt.java
  
  Index: RenderingHintsKeyExt.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/RenderingHintsKeyExt.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RenderingHintsKeyExt.java 2001/07/05 16:54:37     1.3
  +++ RenderingHintsKeyExt.java 2001/11/29 15:05:26     1.4
  @@ -15,9 +15,18 @@
    * KEY_AREA_OF_INTEREST
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Hardy</a>
  - * @version $Id: RenderingHintsKeyExt.java,v 1.3 2001/07/05 16:54:37 deweese Exp $
  + * @version $Id: RenderingHintsKeyExt.java,v 1.4 2001/11/29 15:05:26 deweese Exp $
    */
   public final class RenderingHintsKeyExt {
  +    /**
  +     * Hint as to the transcoding destination.
  +     */
  +    public static final RenderingHints.Key KEY_TRANSCODING =
  +        new TranscodingHintKey();
  +
  +    public static final String VALUE_TRANSCODING_PRINTING = 
  +        new String("Printing");
  +    
       /**
        * Key for the AOI hint. This hint is used to propagate the AOI to Paint
        * and PaintContext instances.
  
  
  
  1.1                  
xml-batik/sources/org/apache/batik/ext/awt/TranscodingHintKey.java
  
  Index: TranscodingHintKey.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.ext.awt;
  
  import java.awt.RenderingHints;
  import java.awt.Shape;
  
  /**
   * TranscodingHint as to what the destination of the drawing is.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas DeWeese</a>
   * @version $Id: TranscodingHintKey.java,v 1.1 2001/11/29 15:05:26 deweese Exp $
   */
  final class TranscodingHintKey extends RenderingHints.Key {
  
      TranscodingHintKey() {
          super(10100);
      }
  
      public boolean isCompatibleValue(Object val) {
          boolean isCompatible = true;
          if ((val != null) && !(val instanceof String)) {
              isCompatible = false;
          }
          return isCompatible;
      }
  }
  
  
  
  
  1.20      +111 -13   
xml-batik/sources/org/apache/batik/ext/awt/image/GraphicsUtil.java
  
  Index: GraphicsUtil.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/GraphicsUtil.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- GraphicsUtil.java 2001/09/17 20:45:18     1.19
  +++ GraphicsUtil.java 2001/11/29 15:05:26     1.20
  @@ -14,6 +14,7 @@
   import java.awt.color.ColorSpace;
   
   import java.awt.Color;
  +import java.awt.Composite;
   import java.awt.Graphics2D;
   import java.awt.GraphicsConfiguration;
   import java.awt.GraphicsDevice;
  @@ -65,7 +66,7 @@
    * implementations.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas DeWeese</a>
  - * @version $Id: GraphicsUtil.java,v 1.19 2001/09/17 20:45:18 deweese Exp $
  + * @version $Id: GraphicsUtil.java,v 1.20 2001/11/29 15:05:26 deweese Exp $
    */
   public class GraphicsUtil {
   
  @@ -130,6 +131,8 @@
           else
               at.preConcatenate(g2dAt);
   
  +        Composite g2dComposite = g2d.getComposite();
  +
           if (false) {
               System.out.println("CR: " + cr);
               System.out.println("CRR: " + cr.getBounds());
  @@ -171,14 +174,13 @@
           ColorModel drawCM = g2dCM;
           if (g2dCM == null) {
               // If we can't find out about our device assume
  -            // it's not premultiplied (Just because this
  -            // seems to work for us!).
  -            drawCM = coerceColorModel(srcCM, false);
  +            // it's SRGB unpremultiplied (Just because this
  +            // seems to work for us).
  +            drawCM = sRGB_Unpre;
           } else if (drawCM.hasAlpha() && g2dCM.hasAlpha() &&
                      (drawCM.isAlphaPremultiplied() !=
                       g2dCM .isAlphaPremultiplied())) {
  -            drawCM = coerceColorModel(drawCM,
  -                                      g2dCM.isAlphaPremultiplied());
  +            drawCM = coerceColorModel(drawCM, g2dCM.isAlphaPremultiplied());
           }
   
           cr = FormatRed.construct(cr, drawCM);
  @@ -190,6 +192,16 @@
           // Now CR is in device space, so clear the g2d transform.
           g2d.setTransform(IDENTITY);
   
  +        // Ugly Hack alert.  This Makes it use our SrcOver implementation
  +        // Which doesn't seem to have as many bugs as the JDK one when
  +        // going between different src's and destinations (of course it's
  +        // also a lot slower).
  +        if (g2d.getRenderingHint(RenderingHintsKeyExt.KEY_TRANSCODING) ==
  +            RenderingHintsKeyExt.VALUE_TRANSCODING_PRINTING) {
  +            if (SVGComposite.OVER.equals(g2dComposite)) {
  +                g2d.setComposite(SVGComposite.OVER);
  +            }
  +        }
           Rectangle crR  = cr.getBounds();
           Shape     clip = g2d.getClip();
   
  @@ -272,6 +284,7 @@
               long startTime = System.currentTimeMillis();
   
               if (false) {
  +                // org.ImageDisplay.showImage("foo: ", cr);
                   // This can be significantly faster but can also
                   // require much more memory.
                   g2d.drawRenderedImage(cr, IDENTITY);
  @@ -350,16 +363,19 @@
                           // System.out.println("Generating tile: " + twr);
                           cr.copyData(twr);
   
  -                        // Make sure we only draw the region that was written...
  +                        // Make sure we only draw the region that was written.
                           BufferedImage subBI;
                           subBI = bi.getSubimage(0, 0, iR.width,  iR.height);
  +
                           if (false) {
                               System.out.println("Drawing: " + tR);
                               System.out.println("IR: "      + iR);
                           }
   
                           AffineTransform trans;
  -                        trans = AffineTransform.getTranslateInstance(iR.x, iR.y);
  +                        trans = AffineTransform.getTranslateInstance(iR.x, 
  +                                                                     iR.y);
  +
                           g2d.drawImage(subBI, trans, null);
                           // big2d.fillRect(0, 0, tw, th);
                       }
  @@ -369,9 +385,13 @@
               }
               long endTime = System.currentTimeMillis();
               // System.out.println("Time: " + (endTime-startTime));
  +
  +
           } finally {
               g2d.setTransform(g2dAt);
  +            g2d.setComposite(g2dComposite);
           }
  +
           // System.out.println("Finished Draw");
       }
   
  @@ -492,7 +512,9 @@
           GraphicsConfiguration gc = g2d.getDeviceConfiguration();
           GraphicsDevice gd = gc.getDevice();
           if (WARN_DESTINATION &&
  -            (gd.getType() == GraphicsDevice.TYPE_IMAGE_BUFFER))
  +            (gd.getType() == GraphicsDevice.TYPE_IMAGE_BUFFER) &&
  +            (g2d.getRenderingHint(RenderingHintsKeyExt.KEY_TRANSCODING) !=
  +                RenderingHintsKeyExt.VALUE_TRANSCODING_PRINTING))
               // throw new IllegalArgumentException
               System.out.println
                   ("Graphics2D from BufferedImage lacks BUFFERED_IMAGE hint");
  @@ -509,18 +531,24 @@
   
           // We are going to a BufferedImage but no hint was provided
           // so we can't determine the destination Color Model.
  -        if (gc.getDevice().getType() == GraphicsDevice.TYPE_IMAGE_BUFFER)
  +        if (gc.getDevice().getType() == GraphicsDevice.TYPE_IMAGE_BUFFER) {
  +            if (g2d.getRenderingHint(RenderingHintsKeyExt.KEY_TRANSCODING) ==
  +                RenderingHintsKeyExt.VALUE_TRANSCODING_PRINTING) 
  +                return sRGB_Unpre;
  +
  +            // System.out.println("CM: " + gc.getColorModel());
  +            // System.out.println("CS: " + gc.getColorModel().getColorSpace());
               return null;
  +        }
   
           return gc.getColorModel();
       }
   
       public static ColorSpace getDestinationColorSpace(Graphics2D g2d) {
           ColorModel cm = getDestinationColorModel(g2d);
  -        if (cm == null)
  -            return null;
  +        if (cm != null) return cm.getColorSpace();
   
  -        return cm.getColorSpace();
  +        return null;
       }
   
       public static Rectangle getDestinationBounds(Graphics2D g2d) {
  @@ -998,6 +1026,8 @@
               // nothing to do alpha state matches...
               return cm;
   
  +        // System.out.println("CoerceData: " + wr.getSampleModel());
  +
           int [] pixel = null;
           int    bands = wr.getNumBands();
           float  norm;
  @@ -1501,4 +1531,72 @@
               }
           }
       }
  +
  +/*
  +  This is skanky debugging code that might be useful in the future:
  +
  +            if (count == 33) {
  +                String label = "sub [" + x + ", " + y + "]: ";
  +                org.ImageDisplay.showImage
  +                    (label, subBI);
  +                org.ImageDisplay.printImage
  +                    (label, subBI,
  +                     new Rectangle(75-iR.x, 90-iR.y, 32, 32));
  +                
  +            }
  +
  +
  +            // if ((count++ % 50) == 10)
  +            //     org.ImageDisplay.showImage("foo: ", subBI);
  +
  +
  +            Graphics2D realG2D = g2d;
  +            while (realG2D instanceof sun.java2d.ProxyGraphics2D) {
  +                realG2D = ((sun.java2d.ProxyGraphics2D)realG2D).getDelegate();
  +            }
  +            if (realG2D instanceof sun.awt.image.BufferedImageGraphics2D) {
  +                count++;
  +                if (count == 34) {
  +                    RenderedImage ri;
  +                    ri = ((sun.awt.image.BufferedImageGraphics2D)realG2D).bufImg;
  +                    // g2d.setComposite(SVGComposite.OVER);
  +                    // org.ImageDisplay.showImage("Bar: " + count, cr);
  +                    org.ImageDisplay.printImage("Bar: " + count, cr,
  +                                                new Rectangle(75, 90, 32, 32));
  +
  +                    org.ImageDisplay.showImage ("Foo: " + count, ri);
  +                    org.ImageDisplay.printImage("Foo: " + count, ri,
  +                                                new Rectangle(75, 90, 32, 32));
  +
  +                    System.out.println("BI: "   + ri);
  +                    System.out.println("BISM: " + ri.getSampleModel());
  +                    System.out.println("BICM: " + ri.getColorModel());
  +                    System.out.println("BICM class: " + 
ri.getColorModel().getClass());
  +                    System.out.println("BICS: " + 
ri.getColorModel().getColorSpace());
  +                    System.out.println
  +                        ("sRGB CS: " + 
  +                         ColorSpace.getInstance(ColorSpace.CS_sRGB));
  +                    System.out.println("G2D info");
  +                    System.out.println("\tComposite: " + g2d.getComposite());
  +                    System.out.println("\tTransform" + g2d.getTransform());
  +                    java.awt.RenderingHints rh = g2d.getRenderingHints();
  +                    java.util.Set keys = rh.keySet();
  +                    java.util.Iterator iter = keys.iterator();
  +                    while (iter.hasNext()) {
  +                        Object o = iter.next();
  +
  +                        System.out.println("\t" + o.toString() + " -> " +
  +                                           rh.get(o).toString());
  +                    }
  +
  +                    ri = cr;
  +                    System.out.println("RI: "   + ri);
  +                    System.out.println("RISM: " + ri.getSampleModel());
  +                    System.out.println("RICM: " + ri.getColorModel());
  +                    System.out.println("RICM class: " + 
ri.getColorModel().getClass());
  +                    System.out.println("RICS: " + 
ri.getColorModel().getColorSpace());
  +                }
  +            }
  +*/
  +
   }
  
  
  
  1.2       +2 -2      
xml-batik/sources/org/apache/batik/ext/awt/image/SVGComposite.java
  
  Index: SVGComposite.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/SVGComposite.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SVGComposite.java 2001/03/26 21:36:07     1.1
  +++ SVGComposite.java 2001/11/29 15:05:26     1.2
  @@ -29,7 +29,7 @@
    * This provides an implementation of all the composite rules in SVG.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas DeWeese</a>
  - * @version $Id: SVGComposite.java,v 1.1 2001/03/26 21:36:07 deweese Exp $
  + * @version $Id: SVGComposite.java,v 1.2 2001/11/29 15:05:26 deweese Exp $
    */
   public class SVGComposite
       implements Composite {
  @@ -379,7 +379,7 @@
               final int pt5  = (1<<23);
   
               int srcP, dstInP, dstM;
  -
  +            
               for (int y = 0; y<height; y++) {
                   final int end = dstOutSp+width;
                   while (dstOutSp<end) {
  
  
  
  1.11      +3 -2      
xml-batik/sources/org/apache/batik/ext/awt/image/renderable/CompositeRable8Bit.java
  
  Index: CompositeRable8Bit.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/renderable/CompositeRable8Bit.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- CompositeRable8Bit.java   2001/05/02 15:41:11     1.10
  +++ CompositeRable8Bit.java   2001/11/29 15:05:26     1.11
  @@ -39,7 +39,7 @@
    * the image are applied in the order they are in the List given.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas DeWeese</a>
  - * @version $Id: CompositeRable8Bit.java,v 1.10 2001/05/02 15:41:11 tkormann Exp $
  + * @version $Id: CompositeRable8Bit.java,v 1.11 2001/11/29 15:05:26 deweese Exp $
    */
   public class CompositeRable8Bit
       extends    AbstractColorInterpolationRable
  @@ -105,8 +105,9 @@
   
           ColorSpace crCS = getOperationColorSpace();
           ColorSpace g2dCS = GraphicsUtil.getDestinationColorSpace(g2d);
  -        if ((g2dCS == null) || (g2dCS != crCS))
  +        if ((g2dCS == null) || (g2dCS != crCS)) {
               return false;
  +        }
   
           // System.out.println("drawImage : " + g2dCS +
           //                    crCS);
  
  
  
  1.4       +6 -5      
xml-batik/sources/org/apache/batik/ext/awt/image/rendered/Any2sRGBRed.java
  
  Index: Any2sRGBRed.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/rendered/Any2sRGBRed.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Any2sRGBRed.java  2001/07/26 18:03:07     1.3
  +++ Any2sRGBRed.java  2001/11/29 15:05:26     1.4
  @@ -34,7 +34,7 @@
    * new image.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas DeWeese</a>
  - * @version $Id: Any2sRGBRed.java,v 1.3 2001/07/26 18:03:07 deweese Exp $ */
  + * @version $Id: Any2sRGBRed.java,v 1.4 2001/11/29 15:05:26 deweese Exp $ */
   public class Any2sRGBRed extends AbstractRed {
   
       boolean srcIsLsRGB = false;
  @@ -124,16 +124,17 @@
           final int height     = wr.getHeight();
           final int scanStride = sm.getScanlineStride();
   
  -        int count=0;
  +        int end, pix;
  +
           // For alpha premult we need to multiply all comps.
           for (int y=0; y<height; y++) {
               int sp  = srcBase + y*scanStride;
  -            final int end = sp + width;
  +            end = sp + width;
   
               while (sp<end) {
  -                final int pix = pixels[sp];
  +                pix = pixels[sp];
                   pixels[sp] = 
  -                    ((pix&0xFF000000)           |
  +                    ((     pix      &0xFF000000)|
                        (lut[(pix>>>16)&0xFF]<<16) |
                        (lut[(pix>>> 8)&0xFF]<< 8) |
                        (lut[(pix     )&0xFF]    ));
  
  
  
  1.18      +8 -4      
xml-batik/sources/org/apache/batik/transcoder/print/PrintTranscoder.java
  
  Index: PrintTranscoder.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/transcoder/print/PrintTranscoder.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- PrintTranscoder.java      2001/10/24 14:52:37     1.17
  +++ PrintTranscoder.java      2001/11/29 15:05:26     1.18
  @@ -48,7 +48,10 @@
   import org.apache.batik.dom.svg.SVGOMDocument;
   import org.apache.batik.dom.util.DocumentFactory;
   
  +import org.apache.batik.ext.awt.RenderingHintsKeyExt;
  +
   import org.apache.batik.gvt.GraphicsNode;
  +import org.apache.batik.gvt.event.EventDispatcher;
   
   import org.apache.batik.bridge.BridgeContext;
   import org.apache.batik.bridge.BridgeException;
  @@ -57,8 +60,6 @@
   import org.apache.batik.bridge.UserAgent;
   import org.apache.batik.bridge.ViewBox;
   
  -import org.apache.batik.gvt.event.EventDispatcher;
  -
   import org.apache.batik.transcoder.Transcoder;
   import org.apache.batik.transcoder.TranscoderException;
   import org.apache.batik.transcoder.TranscoderInput;
  @@ -109,7 +110,7 @@
    * </ul>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Hardy</a>
  - * @version $Id: PrintTranscoder.java,v 1.17 2001/10/24 14:52:37 tkormann Exp $
  + * @version $Id: PrintTranscoder.java,v 1.18 2001/11/29 15:05:26 deweese Exp $
    */
   public class PrintTranscoder extends XMLAbstractTranscoder
       implements Printable {
  @@ -238,7 +239,8 @@
                             pageHeight.floatValue());
           }
   
  -        float x=0, y=0, width=(float)paper.getWidth(), 
height=(float)paper.getHeight();
  +        float x=0, y=0;
  +        float width=(float)paper.getWidth(), height=(float)paper.getHeight();
   
           Float leftMargin = (Float)hints.get(KEY_MARGIN_LEFT);
           Float topMargin = (Float)hints.get(KEY_MARGIN_TOP);
  @@ -353,6 +355,8 @@
                              RenderingHints.VALUE_ANTIALIAS_ON);
           g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                              RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  +        g.setRenderingHint(RenderingHintsKeyExt.KEY_TRANSCODING,
  +                           RenderingHintsKeyExt.VALUE_TRANSCODING_PRINTING);
   
           //
           // Compute transform so that the SVG document fits on one page
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to