]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Check if the image can fit in the area, and scale it if needed.
authoreschaeffer <eschaeffer@unknown>
Mon, 20 Nov 2000 16:36:42 +0000 (16:36 +0000)
committereschaeffer <eschaeffer@unknown>
Mon, 20 Nov 2000 16:36:42 +0000 (16:36 +0000)
PR:
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193828 13f79535-47bb-0310-9956-ffa450edef68

src/org/apache/fop/fo/flow/ExternalGraphic.java

index 53e28aa74aa17c27bda5517743586ca1540d7bc4..a6d2bcee90d92f61669adbd5094375de53950efb 100644 (file)
@@ -181,6 +181,21 @@ public class ExternalGraphic extends FObj {
                 //MessageHandler.errorln("DisplayGraphic: imgW=" + imgWidth + " imgH=" + imgHeight + " w=" + width + " h=" + height);
             }
 
+            // scale image if it doesn't fit in the area/page
+            // Need to be more tested...
+            double ratio = ((double) width) / ((double) height);
+            int areaWidth = area.getAllocationWidth();
+            int areaHeight = area.getMaxHeight();
+            if ((width > areaWidth) || (height > areaHeight)) {
+                    if (width > height) {
+                            width = areaWidth;
+                            height = (int) (((double) width) / ratio);
+                    } else {
+                            height = areaHeight;
+                            width = (int) (ratio * ((double) width));
+                    }
+            }
+
             if (area.spaceLeft() < (height + spaceBefore)) {
                 return new Status(Status.AREA_FULL_NONE);
             }