nsIStyleContext* aStyleContext,
nsStyleContext* aStyleContext,
nscoord CalcLength(const nsCSSValue& aValue,                   const nsFont* aFont,                    nsIStyleContext* aStyleContext,                   nsIPresContext* aPresContext,                   PRBool& aInherited){  NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");  if (aValue.IsFixedLengthUnit()) {    return aValue.GetLengthTwips();  }  nsCSSUnit unit = aValue.GetUnit();  switch (unit) {    case eCSSUnit_EM:    case eCSSUnit_Char: {      aInherited = PR_TRUE;      const nsFont* font = aStyleContext ? &(((nsStyleFont*)aStyleContext->GetStyleData(eStyleStruct_Font))->mFont) : aFont;      return NSToCoordRound(aValue.GetFloatValue() * (float)font->size);      // XXX scale against font metrics height instead?    }    case eCSSUnit_EN: {      aInherited = PR_TRUE;      const nsFont* font = aStyleContext ? &(((nsStyleFont*)aStyleContext->GetStyleData(eStyleStruct_Font))->mFont) : aFont;      return NSToCoordRound((aValue.GetFloatValue() * (float)font->size) / 2.0f);    }    case eCSSUnit_XHeight: {      aInherited = PR_TRUE;      const nsFont* font = aStyleContext ? &(((nsStyleFont*)aStyleContext->GetStyleData(eStyleStruct_Font))->mFont) : aFont;      nsCOMPtr<nsIFontMetrics> fm;      aPresContext->GetMetricsFor(*font, getter_AddRefs(fm));      nscoord xHeight;      fm->GetXHeight(xHeight);      return NSToCoordRound(aValue.GetFloatValue() * (float)xHeight);    }    case eCSSUnit_CapHeight: {      NS_NOTYETIMPLEMENTED("cap height unit");      aInherited = PR_TRUE;      const nsFont* font = aStyleContext ? &(((nsStyleFont*)aStyleContext->GetStyleData(eStyleStruct_Font))->mFont) : aFont;      nscoord capHeight = ((font->size / 3) * 2); // XXX HACK!      return NSToCoordRound(aValue.GetFloatValue() * (float)capHeight);    }    case eCSSUnit_Pixel:      float p2t;      aPresContext->GetScaledPixelsToTwips(&p2t);      return NSFloatPixelsToTwips(aValue.GetFloatValue(), p2t);    default:      NS_NOTREACHED("unexpected unit");      break;  }  return 0;}