From 54aba1a30fe6d7bf18edd7d6be0ae05221a87769 Mon Sep 17 00:00:00 2001 From: eschaeffer Date: Mon, 20 Nov 2000 16:36:42 +0000 Subject: [PATCH] Check if the image can fit in the area, and scale it if needed. 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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/org/apache/fop/fo/flow/ExternalGraphic.java b/src/org/apache/fop/fo/flow/ExternalGraphic.java index 53e28aa74..a6d2bcee9 100644 --- a/src/org/apache/fop/fo/flow/ExternalGraphic.java +++ b/src/org/apache/fop/fo/flow/ExternalGraphic.java @@ -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); } -- 2.39.5