public Value computeValue(CSSStylableElement elt, CSSEngine engine, int idx, Value value) {
   IStyle cs = elt.getComputedStyle();
   CSSValue borderStyle = null;
   switch (idx) {
     case IStyle.STYLE_BORDER_TOP_WIDTH:
       borderStyle = cs.getProperty(IStyle.STYLE_BORDER_TOP_STYLE);
       break;
     case IStyle.STYLE_BORDER_BOTTOM_WIDTH:
       borderStyle = cs.getProperty(IStyle.STYLE_BORDER_BOTTOM_STYLE);
       break;
     case IStyle.STYLE_BORDER_LEFT_WIDTH:
       borderStyle = cs.getProperty(IStyle.STYLE_BORDER_LEFT_STYLE);
       break;
     case IStyle.STYLE_BORDER_RIGHT_WIDTH:
       borderStyle = cs.getProperty(IStyle.STYLE_BORDER_RIGHT_STYLE);
       break;
   }
   if (borderStyle == CSSValueConstants.NONE_VALUE
       || borderStyle == CSSValueConstants.HIDDEN_VALUE) {
     return CSSValueConstants.NUMBER_0;
   }
   if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
     if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
       String ident = value.getStringValue();
       Value cv = (Value) computedValues.get(ident);
       if (cv != null) {
         value = cv;
       }
     }
   }
   return super.computeValue(elt, engine, idx, value);
 }
Exemple #2
0
  /**
   * Implements {@link
   * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
   */
  public Value computeValue(CSSStylableElement elt, CSSEngine engine, int idx, Value value) {
    CSSContext ctx = engine.getCSSContext();

    float fs = ctx.getMediumFontSize();
    // absolute size
    if (value == CSSValueConstants.XX_SMALL_VALUE) {
      return new FloatValue(CSSPrimitiveValue.CSS_PT, fs / 1.2f / 1.2f / 1.2f);
    }
    if (value == CSSValueConstants.X_SMALL_VALUE) {
      return new FloatValue(CSSPrimitiveValue.CSS_PT, fs / 1.2f / 1.2f);
    }
    if (value == CSSValueConstants.SMALL_VALUE) {
      return new FloatValue(CSSPrimitiveValue.CSS_PT, fs / 1.2f);
    }
    if (value == CSSValueConstants.MEDIUM_VALUE) {
      return new FloatValue(CSSPrimitiveValue.CSS_PT, fs);
    }
    if (value == CSSValueConstants.LARGE_VALUE) {
      return new FloatValue(CSSPrimitiveValue.CSS_PT, fs * 1.2f);
    }
    if (value == CSSValueConstants.X_LARGE_VALUE) {
      return new FloatValue(CSSPrimitiveValue.CSS_PT, fs * 1.2f * 1.2f);
    }
    if (value == CSSValueConstants.XX_LARGE_VALUE) {
      return new FloatValue(CSSPrimitiveValue.CSS_PT, fs * 1.2f * 1.2f * 1.2f);
    }

    float scale = 1.0f;
    boolean doParentRelative = false;

    // relative size
    if (value == CSSValueConstants.SMALLER_VALUE) {
      doParentRelative = true;
      scale = 1.0f / 1.2f;
    } else if (value == CSSValueConstants.LARGER_VALUE) {
      doParentRelative = true;
      scale = 1.2f;
    } else if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
      // relative length && percentage
      switch (value.getPrimitiveType()) {
        case CSSPrimitiveValue.CSS_EMS:
          doParentRelative = true;
          scale = value.getFloatValue();
          break;
        case CSSPrimitiveValue.CSS_EXS:
          doParentRelative = true;
          scale = value.getFloatValue() * 0.5f;
          break;
        case CSSPrimitiveValue.CSS_PERCENTAGE:
          doParentRelative = true;
          scale = value.getFloatValue() * 0.01f;
          break;
      }
    }
    if (doParentRelative) {
      CSSStylableElement parent = (CSSStylableElement) elt.getParent();
      if (parent != null) {
        IStyle style = parent.getComputedStyle();
        if (style != null) {
          Value fontSize = (Value) style.getProperty(IStyle.STYLE_FONT_SIZE);
          if (fontSize != null) {
            fs = fontSize.getFloatValue();
            return new FloatValue(fontSize.getPrimitiveType(), fs * scale);
          }
        }
      }
      return new FloatValue(CSSPrimitiveValue.CSS_PT, fs * scale);
    }

    if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_NUMBER) {
      return super.computeValue(
          elt, engine, idx, new FloatValue(CSSPrimitiveValue.CSS_PT, value.getFloatValue()));
    }
    return super.computeValue(elt, engine, idx, value);
  }