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 CSSTypedValue evaluateFunction(CSSFunctionValue function) throws DOMException
      Evaluate the given 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 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.
    • evaluateExpression

      public TypedValue evaluateExpression(ExpressionValue 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 TypedValue 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 TypedValue absoluteTypedValue(TypedValue 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.