Class Evaluator

java.lang.Object
io.sf.carte.doc.style.css.property.Evaluator
Direct Known Subclasses:
PercentageEvaluator

public class Evaluator extends Object
Expression/Function evaluator.

Evaluates calc() expressions as well as functions like min(), clamp() or cos().

To support percentages within calc() expressions, it must be subclassed by something that supports a box model implementation, overriding the percentage(CSSTypedValue, short) method.

  • Constructor Details

    • Evaluator

      public Evaluator()
      Constructs an evaluator with a preferred unit of typographic points (pt).
    • Evaluator

      public Evaluator(short preferredUnit)
      Constructs an evaluator with the given preferred unit.
      Parameters:
      preferredUnit - the preferred unit according to CSSUnit.
  • Method Details

    • evaluateFunction

      public CSSNumberValue evaluateFunction(CSSMathFunctionValue function) throws DOMException
      Evaluate the given mathematical function.

      This method checks the result unit, assuming that the unit must match that of the returned primitive value (some functions may return values where the units are raised to a power greater than one, or lesser than zero).

      Parameters:
      function - the mathematical function to evaluate.
      Returns:
      the result of evaluating the function, or the function itself if this class does not know how to evaluate it.
      Throws:
      DOMException - if a problem was found evaluating the function, or the resulting unit is not a valid CSS unit.
    • createNumberValue

      protected CSSNumberValue createNumberValue(short unit, float valueInSpecifiedUnit, boolean calculated)
      Create a CSSNumberValue in the desired implementation.
      Parameters:
      unit - the unit.
      valueInSpecifiedUnit - the value in the given unit.
      calculated - whether the value was calculated. Implementations may ignore this parameter.
      Returns:
      the number value.
    • evaluateExpression

      public CSSTypedValue evaluateExpression(CSSExpressionValue calc) throws DOMException
      Evaluate the given expression.

      This method checks the result unit, assuming that the unit must match that of the returned primitive value (some functions may return values where the units are raised to a power greater than one, or lesser than zero).

      Parameters:
      calc - the expression value to evaluate.
      Returns:
      the result from evaluating the expression.
      Throws:
      DOMException - if a problem was found evaluating the expression.
    • absoluteValue

      protected CSSTypedValue absoluteValue(CSSPrimitiveValue partialValue) throws DOMException
      Obtain an absolute (numeric) value, starting from a primitive value.

      If the supplied value is already absolute, or it is not known how to express it in absolute units, return it.

      Parameters:
      partialValue - the value that has to be expressed in absolute units.
      Returns:
      the value in absolute units.
      Throws:
      DOMException
    • absoluteTypedValue

      protected CSSTypedValue absoluteTypedValue(CSSTypedValue partialValue)
    • absoluteProxyValue

      protected CSSValue absoluteProxyValue(CSSPrimitiveValue partialValue)
    • percentage

      protected float percentage(CSSTypedValue value, short resultType) throws DOMException
      Obtain the float value (in the requested absolute unit) corresponding to the given percentage value.
      Parameters:
      value - the percentage value.
      resultType - the desired absolute result type.
      Returns:
      the absolute float value in the requested unit.
      Throws:
      DOMException - if the percentage could not be converted to the requested unit.