xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lberna...@apache.org
Subject svn commit: r1448484 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java test/java/org/apache/fop/layoutmgr/inline/ test/java/org/apache/fop/layoutmgr/inline/ImageLayoutTestCase.java
Date Thu, 21 Feb 2013 01:10:36 GMT
Author: lbernardo
Date: Thu Feb 21 01:10:36 2013
New Revision: 1448484

URL: http://svn.apache.org/r1448484
Log:
FOP-2181: Add a test case for the recent fix made in FOP-2174 and XGC-76 regarding source
resolution scaling with SVG and images; patch submitted by Robert Meyer

Added:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/inline/
    xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/inline/ImageLayoutTestCase.java
  (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java?rev=1448484&r1=1448483&r2=1448484&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java Thu Feb
21 01:10:36 2013
@@ -160,8 +160,8 @@ public class ImageLayout implements Cons
         }
         boolean foundNonAuto = (lenWidth.getEnum() != EN_AUTO || lenHeight.getEnum() != EN_AUTO);
         if (!foundNonAuto) {
-            cwidth = intrinsicSize.width / (sourceResolution / UnitConv.IN2PT);
-            cheight = intrinsicSize.height / (sourceResolution / UnitConv.IN2PT);
+            cwidth = (int)(intrinsicSize.width / ((float)sourceResolution / (float)UnitConv.IN2PT));
+            cheight = (int)(intrinsicSize.height / ((float)sourceResolution / (float)UnitConv.IN2PT));
         }
 
         Dimension constrainedIntrinsicSize;

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/inline/ImageLayoutTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/inline/ImageLayoutTestCase.java?rev=1448484&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/inline/ImageLayoutTestCase.java
(added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/inline/ImageLayoutTestCase.java
Thu Feb 21 01:10:36 2013
@@ -0,0 +1,81 @@
+package org.apache.fop.layoutmgr.inline;
+
+import java.awt.Dimension;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.datatypes.Length;
+import org.apache.fop.fo.flow.AbstractGraphics;
+import org.apache.fop.fo.properties.EnumLength;
+import org.apache.fop.fo.properties.EnumProperty;
+import org.apache.fop.fo.properties.LengthRangeProperty;
+import org.apache.fop.fo.properties.Property;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ImageLayoutTestCase {
+
+    private AbstractGraphics gfxProps;
+
+    /**
+     * Initializes the resources needed to run the scaling unit test
+     */
+    @Before
+    public void setUp() {
+        gfxProps = mock(AbstractGraphics.class);
+
+        Property enumProp = EnumProperty.getInstance(9, "AUTO");
+        Length len = new EnumLength(enumProp);
+        len.getEnum();
+
+        LengthRangeProperty lenRangeProp = mock(LengthRangeProperty.class);
+        when(lenRangeProp.getMinimum(null)).thenReturn(enumProp);
+        when(lenRangeProp.getMaximum(null)).thenReturn(enumProp);
+        when(lenRangeProp.getOptimum(null)).thenReturn(enumProp);
+
+        when(gfxProps.getBlockProgressionDimension()).thenReturn(lenRangeProp);
+        when(gfxProps.getInlineProgressionDimension()).thenReturn(lenRangeProp);
+
+        //All values should be set to AUTO to test when no content-width or height has been
specified
+        when(gfxProps.getBlockProgressionDimension().getOptimum(null)).thenReturn(enumProp);
+        when(gfxProps.getBlockProgressionDimension().getOptimum(null).getLength()).thenReturn(len);
+        when(gfxProps.getBlockProgressionDimension().getMinimum(null)).thenReturn(enumProp);
+        when(gfxProps.getBlockProgressionDimension().getMinimum(null).getLength()).thenReturn(len);
+        when(gfxProps.getBlockProgressionDimension().getMaximum(null)).thenReturn(enumProp);
+        when(gfxProps.getBlockProgressionDimension().getMaximum(null).getLength()).thenReturn(len);
+        when(gfxProps.getInlineProgressionDimension().getOptimum(null)).thenReturn(enumProp);
+        when(gfxProps.getInlineProgressionDimension().getOptimum(null).getLength()).thenReturn(len);
+        when(gfxProps.getInlineProgressionDimension().getMinimum(null)).thenReturn(enumProp);
+        when(gfxProps.getInlineProgressionDimension().getMinimum(null).getLength()).thenReturn(len);
+        when(gfxProps.getInlineProgressionDimension().getMaximum(null)).thenReturn(enumProp);
+        when(gfxProps.getInlineProgressionDimension().getMaximum(null).getLength()).thenReturn(len);
+
+        when(gfxProps.getContentWidth()).thenReturn(len);
+        when(gfxProps.getContentHeight()).thenReturn(len);
+    }
+
+    /**
+     * Tests different levels of scaling to see if they match an expected result
+     */
+    @Test
+    public void testImageScaling() {
+        testScaling(114.0f, new Dimension(990000, 765000), 625263.0f, 483157.0f);
+        testScaling(96.0f, new Dimension(990000, 765000), 742500.0f, 573750.0f);
+        testScaling(72.0f, new Dimension(990000, 765000), 990000.0f, 765000.0f);
+    }
+
+    private void testScaling(float sourceResolution, Dimension intrinsicSize,
+            float targetWidth, float targetHeight) {
+        FOUserAgent userAgent = mock(FOUserAgent.class);
+        when(userAgent.getSourceResolution()).thenReturn(sourceResolution);
+        when(gfxProps.getUserAgent()).thenReturn(userAgent);
+
+        ImageLayout imgLayout = new ImageLayout(gfxProps, null, intrinsicSize);
+        assertEquals(imgLayout.getViewportSize().getWidth(), targetWidth, 0.0f);
+        assertEquals(imgLayout.getViewportSize().getHeight(), targetHeight, 0.0f);
+    }
+}

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutmgr/inline/ImageLayoutTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message