You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by tk...@apache.org on 2001/04/13 15:11:35 UTC

cvs commit: xml-batik/sources/org/apache/batik/transcoder/print PrintTranscoder.java

tkormann    01/04/13 06:11:35

  Modified:    sources/org/apache/batik/transcoder
                        XMLAbstractTranscoder.java
               sources/org/apache/batik/transcoder/image
                        ImageTranscoder.java
               sources/org/apache/batik/transcoder/print
                        PrintTranscoder.java
  Log:
  image transcoder now supports SVG URI fragment.
  
  ---------- PrintTranscoder have to support:
  
  1. SVG URI fragment
  2. Optional width and height attributes on the outermost svg element
  
  Revision  Changes    Path
  1.8       +8 -5      xml-batik/sources/org/apache/batik/transcoder/XMLAbstractTranscoder.java
  
  Index: XMLAbstractTranscoder.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/transcoder/XMLAbstractTranscoder.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XMLAbstractTranscoder.java	2001/03/28 06:51:23	1.7
  +++ XMLAbstractTranscoder.java	2001/04/13 13:11:32	1.8
  @@ -41,7 +41,7 @@
    * </ul>
    *
    * @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
  - * @version $Id: XMLAbstractTranscoder.java,v 1.7 2001/03/28 06:51:23 tkormann Exp $
  + * @version $Id: XMLAbstractTranscoder.java,v 1.8 2001/04/13 13:11:32 tkormann Exp $
    */
   public abstract class XMLAbstractTranscoder extends AbstractTranscoder {
   
  @@ -64,6 +64,7 @@
               throws TranscoderException {
   
           Document document = null;
  +        String uri = input.getURI();
           if (input.getDocument() != null) {
               document = input.getDocument();
           } else {
  @@ -109,11 +110,10 @@
                                                   documentElement,
                                                   input.getURI(),
                                                   input.getReader());
  -                } else if (input.getURI() != null) {
  -                    System.out.println("Creating Document from URI...");
  +                } else if (uri != null) {
                       document = f.createDocument(namespaceURI,
                                                   documentElement,
  -                                                input.getURI());
  +                                                uri);
                   }
               } catch (DOMException ex) {
                   handler.fatalError(new TranscoderException(ex));
  @@ -125,7 +125,7 @@
           // call the dedicated transcode method
           if (document != null) {
               try {
  -                transcode(document, output);
  +                transcode(document, uri, output);
               } catch(TranscoderException ex) {
                   // at this time, all TranscoderExceptions are fatal errors
                   handler.fatalError(ex);
  @@ -150,11 +150,14 @@
   
       /**
        * Transcodes the specified Document in the specified output.
  +     *
        * @param document the document to transcode
  +     * @param uri the uri of the document or null if any
        * @param output the ouput where to transcode
        * @exception TranscoderException if an error occured while transcoding
        */
       protected abstract void transcode(Document document,
  +                                      String uri,
                                         TranscoderOutput output)
               throws TranscoderException;
   
  
  
  
  1.20      +24 -5     xml-batik/sources/org/apache/batik/transcoder/image/ImageTranscoder.java
  
  Index: ImageTranscoder.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/transcoder/image/ImageTranscoder.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ImageTranscoder.java	2001/04/13 11:31:16	1.19
  +++ ImageTranscoder.java	2001/04/13 13:11:33	1.20
  @@ -22,6 +22,9 @@
   import java.awt.geom.Rectangle2D;
   import java.awt.image.BufferedImage;
   
  +import java.net.MalformedURLException;
  +import java.net.URL;
  +
   import org.apache.batik.bridge.BridgeContext;
   import org.apache.batik.bridge.BridgeException;
   import org.apache.batik.bridge.GVTBuilder;
  @@ -93,7 +96,7 @@
    * millimeter conversion factor.
    *
    * @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
  - * @version $Id: ImageTranscoder.java,v 1.19 2001/04/13 11:31:16 tkormann Exp $
  + * @version $Id: ImageTranscoder.java,v 1.20 2001/04/13 13:11:33 tkormann Exp $
    */
   public abstract class ImageTranscoder extends XMLAbstractTranscoder {
   
  @@ -114,12 +117,17 @@
   
       /**
        * Transcodes the specified Document as an image in the specified output.
  +     *
        * @param document the document to transcode
  +     * @param uri the uri of the document or null if any
        * @param output the ouput where to transcode
        * @exception TranscoderException if an error occured while transcoding
        */
  -    protected void transcode(Document document, TranscoderOutput output)
  +    protected void transcode(Document document,
  +                             String uri,
  +                             TranscoderOutput output)
               throws TranscoderException {
  +
           if (!(document instanceof SVGOMDocument)) {
               throw new TranscoderException(
                   Messages.formatMessage("notsvg", null));
  @@ -173,8 +181,20 @@
               height = docHeight;
           }
           // compute the preserveAspectRatio matrix
  -        AffineTransform Px =
  -            ViewBox.getPreserveAspectRatioTransform(root, width, height);
  +        AffineTransform Px;
  +        String ref = null;
  +        try {
  +            ref = new URL(uri).getRef();
  +        } catch (MalformedURLException ex) {
  +            // nothing to do, catched previously
  +        }
  +
  +        try {
  +            Px = ViewBox.getViewTransform(ref, root, width, height);
  +        } catch (BridgeException ex) {
  +            throw new TranscoderException(ex);
  +        }
  +
           if (Px.isIdentity() && (width != docWidth || height != docHeight)) {
               // The document has no viewBox, we need to resize it by hand.
               // we want to keep the document size ratio
  @@ -234,7 +254,6 @@
   
               writeImage(dest, output);
           } catch (Exception ex) {
  -            ex.printStackTrace();
               throw new TranscoderException(ex);
           }
       }
  
  
  
  1.5       +8 -3      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PrintTranscoder.java	2001/03/28 06:51:25	1.4
  +++ PrintTranscoder.java	2001/04/13 13:11:34	1.5
  @@ -105,7 +105,7 @@
    * </ul>
    *
    * @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
  - * @version $Id: PrintTranscoder.java,v 1.4 2001/03/28 06:51:25 tkormann Exp $
  + * @version $Id: PrintTranscoder.java,v 1.5 2001/04/13 13:11:34 tkormann Exp $
    */
   public class PrintTranscoder extends XMLAbstractTranscoder
       implements Printable {
  @@ -201,7 +201,7 @@
       }
   
       public void transcode(TranscoderInput in,
  -                           TranscoderOutput out){
  +                          TranscoderOutput out){
           if(in != null){
               inputs.addElement(in);
           }
  @@ -419,12 +419,17 @@
   
       /**
        * Transcodes the specified Document as an image in the specified output.
  +     *
        * @param document the document to transcode
  +     * @param uri the uri of the document or null if any
        * @param output the ouput where to transcode
        * @exception TranscoderException if an error occured while transcoding
        */
  -    protected void transcode(Document document, TranscoderOutput output)
  +    protected void transcode(Document document,
  +                             String uri,
  +                             TranscoderOutput output)
               throws TranscoderException {
  +
           // We can only handle SVG documents.
           if (!(document instanceof SVGOMDocument)) {
               // <!> TO BE FIXED WHEN WE DO ERROR HANDLING PROPERLY
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org