jeremias    2005/01/20 06:08:20

  Modified:    src/java/org/apache/fop/fo/flow ExternalGraphic.java
               src/java/org/apache/fop/image FopImage.java
                        AbstractFopImage.java
               src/java/org/apache/fop/image/analyser JPEGReader.java
               src/java/org/apache/fop/render/pdf PDFRenderer.java
  Log:
  Clipping the background image.
  Added support for fetching bitmap resolution (only implemented for 
JFIF-compliant JPEG files for now, all other remain at 72dpi as before)
  
  Revision  Changes    Path
  1.52      +2 -2      
xml-fop/src/java/org/apache/fop/fo/flow/ExternalGraphic.java
  
  Index: ExternalGraphic.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/ExternalGraphic.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- ExternalGraphic.java      3 Jan 2005 13:06:27 -0000       1.51
  +++ ExternalGraphic.java      20 Jan 2005 14:08:20 -0000      1.52
  @@ -306,7 +306,7 @@
       public int getIntrinsicWidth() {
           prepareIntrinsicSize();
           if (fopimage != null) {
  -            return fopimage.getWidth() * 1000;
  +            return fopimage.getIntrinsicWidth();
           } else {
               return 0;
           }
  @@ -318,7 +318,7 @@
       public int getIntrinsicHeight() {
           prepareIntrinsicSize();
           if (fopimage != null) {
  -            return fopimage.getHeight() * 1000;
  +            return fopimage.getIntrinsicHeight();
           } else {
               return 0;
           }
  
  
  
  1.11      +23 -1     xml-fop/src/java/org/apache/fop/image/FopImage.java
  
  Index: FopImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/image/FopImage.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FopImage.java     16 Aug 2004 19:27:56 -0000      1.10
  +++ FopImage.java     20 Jan 2005 14:08:20 -0000      1.11
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 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.
  @@ -74,6 +74,26 @@
        * @return the height in pixels
        */
       int getHeight();
  +    
  +    /** 
  +     * @return the intrinsic image width (in millipoints) 
  +     */
  +    int getIntrinsicWidth();
  +
  +    /**
  +     *  @return the intrinsic image width (in millipoints) 
  +     */
  +    int getIntrinsicHeight();
  +
  +    /**
  +     * @return the horizontal bitmap resolution (in dpi)
  +     */
  +    double getHorizontalResolution();
  +    
  +    /**
  +     * @return the vertical bitmap resolution (in dpi)
  +     */
  +    double getVerticalResolution();
   
       /**
        * Returns the color space of the image.
  @@ -151,6 +171,8 @@
           public InputStream inputStream;
           public int width;
           public int height;
  +        public double dpiHorizontal = 72.0f;
  +        public double dpiVertical = 72.0f;
           public Object data;
           public String mimeType;
           public String str;
  
  
  
  1.8       +32 -6     
xml-fop/src/java/org/apache/fop/image/AbstractFopImage.java
  
  Index: AbstractFopImage.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/image/AbstractFopImage.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractFopImage.java     12 May 2004 23:19:52 -0000      1.7
  +++ AbstractFopImage.java     20 Jan 2005 14:08:20 -0000      1.8
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 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.
  @@ -55,6 +55,12 @@
        * Image height (in pixel).
        */
       protected int height = 0;
  +    
  +    /** Horizontal bitmap resolution (in dpi) */
  +    protected double dpiHorizontal = 72.0f;
  +
  +    /** Vertical bitmap resolution (in dpi) */
  +    protected double dpiVertical = 72.0f;
   
       /**
        * Image input stream.
  @@ -112,6 +118,8 @@
           if (this.imageInfo.width != -1) {
               width = imageInfo.width;
               height = imageInfo.height;
  +            dpiHorizontal = imageInfo.dpiHorizontal;
  +            dpiVertical = imageInfo.dpiVertical;
               loaded = loaded | DIMENSIONS;
           }
       }
  @@ -197,21 +205,39 @@
       }
   
       /**
  -     * Return the image width.
  -     * @return the image width
  +     * @return the image width (in pixels)
        */
       public int getWidth() {
           return this.width;
       }
  -
  +    
       /**
  -     * Return the image height.
  -     * @return the image height
  +     * @return the image height (in pixels)
        */
       public int getHeight() {
           return this.height;
       }
   
  +    /** @see org.apache.fop.image.FopImage#getIntrinsicWidth() */
  +    public int getIntrinsicWidth() {
  +        return (int)(getWidth() * 72000 / getHorizontalResolution());
  +    }
  +
  +    /** @see org.apache.fop.image.FopImage#getIntrinsicHeight() */
  +    public int getIntrinsicHeight() {
  +        return (int)(getHeight() * 72000 / getVerticalResolution());
  +    }
  +
  +    /** @see org.apache.fop.image.FopImage#getHorizontalResolution() */
  +    public double getHorizontalResolution() {
  +        return this.dpiHorizontal;
  +    }
  +    
  +    /** @see org.apache.fop.image.FopImage#getVerticalResolution() */
  +    public double getVerticalResolution() {
  +        return this.dpiVertical;
  +    }
  +    
       /**
        * Return the image color space.
        * @return the image color space (java.awt.color.ColorSpace)
  
  
  
  1.5       +50 -3     
xml-fop/src/java/org/apache/fop/image/analyser/JPEGReader.java
  
  Index: JPEGReader.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/image/analyser/JPEGReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JPEGReader.java   16 Aug 2004 19:33:19 -0000      1.4
  +++ JPEGReader.java   20 Jan 2005 14:08:20 -0000      1.5
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 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.
  @@ -111,8 +111,8 @@
                           imageStream.mark(avail);
                           pos = (int)this.skip(imageStream, pos);
                           avail -= pos;
  -                }
  -
  +                    }
  +                    //Marker first byte (FF)
                       marker = imageStream.read();
                       pos++; avail--;
                   } while (marker != MARK);
  @@ -125,6 +125,7 @@
                           pos = (int)this.skip(imageStream, pos);
                           avail -= pos;
                       }
  +                    //Marker second byte
                       marker = imageStream.read();
                       pos++; avail--;
                   } while (marker == MARK);
  @@ -133,6 +134,52 @@
                       case SOI:
                           break;
                       case NULL:
  +                        break;
  +                    case APP0:
  +                        if (avail < 14) {
  +                            imageStream.reset();
  +                            avail = 2 * pos;
  +                            imageStream.mark(avail);
  +                            pos = (int)this.skip(imageStream, pos);
  +                            avail -= pos;
  +                        }
  +                        int reclen = this.read2bytes(imageStream);
  +                        pos += 2; avail -= 2;
  +                        this.skip(imageStream, 7);
  +                        pos += 7; avail -= 7;
  +                        int densityUnits = imageStream.read();
  +                        pos++; avail--;
  +                        int xdensity = this.read2bytes(imageStream);
  +                        pos += 2; avail -= 2;
  +                        int ydensity = this.read2bytes(imageStream);
  +                        pos += 2; avail -= 2;
  +                        
  +                        if (densityUnits == 2) {
  +                            info.dpiHorizontal = xdensity * 28.3464567 / 72; 
//dpi
  +                            info.dpiVertical = ydensity * 28.3464567 / 72; 
//dpi
  +                        } else if (densityUnits == 1) {
  +                            info.dpiHorizontal = xdensity;
  +                            info.dpiVertical = ydensity;
  +                        } else {
  +                            //nop, nyi --> 72dpi
  +                        }
  +                        
  +                        int restlen = reclen - 12;
  +                        if (avail < restlen) {
  +                            imageStream.reset();
  +                            avail = 2 * pos;
  +                            if (avail < pos + restlen + 10) {
  +                                avail = (int)(pos + restlen + 10);
  +                            }
  +                            imageStream.mark(avail);
  +                            pos = (int)this.skip(imageStream, pos);
  +                            avail -= pos;
  +                        }
  +                        skipped = this.skip(imageStream, restlen - 2);
  +                        pos += skipped; avail -= skipped;
  +                        if (skipped != restlen - 2) {
  +                            throw new IOException("Skipping Error");
  +                        }
                           break;
                       case SOF1:
                       case SOF2:
  
  
  
  1.72      +7 -2      
xml-fop/src/java/org/apache/fop/render/pdf/PDFRenderer.java
  
  Index: PDFRenderer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/render/pdf/PDFRenderer.java,v
  retrieving revision 1.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- PDFRenderer.java  19 Jan 2005 21:48:12 -0000      1.71
  +++ PDFRenderer.java  20 Jan 2005 14:08:20 -0000      1.72
  @@ -582,6 +582,8 @@
                   ImageFactory fact = ImageFactory.getInstance();
                   FopImage fopimage = fact.getImage(back.getURL(), userAgent);
                   if (fopimage != null && fopimage.load(FopImage.DIMENSIONS)) {
  +                    saveGraphicsState();
  +                    clip(startx, starty, width, height);
                       if (back.getRepeat() == EN_REPEAT) {
                           // create a pattern for the image
                       } else {
  @@ -589,10 +591,13 @@
                           Rectangle2D pos;
                           pos = new Rectangle2D.Float((startx + 
back.getHoriz()) * 1000,
                                                       (starty + 
back.getVertical()) * 1000,
  -                                                    fopimage.getWidth() * 
1000,
  -                                                    fopimage.getHeight() * 
1000);
  +                                                    
fopimage.getIntrinsicWidth(),
  +                                                    
fopimage.getIntrinsicHeight());
                           putImage(back.getURL(), pos);
                       }
  +                    restoreGraphicsState();
  +                } else {
  +                    getLogger().warn("Can't find background image: " + 
back.getURL());
                   }
               }
           }
  
  
  

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

Reply via email to