package org.apache.fop.datatypes;
-import org.apache.fop.fo.expr.PropertyException;
-
/**
* An interface for classes that can participate in numeric operations.
* All the numeric operation (+, -, *, ...) are expressed in terms of
* @return the computed value.
* @throws PropertyException if a property exception occurs
*/
- double getNumericValue() throws PropertyException;
+ double getNumericValue();
/**
* Return the value of this Numeric
* @return the computed value.
* @throws PropertyException if a property exception occurs
*/
- double getNumericValue(PercentBaseContext context) throws PropertyException;
+ double getNumericValue(PercentBaseContext context);
/**
* Return the dimension of this numeric. Plain numbers has a dimension of
* Return the resolved (calculated) value of the expression.
* {@inheritDoc}
*/
- public double getNumericValue() throws PropertyException {
- return getResolved(null).getNumericValue(null);
+ public double getNumericValue() {
+ try {
+ return getResolved(null).getNumericValue(null);
+ } catch (PropertyException pe) {
+ throw new RuntimeException(pe);
+ }
}
/**
* {@inheritDoc}
*/
- public double getNumericValue(PercentBaseContext context) throws PropertyException {
- return getResolved(context).getNumericValue(context);
+ public double getNumericValue(PercentBaseContext context) {
+ try {
+ return getResolved(context).getNumericValue(context);
+ } catch (PropertyException pe) {
+ throw new RuntimeException(pe);
+ }
}
/**
* {@inheritDoc}
*/
public int getValue() {
- try {
- return (int) getNumericValue();
- } catch (PropertyException exc) {
- log.error(exc);
- }
- return 0;
+ return (int) getNumericValue();
}
/**
* {@inheritDoc}
*/
public int getValue(PercentBaseContext context) {
- try {
- return (int) getNumericValue(context);
- } catch (PropertyException exc) {
- log.error(exc);
- }
- return 0;
+ return (int) getNumericValue(context);
}
/**
import org.apache.fop.datatypes.Numeric;
import org.apache.fop.datatypes.PercentBaseContext;
-import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.util.CompareUtil;
/**
* {@inheritDoc}
* logs an error, because it's not supposed to be called
*/
- public double getNumericValue(PercentBaseContext context) throws PropertyException {
+ public double getNumericValue(PercentBaseContext context) {
log.error("getNumericValue() called on " + enumProperty + " number");
return 0;
}
len = props.getBlockProgressionDimension().getOptimum(percentBaseContext).getLength();
if (len.getEnum() != EN_AUTO) {
- bpd = len.getValue(percentBaseContext);
+ bpd = evaluateLength(len, intrinsicSize.height);
}
len = props.getBlockProgressionDimension().getMinimum(percentBaseContext).getLength();
if (bpd == -1 && len.getEnum() != EN_AUTO) {
- //Establish minimum viewport size
- bpd = len.getValue(percentBaseContext);
+ bpd = evaluateLength(len, intrinsicSize.height);
}
len = props.getInlineProgressionDimension().getOptimum(percentBaseContext).getLength();
Length len;
len = range.getMaximum(percentBaseContext).getLength();
if (len.getEnum() != EN_AUTO) {
- int max = len.getValue(percentBaseContext);
+ int max = evaluateLength(len);
if (max != -1 && mayScaleDown) {
extent = Math.min(extent, max);
}
}
len = range.getMinimum(percentBaseContext).getLength();
if (len.getEnum() != EN_AUTO) {
- int min = len.getValue(percentBaseContext);
+ int min = evaluateLength(len);
if (min != -1 && mayScaleUp) {
extent = Math.max(extent, min);
}
return this.clip;
}
+ private int evaluateLength(Length length, int referenceValue) {
+ double numericValue = length.getNumericValue(percentBaseContext);
+ int bpd = numericValue < 0 ? referenceValue : (int) Math.round(numericValue);
+ return bpd;
+ }
+
+ private int evaluateLength(Length length) {
+ return evaluateLength(length, -1);
+ }
}
--- /dev/null
+<?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 relative height
+ </p>
+ </info>
+ <variables>
+ <img>../resources/images/bgimg300dpi.jpg</img>
+ </variables>
+ <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>plain external-graphic</fo:block>
+ <fo:block>
+ <fo:external-graphic src="##img" height="50%" content-height="scale-to-fit" />EOG
+ </fo:block>
+ <fo:block>EOF</fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+ </fo:root>
+ </fo>
+ <checks>
+ <eval expected="360000" xpath="//flow/block[2]/@ipd"/>
+ <eval expected="46080" xpath="//flow/block[2]/lineArea/viewport/@ipd"/>
+ <eval expected="46080" xpath="//flow/block[2]/lineArea/viewport/@ipda"/>
+ <eval expected="46080" xpath="//flow/block[2]/lineArea/viewport/@bpd"/>
+ <eval expected="46080" xpath="//flow/block[2]/lineArea/viewport/@bpda"/>
+ </checks>
+</testcase>