Michael,

         
        Looking through the source code, trying to hunt down how the image finally 
gets encoded, brought to attention the following:
         
        org.apache.cocoon.serialization.SVGSerializer
         
            /**
             * Generate the unique key.
             * This key must be unique inside the space of this component.
             * This method must be invoked before the generateValidity() method.
             *
             * @return The generated key or <code>0</code> if the component
             *              is currently not cacheable.
             */
            public long generateKey() {
                return 1;
            }
        hmmm... wonder how unique that really is.
         
        Meanwhile, I got the latest "HEAD" checkout of xml-batik. After hours of 
trying to figure out what instatiates what, I came across this line in 
         
        org.apache.batik.transcoder.image.JPEGTranscoder
         
            /**
             * Constructs a new transcoder that produces jpeg images.
             */
            public JPEGTranscoder() {
                hints.put(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.white);
            } 
         
        I commented out "hints.put....", re-compiled, touched every xml file in 
webapps/cocoon/documentation/svg and ran the sucker. It worked (although there is some 
strange behaviour still, see attached screenshot- couldn't send... too big... where 
can I send this?). I believe that some of the 
        files might be pre-compiled in the work directory, so I am not too concerned 
with it.
         
        Once that worked, I modified the line to read:
        hints.put(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.black);
        Guess what... it gave me a whole bunch of black boxes on the page... .
         
        Now I'll leave the rest up to the batik-dev group and you guys. At this point 
I am a bit flabbergasted.
         
        The reason I did that is that I had an hunch that the keys might be reversed, 
or something. 
         
        NB: this did not break the previous resolution to change the svg2jpeg 
serializer to svg2png....
         
        Please advise.
         
        Georg von Sperling
        MedAptus, Inc.
        www.medaptus.com
        [EMAIL PROTECTED]
         
        Attachments: modified JPEGTranscoder.java

        screenshot of weird behaviour (screenshot.jpg) == couldn't send still too big 
