Bladeren bron

FOP-2217; Image scaling change was adversely affecting other image types

Submitted by Robert Meyer (rmeyer.at.hotmail.co.uk)

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1452859 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-2_0
Chris Bowditch 11 jaren geleden
bovenliggende
commit
0b97b8f60a

BIN
lib/xmlgraphics-commons-svn-trunk.jar Bestand weergeven


+ 2
- 1
src/java/org/apache/fop/fo/extensions/svg/SVGElement.java Bestand weergeven

@@ -145,7 +145,8 @@ public class SVGElement extends SVGObj {
Point2D p2d = getSize(fontSize, svgRoot, getUserAgent().getSourcePixelUnitToMillimeter());
e.setSVGContext(null);

return p2d;
double pixelToPoint = 72d / getUserAgent().getSourceResolution();
return new Point2D.Double(p2d.getX() * pixelToPoint, p2d.getY() * pixelToPoint);
}

/**

+ 10
- 57
src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java Bestand weergeven

@@ -25,14 +25,10 @@ import java.awt.Rectangle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.apache.xmlgraphics.util.UnitConv;

import org.apache.fop.datatypes.Length;
import org.apache.fop.datatypes.PercentBaseContext;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.GraphicsProperties;
import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.fo.flow.AbstractGraphics;
import org.apache.fop.fo.properties.LengthRangeProperty;

/**
@@ -102,9 +98,9 @@ public class ImageLayout implements Constants {
boolean constrainIntrinsicSize = false;
int cwidth = -1;
int cheight = -1;
Length lenWidth = props.getContentWidth();
if (lenWidth.getEnum() != EN_AUTO) {
switch (lenWidth.getEnum()) {
len = props.getContentWidth();
if (len.getEnum() != EN_AUTO) {
switch (len.getEnum()) {
case EN_SCALE_TO_FIT:
if (ipd != -1) {
cwidth = ipd;
@@ -124,12 +120,12 @@ public class ImageLayout implements Constants {
constrainIntrinsicSize = true;
break;
default:
cwidth = lenWidth.getValue(percentBaseContext);
cwidth = len.getValue(percentBaseContext);
}
}
Length lenHeight = props.getContentHeight();
if (lenHeight.getEnum() != EN_AUTO) {
switch (lenHeight.getEnum()) {
len = props.getContentHeight();
if (len.getEnum() != EN_AUTO) {
switch (len.getEnum()) {
case EN_SCALE_TO_FIT:
if (bpd != -1) {
cheight = bpd;
@@ -149,21 +145,10 @@ public class ImageLayout implements Constants {
constrainIntrinsicSize = true;
break;
default:
cheight = lenHeight.getValue(percentBaseContext);
cheight = len.getValue(percentBaseContext);
}
}

//If no content-width or height is specified, adjust dimensions based upon the source resolution
int sourceResolution = 72;
if (props instanceof AbstractGraphics) {
sourceResolution = (int) ((AbstractGraphics)props).getUserAgent().getSourceResolution();
}
boolean foundNonAuto = (lenWidth.getEnum() != EN_AUTO || lenHeight.getEnum() != EN_AUTO);
if (!foundNonAuto) {
cwidth = (int)(intrinsicSize.width / ((float)sourceResolution / (float)UnitConv.IN2PT));
cheight = (int)(intrinsicSize.height / ((float)sourceResolution / (float)UnitConv.IN2PT));
}

Dimension constrainedIntrinsicSize;
if (constrainIntrinsicSize) {
constrainedIntrinsicSize = constrain(intrinsicSize);
@@ -179,13 +164,11 @@ public class ImageLayout implements Constants {
//Adjust viewport if not explicit
if (ipd == -1) {
ipd = constrainExtent(cwidth,
props.getInlineProgressionDimension(), (foundNonAuto)
? props.getContentWidth() : new DefaultLength());
props.getInlineProgressionDimension(), props.getContentWidth());
}
if (bpd == -1) {
bpd = constrainExtent(cheight,
props.getBlockProgressionDimension(), (foundNonAuto)
? props.getContentHeight() : new DefaultLength());
props.getBlockProgressionDimension(), props.getContentHeight());
}

this.clip = false;
@@ -208,36 +191,6 @@ public class ImageLayout implements Constants {
this.placement = new Rectangle(xoffset, yoffset, cwidth, cheight);
}

private static class DefaultLength implements Length {
public double getNumericValue() throws PropertyException {
return 0;
}

public double getNumericValue(PercentBaseContext context) throws PropertyException {
return 0;
}

public int getDimension() {
return 0;
}

public boolean isAbsolute() {
return false;
}

public int getEnum() {
return 0;
}

public int getValue() {
return 0;
}

public int getValue(PercentBaseContext context) {
return 0;
}
}

private int constrainExtent(int extent, LengthRangeProperty range, Length contextExtent) {
boolean mayScaleUp = (contextExtent.getEnum() != EN_SCALE_DOWN_TO_FIT);
boolean mayScaleDown = (contextExtent.getEnum() != EN_SCALE_UP_TO_FIT);

+ 3
- 0
status.xml Bestand weergeven

@@ -59,6 +59,9 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
<release version="FOP Trunk" date="TBD">
<action context="Layout" dev="CB" type="fix" fixes-bug="FOP-2217" due-to="Robert Meyer">
Image scaling change was adversely affecting other image types
</action>
<action context="Renderers" dev="CB" type="fix" fixes-bug="FOP-2214" due-to="Simon Steiner">
Thin dashed border look like dots
</action>

+ 0
- 81
test/java/org/apache/fop/layoutmgr/inline/ImageLayoutTestCase.java Bestand weergeven

@@ -1,81 +0,0 @@
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);
}
}

Laden…
Annuleren
Opslaan