Author: jeremias
Date: Tue Jan 8 07:48:53 2008
New Revision: 610029
URL: http://svn.apache.org/viewvc?rev=610029&view=rev
Log:
Added minimal support for the .minimum/.maximum components of
block/inline-progression-dimension on fo:external-graphic and
fo:instream-foreign-object. This will only constrain the image itself but not
allow the layout engine itself to resize the image as seen fit.
Added missing Javadocs in ImageLayout.java.
Added:
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/layoutengine/standard-testcases/external-graphic_size_1.xml
(with props)
Modified:
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/status.xml
Modified:
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java?rev=610029&r1=610028&r2=610029&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java
(original)
+++
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/src/java/org/apache/fop/layoutmgr/inline/ImageLayout.java
Tue Jan 8 07:48:53 2008
@@ -29,7 +29,11 @@
import org.apache.fop.datatypes.PercentBaseContext;
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.GraphicsProperties;
+import org.apache.fop.fo.properties.LengthRangeProperty;
+/**
+ * Helper class which calculates the size and position in the viewport of an
image.
+ */
public class ImageLayout implements Constants {
/** logging instance */
@@ -45,6 +49,12 @@
private Dimension viewportSize = new Dimension(-1, -1);
private boolean clip;
+ /**
+ * Main constructor
+ * @param props the properties for the image
+ * @param percentBaseContext the context object for percentage calculations
+ * @param intrinsicSize the image's intrinsic size
+ */
public ImageLayout(GraphicsProperties props, PercentBaseContext
percentBaseContext,
Dimension intrinsicSize) {
this.props = props;
@@ -54,6 +64,9 @@
doLayout();
}
+ /**
+ * Does the actual calculations for the image.
+ */
protected void doLayout() {
Length len;
@@ -63,25 +76,26 @@
len =
props.getBlockProgressionDimension().getOptimum(percentBaseContext).getLength();
if (len.getEnum() != EN_AUTO) {
bpd = len.getValue(percentBaseContext);
- } else {
- len = props.getHeight();
- if (len.getEnum() != EN_AUTO) {
- bpd = len.getValue(percentBaseContext);
- }
+ }
+ len =
props.getBlockProgressionDimension().getMinimum(percentBaseContext).getLength();
+ if (bpd == -1 && len.getEnum() != EN_AUTO) {
+ //Establish minimum viewport size
+ bpd = len.getValue(percentBaseContext);
}
len =
props.getInlineProgressionDimension().getOptimum(percentBaseContext).getLength();
if (len.getEnum() != EN_AUTO) {
ipd = len.getValue(percentBaseContext);
- } else {
- len = props.getWidth();
- if (len.getEnum() != EN_AUTO) {
- ipd = len.getValue(percentBaseContext);
- }
+ }
+ len =
props.getInlineProgressionDimension().getMinimum(percentBaseContext).getLength();
+ if (ipd == -1 && len.getEnum() != EN_AUTO) {
+ //Establish minimum viewport size
+ ipd = len.getValue(percentBaseContext);
}
// if auto then use the intrinsic size of the content scaled
// to the content-height and content-width
+ boolean constrainIntrinsicSize = false;
int cwidth = -1;
int cheight = -1;
len = props.getContentWidth();
@@ -91,16 +105,19 @@
if (ipd != -1) {
cwidth = ipd;
}
+ constrainIntrinsicSize = true;
break;
case EN_SCALE_DOWN_TO_FIT:
if (ipd != -1 && intrinsicSize.width > ipd) {
cwidth = ipd;
}
+ constrainIntrinsicSize = true;
break;
case EN_SCALE_UP_TO_FIT:
if (ipd != -1 && intrinsicSize.width < ipd) {
cwidth = ipd;
}
+ constrainIntrinsicSize = true;
break;
default:
cwidth = len.getValue(percentBaseContext);
@@ -113,64 +130,43 @@
if (bpd != -1) {
cheight = bpd;
}
+ constrainIntrinsicSize = true;
break;
case EN_SCALE_DOWN_TO_FIT:
if (bpd != -1 && intrinsicSize.height > bpd) {
cheight = bpd;
}
+ constrainIntrinsicSize = true;
break;
case EN_SCALE_UP_TO_FIT:
if (bpd != -1 && intrinsicSize.height < bpd) {
cheight = bpd;
}
+ constrainIntrinsicSize = true;
break;
default:
cheight = len.getValue(percentBaseContext);
}
}
- int scaling = props.getScaling();
- if ((scaling == EN_UNIFORM) || (cwidth == -1) || cheight == -1) {
- if (cwidth == -1 && cheight == -1) {
- cwidth = intrinsicSize.width;
- cheight = intrinsicSize.height;
- } else if (cwidth == -1) {
- if (intrinsicSize.height == 0) {
- cwidth = 0;
- } else {
- cwidth = (int)(intrinsicSize.width * (double)cheight
- / intrinsicSize.height);
- }
- } else if (cheight == -1) {
- if (intrinsicSize.width == 0) {
- cheight = 0;
- } else {
- cheight = (int)(intrinsicSize.height * (double)cwidth
- / intrinsicSize.width);
- }
- } else {
- // adjust the larger
- if (intrinsicSize.width == 0 || intrinsicSize.height == 0) {
- cwidth = 0;
- cheight = 0;
- } else {
- double rat1 = (double) cwidth / intrinsicSize.width;
- double rat2 = (double) cheight / intrinsicSize.height;
- if (rat1 < rat2) {
- // reduce cheight
- cheight = (int)(rat1 * intrinsicSize.height);
- } else if (rat1 > rat2) {
- cwidth = (int)(rat2 * intrinsicSize.width);
- }
- }
- }
+ Dimension constrainedIntrinsicSize;
+ if (constrainIntrinsicSize) {
+ constrainedIntrinsicSize = constrain(intrinsicSize);
+ } else {
+ constrainedIntrinsicSize = intrinsicSize;
}
+
+ //Derive content extents where not explicit
+ Dimension adjustedDim = adjustContentSize(cwidth, cheight,
constrainedIntrinsicSize);
+ cwidth = adjustedDim.width;
+ cheight = adjustedDim.height;
+ //Adjust viewport if not explicit
if (ipd == -1) {
- ipd = cwidth;
+ ipd = constrainExtent(cwidth,
props.getInlineProgressionDimension());
}
if (bpd == -1) {
- bpd = cheight;
+ bpd = constrainExtent(cheight,
props.getBlockProgressionDimension());
}
this.clip = false;
@@ -193,6 +189,90 @@
this.placement = new Rectangle(xoffset, yoffset, cwidth, cheight);
}
+ private int constrainExtent(int extent, LengthRangeProperty range) {
+ Length len;
+ len = range.getMaximum(percentBaseContext).getLength();
+ if (len.getEnum() != EN_AUTO) {
+ int max = len.getValue(percentBaseContext);
+ if (max != -1) {
+ extent = Math.min(extent, max);
+ }
+ }
+ len = range.getMinimum(percentBaseContext).getLength();
+ if (len.getEnum() != EN_AUTO) {
+ int min = len.getValue(percentBaseContext);
+ if (min != -1) {
+ extent = Math.max(extent, min);
+ }
+ }
+ return extent;
+ }
+
+ private Dimension constrain(Dimension size) {
+ Dimension adjusted = new Dimension(size);
+ int effWidth = constrainExtent(size.width,
props.getInlineProgressionDimension());
+ int effHeight = constrainExtent(size.height,
props.getBlockProgressionDimension());
+ int scaling = props.getScaling();
+ if (scaling == EN_UNIFORM) {
+ double rat1 = (double)effWidth / size.width;
+ double rat2 = (double)effHeight / size.height;
+ if (rat1 < rat2) {
+ adjusted.width = effWidth;
+ adjusted.height = (int)(rat1 * size.height);
+ } else if (rat1 > rat2) {
+ adjusted.width = (int)(rat2 * size.width);
+ adjusted.height = effHeight;
+ }
+ } else {
+ adjusted.width = effWidth;
+ adjusted.height = effHeight;
+ }
+ return adjusted;
+ }
+
+ private Dimension adjustContentSize(
+ final int cwidth, final int cheight,
+ Dimension defaultSize) {
+ Dimension dim = new Dimension(cwidth, cheight);
+ int scaling = props.getScaling();
+ if ((scaling == EN_UNIFORM) || (cwidth == -1) || cheight == -1) {
+ if (cwidth == -1 && cheight == -1) {
+ dim.width = defaultSize.width;
+ dim.height = defaultSize.height;
+ } else if (cwidth == -1) {
+ if (defaultSize.height == 0) {
+ dim.width = 0;
+ } else {
+ dim.width = (int)(defaultSize.width * (double)cheight
+ / defaultSize.height);
+ }
+ } else if (cheight == -1) {
+ if (defaultSize.width == 0) {
+ dim.height = 0;
+ } else {
+ dim.height = (int)(defaultSize.height * (double)cwidth
+ / defaultSize.width);
+ }
+ } else {
+ // adjust the larger
+ if (defaultSize.width == 0 || defaultSize.height == 0) {
+ dim.width = 0;
+ dim.height = 0;
+ } else {
+ double rat1 = (double)cwidth / defaultSize.width;
+ double rat2 = (double)cheight / defaultSize.height;
+ if (rat1 < rat2) {
+ // reduce height
+ dim.height = (int)(rat1 * defaultSize.height);
+ } else if (rat1 > rat2) {
+ dim.width = (int)(rat2 * defaultSize.width);
+ }
+ }
+ }
+ }
+ return dim;
+ }
+
/**
* Given the ipd and the content width calculates the
* required x offset based on the text-align property
@@ -243,18 +323,34 @@
return yoffset;
}
+ /**
+ * Returns the placement of the image inside the viewport.
+ * @return the placement of the image inside the viewport (coordinates in
millipoints)
+ */
public Rectangle getPlacement() {
return this.placement;
}
+ /**
+ * Returns the size of the image's viewport.
+ * @return the viewport size (in millipoints)
+ */
public Dimension getViewportSize() {
return this.viewportSize;
}
+ /**
+ * Returns the size of the image's intrinsic (natural) size.
+ * @return the intrinsic size (in millipoints)
+ */
public Dimension getIntrinsicSize() {
return this.intrinsicSize;
}
+ /**
+ * Indicates whether the image is clipped.
+ * @return true if the image shall be clipped
+ */
public boolean isClipped() {
return this.clip;
}
Modified: xmlgraphics/fop/branches/Temp_ImagePackageRedesign/status.xml
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/status.xml?rev=610029&r1=610028&r2=610029&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_ImagePackageRedesign/status.xml (original)
+++ xmlgraphics/fop/branches/Temp_ImagePackageRedesign/status.xml Tue Jan 8
07:48:53 2008
@@ -34,6 +34,10 @@
will make up an entire page. See the documentation for details.
</action>
<action context="Code" dev="JM" type="add">
+ Added minimal support for the .minimum/.maximum components of
block/inline-progression-dimension
+ on fo:external-graphic and fo:instream-foreign-object.
+ </action>
+ <action context="Code" dev="JM" type="add">
Added support for scale-down-to-fit and scale-up-to-fit (introduced in
XSL 1.1).
</action>
<action context="Code" dev="VH" type="fix" fixes-bug="43633">
Added:
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/layoutengine/standard-testcases/external-graphic_size_1.xml
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/layoutengine/standard-testcases/external-graphic_size_1.xml?rev=610029&view=auto
==============================================================================
---
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/layoutengine/standard-testcases/external-graphic_size_1.xml
(added)
+++
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/layoutengine/standard-testcases/external-graphic_size_1.xml
Tue Jan 8 07:48:53 2008
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- $Id$ -->
+<testcase>
+ <info>
+ <p>
+ This test checks external-graphics with size properties.
+ </p>
+ </info>
+ <fo>
+ <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="normal" page-width="5in"
page-height="5in">
+ <fo:region-body/>
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+ <fo:page-sequence master-reference="normal">
+ <fo:flow flow-name="xsl-region-body">
+ <fo:block>
+ <fo:external-graphic src="../../resources/images/big-image.png"
+ block-progression-dimension.maximum="4in"
+ inline-progression-dimension.maximum="auto"
+ content-width="scale-down-to-fit"
content-height="scale-down-to-fit"
+ overflow="hidden" background-color="yellow" id="big1"/>
+ </fo:block>
+ <fo:block>
+ <fo:external-graphic src="../../resources/images/big-image.png"
+ block-progression-dimension.maximum="4in"
+ inline-progression-dimension.maximum="4in"
+ content-width="scale-down-to-fit"
content-height="scale-down-to-fit"
+ overflow="hidden" scaling="non-uniform"
background-color="yellow" id="big2"/>
+ </fo:block>
+ <fo:block>
+ <fo:external-graphic src="../../resources/images/big-image.png"
+ block-progression-dimension.maximum="4in"
+ inline-progression-dimension.maximum="4in"
+ overflow="hidden" background-color="yellow" id="big3"/>
+ </fo:block>
+ <fo:block>
+ <fo:external-graphic src="../../resources/images/box1.png"
+ inline-progression-dimension.minimum="1in"
+ content-width="scale-to-fit"
+ overflow="hidden" background-color="yellow" id="box1"/>
+ </fo:block>
+ <fo:block>
+ <fo:external-graphic src="../../resources/images/box1.png"
+ inline-progression-dimension.minimum="1in"
+ overflow="hidden" background-color="yellow" id="box2"/>
+ </fo:block>
+ <fo:block>
+ <fo:external-graphic src="../../resources/images/box1.png"
+ inline-progression-dimension.minimum="1in"
+ inline-progression-dimension.optimum="2in"
+ overflow="hidden" background-color="yellow" id="box3"/>
+ </fo:block>
+ <fo:block>
+ <fo:external-graphic src="../../resources/images/box1.png"
+ inline-progression-dimension.minimum="1in"
+ inline-progression-dimension.optimum="2in"
+ content-width="scale-up-to-fit"
+ overflow="hidden" background-color="yellow" id="box4"/>
+ </fo:block>
+ <fo:block>EOF</fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+ </fo:root>
+ </fo>
+ <checks>
+ <!-- uniform fitting down to the maximum viewport size -->
+ <eval expected="203795" xpath="//[EMAIL PROTECTED]'big1']/@ipd"/>
+ <eval expected="288000" xpath="//[EMAIL PROTECTED]'big1']/@bpd"/>
+ <eval expected="0 0 203795 288000" xpath="//[EMAIL
PROTECTED]'big1']/@pos"/>
+
+ <!-- non-uniform fitting -->
+ <eval expected="288000" xpath="//[EMAIL PROTECTED]'big2']/@ipd"/>
+ <eval expected="288000" xpath="//[EMAIL PROTECTED]'big2']/@bpd"/>
+ <eval expected="0 0 288000 288000" xpath="//[EMAIL
PROTECTED]'big2']/@pos"/>
+
+ <!-- content is clipped -->
+ <eval expected="288000" xpath="//[EMAIL PROTECTED]'big3']/@ipd"/>
+ <eval expected="288000" xpath="//[EMAIL PROTECTED]'big3']/@bpd"/>
+ <eval expected="0 0 597172 843913" xpath="//[EMAIL
PROTECTED]'big3']/@pos"/>
+ <eval expected="true" xpath="//[EMAIL PROTECTED]'big3']/@clip"/>
+
+ <!-- uniform fitting up to the minimum viewport size -->
+ <eval expected="72000" xpath="//[EMAIL PROTECTED]'box1']/@ipd"/>
+ <eval expected="72000" xpath="//[EMAIL PROTECTED]'box1']/@bpd"/>
+ <eval expected="0 0 72000 72000" xpath="//[EMAIL PROTECTED]'box1']/@pos"/>
+
+ <!-- minimum viewport but not fitting -->
+ <eval expected="72000" xpath="//[EMAIL PROTECTED]'box2']/@ipd"/>
+ <eval expected="40009" xpath="//[EMAIL PROTECTED]'box2']/@bpd"/>
+ <eval expected="0 0 40009 40009" xpath="//[EMAIL PROTECTED]'box2']/@pos"/>
+
+ <!-- minimum/optimum viewport but not fitting -->
+ <eval expected="144000" xpath="//[EMAIL PROTECTED]'box3']/@ipd"/>
+ <eval expected="40009" xpath="//[EMAIL PROTECTED]'box3']/@bpd"/>
+ <eval expected="0 0 40009 40009" xpath="//[EMAIL PROTECTED]'box3']/@pos"/>
+
+ <!-- minimum/optimum viewport with fitting -->
+ <eval expected="144000" xpath="//[EMAIL PROTECTED]'box4']/@ipd"/>
+ <eval expected="144000" xpath="//[EMAIL PROTECTED]'box4']/@bpd"/>
+ <eval expected="0 0 144000 144000" xpath="//[EMAIL
PROTECTED]'box4']/@pos"/>
+
+ </checks>
+</testcase>
Propchange:
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/layoutengine/standard-testcases/external-graphic_size_1.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xmlgraphics/fop/branches/Temp_ImagePackageRedesign/test/layoutengine/standard-testcases/external-graphic_size_1.xml
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]