: (
                                                          
        I was gonna attach the compiled batik.jar  (ant libs-jar) (note that it is 
100kb larger than the batik1.1.1.jar that is in the cocoon distro), but the email 
bounced because of the size of the email, so let me know if you want me to eMail it to 
someone directly, or otherwise

                -----Original Message----- 
                From: Michael Hartle [mailto:[EMAIL PROTECTED]] 
                Sent: Mon 2/25/2002 5:26 PM 
                To: [EMAIL PROTECTED] 
                Cc: 
                Subject: Re: SVGSerializer issue temporarily resolved - still needs 
fixin' though ;)
                
                

                Georg Von Sperling wrote:
                
                >Configuration:
                >Windows 2000
                >Ant 1.4
                >JDK 1.4.0 build 92
                >Tomcat (standalone) 4.0.1
                >xml-cocoon2 checkout "HEAD" on Feb. 25, 2002 @ 11:30 am
                >                     compile "build.bat -Dinclude.webapp.libs=yes 
webapp"
                >
                >
                >How do I fix the svg2jpg serializer?
                >
                I'd like to be able to answer the question - the SVG2JPG serializer
                works with the Batik library, which in turn uses Suns auxiliary 
classes
                to generate JPEGs; sadly, this broke with the release of JDK 1.4.0, 
and
                nobody seems to know why; currently, generated images under that JDK
                just contain plain white space; if you find a solution for that issue,
                please be so kind and drop a note in the batik-dev mailinglist.
                
                >Cheers,
                >Georg von Sperling
                >MedAptus, Inc.
                >http://www.medaptus.com
                >[EMAIL PROTECTED]
                >
                Best regards,
                
                Michael Hartle,
                Hartle & Klug GbR
                
                
                ---------------------------------------------------------------------
                To unsubscribe, e-mail: [EMAIL PROTECTED]
                For additional commands, email: [EMAIL PROTECTED]
                
                

/*****************************************************************************
 * 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.transcoder.image;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.TranscodingHints;
import org.apache.batik.transcoder.image.resources.Messages;

/**
 * This class is an <tt>ImageTranscoder</tt> that produces a JPEG image.
 *
 * @author <a href="mailto:[EMAIL PROTECTED]";>Thierry Kormann</a>
 * @version $Id: JPEGTranscoder.java,v 1.5 2001/11/12 15:37:22 deweese Exp $
 */
public class JPEGTranscoder extends ImageTranscoder {

    /**
     * Constructs a new transcoder that produces jpeg images.
     */
    public JPEGTranscoder() {
       // GvS: uncomment to get white boxes
       //hints.put(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.white);

       // GvS: uncomment to get black boxes
       //hints.put(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.black);
    }

    /**
     * Creates a new ARGB image with the specified dimension.
     * @param width the image width in pixels
     * @param height the image height in pixels
     */
    public BufferedImage createImage(int width, int height) {
        return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    }

    /**
     * Writes the specified image to the specified output.
     * @param img the image to write
     * @param output the output where to store the image
     * @param TranscoderException if an error occured while storing the image
     */
    public void writeImage(BufferedImage img, TranscoderOutput output)
            throws TranscoderException {
        OutputStream ostream = output.getOutputStream();
        // The outputstream wrapper protects the JPEG encoder from
        // exceptions due to stream closings.  If it gets an exception
        // it nulls out the stream and just ignores any future calls.
        ostream = new OutputStreamWrapper(ostream);

        if (ostream == null) {
            throw new TranscoderException(
                Messages.formatMessage("jpeg.badoutput", null));
        }
        float quality;
        if (hints.containsKey(KEY_QUALITY)) {
            quality = ((Float)hints.get(KEY_QUALITY)).floatValue();
        } else {
            handler.error(new TranscoderException(
                Messages.formatMessage("jpeg.unspecifiedQuality", null)));
            quality = 1f;
        }
        try {
            JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(ostream);
            JPEGEncodeParam params = JPEGCodec.getDefaultJPEGEncodeParam(img);
            params.setQuality(quality, true);
            jpegEncoder.encode(img, params);
        } catch (IOException ex) {
            throw new TranscoderException(ex);
        }
    }

    // --------------------------------------------------------------------
    // Keys definition
    // --------------------------------------------------------------------

    /**
     * The encoder quality factor key.
     * <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Key: </TH>
     * <TD VALIGN="TOP">KEY_QUALITY</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Value: </TH>
     * <TD VALIGN="TOP">Float (between 0 and 1)</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Default: </TH>
     * <TD VALIGN="TOP">1 (no lossy)</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Required: </TH>
     * <TD VALIGN="TOP">Recommended</TD></TR>
     * <TR>
     * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN="RIGHT">Description: </TH>
     * <TD VALIGN="TOP">Specify the JPEG image encoding quality.</TD></TR>
     * </TABLE>
     */
    public static final TranscodingHints.Key KEY_QUALITY
        = new QualityKey();

    /**
     * A transcoding Key represented the JPEG image quality.
     */
    private static class QualityKey extends TranscodingHints.Key {
        public boolean isCompatibleValue(Object v) {
            if (v instanceof Float) {
                float q = ((Float)v).floatValue();
                return (q > 0 && q <= 1f);
            } else {
                return false;
            }
        }
    }

    /**
     *  This class will never throw an IOException, instead it eats
     * them and then ignores any future calls to it's interface.
     */
    private static class OutputStreamWrapper extends OutputStream {
        OutputStream os;
        /**
         * Constructs a wrapper around <tt>os</tt> that will not throw
         * IOExceptions.
         * <@param os>The Stream to wrap.
         */
        OutputStreamWrapper(OutputStream os) {
            this.os = os;
        }

        public void close() throws IOException {
            if (os == null) return;
            try {
                os.close();
            } catch (IOException ioe) {
                os = null;
            }
        }

        public void flush() throws IOException {
            if (os == null) return;
            try {
                os.flush();
            } catch (IOException ioe) {
                os = null;
            }
        }

        public void write(byte[] b) throws IOException {
            if (os == null) return;
            try {
                os.write(b);
            } catch (IOException ioe) {
                os = null;
            }
        }

        public void write(byte[] b, int off, int len) throws IOException {
            if (os == null) return;
            try {
                os.write(b, off, len);
            } catch (IOException ioe) {
                os = null;
            }
        }

        public void write(int b)  throws IOException {
            if (os == null) return;
            try {
                os.write(b);
            } catch (IOException ioe) {
                os = null;
            }
        }
    }
}


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


Reply via email to