From 7ee30cf256088a4cc15e94915e84ba9b7fb8c790 Mon Sep 17 00:00:00 2001 From: "Andreas L. Delmelle" Date: Sun, 10 Feb 2008 12:31:46 +0000 Subject: [PATCH] Some minor tweaks: * added convenience shortcut to PropertyInfo to get to the user agent. * replaced occurrences to use the shortcut in PropertyParser and RGBColorFunction. * PropertyParser -> 0% of a length always yields FixedLength.ZERO_FIXED_LENGTH git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@620272 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/expr/PropertyInfo.java | 12 ++++++++++++ src/java/org/apache/fop/fo/expr/PropertyParser.java | 9 ++++++--- .../org/apache/fop/fo/expr/RGBColorFunction.java | 10 ++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/fop/fo/expr/PropertyInfo.java b/src/java/org/apache/fop/fo/expr/PropertyInfo.java index 491be64fc..039e8783e 100644 --- a/src/java/org/apache/fop/fo/expr/PropertyInfo.java +++ b/src/java/org/apache/fop/fo/expr/PropertyInfo.java @@ -21,6 +21,7 @@ package org.apache.fop.fo.expr; import java.util.Stack; +import org.apache.fop.apps.FOUserAgent; import org.apache.fop.datatypes.Length; import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.Constants; @@ -114,6 +115,17 @@ public class PropertyInfo { } } + /** + * Convenience shortcut to get a reference to the FOUserAgent + * + * @return the FOUserAgent + */ + protected FOUserAgent getUserAgent() { + return (plist.getFObj() != null) + ? plist.getFObj().getUserAgent() + : null; + } + private PercentBase getFunctionPercentBase() { if (stkFunction != null) { Function f = (Function)stkFunction.peek(); diff --git a/src/java/org/apache/fop/fo/expr/PropertyParser.java b/src/java/org/apache/fop/fo/expr/PropertyParser.java index cd3393ef3..c63142773 100644 --- a/src/java/org/apache/fop/fo/expr/PropertyParser.java +++ b/src/java/org/apache/fop/fo/expr/PropertyParser.java @@ -275,6 +275,11 @@ public final class PropertyParser extends PropertyTokenizer { prop = NumberProperty.getInstance(pcval * pcBase.getBaseValue()); } else if (pcBase.getDimension() == 1) { if (pcBase instanceof LengthBase) { + if (pcval == 0.0) { + prop = FixedLength.ZERO_FIXED_LENGTH; + break; + } + //If the base of the percentage is known //and absolute, it can be resolved by the //parser @@ -319,9 +324,7 @@ public final class PropertyParser extends PropertyTokenizer { break; case TOK_COLORSPEC: - prop = ColorProperty.getInstance( - propInfo.getPropertyList().getFObj().getUserAgent(), - currentTokenValue); + prop = ColorProperty.getInstance(propInfo.getUserAgent(), currentTokenValue); break; case TOK_FUNCTION_LPAR: diff --git a/src/java/org/apache/fop/fo/expr/RGBColorFunction.java b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java index 9b3287154..ba39662eb 100644 --- a/src/java/org/apache/fop/fo/expr/RGBColorFunction.java +++ b/src/java/org/apache/fop/fo/expr/RGBColorFunction.java @@ -19,7 +19,6 @@ package org.apache.fop.fo.expr; -import org.apache.fop.apps.FOUserAgent; import org.apache.fop.datatypes.PercentBaseContext; import org.apache.fop.datatypes.PercentBase; import org.apache.fop.fo.properties.ColorProperty; @@ -47,14 +46,13 @@ class RGBColorFunction extends FunctionBase { /** {@inheritDoc} */ public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { - FOUserAgent ua = (pInfo == null) - ? null - : (pInfo.getFO() == null ? null : pInfo.getFO().getUserAgent()); - return ColorProperty.getInstance(ua, "rgb(" + args[0] + "," + args[1] + "," + args[2] + ")"); + return ColorProperty.getInstance(pInfo.getUserAgent(), + "rgb(" + args[0] + "," + + args[1] + "," + args[2] + ")"); } - static class RGBPercentBase implements PercentBase { + private static class RGBPercentBase implements PercentBase { public int getDimension() { return 0; } -- 2.39.5